@@ -10,21 +10,35 @@ import (
10
10
// Function to configure the firewall
11
11
func ConfigureFirewall () {
12
12
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
+ }
14
20
15
21
// Allow HTTP and HTTPS traffic
16
- err : = exec .Command ("ufw" , "allow" , "Nginx Full" ).Run ()
22
+ err = exec .Command ("ufw" , "allow" , "Nginx Full" ).Run ()
17
23
if err != nil {
18
24
pterm .Println ()
19
25
pterm .Error .Println (fmt .Sprintf ("Failed to allow Nginx Full: %v" , err ))
20
26
os .Exit (1 )
21
27
}
22
28
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 ()
25
39
if err != nil {
26
40
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 ))
28
42
os .Exit (1 )
29
43
}
30
44
0 commit comments