#!/bin/bash # Test script for Forgejo domain setup # Usage: ./test-forgejo-domain.sh set -e # Load configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/config.sh" echo "๐Ÿงช Testing Forgejo domain setup..." # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color print_status() { echo -e "${GREEN}[INFO]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_info() { echo -e "${BLUE}[INFO]${NC} $1" } # Test DNS resolution print_status "Testing DNS resolution for code.mnemo-cards.online..." DNS_IP=$(dig +short code.mnemo-cards.online A) if [ "$DNS_IP" = "$SERVER_IP" ]; then print_success "DNS resolution: code.mnemo-cards.online -> $DNS_IP โœ“" else print_warning "DNS resolution: code.mnemo-cards.online -> $DNS_IP (expected: $SERVER_IP)" print_warning "Make sure DNS is properly configured!" fi # Test HTTP redirect to HTTPS print_status "Testing HTTP redirect to HTTPS..." HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://code.mnemo-cards.online/) if [ "$HTTP_STATUS" = "301" ]; then print_success "HTTP redirect: $HTTP_STATUS (redirect to HTTPS) โœ“" else print_warning "HTTP redirect: $HTTP_STATUS (expected: 301)" fi # Test HTTPS access print_status "Testing HTTPS access to code.mnemo-cards.online..." HTTPS_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --insecure https://code.mnemo-cards.online/) if [ "$HTTPS_STATUS" = "200" ]; then print_success "HTTPS access: $HTTPS_STATUS โœ“" elif [ "$HTTPS_STATUS" = "000" ]; then print_error "HTTPS access: Connection failed (check if nginx is running and SSL is configured)" else print_warning "HTTPS access: $HTTPS_STATUS (may be normal for Forgejo auth redirects)" fi # Test that IP access is blocked print_status "Testing that IP access is blocked..." IP_BLOCK_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 https://147.45.152.129/) if [ "$IP_BLOCK_STATUS" = "444" ] || [ "$IP_BLOCK_STATUS" = "000" ]; then print_success "IP access blocked: $IP_BLOCK_STATUS โœ“" else print_warning "IP access not blocked: $IP_BLOCK_STATUS (should be 444)" fi # Test SSL certificate print_status "Testing SSL certificate..." SSL_INFO=$(openssl s_client -connect code.mnemo-cards.online:443 -servername code.mnemo-cards.online < /dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -dates 2>/dev/null) if [ $? -eq 0 ]; then print_success "SSL certificate is valid โœ“" echo "$SSL_INFO" | head -3 else print_error "SSL certificate validation failed" fi # Test server connectivity print_status "Testing server connectivity..." ssh -o ConnectTimeout=10 -o BatchMode=yes "$SERVER_USER@$SERVER_IP" "echo 'SSH connection successful'" 2>/dev/null if [ $? -eq 0 ]; then print_success "SSH connection to server: OK โœ“" else print_error "SSH connection to server: FAILED" fi # Test nginx configuration on server print_status "Testing nginx configuration on server..." ssh "$SERVER_USER@$SERVER_IP" << EOF # Test nginx config if nginx -t 2>/dev/null; then echo "โœ… Nginx configuration: VALID" else echo "โŒ Nginx configuration: INVALID" exit 1 fi # Check if Forgejo site is enabled if [ -L "/etc/nginx/sites-enabled/forgejo" ]; then echo "โœ… Forgejo nginx site: ENABLED" else echo "โŒ Forgejo nginx site: NOT ENABLED" fi # Check if Forgejo is running if pgrep -f "gitea" > /dev/null || pgrep -f "forgejo" > /dev/null; then echo "โœ… Forgejo process: RUNNING" else echo "โš ๏ธ Forgejo process: NOT FOUND (check if Forgejo is started)" fi # Check SSL certificate if [ -f "/etc/letsencrypt/live/code.mnemo-cards.online/fullchain.pem" ]; then echo "โœ… Let's Encrypt certificate: EXISTS" else echo "โš ๏ธ Let's Encrypt certificate: NOT FOUND (using self-signed?)" fi # Check Forgejo ROOT_URL configuration FORGEJO_CONFIG="" for config_path in "/etc/forgejo/app.ini" "/home/forgejo/custom/conf/app.ini" "/var/lib/forgejo/custom/conf/app.ini" "/opt/forgejo/custom/conf/app.ini"; do if [ -f "$config_path" ]; then FORGEJO_CONFIG="$config_path" break fi done if [ -n "$FORGEJO_CONFIG" ]; then ROOT_URL=$(grep "^ROOT_URL" "$FORGEJO_CONFIG" | cut -d'=' -f2 | tr -d ' ') if [ "$ROOT_URL" = "https://code.mnemo-cards.online" ]; then echo "โœ… Forgejo ROOT_URL: CORRECT ($ROOT_URL)" else echo "โŒ Forgejo ROOT_URL: INCORRECT ($ROOT_URL) - should be https://code.mnemo-cards.online" fi else echo "โš ๏ธ Forgejo config: NOT FOUND" fi EOF print_info "Forgejo domain test completed!" print_info "If everything looks good, Forgejo should be accessible at: https://code.mnemo-cards.online"