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.
|
||||
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
|
||||
// passed. Available options are defined below this function.
|
||||
//
|
||||
|
@ -80,13 +80,13 @@ func Set(host string, options ...Option) error {
|
|||
Jar: jar,
|
||||
}
|
||||
|
||||
// Get the request body required for log in.
|
||||
// Get the request body required for log-in.
|
||||
body, err := getLogin(client, id, host)
|
||||
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)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not login: %v", err)
|
||||
|
|
|
@ -37,8 +37,8 @@ import (
|
|||
|
||||
// Relevant sub directories.
|
||||
const (
|
||||
loginSubDir = "/ssi.cgi/login.htm" // Used to get log in page.
|
||||
loggedInSubDir = "/LoginPC.cgi" // Used to submit log in.
|
||||
loginSubDir = "/ssi.cgi/login.htm" // Used to get log-in page.
|
||||
loggedInSubDir = "/LoginPC.cgi" // Used to submit log-in.
|
||||
settingsSubDir = "/VideoSetting.cgi" // Used to submit settings.
|
||||
)
|
||||
|
||||
|
@ -48,13 +48,13 @@ const (
|
|||
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.
|
||||
// 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) {
|
||||
req, err := http.NewRequest("GET", "https://"+host+loginSubDir, 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")
|
||||
|
@ -68,18 +68,18 @@ func getLogin(c *http.Client, id, host string) (string, error) {
|
|||
|
||||
resp, err := c.Do(req)
|
||||
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()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
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.
|
||||
// These are used in calculation of the md5 hashes for the form submitted at
|
||||
// log in.
|
||||
// log-in.
|
||||
var cc [2]string
|
||||
for i := range cc {
|
||||
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 {
|
||||
req, err := http.NewRequest("POST", "http://"+host+loggedInSubDir, bytes.NewBuffer([]byte(b)))
|
||||
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")
|
||||
|
@ -122,7 +122,7 @@ func login(c *http.Client, id, host, b string) error {
|
|||
|
||||
_, err = c.Do(req)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue