Add bypass login for TP-Link cameras

This commit is contained in:
Alexey Khit
2023-02-10 11:16:03 +03:00
parent f60b55b6fa
commit 80f77d28c8
2 changed files with 16 additions and 1 deletions

View File

@@ -220,12 +220,15 @@ func (c *Conn) Do(req *tcp.Request) (*tcp.Response, error) {
if res.StatusCode == http.StatusUnauthorized {
switch c.auth.Method {
case tcp.AuthNone:
if c.auth.ReadNone(res) {
return c.Do(req)
}
return nil, errors.New("user/pass not provided")
case tcp.AuthUnknown:
if c.auth.Read(res) {
return c.Do(req)
}
case tcp.AuthBasic, tcp.AuthDigest:
default:
return nil, errors.New("wrong user/pass")
}
}

View File

@@ -22,6 +22,7 @@ const (
AuthUnknown
AuthBasic
AuthDigest
AuthTPLink // https://drmnsamoliu.github.io/video.html
)
func NewAuth(user *url.Userinfo) *Auth {
@@ -79,6 +80,8 @@ func (a *Auth) Write(req *Request) {
`, uri="%s", response="%s"`, uri, response,
)
req.Header.Set("Authorization", header)
case AuthTPLink:
req.URL.Host = "127.0.0.1"
}
}
@@ -100,6 +103,15 @@ func (a *Auth) Validate(req *Request) bool {
return header == a.header
}
func (a *Auth) ReadNone(res *Response) bool {
auth := res.Header.Get("WWW-Authenticate")
if strings.Contains(auth, "TP-LINK Streaming Media") {
a.Method = AuthTPLink
return true
}
return false
}
func Between(s, sub1, sub2 string) string {
i := strings.Index(s, sub1)
if i < 0 {