Fix a few firewall bugs.
This commit is contained in:
+29
-2
@@ -12,6 +12,27 @@ ufw_status_output() {
|
|||||||
sudo "${sudoFlags[@]}" ufw status 2>&1
|
sudo "${sudoFlags[@]}" ufw status 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sudo_ready_noninteractive() {
|
||||||
|
# `sudoFlags` is initialized by the main launcher before sourcing this file.
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
sudo "${sudoFlags[@]}" -n true &> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
ufw_status_output_noninteractive() {
|
||||||
|
# `sudoFlags` is initialized by the main launcher before sourcing this file.
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
sudo "${sudoFlags[@]}" -n ufw status 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
warn_sudo_authentication() {
|
||||||
|
if sudo_ready_noninteractive; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
msgbox "This firewall action may require sudo authentication. If you hear the password prompt sound, enter your password and press Enter."
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
firewall_reboot_required() {
|
firewall_reboot_required() {
|
||||||
[[ ! -d "/lib/modules/$(uname -r)" ]]
|
[[ ! -d "/lib/modules/$(uname -r)" ]]
|
||||||
}
|
}
|
||||||
@@ -36,8 +57,12 @@ firewall_enabled() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
statusText="$(ufw_status_output)"
|
if ! sudo_ready_noninteractive; then
|
||||||
[[ "$statusText" =~ ^Status:[[:space:]]+active$ ]]
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
statusText="$(ufw_status_output_noninteractive)"
|
||||||
|
grep -q '^Status: active$' <<< "$statusText"
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_ufw() {
|
ensure_ufw() {
|
||||||
@@ -50,6 +75,7 @@ ensure_ufw() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
warn_sudo_authentication
|
||||||
if ! install_package ufw; then
|
if ! install_package ufw; then
|
||||||
msgbox "Failed to install ufw."
|
msgbox "Failed to install ufw."
|
||||||
return 1
|
return 1
|
||||||
@@ -152,6 +178,7 @@ allow_ssh_port() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn_sudo_authentication
|
||||||
allow_rule "${sshPort}/tcp" "SSH port ${sshPort}/tcp"
|
allow_rule "${sshPort}/tcp" "SSH port ${sshPort}/tcp"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user