mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
43 lines
1 KiB
Go
43 lines
1 KiB
Go
package core
|
|
|
|
import (
|
|
"github.com/safing/portbase/api"
|
|
"github.com/safing/portbase/log"
|
|
"github.com/safing/portbase/modules"
|
|
"github.com/safing/portmaster/updates"
|
|
)
|
|
|
|
func registerActions() error {
|
|
if err := api.RegisterEndpoint(api.Endpoint{
|
|
Path: "core/shutdown",
|
|
Read: api.PermitSelf,
|
|
ActionFn: shutdown,
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := api.RegisterEndpoint(api.Endpoint{
|
|
Path: "core/restart",
|
|
Read: api.PermitSelf,
|
|
ActionFn: restart,
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// shutdown shuts the Portmaster down.
|
|
func shutdown(_ *api.Request) (msg string, err error) {
|
|
log.Warning("core: user requested shutdown via action")
|
|
// Do not use a worker, as this would block itself here.
|
|
go modules.Shutdown() //nolint:errcheck
|
|
return "shutdown initiated", nil
|
|
}
|
|
|
|
// restart restarts the Portmaster.
|
|
func restart(_ *api.Request) (msg string, err error) {
|
|
log.Info("core: user requested restart via action")
|
|
updates.RestartNow()
|
|
return "restart initiated", nil
|
|
}
|