mnemo_cards/mnemo_cards_web_v2/deploy/test-forgejo-domain.sh
2025-11-16 16:16:01 +03:00

171 lines
5.9 KiB
Bash
Executable file

#!/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 HTTP IP access is blocked
print_status "Testing that HTTP IP access is blocked..."
HTTP_IP_BLOCK_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 http://147.45.152.129/)
if [ "$HTTP_IP_BLOCK_STATUS" = "444" ] || [ "$HTTP_IP_BLOCK_STATUS" = "000" ]; then
print_success "HTTP IP access blocked: $HTTP_IP_BLOCK_STATUS"
else
print_warning "HTTP IP access not blocked: $HTTP_IP_BLOCK_STATUS (should be 444)"
fi
# Test that HTTPS IP access is blocked
print_status "Testing that HTTPS IP access is blocked..."
HTTPS_IP_BLOCK_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 --insecure https://147.45.152.129/)
if [ "$HTTPS_IP_BLOCK_STATUS" = "444" ] || [ "$HTTPS_IP_BLOCK_STATUS" = "000" ]; then
print_success "HTTPS IP access blocked: $HTTPS_IP_BLOCK_STATUS"
else
print_warning "HTTPS IP access not blocked: $HTTPS_IP_BLOCK_STATUS (should be 444)"
fi
# Test that direct port 3000 access is blocked
print_status "Testing that direct port 3000 access is blocked..."
PORT_3000_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 http://147.45.152.129:3000/)
if [ "$PORT_3000_STATUS" = "000" ]; then
print_success "Direct port 3000 access blocked: $PORT_3000_STATUS"
else
print_warning "Direct port 3000 access not blocked: $PORT_3000_STATUS (should be connection failed)"
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"