From 34ffd4f7c64bd80eabb8d981dd945dc16430a3da Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 11 Feb 2021 10:57:08 -0800 Subject: [PATCH] cmd/hello: serve fake data in dev mode on whois failure --- cmd/hello/hello.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/cmd/hello/hello.go b/cmd/hello/hello.go index ecb536bda..2aa16f694 100644 --- a/cmd/hello/hello.go +++ b/cmd/hello/hello.go @@ -108,18 +108,30 @@ func root(w http.ResponseWriter, r *http.Request) { } who, err := whoIs(ip) + var data tmplData if err != nil { - log.Printf("whois(%q) error: %v", ip, err) - http.Error(w, "Your Tailscale works, but we failed to look you up.", 500) - return + if devMode() { + data = tmplData{ + DisplayName: "Taily Scalerson", + LoginName: "taily@scaler.son", + MachineName: "scaled", + IP: "100.1.2.3", + } + } else { + log.Printf("whois(%q) error: %v", ip, err) + http.Error(w, "Your Tailscale works, but we failed to look you up.", 500) + return + } + } else { + data = tmplData{ + DisplayName: who.UserProfile.DisplayName, + LoginName: who.UserProfile.LoginName, + MachineName: who.Node.ComputedName, + IP: ip, + } } w.Header().Set("Content-Type", "text/html; charset=utf-8") - tmpl.Execute(w, tmplData{ - DisplayName: who.UserProfile.DisplayName, - LoginName: who.UserProfile.LoginName, - MachineName: who.Node.ComputedName, - IP: ip, - }) + tmpl.Execute(w, data) } // tsSockClient does HTTP requests to the local Tailscale daemon.