Add debug/core endpoint to add more Portmaster debug data

This commit is contained in:
Daniel
2021-02-23 13:00:54 +01:00
parent 6c0df1155e
commit 0e51a9523a
4 changed files with 62 additions and 9 deletions

View File

@@ -1,13 +1,17 @@
package core
import (
"net/http"
"github.com/safing/portbase/api"
"github.com/safing/portbase/log"
"github.com/safing/portbase/modules"
"github.com/safing/portbase/utils/debug"
"github.com/safing/portmaster/status"
"github.com/safing/portmaster/updates"
)
func registerActions() error {
func registerAPIEndpoints() error {
if err := api.RegisterEndpoint(api.Endpoint{
Path: "core/shutdown",
Read: api.PermitSelf,
@@ -24,6 +28,22 @@ func registerActions() error {
return err
}
if err := api.RegisterEndpoint(api.Endpoint{
Path: "debug/core",
Read: api.PermitAnyone,
DataFunc: debugInfo,
Name: "Get Debug Information",
Description: "Returns network debugging information, similar to debug/info, but with system status data.",
Parameters: []api.Parameter{{
Method: http.MethodGet,
Field: "style",
Value: "github",
Description: "Specify the formatting style. The default is simple markdown formatting.",
}},
}); err != nil {
return err
}
return nil
}
@@ -41,3 +61,21 @@ func restart(_ *api.Request) (msg string, err error) {
updates.RestartNow()
return "restart initiated", nil
}
// debugInfo returns the debugging information for support requests.
func debugInfo(ar *api.Request) (data []byte, err error) {
// Create debug information helper.
di := new(debug.Info)
di.Style = ar.Request.URL.Query().Get("style")
// Add debug information.
di.AddVersionInfo()
di.AddPlatformInfo(ar.Context())
status.AddToDebugInfo(di)
di.AddLastReportedModuleError()
di.AddLastUnexpectedLogs()
di.AddGoroutineStack()
// Return data.
return di.Bytes(), nil
}

View File

@@ -55,7 +55,7 @@ func start() error {
return err
}
if err := registerActions(); err != nil {
if err := registerAPIEndpoints(); err != nil {
return err
}