#!/bin/bash

echo "Checking domain status..."
echo "---------------------------------------------"

for domain in $(cut -d: -f1 /etc/userdomains)
do
    status=$(curl -o /dev/null -s -w "%{http_code}" --connect-timeout 10 http://$domain)

    if [ "$status" == "200" ]; then
        echo "$domain : WORKING FINE (200)"
    elif [ "$status" == "301" ] || [ "$status" == "302" ]; then
        echo "$domain : REDIRECT ($status)"
    elif [ "$status" == "403" ]; then
        echo "$domain : FORBIDDEN (403)"
    elif [ "$status" == "404" ]; then
        echo "$domain : NOT FOUND (404)"
    elif [ "$status" == "500" ]; then
        echo "$domain : INTERNAL SERVER ERROR (500)"
    elif [ "$status" == "000" ]; then
        echo "$domain : CONNECTION FAILED"
    else
        echo "$domain : OTHER ERROR ($status)"
    fi
done

echo "---------------------------------------------"
echo "Check completed"
