Browse Source

tsnet: add option to run integrated web client

Updates #10261

Signed-off-by: Will Norris <[email protected]>
Will Norris 2 years ago
parent
commit
5aa22ff3eb
2 changed files with 7 additions and 1 deletions
  1. 1 1
      tsnet/example/web-client/web-client.go
  2. 6 0
      tsnet/tsnet.go

+ 1 - 1
tsnet/example/web-client/web-client.go

@@ -20,7 +20,7 @@ var (
 func main() {
 	flag.Parse()
 
-	s := new(tsnet.Server)
+	s := &tsnet.Server{RunWebClient: true}
 	defer s.Close()
 
 	lc, err := s.LocalClient()

+ 6 - 0
tsnet/tsnet.go

@@ -108,6 +108,10 @@ type Server struct {
 	// If empty, the Tailscale default is used.
 	ControlURL string
 
+	// RunWebClient, if true, runs a client for managing this node over
+	// its Tailscale interface on port 5252.
+	RunWebClient bool
+
 	// Port is the UDP port to listen on for WireGuard and peer-to-peer
 	// traffic. If zero, a port is automatically selected. Leave this
 	// field at zero unless you know what you are doing.
@@ -575,6 +579,7 @@ func (s *Server) start() (reterr error) {
 	prefs.Hostname = s.hostname
 	prefs.WantRunning = true
 	prefs.ControlURL = s.ControlURL
+	prefs.RunWebClient = s.RunWebClient
 	authKey := s.getAuthKey()
 	err = lb.Start(ipn.Options{
 		UpdatePrefs: prefs,
@@ -603,6 +608,7 @@ func (s *Server) start() (reterr error) {
 	s.localAPIListener = lal
 	s.localClient = &tailscale.LocalClient{Dial: lal.Dial}
 	s.localAPIServer = &http.Server{Handler: lah}
+	s.lb.ConfigureWebClient(s.localClient)
 	go func() {
 		if err := s.localAPIServer.Serve(lal); err != nil {
 			logf("localapi serve error: %v", err)