Skip to content

Commit 9bebdd1

Browse files
Merge pull request #8892 from inverse-inc/fix/consistency_enabled_1
Use sharedutils.IsEnabled for consistency
2 parents f232498 + e9b1e24 commit 9bebdd1

File tree

8 files changed

+20
-32
lines changed

8 files changed

+20
-32
lines changed

go/cmd/pfacct/pfacct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (pfAcct *PfAcct) SetupConfig(ctx context.Context) {
145145
keyConfAdvanced.PfconfigNS = "config::Pf"
146146
keyConfAdvanced.PfconfigHostnameOverlay = "yes"
147147
pfconfigdriver.FetchDecodeSocket(ctx, &keyConfAdvanced)
148-
pfAcct.AllNetworks = keyConfAdvanced.NetFlowOnAllNetworks == "enabled"
148+
pfAcct.AllNetworks = sharedutils.IsEnabled(keyConfAdvanced.NetFlowOnAllNetworks)
149149
var ports pfconfigdriver.PfConfPorts
150150
pfconfigdriver.FetchDecodeSocket(ctx, &ports)
151151
pfAcct.TimeDuration = time.Duration(keyConfAdvanced.AccountingTimebucketSize) * time.Second

go/cmd/pfdhcp/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (d *Interfaces) readConfig(ctx context.Context, MyDB *sql.DB) {
156156
}
157157

158158
// IP per role
159-
if ConfNet.SplitNetwork == "enabled" {
159+
if sharedutils.IsEnabled(ConfNet.SplitNetwork) {
160160
var keyConfRoles pfconfigdriver.PfconfigKeys
161161
keyConfRoles.PfconfigNS = "config::Roles"
162162

@@ -284,7 +284,7 @@ func (d *Interfaces) readConfig(ctx context.Context, MyDB *sql.DB) {
284284
options[dhcp.OptionDomainNameServer] = []byte(DHCPScope.ip.To4())
285285
options[dhcp.OptionRouter] = []byte(DHCPScope.ip.To4())
286286
options[dhcp.OptionDomainName] = []byte(ConfNet.DomainName)
287-
if portal.SecureRedirect == "enabled" {
287+
if sharedutils.IsEnabled(portal.SecureRedirect) {
288288
options[dhcp.OptionCaptivePortal] = []byte(detectPortalURL(ConfNet, general))
289289
}
290290
DHCPScope.options = options
@@ -365,7 +365,7 @@ func (d *Interfaces) readConfig(ctx context.Context, MyDB *sql.DB) {
365365
options[dhcp.OptionDomainNameServer] = ShuffleDNS(ctx, ConfNet)
366366
options[dhcp.OptionRouter] = ShuffleGateway(ctx, ConfNet)
367367
options[dhcp.OptionDomainName] = []byte(ConfNet.DomainName)
368-
if portal.SecureRedirect == "enabled" {
368+
if sharedutils.IsEnabled(portal.SecureRedirect) {
369369
options[dhcp.OptionCaptivePortal] = []byte(detectPortalURL(ConfNet, general))
370370
}
371371
DHCPScope.options = options

go/cmd/pfstats/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func main() {
304304
source.PfconfigNS = "resource::authentication_sources_ldap"
305305
source.PfconfigHashNS = src
306306
pfconfigdriver.FetchDecodeSocket(ctx, &source)
307-
if source.Monitor == "1" {
307+
if sharedutils.IsEnabled(source.Monitor) {
308308
var Source = TestSource{LDAP}
309309
go Source.SourceType.Test(source, ctx)
310310
}
@@ -324,7 +324,7 @@ func main() {
324324
source.PfconfigNS = "resource::authentication_sources_radius"
325325
source.PfconfigHashNS = src
326326
pfconfigdriver.FetchDecodeSocket(ctx, &source)
327-
if source.Monitor == "1" {
327+
if sharedutils.IsEnabled(source.Monitor) {
328328
var Source = TestSource{RADIUS}
329329
go Source.SourceType.Test(source, ctx)
330330
}

go/cron/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func GetConfiguredJobs(maintConfig map[string]interface{}) []JobSetupConfig {
7676
jobs := []JobSetupConfig{}
7777
for name, config := range maintConfig {
7878
data := config.(map[string]interface{})
79-
if data["status"].(string) == "enabled" {
79+
if sharedutils.IsEnabled(data["status"].(string)) {
8080
if job := BuildJob(name, data); job != nil {
8181
jobs = append(jobs, job)
8282
}

go/firewallsso/base.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,25 @@ func (fw *FirewallSSO) GetFirewallSSO(ctx context.Context) *FirewallSSO {
111111

112112
// Check whether or not the cached updates are enabled for this firewall
113113
func (fw *FirewallSSO) ShouldCacheUpdates(ctx context.Context) bool {
114-
return fw.CacheUpdates == "enabled"
114+
return sharedutils.IsEnabled(fw.CacheUpdates)
115115
}
116116

117117
// Check if sso needs to be triggered on accounting stop
118118
func (fw *FirewallSSO) SendOnAcctStop(ctx context.Context) bool {
119-
return fw.ActOnAccountingStop == "1"
119+
return sharedutils.IsEnabled(fw.ActOnAccountingStop)
120120
}
121121

122122
// Check if sso needs to be triggered on accounting
123123
func (fw *FirewallSSO) SendOnAcct(ctx context.Context) bool {
124-
return fw.SsoOnAccounting == "1"
124+
return sharedutils.IsEnabled(fw.SsoOnAccounting)
125125
}
126126

127127
// Check if sso needs to be triggered on Access Reevaluation
128128
func (fw *FirewallSSO) SendOnAccessReevaluation(ctx context.Context) bool {
129-
return fw.SsoOnAccessReevaluation == "1"
129+
return sharedutils.IsEnabled(fw.SsoOnAccessReevaluation)
130130
}
131131
func (fw *FirewallSSO) SendOnDhcp(ctx context.Context) bool {
132-
return fw.SsoOnDhcp == "1"
132+
return sharedutils.IsEnabled(fw.SsoOnDhcp)
133133
}
134134

135135
// Get the cache_timeout configured in the firewall as an int

go/httpdispatcher/proxy.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,7 @@ func (p *Proxy) Configure(ctx context.Context) {
330330

331331
parking := pfconfigdriver.GetType[pfconfigdriver.PfConfParking](ctx)
332332

333-
if parking.ShowParkingPortal == "enabled" {
334-
p.ShowParkingPortal = true
335-
} else {
336-
p.ShowParkingPortal = false
337-
}
333+
p.ShowParkingPortal = sharedutils.IsEnabled(parking.ShowParkingPortal)
338334

339335
go func() {
340336
for {
@@ -371,24 +367,19 @@ func (p *passthrough) readConfig(ctx context.Context) {
371367
p.addOtherDomainsToList(ctx, v)
372368
}
373369

374-
p.DetectionMecanismBypass = portal.DetectionMecanismBypass == "enabled"
370+
p.DetectionMecanismBypass = sharedutils.IsEnabled(portal.DetectionMecanismBypass)
375371

376372
rgx, _ := regexp.Compile("CaptiveNetworkSupport")
377373
p.URIException = rgx
378374

379-
if portal.SecureRedirect == "enabled" {
380-
p.SecureRedirect = true
375+
p.SecureRedirect = sharedutils.IsEnabled(portal.SecureRedirect)
376+
if p.SecureRedirect {
381377
scheme = "https"
382378
} else {
383-
p.SecureRedirect = false
384379
scheme = "http"
385380
}
386381

387-
if portal.WisprRedirection == "enabled" {
388-
p.Wispr = true
389-
} else {
390-
p.Wispr = false
391-
}
382+
p.Wispr = sharedutils.IsEnabled(portal.WisprRedirection)
392383

393384
index := 0
394385

go/plugin/coredns/pfdns/pfconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func newPfconfigRefreshableConfig(ctx context.Context) *pfdnsRefreshableConfig {
3939
pfconfigdriver.FetchDecodeSocket(ctx, &rc.PfConfDns)
4040
rc.PassthroughsInit(ctx)
4141
rc.PassthroughsIsolationInit(ctx)
42-
rc.recordDNS = rc.PfConfDns.RecordDNS == "enabled"
42+
rc.recordDNS = sharedutils.IsEnabled(rc.PfConfDns.RecordDNS)
4343
return rc
4444
}
4545

@@ -86,7 +86,7 @@ func (rc *pfdnsRefreshableConfig) Refresh(ctx context.Context) {
8686
rc.PassthroughsInit(ctx)
8787
rc.PassthroughsIsolationInit(ctx)
8888

89-
rc.recordDNS = rc.PfConfDns.RecordDNS == "enabled"
89+
rc.recordDNS = sharedutils.IsEnabled(rc.PfConfDns.RecordDNS)
9090
}
9191

9292
func (rc *pfdnsRefreshableConfig) Clone() pfconfigdriver.Refresh {

go/plugin/coredns/pfdns/pfdns.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,7 @@ func (pf *pfdns) MakeDetectionMecanism(ctx context.Context) error {
736736

737737
pfconfigdriver.FetchDecodeSocket(ctx, &portal)
738738

739-
pf.detectionBypass = false
740-
if portal.DetectionMecanismBypass == "enabled" {
741-
pf.detectionBypass = true
742-
}
739+
pf.detectionBypass = sharedutils.IsEnabled(portal.DetectionMecanismBypass)
743740

744741
pf.detectionMechanisms = make([]*regexp.Regexp, 0)
745742
var err error

0 commit comments

Comments
 (0)