debug-websocket.sh raw

   1  #!/bin/bash
   2  # WebSocket Debug Script for Stella's Orly Relay
   3  
   4  echo "🔍 Debugging WebSocket Connection for orly-relay.imwald.eu"
   5  echo "=================================================="
   6  
   7  echo ""
   8  echo "📋 Step 1: Check if relay container is running"
   9  echo "----------------------------------------------"
  10  docker ps | grep -E "(stella|relay|orly)" || echo "❌ No relay containers found"
  11  
  12  echo ""
  13  echo "📋 Step 2: Test local relay connection"
  14  echo "--------------------------------------"
  15  if curl -s -I http://127.0.0.1:7777 | grep -q "426"; then
  16      echo "✅ Local relay responding correctly (HTTP 426)"
  17  else
  18      echo "❌ Local relay not responding correctly"
  19      curl -I http://127.0.0.1:7777
  20  fi
  21  
  22  echo ""
  23  echo "📋 Step 3: Check Apache modules"
  24  echo "------------------------------"
  25  if apache2ctl -M 2>/dev/null | grep -q "proxy_wstunnel"; then
  26      echo "✅ proxy_wstunnel module enabled"
  27  else
  28      echo "❌ proxy_wstunnel module NOT enabled"
  29      echo "Run: sudo a2enmod proxy_wstunnel"
  30  fi
  31  
  32  if apache2ctl -M 2>/dev/null | grep -q "rewrite"; then
  33      echo "✅ rewrite module enabled"
  34  else
  35      echo "❌ rewrite module NOT enabled"
  36      echo "Run: sudo a2enmod rewrite"
  37  fi
  38  
  39  echo ""
  40  echo "📋 Step 4: Check Plesk Apache configuration"
  41  echo "------------------------------------------"
  42  if [ -f "/etc/apache2/plesk.conf.d/vhosts/orly-relay.imwald.eu.conf" ]; then
  43      echo "✅ Plesk config file exists"
  44      echo "Current proxy configuration:"
  45      grep -E "(Proxy|Rewrite|proxy|rewrite)" /etc/apache2/plesk.conf.d/vhosts/orly-relay.imwald.eu.conf || echo "❌ No proxy/rewrite rules found"
  46  else
  47      echo "❌ Plesk config file not found"
  48  fi
  49  
  50  echo ""
  51  echo "📋 Step 5: Test WebSocket connections"
  52  echo "------------------------------------"
  53  
  54  # Test with curl first (simpler)
  55  echo "Testing HTTP upgrade request to local relay..."
  56  if curl -s -I -H "Connection: Upgrade" -H "Upgrade: websocket" http://127.0.0.1:7777 | grep -q "426\|101"; then
  57      echo "✅ Local relay accepts upgrade requests"
  58  else
  59      echo "❌ Local relay doesn't accept upgrade requests"
  60  fi
  61  
  62  echo "Testing HTTP upgrade request to remote relay..."
  63  if curl -s -I -H "Connection: Upgrade" -H "Upgrade: websocket" https://orly-relay.imwald.eu | grep -q "426\|101"; then
  64      echo "✅ Remote relay accepts upgrade requests"
  65  else
  66      echo "❌ Remote relay doesn't accept upgrade requests"
  67      echo "This indicates Apache proxy issue"
  68  fi
  69  
  70  # Try to install websocat if not available
  71  if ! command -v websocat >/dev/null 2>&1; then
  72      echo ""
  73      echo "📥 Installing websocat for proper WebSocket testing..."
  74      if wget -q https://github.com/vi/websocat/releases/download/v1.12.0/websocat.x86_64-unknown-linux-musl -O websocat 2>/dev/null; then
  75          chmod +x websocat
  76          echo "✅ websocat installed"
  77      else
  78          echo "❌ Could not install websocat (no internet or wget issue)"
  79          echo "Manual install: wget https://github.com/vi/websocat/releases/download/v1.12.0/websocat.x86_64-unknown-linux-musl -O websocat && chmod +x websocat"
  80      fi
  81  fi
  82  
  83  # Test with websocat if available
  84  if command -v ./websocat >/dev/null 2>&1; then
  85      echo ""
  86      echo "Testing actual WebSocket connection..."
  87      echo "Local WebSocket test:"
  88      timeout 3 bash -c 'echo "[\"REQ\",\"test\",{}]" | ./websocat ws://127.0.0.1:7777/' 2>/dev/null || echo "❌ Local WebSocket failed"
  89      
  90      echo "Remote WebSocket test (ignoring SSL):"
  91      timeout 3 bash -c 'echo "[\"REQ\",\"test\",{}]" | ./websocat --insecure wss://orly-relay.imwald.eu/' 2>/dev/null || echo "❌ Remote WebSocket failed"
  92  fi
  93  
  94  echo ""
  95  echo "📋 Step 6: Check ports and connections"
  96  echo "------------------------------------"
  97  echo "Ports listening on 7777:"
  98  netstat -tlnp 2>/dev/null | grep :7777 || ss -tlnp 2>/dev/null | grep :7777 || echo "❌ No process listening on port 7777"
  99  
 100  echo ""
 101  echo "📋 Step 7: Test SSL certificate"
 102  echo "------------------------------"
 103  echo "Certificate issuer:"
 104  echo | openssl s_client -connect orly-relay.imwald.eu:443 -servername orly-relay.imwald.eu 2>/dev/null | openssl x509 -noout -issuer 2>/dev/null || echo "❌ SSL test failed"
 105  
 106  echo ""
 107  echo "🎯 RECOMMENDED NEXT STEPS:"
 108  echo "========================="
 109  echo "1. If proxy_wstunnel is missing: sudo a2enmod proxy_wstunnel && sudo systemctl restart apache2"
 110  echo "2. If no proxy rules found: Add configuration in Plesk Apache & nginx Settings"
 111  echo "3. If local WebSocket fails: Check if relay container is actually running"
 112  echo "4. If remote WebSocket fails but local works: Apache proxy configuration issue"
 113  echo ""
 114  echo "🔧 Try this simple Plesk configuration:"
 115  echo "ProxyPass / http://127.0.0.1:7777/"
 116  echo "ProxyPassReverse / http://127.0.0.1:7777/"
 117