mirror of
https://github.com/safing/portmaster
synced 2025-04-22 20:09:09 +00:00
Adapt and update status package
This commit is contained in:
parent
c146c99273
commit
247c7dca00
3 changed files with 40 additions and 20 deletions
|
@ -2,10 +2,16 @@ package status
|
|||
|
||||
// Definitions of Security and Status Levels
|
||||
const (
|
||||
SecurityLevelOff uint8 = 0
|
||||
SecurityLevelOff uint8 = 0
|
||||
|
||||
SecurityLevelDynamic uint8 = 1
|
||||
SecurityLevelSecure uint8 = 2
|
||||
SecurityLevelFortress uint8 = 3
|
||||
SecurityLevelFortress uint8 = 4
|
||||
|
||||
SecurityLevelsDynamicAndSecure uint8 = SecurityLevelDynamic | SecurityLevelSecure
|
||||
SecurityLevelsDynamicAndFortress uint8 = SecurityLevelDynamic | SecurityLevelFortress
|
||||
SecurityLevelsSecureAndFortress uint8 = SecurityLevelSecure | SecurityLevelFortress
|
||||
SecurityLevelsAll uint8 = SecurityLevelDynamic | SecurityLevelSecure | SecurityLevelFortress
|
||||
|
||||
StatusOff uint8 = 0
|
||||
StatusError uint8 = 1
|
||||
|
|
|
@ -27,23 +27,37 @@ type SystemStatus struct {
|
|||
Gate17StatusMsg string `json:",omitempty" bson:",omitempty"`
|
||||
}
|
||||
|
||||
// FmtSecurityLevel returns the current security level as a string.
|
||||
func FmtSecurityLevel() string {
|
||||
// FmtCurrentSecurityLevel returns the current security level as a string.
|
||||
func FmtCurrentSecurityLevel() string {
|
||||
current := CurrentSecurityLevel()
|
||||
selected := SelectedSecurityLevel()
|
||||
var s string
|
||||
switch current {
|
||||
case SecurityLevelOff:
|
||||
s = "Off"
|
||||
case SecurityLevelDynamic:
|
||||
s = "Dynamic"
|
||||
case SecurityLevelSecure:
|
||||
s = "Secure"
|
||||
case SecurityLevelFortress:
|
||||
s = "Fortress"
|
||||
}
|
||||
s := FmtSecurityLevel(current)
|
||||
if current != selected {
|
||||
s += "*"
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// FmtSecurityLevel returns the given security level as a string.
|
||||
func FmtSecurityLevel(level uint8) string {
|
||||
switch level {
|
||||
case SecurityLevelOff:
|
||||
return "Off"
|
||||
case SecurityLevelDynamic:
|
||||
return "Dynamic"
|
||||
case SecurityLevelSecure:
|
||||
return "Secure"
|
||||
case SecurityLevelFortress:
|
||||
return "Fortress"
|
||||
case SecurityLevelsDynamicAndSecure:
|
||||
return "Dynamic and Secure"
|
||||
case SecurityLevelsDynamicAndFortress:
|
||||
return "Dynamic and Fortress"
|
||||
case SecurityLevelsSecureAndFortress:
|
||||
return "Secure and Fortress"
|
||||
case SecurityLevelsAll:
|
||||
return "Dynamic, Secure and Fortress"
|
||||
default:
|
||||
return "INVALID"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,30 +6,30 @@ func TestStatus(t *testing.T) {
|
|||
|
||||
SetCurrentSecurityLevel(SecurityLevelOff)
|
||||
SetSelectedSecurityLevel(SecurityLevelOff)
|
||||
if FmtSecurityLevel() != "Off" {
|
||||
if FmtCurrentSecurityLevel() != "Off" {
|
||||
t.Error("unexpected string representation")
|
||||
}
|
||||
|
||||
SetCurrentSecurityLevel(SecurityLevelDynamic)
|
||||
SetSelectedSecurityLevel(SecurityLevelDynamic)
|
||||
if FmtSecurityLevel() != "Dynamic" {
|
||||
if FmtCurrentSecurityLevel() != "Dynamic" {
|
||||
t.Error("unexpected string representation")
|
||||
}
|
||||
|
||||
SetCurrentSecurityLevel(SecurityLevelSecure)
|
||||
SetSelectedSecurityLevel(SecurityLevelSecure)
|
||||
if FmtSecurityLevel() != "Secure" {
|
||||
if FmtCurrentSecurityLevel() != "Secure" {
|
||||
t.Error("unexpected string representation")
|
||||
}
|
||||
|
||||
SetCurrentSecurityLevel(SecurityLevelFortress)
|
||||
SetSelectedSecurityLevel(SecurityLevelFortress)
|
||||
if FmtSecurityLevel() != "Fortress" {
|
||||
if FmtCurrentSecurityLevel() != "Fortress" {
|
||||
t.Error("unexpected string representation")
|
||||
}
|
||||
|
||||
SetSelectedSecurityLevel(SecurityLevelDynamic)
|
||||
if FmtSecurityLevel() != "Fortress*" {
|
||||
if FmtCurrentSecurityLevel() != "Fortress*" {
|
||||
t.Error("unexpected string representation")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue