mirror of
https://github.com/safing/portmaster
synced 2025-09-01 10:09:11 +00:00
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
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
|
|
}
|