Skip to content

Commit 2595774

Browse files
authored
chore: update firewall to allow ssh, disable logging, and enable firewall (#66)
1 parent 970fcaa commit 2595774

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

pkg/network/firewall.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,35 @@ import (
1010
// Function to configure the firewall
1111
func ConfigureFirewall() {
1212
spinner, _ := pterm.DefaultSpinner.Start("Configuring firewall...")
13-
exec.Command("ufw", "enable").Run()
13+
// Allow SSH connections
14+
err := exec.Command("ufw", "allow", "ssh").Run()
15+
if err != nil {
16+
pterm.Println()
17+
pterm.Error.Println(fmt.Sprintf("Failed to allow SSH: %v", err))
18+
os.Exit(1)
19+
}
1420

1521
// Allow HTTP and HTTPS traffic
16-
err := exec.Command("ufw", "allow", "Nginx Full").Run()
22+
err = exec.Command("ufw", "allow", "Nginx Full").Run()
1723
if err != nil {
1824
pterm.Println()
1925
pterm.Error.Println(fmt.Sprintf("Failed to allow Nginx Full: %v", err))
2026
os.Exit(1)
2127
}
2228

23-
// Reload the firewall to apply the changes
24-
err = exec.Command("ufw", "reload").Run()
29+
// Disable logging
30+
err = exec.Command("ufw", "logging", "off").Run()
31+
if err != nil {
32+
pterm.Println()
33+
pterm.Error.Println(fmt.Sprintf("Failed to disable logging: %v", err))
34+
os.Exit(1)
35+
}
36+
37+
// Enable the firewall to apply the changes
38+
err = exec.Command("ufw", "--force", "enable").Run()
2539
if err != nil {
2640
pterm.Println()
27-
pterm.Error.Println(fmt.Sprintf("Failed to reload firewall: %v", err))
41+
pterm.Error.Println(fmt.Sprintf("Failed to enable firewall: %v", err))
2842
os.Exit(1)
2943
}
3044

0 commit comments

Comments
 (0)