@ -19,6 +19,7 @@ import (
"expvar"
"flag"
"fmt"
"html/template"
"io"
"log"
"math"
@ -212,25 +213,16 @@ func main() {
tsweb . AddBrowserHeaders ( w )
w . Header ( ) . Set ( "Content-Type" , "text/html; charset=utf-8" )
w . WriteHeader ( 200 )
io . WriteString ( w , ` < html > < body >
< h1 > DERP < / h1 >
< p >
This is a < a href = "https://tailscale.com/" > Tailscale < / a > DERP server .
< / p >
< p >
Documentation :
< / p >
< ul >
< li > < a href = "https://tailscale.com/kb/1232/derp-servers" > About DERP < / a > < / li >
< li > < a href = "https://pkg.go.dev/tailscale.com/derp" > Protocol & Go docs < / a > < / li >
< li > < a href = "https://github.com/tailscale/tailscale/tree/main/cmd/derper#derp" > How to run a DERP server < / a > < / li >
< / ul >
` )
if ! * runDERP {
io . WriteString ( w , ` <p>Status: <b>disabled</b></p> ` )
err := homePageTemplate . Execute ( w , templateData {
ShowAbuseInfo : validProdHostname . MatchString ( * hostname ) ,
Disabled : ! * runDERP ,
AllowDebug : tsweb . AllowDebugAccess ( r ) ,
} )
if err != nil {
if r . Context ( ) . Err ( ) == nil {
log . Printf ( "homePageTemplate.Execute: %v" , err )
}
if tsweb . AllowDebugAccess ( r ) {
io . WriteString ( w , "<p>Debug info at <a href='/debug/'>/debug/</a>.</p>\n" )
return
}
} ) )
mux . Handle ( "/robots.txt" , http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) {
@ -468,3 +460,52 @@ func init() {
return 0
} ) )
}
type templateData struct {
ShowAbuseInfo bool
Disabled bool
AllowDebug bool
}
// homePageTemplate renders the home page using [templateData].
var homePageTemplate = template . Must ( template . New ( "home" ) . Parse ( ` < html > < body >
< h1 > DERP < / h1 >
< p >
This is a < a href = "https://tailscale.com/" > Tailscale < / a > DERP server .
< / p >
< p >
It provides STUN , interactive connectivity establishment , and relaying of end - to - end encrypted traffic
for Tailscale clients .
< / p >
{ { if . ShowAbuseInfo } }
< p >
If you suspect abuse , please contact < a href = "mailto:security@tailscale.com" > security @ tailscale . com < / a > .
< / p >
{ { end } }
< p >
Documentation :
< / p >
< ul >
{ { if . ShowAbuseInfo } }
< li > < a href = "https://tailscale.com/security-policies" > Tailscale Security Policies < / a > < / li >
< li > < a href = "https://tailscale.com/tailscale-aup" > Tailscale Acceptable Use Policies < / a > < / li >
{ { end } }
< li > < a href = "https://tailscale.com/kb/1232/derp-servers" > About DERP < / a > < / li >
< li > < a href = "https://pkg.go.dev/tailscale.com/derp" > Protocol & Go docs < / a > < / li >
< li > < a href = "https://github.com/tailscale/tailscale/tree/main/cmd/derper#derp" > How to run a DERP server < / a > < / li >
< / ul >
{ { if . Disabled } }
< p > Status : < b > disabled < / b > < / p >
{ { end } }
{ { if . AllowDebug } }
< p > Debug info at < a href = ' / debug / ' > / debug / < / a > . < / p >
{ { end } }
< / body >
< / html >
` ) )