mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Add network api endpoints
This commit is contained in:
parent
5731be026d
commit
ab89a326c5
2 changed files with 55 additions and 0 deletions
51
netenv/api.go
Normal file
51
netenv/api.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package netenv
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/safing/portbase/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
func registerAPIEndpoints() error {
|
||||||
|
if err := api.RegisterEndpoint(api.Endpoint{
|
||||||
|
Path: "network/gateways",
|
||||||
|
Read: api.PermitUser,
|
||||||
|
StructFunc: func(ar *api.Request) (i interface{}, err error) {
|
||||||
|
return Gateways(), nil
|
||||||
|
},
|
||||||
|
Name: "Get Default Gateways",
|
||||||
|
Description: "Returns the current active default gateways of the network.",
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := api.RegisterEndpoint(api.Endpoint{
|
||||||
|
Path: "network/nameservers",
|
||||||
|
Read: api.PermitUser,
|
||||||
|
StructFunc: func(ar *api.Request) (i interface{}, err error) {
|
||||||
|
return Nameservers(), nil
|
||||||
|
},
|
||||||
|
Name: "Get System Nameservers",
|
||||||
|
Description: "Returns the currently configured nameservers on the OS.",
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := api.RegisterEndpoint(api.Endpoint{
|
||||||
|
Path: "network/location",
|
||||||
|
Read: api.PermitUser,
|
||||||
|
StructFunc: func(ar *api.Request) (i interface{}, err error) {
|
||||||
|
locs, ok := GetInternetLocation()
|
||||||
|
if ok {
|
||||||
|
return locs, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("no location data available")
|
||||||
|
},
|
||||||
|
Name: "Get Approximate Internet Location",
|
||||||
|
Description: "Returns an approximation of where the device is on the Internet.",
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -29,6 +29,10 @@ func prep() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func start() error {
|
func start() error {
|
||||||
|
if err := registerAPIEndpoints(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
module.StartServiceWorker(
|
module.StartServiceWorker(
|
||||||
"monitor network changes",
|
"monitor network changes",
|
||||||
0,
|
0,
|
||||||
|
|
Loading…
Add table
Reference in a new issue