mirror of
https://github.com/safing/portmaster
synced 2025-09-01 18:19:12 +00:00
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package status
|
|
|
|
import (
|
|
"github.com/safing/portbase/database"
|
|
"github.com/safing/portbase/database/query"
|
|
"github.com/safing/portbase/database/record"
|
|
)
|
|
|
|
const (
|
|
statusDBKey = "core:status/status"
|
|
)
|
|
|
|
var (
|
|
statusDB = database.NewInterface(nil)
|
|
hook *database.RegisteredHook
|
|
)
|
|
|
|
type statusHook struct {
|
|
database.HookBase
|
|
}
|
|
|
|
// UsesPrePut implements the Hook interface.
|
|
func (sh *statusHook) UsesPrePut() bool {
|
|
return true
|
|
}
|
|
|
|
// PrePut implements the Hook interface.
|
|
func (sh *statusHook) PrePut(r record.Record) (record.Record, error) {
|
|
// record is already locked!
|
|
|
|
newStatus, err := EnsureSystemStatus(r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// apply applicable settings
|
|
if SelectedSecurityLevel() != newStatus.SelectedSecurityLevel {
|
|
go setSelectedSecurityLevel(newStatus.SelectedSecurityLevel)
|
|
}
|
|
|
|
// TODO: allow setting of Gate17 status (on/off)
|
|
|
|
// return original status
|
|
return status, nil
|
|
}
|
|
|
|
func initStatusHook() (err error) {
|
|
hook, err = database.RegisterHook(query.New(statusDBKey), &statusHook{})
|
|
return err
|
|
}
|
|
|
|
func stopStatusHook() error {
|
|
return hook.Cancel()
|
|
}
|