From 5a9e8eebe8fbfcdac7c62a8d3014639bef8530d1 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 10 Oct 2023 17:27:57 -0500 Subject: [PATCH] Add script to check if CasaOS is blocked by ufw --- casaos-check-if-blocked-by-ufw/README.md | 5 +++ casaos-check-if-blocked-by-ufw/run.sh | 47 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 casaos-check-if-blocked-by-ufw/README.md create mode 100644 casaos-check-if-blocked-by-ufw/run.sh diff --git a/casaos-check-if-blocked-by-ufw/README.md b/casaos-check-if-blocked-by-ufw/README.md new file mode 100644 index 0000000..40c5b3e --- /dev/null +++ b/casaos-check-if-blocked-by-ufw/README.md @@ -0,0 +1,5 @@ +# Run command + +```bash +bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/casaos-check-if-blocked-by-ufw/run.sh)" +``` diff --git a/casaos-check-if-blocked-by-ufw/run.sh b/casaos-check-if-blocked-by-ufw/run.sh new file mode 100644 index 0000000..b7a51d1 --- /dev/null +++ b/casaos-check-if-blocked-by-ufw/run.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# Path to the configuration file +CONFIG_FILE="/etc/casaos/gateway.ini" + +# Check if the configuration file exists +if [[ -f $CONFIG_FILE ]]; then + # Use grep to find the line with 'port' and use awk to print the value + PORT=$(grep '^port=' $CONFIG_FILE | awk -F'=' '{print $2}') + # Get the local IP address + IP_ADDR=$(hostname -I | awk '{print $1}') + echo "The local IP address is: $IP_ADDR" + echo "The port number is: $PORT" + echo "You can access it in the browser at: http://$IP_ADDR:$PORT" + + # Check if UFW is active + UFW_ACTIVE=$(sudo ufw status | grep "Status: active") + + if [[ ! -z $UFW_ACTIVE ]]; then + # If UFW is active, check if the port is listed in the UFW status + UFW_PORT_STATUS=$(sudo ufw status | grep "$PORT") + + # If port is not listed or if it's listed as DENY, it's considered blocked + if [[ -z $UFW_PORT_STATUS || $UFW_PORT_STATUS == *DENY* ]]; then + echo "The port $PORT is blocked by UFW." + + # Ask the user if they want to unblock the port + read -p "Do you want to unblock port $PORT in UFW? (yes/no): " choice + case "$choice" in + yes|y|Y|YES) + sudo ufw allow $PORT + echo "Port $PORT has been unblocked in UFW." + ;; + *) + echo "Port remains blocked." + ;; + esac + else + echo "The port $PORT is not blocked by UFW." + fi + else + echo "UFW is not active." + fi + +else + echo "Error: Configuration file not found." +fi