From 537877604301299d439361585688655bcc92e626 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 11 Feb 2021 16:38:26 -0800 Subject: [PATCH] cmd/hello: chop DNS name at first dot --- cmd/hello/hello.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/hello/hello.go b/cmd/hello/hello.go index 8b0b19dab..e768c1ef2 100644 --- a/cmd/hello/hello.go +++ b/cmd/hello/hello.go @@ -131,7 +131,7 @@ func root(w http.ResponseWriter, r *http.Request) { DisplayName: who.UserProfile.DisplayName, LoginName: who.UserProfile.LoginName, ProfilePicURL: who.UserProfile.ProfilePicURL, - MachineName: who.Node.ComputedName, + MachineName: firstLabel(who.Node.ComputedName), MachineOS: who.Node.Hostinfo.OS, IP: ip, } @@ -140,6 +140,14 @@ func root(w http.ResponseWriter, r *http.Request) { tmpl.Execute(w, data) } +// firstLabel s up until the first period, if any. +func firstLabel(s string) string { + if i := strings.Index(s, "."); i != -1 { + return s[:i] + } + return s +} + // tsSockClient does HTTP requests to the local Tailscale daemon. // The hostname in the HTTP request is ignored. var tsSockClient = &http.Client{