@ -228,33 +228,48 @@ func qnapAuthn(r *http.Request) (string, *qnapAuthResponse, error) {
return "" , nil , fmt . Errorf ( "not authenticated by any mechanism" )
return "" , nil , fmt . Errorf ( "not authenticated by any mechanism" )
}
}
func qnapAuthnQtoken ( r * http . Request , user , token string ) ( string , * qnapAuthResponse , error ) {
// qnapAuthnURL returns the auth URL to use by inferring where the UI is
query := url . Values {
// running based on the request URL. This is necessary because QNAP has so
"qtoken" : [ ] string { token } ,
// many options, see https://github.com/tailscale/tailscale/issues/7108
"user" : [ ] string { user } ,
// and https://github.com/tailscale/tailscale/issues/6903
func qnapAuthnURL ( requestUrl string , query url . Values ) string {
in , err := url . Parse ( requestUrl )
scheme := ""
host := ""
if err != nil || in . Scheme == "" {
log . Printf ( "Cannot parse QNAP login URL %v" , err )
// try localhost and hope for the best
scheme = "http"
host = "localhost"
} else {
scheme = in . Scheme
host = in . Host
}
}
u := url . URL {
u := url . URL {
Scheme : "http" ,
Scheme : scheme ,
Host : "127.0.0.1:8080" ,
Host : host ,
Path : "/cgi-bin/authLogin.cgi" ,
Path : "/cgi-bin/authLogin.cgi" ,
RawQuery : query . Encode ( ) ,
RawQuery : query . Encode ( ) ,
}
}
return qnapAuthnFinish ( user , u . String ( ) )
return u . String ( )
}
}
func qnapAuthnSid ( r * http . Request , user , sid string ) ( string , * qnapAuthResponse , error ) {
func qnapAuthn Qtoken ( r * http . Request , user , token string ) ( string , * qnapAuthResponse , error ) {
query := url . Values {
query := url . Values {
"sid" : [ ] string { sid } ,
"qtoken" : [ ] string { token } ,
"user" : [ ] string { user } ,
}
}
u := url . URL {
return qnapAuthnFinish ( user , qnapAuthnURL ( r . URL . String ( ) , query ) )
Scheme : "http" ,
Host : "127.0.0.1:8080" ,
Path : "/cgi-bin/authLogin.cgi" ,
RawQuery : query . Encode ( ) ,
}
}
return qnapAuthnFinish ( user , u . String ( ) )
func qnapAuthnSid ( r * http . Request , user , sid string ) ( string , * qnapAuthResponse , error ) {
query := url . Values {
"sid" : [ ] string { sid } ,
}
return qnapAuthnFinish ( user , qnapAuthnURL ( r . URL . String ( ) , query ) )
}
}
func qnapAuthnFinish ( user , url string ) ( string , * qnapAuthResponse , error ) {
func qnapAuthnFinish ( user , url string ) ( string , * qnapAuthResponse , error ) {