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