mirror of
https://github.com/safing/portmaster
synced 2025-09-01 10:09:11 +00:00
Link api endpoints and http handlers to their modules
This commit is contained in:
parent
3d5807e3a9
commit
78c56861ab
7 changed files with 28 additions and 12 deletions
|
@ -27,6 +27,7 @@ func registerAPIEndpoints() error {
|
|||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "core/shutdown",
|
||||
Write: api.PermitSelf,
|
||||
BelongsTo: module,
|
||||
ActionFunc: shutdown,
|
||||
Name: "Shut Down Portmaster",
|
||||
Description: "Shut down the Portmaster Core Service and all UI components.",
|
||||
|
@ -37,6 +38,7 @@ func registerAPIEndpoints() error {
|
|||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "core/restart",
|
||||
Write: api.PermitAdmin,
|
||||
BelongsTo: module,
|
||||
ActionFunc: restart,
|
||||
Name: "Restart Portmaster",
|
||||
Description: "Restart the Portmaster Core Service.",
|
||||
|
@ -47,6 +49,7 @@ func registerAPIEndpoints() error {
|
|||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "debug/core",
|
||||
Read: api.PermitAnyone,
|
||||
BelongsTo: module,
|
||||
DataFunc: debugInfo,
|
||||
Name: "Get Debug Information",
|
||||
Description: "Returns network debugging information, similar to debug/info, but with system status data.",
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
|
||||
func registerAPIEndpoints() error {
|
||||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "network/gateways",
|
||||
Read: api.PermitUser,
|
||||
Path: "network/gateways",
|
||||
Read: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
StructFunc: func(ar *api.Request) (i interface{}, err error) {
|
||||
return Gateways(), nil
|
||||
},
|
||||
|
@ -20,8 +21,9 @@ func registerAPIEndpoints() error {
|
|||
}
|
||||
|
||||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "network/nameservers",
|
||||
Read: api.PermitUser,
|
||||
Path: "network/nameservers",
|
||||
Read: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
StructFunc: func(ar *api.Request) (i interface{}, err error) {
|
||||
return Nameservers(), nil
|
||||
},
|
||||
|
@ -32,8 +34,9 @@ func registerAPIEndpoints() error {
|
|||
}
|
||||
|
||||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "network/location",
|
||||
Read: api.PermitUser,
|
||||
Path: "network/location",
|
||||
Read: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
StructFunc: func(ar *api.Request) (i interface{}, err error) {
|
||||
locs, ok := GetInternetLocation()
|
||||
if ok {
|
||||
|
|
|
@ -20,6 +20,7 @@ func registerAPIEndpoints() error {
|
|||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "debug/network",
|
||||
Read: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
DataFunc: debugInfo,
|
||||
Name: "Get Network Debug Information",
|
||||
Description: "Returns network debugging information, similar to debug/core, but with connection data.",
|
||||
|
@ -48,8 +49,9 @@ func registerAPIEndpoints() error {
|
|||
}
|
||||
|
||||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "debug/network/state",
|
||||
Read: api.PermitUser,
|
||||
Path: "debug/network/state",
|
||||
Read: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
StructFunc: func(ar *api.Request) (i interface{}, err error) {
|
||||
return state.GetInfo(), nil
|
||||
},
|
||||
|
|
|
@ -11,6 +11,7 @@ func registerAPI() error {
|
|||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "dns/clear",
|
||||
Write: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
ActionFunc: clearNameCache,
|
||||
Name: "Clear cached DNS records",
|
||||
Description: "Deletes all saved DNS records from the database.",
|
||||
|
@ -21,6 +22,7 @@ func registerAPI() error {
|
|||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "dns/resolvers",
|
||||
Read: api.PermitAnyone,
|
||||
BelongsTo: module,
|
||||
StructFunc: exportDNSResolvers,
|
||||
Name: "List DNS Resolvers",
|
||||
Description: "List currently configured DNS resolvers and their status.",
|
||||
|
@ -29,8 +31,9 @@ func registerAPI() error {
|
|||
}
|
||||
|
||||
if err := api.RegisterEndpoint(api.Endpoint{
|
||||
Path: `dns/cache/{query:[a-z0-9\.-]{0,512}\.[A-Z]{1,32}}`,
|
||||
Read: api.PermitUser,
|
||||
Path: `dns/cache/{query:[a-z0-9\.-]{0,512}\.[A-Z]{1,32}}`,
|
||||
Read: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
RecordFunc: func(r *api.Request) (record.Record, error) {
|
||||
return recordDatabase.Get(nameRecordsKeyPrefix + r.URLVars["query"])
|
||||
},
|
||||
|
|
|
@ -10,6 +10,7 @@ func registerAPIEndpoints() error {
|
|||
return api.RegisterEndpoint(api.Endpoint{
|
||||
Path: "ui/reload",
|
||||
Write: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
ActionFunc: reloadUI,
|
||||
Name: "Reload UI Assets",
|
||||
Description: "Removes all assets from the cache and reloads the current (possibly updated) version from disk when requested.",
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/safing/portbase/api"
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/modules"
|
||||
"github.com/safing/portbase/updater"
|
||||
"github.com/safing/portmaster/updates"
|
||||
)
|
||||
|
@ -53,6 +54,8 @@ type bundleServer struct {
|
|||
defaultModuleName string
|
||||
}
|
||||
|
||||
func (bs *bundleServer) BelongsTo() *modules.Module { return module }
|
||||
|
||||
func (bs *bundleServer) ReadPermission(*http.Request) api.Permission { return api.PermitAnyone }
|
||||
|
||||
func (bs *bundleServer) WritePermission(*http.Request) api.Permission { return api.NotSupported }
|
||||
|
|
|
@ -10,8 +10,9 @@ const (
|
|||
|
||||
func registerAPIEndpoints() error {
|
||||
return api.RegisterEndpoint(api.Endpoint{
|
||||
Path: apiPathCheckForUpdates,
|
||||
Write: api.PermitUser,
|
||||
Path: apiPathCheckForUpdates,
|
||||
Write: api.PermitUser,
|
||||
BelongsTo: module,
|
||||
ActionFunc: func(_ *api.Request) (msg string, err error) {
|
||||
if err := TriggerUpdate(); err != nil {
|
||||
return "", err
|
||||
|
|
Loading…
Add table
Reference in a new issue