mirror of https://bitbucket.org/ausocean/av.git
input/gvctrl/request.go: added documentation to request.go
This commit is contained in:
parent
5b17613489
commit
c726571399
|
@ -35,11 +35,11 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Relevant sub directories.
|
||||||
const (
|
const (
|
||||||
baseURL = "http://192.168.1.50"
|
loginSubDir = "/ssi.cgi/login.htm" // Used to get log in page.
|
||||||
loginPageURL = baseURL + "/ssi.cgi/login.htm"
|
loggedInSubDir = "/LoginPC.cgi" // Used to submit log in.
|
||||||
loggedInURL = baseURL + "/LoginPC.cgi"
|
settingsSubDir = "/VideoSetting.cgi" // Used to submit settings.
|
||||||
settingsURL = baseURL + "/VideoSetting.cgi"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: make this configurable.
|
// TODO: make this configurable.
|
||||||
|
@ -48,8 +48,11 @@ const (
|
||||||
pass = "admin"
|
pass = "admin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// genLogIn 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 genLogIn(c *http.Client, id, host string) (string, error) {
|
func genLogIn(c *http.Client, id, host string) (string, error) {
|
||||||
req, err := http.NewRequest("GET", loginPageURL, 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)
|
||||||
}
|
}
|
||||||
|
@ -97,8 +100,9 @@ func genLogIn(c *http.Client, id, host string) (string, error) {
|
||||||
return f.Encode(), nil
|
return f.Encode(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// logIn will submit the form b generated by genLogIn.
|
||||||
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", loggedInURL, 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)
|
||||||
}
|
}
|
||||||
|
@ -106,12 +110,12 @@ func logIn(c *http.Client, id, host, b string) error {
|
||||||
req.Header.Set("Connection", "keep-alive")
|
req.Header.Set("Connection", "keep-alive")
|
||||||
req.Header.Set("Content-Length", "142")
|
req.Header.Set("Content-Length", "142")
|
||||||
req.Header.Set("Cache-Control", "max-age=0")
|
req.Header.Set("Cache-Control", "max-age=0")
|
||||||
req.Header.Set("Origin", "http://192.168.1.50")
|
req.Header.Set("Origin", "http://"+host)
|
||||||
req.Header.Set("Upgrade-Insecure-Requests", "1")
|
req.Header.Set("Upgrade-Insecure-Requests", "1")
|
||||||
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36")
|
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36")
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
|
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
|
||||||
req.Header.Set("Referer", "http://192.168.1.50/ssi.cgi/Login.htm")
|
req.Header.Set("Referer", "http://"+host+"/ssi.cgi/Login.htm")
|
||||||
req.Header.Set("Accept-Encoding", "gzip, deflate")
|
req.Header.Set("Accept-Encoding", "gzip, deflate")
|
||||||
req.Header.Set("Accept-Language", "en-GB,en-US;q=0.9,en;q=0.8")
|
req.Header.Set("Accept-Language", "en-GB,en-US;q=0.9,en;q=0.8")
|
||||||
req.Header.Set("Cookie", "CLIENT_ID="+id+"; CLIENT_ID="+id)
|
req.Header.Set("Cookie", "CLIENT_ID="+id+"; CLIENT_ID="+id)
|
||||||
|
@ -124,9 +128,11 @@ func logIn(c *http.Client, id, host, b string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// submitSettings will populate a url encoded form using s and submit the
|
||||||
|
// settings to the server.
|
||||||
func submitSettings(c *http.Client, id, host string, s settings) error {
|
func submitSettings(c *http.Client, id, host string, s settings) error {
|
||||||
fBytes := []byte(populateForm(s).Encode())
|
fBytes := []byte(populateForm(s).Encode())
|
||||||
req, err := http.NewRequest("POST", settingsURL, bytes.NewReader(fBytes))
|
req, err := http.NewRequest("POST", "http://"+host+settingsSubDir, bytes.NewReader(fBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not create settings submit request: %v", err)
|
return fmt.Errorf("could not create settings submit request: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -134,12 +140,12 @@ func submitSettings(c *http.Client, id, host string, s settings) error {
|
||||||
req.Header.Set("Connection", "keep-alive")
|
req.Header.Set("Connection", "keep-alive")
|
||||||
req.Header.Set("Content-Length", strconv.Itoa(len(fBytes)))
|
req.Header.Set("Content-Length", strconv.Itoa(len(fBytes)))
|
||||||
req.Header.Set("Cache-Control", "max-age=0")
|
req.Header.Set("Cache-Control", "max-age=0")
|
||||||
req.Header.Set("Origin", "http://192.168.1.50")
|
req.Header.Set("Origin", "http://"+host)
|
||||||
req.Header.Set("Upgrade-Insecure-Requests", "1")
|
req.Header.Set("Upgrade-Insecure-Requests", "1")
|
||||||
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36")
|
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36")
|
||||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
|
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
|
||||||
req.Header.Set("Referer", "http://192.168.1.50/ssi.cgi/VideoSettingSub.htm?cam=2")
|
req.Header.Set("Referer", "http://"+host+"/ssi.cgi/VideoSettingSub.htm?cam=2")
|
||||||
req.Header.Set("Accept-Encoding", "gzip, deflate")
|
req.Header.Set("Accept-Encoding", "gzip, deflate")
|
||||||
req.Header.Set("Accept-Language", "en-GB,en-US;q=0.9,en;q=0.8")
|
req.Header.Set("Accept-Language", "en-GB,en-US;q=0.9,en;q=0.8")
|
||||||
req.Header.Set("Cookie", "CLIENT_ID="+id)
|
req.Header.Set("Cookie", "CLIENT_ID="+id)
|
||||||
|
|
Loading…
Reference in New Issue