@ -61,39 +61,41 @@ var handler = map[string]localAPIHandler{
// 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:
"bugreport" : ( * Handler ) . serveBugReport ,
"bugreport" : ( * Handler ) . serveBugReport ,
"check-ip-forwarding" : ( * Handler ) . serveCheckIPForwarding ,
"check-ip-forwarding" : ( * Handler ) . serveCheckIPForwarding ,
"check-prefs" : ( * Handler ) . serveCheckPrefs ,
"check-prefs" : ( * Handler ) . serveCheckPrefs ,
"component-debug-logging" : ( * Handler ) . serveComponentDebugLogging ,
"component-debug-logging" : ( * Handler ) . serveComponentDebugLogging ,
"debug" : ( * Handler ) . serveDebug ,
"debug" : ( * Handler ) . serveDebug ,
"debug-derp-region" : ( * Handler ) . serveDebugDERPRegion ,
"debug-derp-region" : ( * Handler ) . serveDebugDERPRegion ,
"derpmap" : ( * Handler ) . serveDERPMap ,
"debug-packet-filter-matches" : ( * Handler ) . serveDebugPacketFilterMatches ,
"dev-set-state-store" : ( * Handler ) . serveDevSetStateStore ,
"debug-packet-filter-rules" : ( * Handler ) . serveDebugPacketFilterRules ,
"dial" : ( * Handler ) . serveDial ,
"derpmap" : ( * Handler ) . serveDERPMap ,
"file-targets" : ( * Handler ) . serveFileTargets ,
"dev-set-state-store" : ( * Handler ) . serveDevSetStateStore ,
"goroutines" : ( * Handler ) . serveGoroutines ,
"dial" : ( * Handler ) . serveDial ,
"id-token" : ( * Handler ) . serveIDToken ,
"file-targets" : ( * Handler ) . serveFileTargets ,
"login-interactive" : ( * Handler ) . serveLoginInteractive ,
"goroutines" : ( * Handler ) . serveGoroutines ,
"logout" : ( * Handler ) . serveLogout ,
"id-token" : ( * Handler ) . serveIDToken ,
"metrics" : ( * Handler ) . serveMetrics ,
"login-interactive" : ( * Handler ) . serveLoginInteractive ,
"ping" : ( * Handler ) . servePing ,
"logout" : ( * Handler ) . serveLogout ,
"prefs" : ( * Handler ) . servePrefs ,
"metrics" : ( * Handler ) . serveMetrics ,
"pprof" : ( * Handler ) . servePprof ,
"ping" : ( * Handler ) . servePing ,
"serve-config" : ( * Handler ) . serveServeConfig ,
"prefs" : ( * Handler ) . servePrefs ,
"set-dns" : ( * Handler ) . serveSetDNS ,
"pprof" : ( * Handler ) . servePprof ,
"set-expiry-sooner" : ( * Handler ) . serveSetExpirySooner ,
"serve-config" : ( * Handler ) . serveServeConfig ,
"start" : ( * Handler ) . serveStart ,
"set-dns" : ( * Handler ) . serveSetDNS ,
"status" : ( * Handler ) . serveStatus ,
"set-expiry-sooner" : ( * Handler ) . serveSetExpirySooner ,
"tka/init" : ( * Handler ) . serveTKAInit ,
"start" : ( * Handler ) . serveStart ,
"tka/log" : ( * Handler ) . serveTKALog ,
"status" : ( * Handler ) . serveStatus ,
"tka/modify" : ( * Handler ) . serveTKAModify ,
"tka/init" : ( * Handler ) . serveTKAInit ,
"tka/sign" : ( * Handler ) . serveTKASign ,
"tka/log" : ( * Handler ) . serveTKALog ,
"tka/status" : ( * Handler ) . serveTKAStatus ,
"tka/modify" : ( * Handler ) . serveTKAModify ,
"tka/disable" : ( * Handler ) . serveTKADisable ,
"tka/sign" : ( * Handler ) . serveTKASign ,
"tka/force-local-disable" : ( * Handler ) . serveTKALocalDisable ,
"tka/status" : ( * Handler ) . serveTKAStatus ,
"upload-client-metrics" : ( * Handler ) . serveUploadClientMetrics ,
"tka/disable" : ( * Handler ) . serveTKADisable ,
"watch-ipn-bus" : ( * Handler ) . serveWatchIPNBus ,
"tka/force-local-disable" : ( * Handler ) . serveTKALocalDisable ,
"whois" : ( * Handler ) . serveWhoIs ,
"upload-client-metrics" : ( * Handler ) . serveUploadClientMetrics ,
"watch-ipn-bus" : ( * Handler ) . serveWatchIPNBus ,
"whois" : ( * Handler ) . serveWhoIs ,
}
}
func randHex ( n int ) string {
func randHex ( n int ) string {
@ -506,6 +508,40 @@ func (h *Handler) serveDevSetStateStore(w http.ResponseWriter, r *http.Request)
io . WriteString ( w , "done\n" )
io . WriteString ( w , "done\n" )
}
}
func ( h * Handler ) serveDebugPacketFilterRules ( w http . ResponseWriter , r * http . Request ) {
if ! h . PermitWrite {
http . Error ( w , "debug access denied" , http . StatusForbidden )
return
}
nm := h . b . NetMap ( )
if nm == nil {
http . Error ( w , "no netmap" , http . StatusNotFound )
return
}
w . Header ( ) . Set ( "Content-Type" , "application/json" )
enc := json . NewEncoder ( w )
enc . SetIndent ( "" , "\t" )
enc . Encode ( nm . PacketFilterRules )
}
func ( h * Handler ) serveDebugPacketFilterMatches ( w http . ResponseWriter , r * http . Request ) {
if ! h . PermitWrite {
http . Error ( w , "debug access denied" , http . StatusForbidden )
return
}
nm := h . b . NetMap ( )
if nm == nil {
http . Error ( w , "no netmap" , http . StatusNotFound )
return
}
w . Header ( ) . Set ( "Content-Type" , "application/json" )
enc := json . NewEncoder ( w )
enc . SetIndent ( "" , "\t" )
enc . Encode ( nm . PacketFilter )
}
func ( h * Handler ) serveComponentDebugLogging ( w http . ResponseWriter , r * http . Request ) {
func ( h * Handler ) serveComponentDebugLogging ( w http . ResponseWriter , r * http . Request ) {
if ! h . PermitWrite {
if ! h . PermitWrite {
http . Error ( w , "debug access denied" , http . StatusForbidden )
http . Error ( w , "debug access denied" , http . StatusForbidden )