Add support to enable/disable the network rating system
This commit is contained in:
38
status/config.go
Normal file
38
status/config.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package status
|
||||
|
||||
import "github.com/safing/portbase/config"
|
||||
|
||||
var (
|
||||
CfgEnableNetworkRatingSystemKey = "core/enableNetworkRating"
|
||||
cfgEnableNetworkRatingSystem config.BoolOption
|
||||
)
|
||||
|
||||
func registerConfig() error {
|
||||
if err := config.Register(&config.Option{
|
||||
Name: "Enable Network Rating System",
|
||||
Key: CfgEnableNetworkRatingSystemKey,
|
||||
Description: "Enables the Network Rating System, which allows you to quickly increase security and privacy throughout the settings by changing your the network rating level in the top left. Please note that this feature is now in the sunset phase and will be replaced by a superior and easier to understand system in the future.",
|
||||
OptType: config.OptTypeBool,
|
||||
ExpertiseLevel: config.ExpertiseLevelExpert,
|
||||
ReleaseLevel: config.ReleaseLevelExperimental,
|
||||
DefaultValue: false,
|
||||
Annotations: config.Annotations{
|
||||
config.DisplayOrderAnnotation: 514,
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
cfgEnableNetworkRatingSystem = config.Concurrent.GetAsBool(CfgEnableNetworkRatingSystemKey, false)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NetworkRatingEnabled returns true if the network rating system has been enabled.
|
||||
func NetworkRatingEnabled() bool {
|
||||
return cfgEnableNetworkRatingSystem()
|
||||
}
|
||||
|
||||
// SetNetworkRating enables or disables the network rating system.
|
||||
func SetNetworkRating(enabled bool) {
|
||||
config.SetConfigOption(CfgEnableNetworkRatingSystemKey, enabled)
|
||||
}
|
||||
@@ -14,7 +14,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
module = modules.Register("status", nil, start, nil, "base")
|
||||
module = modules.Register("status", prepare, start, nil, "base", "config")
|
||||
}
|
||||
|
||||
func start() error {
|
||||
@@ -26,7 +26,7 @@ func start() error {
|
||||
|
||||
triggerAutopilot()
|
||||
|
||||
err := module.RegisterEventHook(
|
||||
if err := module.RegisterEventHook(
|
||||
netenv.ModuleName,
|
||||
netenv.OnlineStatusChangedEvent,
|
||||
"update online status in system status",
|
||||
@@ -34,8 +34,30 @@ func start() error {
|
||||
triggerAutopilot()
|
||||
return nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := module.RegisterEventHook(
|
||||
"config",
|
||||
"config change",
|
||||
"Update network rating system",
|
||||
func(_ context.Context, _ interface{}) error {
|
||||
if !NetworkRatingEnabled() && ActiveSecurityLevel() != SecurityLevelNormal {
|
||||
setSelectedLevel(SecurityLevelNormal)
|
||||
triggerAutopilot()
|
||||
}
|
||||
return nil
|
||||
},
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func prepare() error {
|
||||
if err := registerConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,12 @@ func setSelectedSecurityLevel(r record.Record) (record.Record, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// if the network rating system is not used at all we always force the security
|
||||
// level to trusted.
|
||||
if !NetworkRatingEnabled() {
|
||||
upd.SelectedSecurityLevel = SecurityLevelNormal
|
||||
}
|
||||
|
||||
if !IsValidSecurityLevel(upd.SelectedSecurityLevel) {
|
||||
return nil, fmt.Errorf("invalid security level: %d", upd.SelectedSecurityLevel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user