From 3b97694bd763508aa05f88b41d68d79e57fa4a70 Mon Sep 17 00:00:00 2001 From: Shaygan <shayganshok0@gmail.com> Date: Mon, 25 Jan 2021 18:39:54 +0330 Subject: [PATCH 1/3] Add "Adding IPs to the Firewall" text --- src/ar-whitelister.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ar-whitelister.sh b/src/ar-whitelister.sh index 8cde4ad..9d28281 100755 --- a/src/ar-whitelister.sh +++ b/src/ar-whitelister.sh @@ -37,10 +37,12 @@ else fi clear +echo "Adding IPs to the selected Firewall" + # Process user input case "$option" in 1 | ufw) - if [ ! -x "$(command -v ufw)" ]; then + if [[ ! -x "$(command -v ufw)" ]]; then abort "ufw is not installed." fi @@ -50,7 +52,7 @@ case "$option" in sudo ufw reload ;; 2 | csf) - if [ ! -x "$(command -v csf)" ]; then + if [[ ! -x "$(command -v csf)" ]]; then abort "csf is not installed." fi @@ -60,7 +62,7 @@ case "$option" in sudo csf -r ;; 3 | firewalld) - if [ ! -x "$(command -v firewall-cmd)" ]; then + if [[ ! -x "$(command -v firewall-cmd)" ]]; then abort "firewalld is not installed." fi -- GitLab From 265810f19cd706706566a2afb2581bf5ba472da4 Mon Sep 17 00:00:00 2001 From: Shaygan <shayganshok0@gmail.com> Date: Mon, 25 Jan 2021 18:55:05 +0330 Subject: [PATCH 2/3] Abort the script if endpoint's status code wasn't 200 --- src/ar-whitelister.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ar-whitelister.sh b/src/ar-whitelister.sh index 9d28281..e6fed64 100755 --- a/src/ar-whitelister.sh +++ b/src/ar-whitelister.sh @@ -24,17 +24,27 @@ fi clear -IPsLink="https://www.arvancloud.com/fa/ips.txt" - echo "Downloading Arvancloud IPs list..." -if [ -x "$(command -v curl)" ]; then - IPs=$(curl -s ${IPsLink}) -elif [ -x "$(command -v wget)" ]; then - IPs=$(wget -q -O - ${IPsLink}) +IPsLink="https://www.arvancloud.com/fa/ips.txt" +IPsFile=$(mktemp /tmp/ar-ips.XXXXXX) +# Delete the temp file if the script stopped for any reason +trap 'rm -f ${IPsFile}' 0 2 3 15 + +if [[ ! -x "$(command -v curl)" ]]; then + downloadStatus=$(curl "${IPsLink}" -o "${IPsFile}" -L -s -w "%{http_code}\n") +elif [[ -x "$(command -v wget)" ]]; then + downloadStatus=$(wget "${IPsLink}" -O "${IPsFile}" --server-response 2>&1 | awk '/^ HTTP/{print $2}' | tail -n1) else abort "curl or wget is required to run this script." fi + +if [[ "$downloadStatus" -ne 200 ]]; then + abort "Downloading the IP list wasn't successful. status code: ${downloadStatus}" +else + IPs=$(cat "$IPsFile") +fi + clear echo "Adding IPs to the selected Firewall" -- GitLab From df89b873a011c42f1c9995381f40ea740393ea03 Mon Sep 17 00:00:00 2001 From: Shaygan <shayganshok0@gmail.com> Date: Mon, 25 Jan 2021 19:01:45 +0330 Subject: [PATCH 3/3] Fix curl checker's condition --- src/ar-whitelister.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ar-whitelister.sh b/src/ar-whitelister.sh index e6fed64..65272a0 100755 --- a/src/ar-whitelister.sh +++ b/src/ar-whitelister.sh @@ -31,7 +31,7 @@ IPsFile=$(mktemp /tmp/ar-ips.XXXXXX) # Delete the temp file if the script stopped for any reason trap 'rm -f ${IPsFile}' 0 2 3 15 -if [[ ! -x "$(command -v curl)" ]]; then +if [[ -x "$(command -v curl)" ]]; then downloadStatus=$(curl "${IPsLink}" -o "${IPsFile}" -L -s -w "%{http_code}\n") elif [[ -x "$(command -v wget)" ]]; then downloadStatus=$(wget "${IPsLink}" -O "${IPsFile}" --server-response 2>&1 | awk '/^ HTTP/{print $2}' | tail -n1) -- GitLab