ipn/localapi: add debug (root-required) access to inject debug Notify

For testing of Windows GUI client.

Updates #6480

Change-Id: I42f7526d95723e14bed7085fb759e371b43aa9da
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-12-02 20:13:36 -08:00
committed by Brad Fitzpatrick
parent 96cad35870
commit 57124e2126
2 changed files with 28 additions and 2 deletions

View File

@ -434,7 +434,16 @@ func (h *Handler) serveDebug(w http.ResponseWriter, r *http.Request) {
http.Error(w, "POST required", http.StatusMethodNotAllowed)
return
}
action := r.FormValue("action")
// The action is normally in a POST form parameter, but
// some actions (like "notify") want a full JSON body, so
// permit some to have their action in a header.
var action string
switch v := r.Header.Get("Debug-Action"); v {
case "notify":
action = v
default:
action = r.FormValue("action")
}
var err error
switch action {
case "rebind":
@ -455,6 +464,14 @@ func (h *Handler) serveDebug(w http.ResponseWriter, r *http.Request) {
// client already did. A future change will remove this, so don't depend
// on it.
h.b.RequestEngineStatus()
case "notify":
var n ipn.Notify
err = json.NewDecoder(r.Body).Decode(&n)
if err != nil {
break
}
h.b.DebugNotify(n)
case "":
err = fmt.Errorf("missing parameter 'action'")
default: