From 7c38996391a0f7c4ff062bc68fcffe261d367d73 Mon Sep 17 00:00:00 2001 From: Christopher <1289128+dragonfire1119@users.noreply.github.com> Date: Sat, 5 Oct 2024 11:45:44 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(casaos-healthcheck):=20Add=20D?= =?UTF-8?q?ocker=20port=20check=20and=20improve=20version=20display=20(#11?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces the following changes: 1. Adds a new function `check_docker_ports` to the `casaos-healthcheck/run.sh` script. This function checks if Docker is installed and running, and if UFW (Uncomplicated Firewall) is installed and active. It then retrieves all running Docker containers and checks if the ports exposed by these containers are allowed by the UFW rules. If a port is not allowed, a warning is displayed. 2. Updates the version display in the `print_header` function from "BigBearCasaOS Healthcheck V3.0" to "BigBearCasaOS Healthcheck V3.1". The Docker port check is an important addition to the healthcheck script, as it helps identify potential issues with firewall rules that may be blocking Docker container ports. This can be especially useful in troubleshooting network-related problems. The version update reflects the changes introduced in this commit. --- casaos-healthcheck/run.sh | 44 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/casaos-healthcheck/run.sh b/casaos-healthcheck/run.sh index 3eb34bb..42c0fdb 100644 --- a/casaos-healthcheck/run.sh +++ b/casaos-healthcheck/run.sh @@ -287,6 +287,45 @@ check_system_updates() { fi } +check_docker_ports() { + print_header "Docker Container Port Check" + + # Check if Docker is installed and running + if ! command -v docker &> /dev/null || ! docker info &> /dev/null; then + print_color "0;33" "${WARNING_MARK} Docker is not installed or not running. Skipping Docker port check." + return + fi + + # Check if UFW is installed and active + if ! command -v ufw &> /dev/null || ! ufw status | grep -q "Status: active"; then + print_color "0;33" "${WARNING_MARK} UFW is not installed or not active. Skipping firewall check for Docker ports." + return + fi + + # Get UFW rules + ufw_rules=$(sudo ufw status | grep -E '^[0-9]+' | awk '{print $1}') + + # Get all running Docker containers + containers=$(docker ps --format "{{.Names}}") + + for container in $containers; do + # Get port mappings for each container + ports=$(docker port $container | awk '{print $3}' | cut -d ':' -f2) + + for port in $ports; do + if echo "$ufw_rules" | grep -q "^$port$"; then + print_color "0;32" "${CHECK_MARK} Port $port for container $container is allowed by UFW." + else + print_color "0;31" "${CROSS_MARK} Port $port for container $container might be blocked by UFW." + fi + done + done + + echo + print_color "0;33" "Note: Please manually verify UFW rules for more complex configurations." + echo " You can do this by running 'sudo ufw status verbose'" +} + # Main execution if [[ "$1" == "simulated_test" ]]; then echo "Running in simulated test mode..." @@ -303,7 +342,7 @@ elif [[ "$1" == "real_test" ]]; then else # Normal script execution # Display Welcome - print_header "BigBearCasaOS Healthcheck V3.0" + print_header "BigBearCasaOS Healthcheck V3.1" echo "Here are some links:" echo "https://community.bigbeartechworld.com" echo "https://github.com/BigBearTechWorld" @@ -352,6 +391,9 @@ else print_color "0;31" "${CROSS_MARK} Error: Configuration file not found." fi + # Docker port check + check_docker_ports + # DNS resolution check for Docker registries check_dns_resolution