@ -42,6 +42,7 @@ Tailscale, as opposed to a CLI or a native app.
webf . StringVar ( & webArgs . listen , "listen" , "localhost:8088" , "listen address; use port 0 for automatic" )
webf . StringVar ( & webArgs . listen , "listen" , "localhost:8088" , "listen address; use port 0 for automatic" )
webf . BoolVar ( & webArgs . cgi , "cgi" , false , "run as CGI script" )
webf . BoolVar ( & webArgs . cgi , "cgi" , false , "run as CGI script" )
webf . StringVar ( & webArgs . prefix , "prefix" , "" , "URL prefix added to requests (for cgi or reverse proxies)" )
webf . StringVar ( & webArgs . prefix , "prefix" , "" , "URL prefix added to requests (for cgi or reverse proxies)" )
webf . BoolVar ( & webArgs . readonly , "readonly" , false , "run web UI in read-only mode" )
return webf
return webf
} ) ( ) ,
} ) ( ) ,
Exec : runWeb ,
Exec : runWeb ,
@ -51,6 +52,7 @@ var webArgs struct {
listen string
listen string
cgi bool
cgi bool
prefix string
prefix string
readonly bool
}
}
func tlsConfigFromEnvironment ( ) * tls . Config {
func tlsConfigFromEnvironment ( ) * tls . Config {
@ -94,20 +96,26 @@ func runWeb(ctx context.Context, args []string) error {
if prefs , err := localClient . GetPrefs ( ctx ) ; err == nil {
if prefs , err := localClient . GetPrefs ( ctx ) ; err == nil {
existingWebClient = prefs . RunWebClient
existingWebClient = prefs . RunWebClient
}
}
if ! existingWebClient {
var startedManagementClient bool // we started the management client
if ! existingWebClient && ! webArgs . readonly {
// Also start full client in tailscaled.
// Also start full client in tailscaled.
log . Printf ( "starting tailscaled web client at %s:%d\n" , selfIP . String ( ) , web . ListenPort )
log . Printf ( "starting tailscaled web client at %s:%d\n" , selfIP . String ( ) , web . ListenPort )
if err := setRunWebClient ( ctx , true ) ; err != nil {
if err := setRunWebClient ( ctx , true ) ; err != nil {
return fmt . Errorf ( "starting web client in tailscaled: %w" , err )
return fmt . Errorf ( "starting web client in tailscaled: %w" , err )
}
}
startedManagementClient = true
}
}
webServer, err := web . NewServer ( web . ServerOpts {
opts := web . ServerOpts {
Mode : web . LoginServerMode ,
Mode : web . LoginServerMode ,
CGIMode : webArgs . cgi ,
CGIMode : webArgs . cgi ,
PathPrefix : webArgs . prefix ,
PathPrefix : webArgs . prefix ,
LocalClient : & localClient ,
LocalClient : & localClient ,
} )
}
if webArgs . readonly {
opts . Mode = web . ReadOnlyServerMode
}
webServer , err := web . NewServer ( opts )
if err != nil {
if err != nil {
log . Printf ( "tailscale.web: %v" , err )
log . Printf ( "tailscale.web: %v" , err )
return err
return err
@ -117,10 +125,10 @@ func runWeb(ctx context.Context, args []string) error {
case <- ctx . Done ( ) :
case <- ctx . Done ( ) :
// Shutdown the server.
// Shutdown the server.
webServer . Shutdown ( )
webServer . Shutdown ( )
if ! webArgs . cgi && ! existingWeb Client {
if ! webArgs . cgi && startedManagement Client {
log . Println ( "stopping tailscaled web client" )
log . Println ( "stopping tailscaled web client" )
// When not in cgi mode, shut down the tailscaled
// When not in cgi mode, shut down the tailscaled
// web client on cli termination .
// web client on cli termination if we started it .
if err := setRunWebClient ( context . Background ( ) , false ) ; err != nil {
if err := setRunWebClient ( context . Background ( ) , false ) ; err != nil {
log . Printf ( "stopping tailscaled web client: %v" , err )
log . Printf ( "stopping tailscaled web client: %v" , err )
}
}