|
|
@ -62,11 +62,10 @@ 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,
|
|
|
|
"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:
|
|
|
@ -2243,43 +2242,6 @@ 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) serveWebClient(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
|
|
if !h.PermitWrite {
|
|
|
|
|
|
|
|
http.Error(w, "access denied", http.StatusForbidden)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.Method != httpm.POST {
|
|
|
|
|
|
|
|
http.Error(w, "use POST", http.StatusMethodNotAllowed)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch r.URL.Path {
|
|
|
|
|
|
|
|
case "/localapi/v0/webclient/start":
|
|
|
|
|
|
|
|
if err := h.b.WebClientInit(); err != nil {
|
|
|
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to set pref, but ignore errors
|
|
|
|
|
|
|
|
_, _ = h.b.EditPrefs(&ipn.MaskedPrefs{
|
|
|
|
|
|
|
|
Prefs: ipn.Prefs{RunWebClient: true},
|
|
|
|
|
|
|
|
RunWebClientSet: true,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
case "/localapi/v0/webclient/stop":
|
|
|
|
|
|
|
|
h.b.WebClientShutdown()
|
|
|
|
|
|
|
|
// try to set pref, but ignore errors
|
|
|
|
|
|
|
|
_, _ = h.b.EditPrefs(&ipn.MaskedPrefs{
|
|
|
|
|
|
|
|
Prefs: ipn.Prefs{RunWebClient: false},
|
|
|
|
|
|
|
|
RunWebClientSet: true,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
http.Error(w, "invalid action", http.StatusBadRequest)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func defBool(a string, def bool) bool {
|
|
|
|
func defBool(a string, def bool) bool {
|
|
|
|
if a == "" {
|
|
|
|
if a == "" {
|
|
|
|
return def
|
|
|
|
return def
|
|
|
|