mirror of https://bitbucket.org/ausocean/av.git
input/gvctrl: using log-in rather than log in in comments
This commit is contained in:
parent
0111ba706d
commit
239db674a3
|
@ -46,7 +46,7 @@ import (
|
||||||
// Option describes a function that will apply an option to the passed s.
|
// Option describes a function that will apply an option to the passed s.
|
||||||
type Option func(s settings) (settings, error)
|
type Option func(s settings) (settings, error)
|
||||||
|
|
||||||
// Set will log in to the camera at host and submit a form of settings. The
|
// Set will log-in to the camera at host and submit a form of settings. The
|
||||||
// settings form is populated with values influenced by the optional options
|
// settings form is populated with values influenced by the optional options
|
||||||
// passed. Available options are defined below this function.
|
// passed. Available options are defined below this function.
|
||||||
//
|
//
|
||||||
|
@ -80,13 +80,13 @@ func Set(host string, options ...Option) error {
|
||||||
Jar: jar,
|
Jar: jar,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the request body required for log in.
|
// Get the request body required for log-in.
|
||||||
body, err := getLogin(client, id, host)
|
body, err := getLogin(client, id, host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not generate log in request data: %v", err)
|
return fmt.Errorf("could not generate log-in request data: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log in using generated log in request body.
|
// Log in using generated log-in request body.
|
||||||
err = login(client, id, host, body)
|
err = login(client, id, host, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not login: %v", err)
|
return fmt.Errorf("could not login: %v", err)
|
||||||
|
|
|
@ -37,8 +37,8 @@ import (
|
||||||
|
|
||||||
// Relevant sub directories.
|
// Relevant sub directories.
|
||||||
const (
|
const (
|
||||||
loginSubDir = "/ssi.cgi/login.htm" // Used to get log in page.
|
loginSubDir = "/ssi.cgi/login.htm" // Used to get log-in page.
|
||||||
loggedInSubDir = "/LoginPC.cgi" // Used to submit log in.
|
loggedInSubDir = "/LoginPC.cgi" // Used to submit log-in.
|
||||||
settingsSubDir = "/VideoSetting.cgi" // Used to submit settings.
|
settingsSubDir = "/VideoSetting.cgi" // Used to submit settings.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,13 +48,13 @@ const (
|
||||||
pass = "admin"
|
pass = "admin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getLogin gets the log in page and extracts the randomly generated cc values
|
// getLogin gets the log-in page and extracts the randomly generated cc values
|
||||||
// from which (as well as username and password) two hashes are generated.
|
// from which (as well as username and password) two hashes are generated.
|
||||||
// The generated hex is encoded into a url encoded form and returned as a string.
|
// The generated hex is encoded into a url encoded form and returned as a string.
|
||||||
func getLogin(c *http.Client, id, host string) (string, error) {
|
func getLogin(c *http.Client, id, host string) (string, error) {
|
||||||
req, err := http.NewRequest("GET", "https://"+host+loginSubDir, nil)
|
req, err := http.NewRequest("GET", "https://"+host+loginSubDir, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("can't create GET request for log in page: %v", err)
|
return "", fmt.Errorf("can't create GET request for log-in page: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Connection", "keep-alive")
|
req.Header.Set("Connection", "keep-alive")
|
||||||
|
@ -68,18 +68,18 @@ func getLogin(c *http.Client, id, host string) (string, error) {
|
||||||
|
|
||||||
resp, err := c.Do(req)
|
resp, err := c.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not do GET request for log in page: %v", err)
|
return "", fmt.Errorf("could not do GET request for log-in page: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not read response of GET request for log in page: %v", err)
|
return "", fmt.Errorf("could not read response of GET request for log-in page: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the CC values in the source of the response.
|
// Find the CC values in the source of the response.
|
||||||
// These are used in calculation of the md5 hashes for the form submitted at
|
// These are used in calculation of the md5 hashes for the form submitted at
|
||||||
// log in.
|
// log-in.
|
||||||
var cc [2]string
|
var cc [2]string
|
||||||
for i := range cc {
|
for i := range cc {
|
||||||
regStr := "cc" + strconv.Itoa(i+1) + "=\".{4}\""
|
regStr := "cc" + strconv.Itoa(i+1) + "=\".{4}\""
|
||||||
|
@ -104,7 +104,7 @@ func getLogin(c *http.Client, id, host string) (string, error) {
|
||||||
func login(c *http.Client, id, host, b string) error {
|
func login(c *http.Client, id, host, b string) error {
|
||||||
req, err := http.NewRequest("POST", "http://"+host+loggedInSubDir, bytes.NewBuffer([]byte(b)))
|
req, err := http.NewRequest("POST", "http://"+host+loggedInSubDir, bytes.NewBuffer([]byte(b)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create log in request: %v", err)
|
return fmt.Errorf("could not create log-in request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Connection", "keep-alive")
|
req.Header.Set("Connection", "keep-alive")
|
||||||
|
@ -122,7 +122,7 @@ func login(c *http.Client, id, host, b string) error {
|
||||||
|
|
||||||
_, err = c.Do(req)
|
_, err = c.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not do log in request: %v", err)
|
return fmt.Errorf("could not do log-in request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue