mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 21:15:39 +00:00
89953b015b
Allows for serving the web interface from tailscaled, with the ability to start and stop the server via localapi endpoints (/web/start and /web/stop). This will be used to run the new full management web client, which will only be accessible over Tailscale (with an extra auth check step over noise) from the daemon. This switch also allows us to run the web interface as a long-lived service in environments where the CLI version is restricted to CGI, allowing us to manage certain auth state in memory. ipn/ipnlocal/web is stubbed out in ipn/ipnlocal/web_stub for ios builds to satisfy ios restriction from adding "text/template" and "html/template" dependencies. Updates tailscale/corp#14335 Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
48 lines
933 B
Go
48 lines
933 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// The web-client command demonstrates serving the Tailscale web client over tsnet.
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"net/http"
|
|
|
|
"tailscale.com/client/web"
|
|
"tailscale.com/tsnet"
|
|
)
|
|
|
|
var (
|
|
addr = flag.String("addr", "localhost:8060", "address of Tailscale web client")
|
|
devMode = flag.Bool("dev", false, "run web client in dev mode")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
s := new(tsnet.Server)
|
|
defer s.Close()
|
|
|
|
lc, err := s.LocalClient()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Serve the Tailscale web client.
|
|
ws, err := web.NewServer(web.ServerOpts{
|
|
DevMode: *devMode,
|
|
LocalClient: lc,
|
|
})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer ws.Shutdown()
|
|
log.Printf("Serving Tailscale web client on http://%s", *addr)
|
|
if err := http.ListenAndServe(*addr, ws); err != nil {
|
|
if err != http.ErrServerClosed {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
}
|