Skip to content

Commit d3e2826

Browse files
authored
update firewall module to use sudo ufw status properly (#1700)
* update firewall module to use sudo ufw status properly * update with gofmt -s output (spacing issue)
1 parent 2eccc3b commit d3e2826

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

modules/security/firewall.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,22 @@ func FirewallStealthState() string {
4444

4545
func firewallStateLinux() string { // might be very Ubuntu specific
4646
user, _ := user.Current()
47+
cmd := exec.Command("sudo", "/usr/sbin/ufw", "status")
4748

4849
if strings.Contains(user.Username, "root") {
49-
cmd := exec.Command("ufw", "status")
50-
51-
var o bytes.Buffer
52-
cmd.Stdout = &o
53-
if err := cmd.Run(); err != nil {
54-
return "[red]NA[white]"
55-
}
56-
57-
if strings.Contains(o.String(), "inactive") {
58-
return "[red]Disabled[white]"
59-
} else {
60-
return "[green]Enabled[white]"
61-
}
50+
cmd = exec.Command("ufw", "status")
51+
}
52+
53+
var o bytes.Buffer
54+
cmd.Stdout = &o
55+
if err := cmd.Run(); err != nil {
56+
return "[red]NA[white]"
57+
}
58+
59+
if strings.Contains(o.String(), "inactive") {
60+
return "[red]Disabled[white]"
6261
} else {
63-
return "[red]N/A[white]"
62+
return "[green]Enabled[white]"
6463
}
6564
}
6665

0 commit comments

Comments
 (0)