mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-06 00:37:00 +08:00
Add bypass login for TP-Link cameras
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user