mirror of
https://github.com/tailscale/tailscale.git
synced 2025-07-31 16:23:44 +00:00
ipn/ipnlocal: rename web fields/structs to webClient
For consistency and clarity around what the LocalBackend.web field is used for. Updates tailscale/corp#14335 Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
This commit is contained in:
parent
3114a1c88d
commit
44175653dc
@ -206,7 +206,7 @@ type LocalBackend struct {
|
|||||||
httpTestClient *http.Client // for controlclient. nil by default, used by tests.
|
httpTestClient *http.Client // for controlclient. nil by default, used by tests.
|
||||||
ccGen clientGen // function for producing controlclient; lazily populated
|
ccGen clientGen // function for producing controlclient; lazily populated
|
||||||
sshServer SSHServer // or nil, initialized lazily.
|
sshServer SSHServer // or nil, initialized lazily.
|
||||||
web webServer
|
webClient webClient
|
||||||
notify func(ipn.Notify)
|
notify func(ipn.Notify)
|
||||||
cc controlclient.Client
|
cc controlclient.Client
|
||||||
ccAuto *controlclient.Auto // if cc is of type *controlclient.Auto
|
ccAuto *controlclient.Auto // if cc is of type *controlclient.Auto
|
||||||
@ -645,7 +645,7 @@ func (b *LocalBackend) Shutdown() {
|
|||||||
b.debugSink = nil
|
b.debugSink = nil
|
||||||
}
|
}
|
||||||
b.mu.Unlock()
|
b.mu.Unlock()
|
||||||
b.WebShutdown()
|
b.WebClientShutdown()
|
||||||
|
|
||||||
if b.sockstatLogger != nil {
|
if b.sockstatLogger != nil {
|
||||||
b.sockstatLogger.Shutdown()
|
b.sockstatLogger.Shutdown()
|
||||||
@ -3018,7 +3018,7 @@ func (b *LocalBackend) setPrefsLockedOnEntry(caller string, newp *ipn.Prefs) ipn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if oldp.ShouldWebClientBeRunning() && !newp.ShouldWebClientBeRunning() {
|
if oldp.ShouldWebClientBeRunning() && !newp.ShouldWebClientBeRunning() {
|
||||||
b.WebShutdown()
|
b.WebClientShutdown()
|
||||||
}
|
}
|
||||||
if netMap != nil {
|
if netMap != nil {
|
||||||
newProfile := netMap.UserProfiles[netMap.User()]
|
newProfile := netMap.UserProfiles[netMap.User()]
|
||||||
|
@ -17,11 +17,11 @@ import (
|
|||||||
"tailscale.com/net/netutil"
|
"tailscale.com/net/netutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// webServer holds state for the web interface for managing
|
// webClient holds state for the web interface for managing
|
||||||
// this tailscale instance. The web interface is not used by
|
// this tailscale instance. The web interface is not used by
|
||||||
// default, but initialized by calling LocalBackend.WebOrInit.
|
// default, but initialized by calling LocalBackend.WebOrInit.
|
||||||
type webServer struct {
|
type webClient struct {
|
||||||
ws *web.Server // or nil, initialized lazily
|
server *web.Server // or nil, initialized lazily
|
||||||
|
|
||||||
// lc optionally specifies a LocalClient to use to connect
|
// lc optionally specifies a LocalClient to use to connect
|
||||||
// to the localapi for this tailscaled instance.
|
// to the localapi for this tailscaled instance.
|
||||||
@ -34,57 +34,56 @@ type webServer struct {
|
|||||||
func (b *LocalBackend) SetWebLocalClient(lc *tailscale.LocalClient) {
|
func (b *LocalBackend) SetWebLocalClient(lc *tailscale.LocalClient) {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
defer b.mu.Unlock()
|
||||||
b.web.lc = lc
|
b.webClient.lc = lc
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebInit initializes the web interface for managing
|
// WebClientInit initializes the web interface for managing this
|
||||||
// this tailscaled instance. If the web interface is
|
// tailscaled instance.
|
||||||
// already running, WebInit is a no-op.
|
// If the web interface is already running, WebClientInit is a no-op.
|
||||||
func (b *LocalBackend) WebInit() (err error) {
|
func (b *LocalBackend) WebClientInit() (err error) {
|
||||||
if !envknob.Bool("TS_DEBUG_WEB_UI") {
|
if !envknob.Bool("TS_DEBUG_WEB_UI") {
|
||||||
return errors.New("web ui flag unset")
|
return errors.New("web ui flag unset")
|
||||||
}
|
}
|
||||||
|
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
defer b.mu.Unlock()
|
defer b.mu.Unlock()
|
||||||
if b.web.ws != nil {
|
if b.webClient.server != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b.logf("WebInit: initializing web ui")
|
b.logf("WebClientInit: initializing web ui")
|
||||||
if b.web.ws, err = web.NewServer(web.ServerOpts{
|
if b.webClient.server, err = web.NewServer(web.ServerOpts{
|
||||||
// TODO(sonia): allow passing back dev mode flag
|
// TODO(sonia): allow passing back dev mode flag
|
||||||
LocalClient: b.web.lc,
|
LocalClient: b.webClient.lc,
|
||||||
Logf: b.logf,
|
Logf: b.logf,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("web.NewServer: %w", err)
|
return fmt.Errorf("web.NewServer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.logf("WebInit: started web ui")
|
b.logf("WebClientInit: started web ui")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebShutdown shuts down any running b.web servers and
|
// WebClientShutdown shuts down any running b.webClient servers and
|
||||||
// clears out b.web state (besides the b.web.lc field,
|
// clears out b.webClient state (besides the b.webClient.lc field,
|
||||||
// which is left untouched because required for future
|
// which is left untouched because required for future web startups).
|
||||||
// web startups).
|
// WebClientShutdown obtains the b.mu lock.
|
||||||
// WebShutdown obtains the b.mu lock.
|
func (b *LocalBackend) WebClientShutdown() {
|
||||||
func (b *LocalBackend) WebShutdown() {
|
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
webS := b.web.ws
|
server := b.webClient.server
|
||||||
b.web.ws = nil
|
b.webClient.server = nil
|
||||||
b.mu.Unlock() // release lock before shutdown
|
b.mu.Unlock() // release lock before shutdown
|
||||||
if webS != nil {
|
if server != nil {
|
||||||
b.web.ws.Shutdown()
|
server.Shutdown()
|
||||||
}
|
}
|
||||||
b.logf("WebShutdown: shut down web ui")
|
b.logf("WebClientShutdown: shut down web ui")
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleWebClientConn serves web client requests.
|
// handleWebClientConn serves web client requests.
|
||||||
func (b *LocalBackend) handleWebClientConn(c net.Conn) error {
|
func (b *LocalBackend) handleWebClientConn(c net.Conn) error {
|
||||||
if err := b.WebInit(); err != nil {
|
if err := b.WebClientInit(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s := http.Server{Handler: b.web.ws}
|
s := http.Server{Handler: b.webClient.server}
|
||||||
return s.Serve(netutil.NewOneConnListener(c, nil))
|
return s.Serve(netutil.NewOneConnListener(c, nil))
|
||||||
}
|
}
|
@ -12,15 +12,15 @@ import (
|
|||||||
"tailscale.com/client/tailscale"
|
"tailscale.com/client/tailscale"
|
||||||
)
|
)
|
||||||
|
|
||||||
type webServer struct{}
|
type webClient struct{}
|
||||||
|
|
||||||
func (b *LocalBackend) SetWebLocalClient(lc *tailscale.LocalClient) {}
|
func (b *LocalBackend) SetWebLocalClient(lc *tailscale.LocalClient) {}
|
||||||
|
|
||||||
func (b *LocalBackend) WebInit() error {
|
func (b *LocalBackend) WebClientInit() error {
|
||||||
return errors.New("not implemented")
|
return errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *LocalBackend) WebShutdown() {}
|
func (b *LocalBackend) WebClientShutdown() {}
|
||||||
|
|
||||||
func (b *LocalBackend) handleWebClientConn(c net.Conn) error {
|
func (b *LocalBackend) handleWebClientConn(c net.Conn) error {
|
||||||
return errors.New("not implemented")
|
return errors.New("not implemented")
|
@ -62,11 +62,11 @@ type localAPIHandler func(*Handler, http.ResponseWriter, *http.Request)
|
|||||||
// then it's a prefix match.
|
// then it's a prefix match.
|
||||||
var handler = map[string]localAPIHandler{
|
var handler = map[string]localAPIHandler{
|
||||||
// The prefix match handlers end with a slash:
|
// The prefix match handlers end with a slash:
|
||||||
"cert/": (*Handler).serveCert,
|
"cert/": (*Handler).serveCert,
|
||||||
"file-put/": (*Handler).serveFilePut,
|
"file-put/": (*Handler).serveFilePut,
|
||||||
"files/": (*Handler).serveFiles,
|
"files/": (*Handler).serveFiles,
|
||||||
"profiles/": (*Handler).serveProfiles,
|
"profiles/": (*Handler).serveProfiles,
|
||||||
"web/": (*Handler).serveWeb,
|
"webclient/": (*Handler).serveWebClient,
|
||||||
|
|
||||||
// The other /localapi/v0/NAME handlers are exact matches and contain only NAME
|
// The other /localapi/v0/NAME handlers are exact matches and contain only NAME
|
||||||
// without a trailing slash:
|
// without a trailing slash:
|
||||||
@ -2234,7 +2234,7 @@ func (h *Handler) serveDebugWebClient(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) serveWeb(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) serveWebClient(w http.ResponseWriter, r *http.Request) {
|
||||||
if !h.PermitWrite {
|
if !h.PermitWrite {
|
||||||
http.Error(w, "access denied", http.StatusForbidden)
|
http.Error(w, "access denied", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
@ -2244,8 +2244,8 @@ func (h *Handler) serveWeb(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/localapi/v0/web/start":
|
case "/localapi/v0/webclient/start":
|
||||||
if err := h.b.WebInit(); err != nil {
|
if err := h.b.WebClientInit(); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -2256,8 +2256,8 @@ func (h *Handler) serveWeb(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
case "/localapi/v0/web/stop":
|
case "/localapi/v0/webclient/stop":
|
||||||
h.b.WebShutdown()
|
h.b.WebClientShutdown()
|
||||||
// try to set pref, but ignore errors
|
// try to set pref, but ignore errors
|
||||||
_, _ = h.b.EditPrefs(&ipn.MaskedPrefs{
|
_, _ = h.b.EditPrefs(&ipn.MaskedPrefs{
|
||||||
Prefs: ipn.Prefs{RunWebClient: false},
|
Prefs: ipn.Prefs{RunWebClient: false},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user