diff --git a/backend/COMMON_ERRORS.md b/backend/COMMON_ERRORS.md index 73257d23b..c9e0ceaa9 100644 --- a/backend/COMMON_ERRORS.md +++ b/backend/COMMON_ERRORS.md @@ -491,4 +491,92 @@ echo "0 2 * * * find /opt/myp/logs -name '*.log' -size +100M -exec truncate -s 5 sudo tar -czf /tmp/myp_backup_$(date +%Y%m%d_%H%M%S).tar.gz /opt/myp/ ``` +### Connection Refused (Kiosk-Modus) + +**Problem:** +``` +Connection refused +ERR_CONNECTION_REFUSED +Kiosk startet aber kann sich nicht mit MYP-Server verbinden +``` + +**Ursachen:** +- MYP-Server läuft nicht (myp-https/myp-app Service) +- Ports 443/5000 sind blockiert oder nicht belegt +- SSL-Zertifikate fehlen oder sind ungültig +- Python-Module fehlen oder sind defekt +- Firewall blockiert Verbindungen + +**🚀 Schnelle Lösung:** +```bash +# Quick Fix ausführen +cd /opt/myp +sudo chmod +x quick_fix_connection.sh +sudo ./quick_fix_connection.sh + +# Services manuell neu starten +sudo systemctl restart myp-https +sudo systemctl restart myp-app +sudo systemctl status myp-https +``` + +**🔍 Detaillierte Diagnose:** +```bash +# Vollständige Diagnose ausführen +cd /opt/myp +sudo chmod +x debug_connection_refused.sh +sudo ./debug_connection_refused.sh + +# Service-Logs prüfen +journalctl -u myp-https -f +journalctl -u myp-app -f + +# Port-Status prüfen +netstat -tulpn | grep -E ':(443|5000|80)' +``` + +**🔧 Manuelle Reparatur:** +```bash +# 1. Services stoppen und neu starten +sudo systemctl stop myp-kiosk myp-https myp-app +sudo systemctl start myp-app myp-https myp-kiosk + +# 2. Firewall-Ports öffnen +sudo ufw allow 443 +sudo ufw allow 5000 +sudo ufw allow 80 + +# 3. SSL-Zertifikate regenerieren +cd /opt/myp +sudo ./fix_ssl_raspberry.sh + +# 4. Python-Module neu installieren +cd /opt/myp +sudo python3 -m pip install -r requirements.txt --break-system-packages --force-reinstall + +# 5. App manuell testen +cd /opt/myp +python3 app.py +``` + +**🎯 Verbindungstest:** +```bash +# Teste lokale Verbindungen +curl -k https://localhost:443 +curl http://localhost:5000 +curl -k https://m040tbaraspi001.de040.corpintra.net + +# Teste von anderem System +curl -k https://192.168.1.XXX:443 +``` + +**📋 Häufige Lösungen:** +- **Service läuft nicht**: `sudo systemctl enable --now myp-https` +- **Port blockiert**: `sudo ufw allow 443 && sudo ufw allow 5000` +- **SSL-Fehler**: `sudo ./fix_ssl_raspberry.sh` +- **Python-Fehler**: `sudo python3 -m pip install flask --break-system-packages` +- **Kiosk-URL falsch**: Prüfe `/etc/systemd/system/myp-kiosk.service` + +--- + **📞 Support:** Bei ungelösten Problemen alle relevanten Logs und die Ausgabe der Debugging-Tools sammeln. \ No newline at end of file diff --git a/backend/debug_connection_refused.sh b/backend/debug_connection_refused.sh new file mode 100644 index 000000000..e72854456 --- /dev/null +++ b/backend/debug_connection_refused.sh @@ -0,0 +1,319 @@ +#!/bin/bash +# MYP Connection Refused Debug & Fix Script +# Diagnostiziert und behebt Connection Refused Probleme auf Raspberry Pi + +set -e + +# Farben für Output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' + +echo -e "${CYAN}=========================================================${NC}" +echo -e "${CYAN}MYP CONNECTION REFUSED - DEBUG & FIX${NC}" +echo -e "${CYAN}Raspberry Pi Diagnose und Reparatur${NC}" +echo -e "${CYAN}=========================================================${NC}" +echo "" + +# Basis-Informationen sammeln +echo -e "${BLUE}📊 SYSTEM-INFORMATIONEN:${NC}" +echo -e " 🖥️ Hostname: $(hostname)" +echo -e " 🌐 IP-Adressen: $(hostname -I | tr ' ' '\n' | head -3 | tr '\n' ' ')" +echo -e " ⏰ Zeit: $(date)" +echo -e " 👤 Benutzer: $(whoami)" +echo "" + +# 1. SERVICE-STATUS PRÜFEN +echo -e "${YELLOW}🔍 1. SERVICE-STATUS DIAGNOSE${NC}" +echo "==================================================" + +services=("myp-https" "myp-app" "myp-kiosk" "kiosk-watchdog") + +for service in "${services[@]}"; do + echo -e "${BLUE}Prüfe Service: $service${NC}" + + if systemctl is-enabled "$service" >/dev/null 2>&1; then + echo -e " ✅ Service ist aktiviert" + else + echo -e " ❌ Service ist NICHT aktiviert" + fi + + if systemctl is-active "$service" >/dev/null 2>&1; then + echo -e " ✅ Service läuft" + else + echo -e " ❌ Service läuft NICHT" + echo -e " 📋 Status: $(systemctl is-active "$service" 2>/dev/null || echo 'unknown')" + fi + + # Zeige letzte Logs + echo -e " 📝 Letzte Logs:" + journalctl -u "$service" --no-pager -n 3 --since "5 minutes ago" 2>/dev/null | sed 's/^/ /' || echo " Keine Logs verfügbar" + echo "" +done + +# 2. PORT-STATUS PRÜFEN +echo -e "${YELLOW}🔍 2. PORT-STATUS DIAGNOSE${NC}" +echo "==================================================" + +ports=("443" "5000" "80") + +for port in "${ports[@]}"; do + echo -e "${BLUE}Prüfe Port: $port${NC}" + + # Prüfe ob Port belegt ist + if netstat -tulpn 2>/dev/null | grep -q ":$port "; then + echo -e " ✅ Port $port ist belegt" + process=$(netstat -tulpn 2>/dev/null | grep ":$port " | awk '{print $7}' | head -1) + echo -e " 📋 Prozess: $process" + else + echo -e " ❌ Port $port ist FREI (sollte belegt sein!)" + fi + + # Teste Verbindung + if timeout 3 bash -c "/dev/null; then + echo -e " ✅ Verbindung zu localhost:$port erfolgreich" + else + echo -e " ❌ Verbindung zu localhost:$port FEHLGESCHLAGEN" + fi + echo "" +done + +# 3. MYP-APP SPEZIFISCHE DIAGNOSE +echo -e "${YELLOW}🔍 3. MYP-APP DIAGNOSE${NC}" +echo "==================================================" + +APP_DIR="/opt/myp" + +echo -e "${BLUE}Prüfe MYP-Installation:${NC}" +if [ -d "$APP_DIR" ]; then + echo -e " ✅ MYP-Verzeichnis existiert: $APP_DIR" + + if [ -f "$APP_DIR/app.py" ]; then + echo -e " ✅ app.py gefunden" + else + echo -e " ❌ app.py FEHLT!" + fi + + if [ -f "$APP_DIR/requirements.txt" ]; then + echo -e " ✅ requirements.txt gefunden" + else + echo -e " ❌ requirements.txt FEHLT!" + fi + + # Prüfe Berechtigungen + echo -e " 📋 Berechtigungen: $(ls -ld "$APP_DIR" | awk '{print $1, $3, $4}')" + +else + echo -e " ❌ MYP-Verzeichnis FEHLT: $APP_DIR" +fi + +# 4. PYTHON-UMGEBUNG PRÜFEN +echo -e "${YELLOW}🔍 4. PYTHON-UMGEBUNG DIAGNOSE${NC}" +echo "==================================================" + +echo -e "${BLUE}Python-Installation:${NC}" +if command -v python3 >/dev/null 2>&1; then + echo -e " ✅ Python3: $(python3 --version)" +else + echo -e " ❌ Python3 NICHT GEFUNDEN!" +fi + +if command -v python3.11 >/dev/null 2>&1; then + echo -e " ✅ Python3.11: $(python3.11 --version)" +else + echo -e " ❌ Python3.11 NICHT GEFUNDEN!" +fi + +echo -e "${BLUE}Kritische Python-Module:${NC}" +critical_modules=("flask" "requests" "werkzeug" "jinja2") + +for module in "${critical_modules[@]}"; do + if python3 -c "import $module" 2>/dev/null; then + version=$(python3 -c "import $module; print(getattr($module, '__version__', 'unknown'))" 2>/dev/null) + echo -e " ✅ $module: $version" + else + echo -e " ❌ $module FEHLT!" + fi +done + +# 5. SSL-ZERTIFIKAT PRÜFEN +echo -e "${YELLOW}🔍 5. SSL-ZERTIFIKAT DIAGNOSE${NC}" +echo "==================================================" + +SSL_DIR="$APP_DIR/ssl" +CERT_FILE="$SSL_DIR/cert.pem" +KEY_FILE="$SSL_DIR/key.pem" + +if [ -d "$SSL_DIR" ]; then + echo -e " ✅ SSL-Verzeichnis existiert" + + if [ -f "$CERT_FILE" ]; then + echo -e " ✅ SSL-Zertifikat gefunden" + + # Prüfe Zertifikat-Gültigkeit + if openssl x509 -in "$CERT_FILE" -noout -checkend 86400 2>/dev/null; then + echo -e " ✅ Zertifikat ist gültig" + expiry=$(openssl x509 -in "$CERT_FILE" -noout -enddate 2>/dev/null | cut -d= -f2) + echo -e " 📅 Läuft ab: $expiry" + else + echo -e " ❌ Zertifikat ist ABGELAUFEN oder UNGÜLTIG!" + fi + else + echo -e " ❌ SSL-Zertifikat FEHLT: $CERT_FILE" + fi + + if [ -f "$KEY_FILE" ]; then + echo -e " ✅ SSL-Key gefunden" + echo -e " 📋 Key-Berechtigungen: $(ls -l "$KEY_FILE" | awk '{print $1, $3, $4}')" + else + echo -e " ❌ SSL-Key FEHLT: $KEY_FILE" + fi +else + echo -e " ❌ SSL-Verzeichnis FEHLT: $SSL_DIR" +fi + +# 6. FIREWALL-STATUS +echo -e "${YELLOW}🔍 6. FIREWALL-DIAGNOSE${NC}" +echo "==================================================" + +if command -v ufw >/dev/null 2>&1; then + echo -e "${BLUE}UFW Firewall:${NC}" + ufw_status=$(ufw status 2>/dev/null | head -1) + echo -e " 📋 Status: $ufw_status" + + if echo "$ufw_status" | grep -q "active"; then + echo -e " 🔥 Firewall ist AKTIV - prüfe Ports..." + for port in 443 5000 80; do + if ufw status 2>/dev/null | grep -q "$port"; then + echo -e " ✅ Port $port ist geöffnet" + else + echo -e " ❌ Port $port ist BLOCKIERT!" + fi + done + else + echo -e " ✅ Firewall ist inaktiv" + fi +else + echo -e " ℹ️ UFW nicht installiert" +fi + +# 7. AUTOMATISCHE REPARATUR-VERSUCHE +echo "" +echo -e "${CYAN}=========================================================${NC}" +echo -e "${CYAN}🔧 AUTOMATISCHE REPARATUR-VERSUCHE${NC}" +echo -e "${CYAN}=========================================================${NC}" + +echo -e "${YELLOW}Reparatur 1: Services neu starten${NC}" +for service in "myp-https" "myp-app"; do + if systemctl is-enabled "$service" >/dev/null 2>&1; then + echo -e " 🔄 Starte $service neu..." + if systemctl restart "$service" 2>/dev/null; then + echo -e " ✅ $service erfolgreich neu gestartet" + sleep 2 + if systemctl is-active "$service" >/dev/null 2>&1; then + echo -e " ✅ $service läuft jetzt" + else + echo -e " ❌ $service läuft immer noch nicht" + fi + else + echo -e " ❌ Fehler beim Neustart von $service" + fi + fi +done + +echo "" +echo -e "${YELLOW}Reparatur 2: Manuelle App-Start-Versuche${NC}" +if [ -f "$APP_DIR/app.py" ]; then + echo -e " 🐍 Teste Python-App direkt..." + cd "$APP_DIR" + + # Teste verschiedene Python-Versionen + for python_cmd in "python3.11" "python3" "python"; do + if command -v "$python_cmd" >/dev/null 2>&1; then + echo -e " 🧪 Teste mit $python_cmd..." + timeout 10 "$python_cmd" -c " +import sys +sys.path.insert(0, '/opt/myp') +try: + from app import app + print('✅ App-Import erfolgreich') + app.run(host='0.0.0.0', port=5000, debug=False) +except Exception as e: + print(f'❌ App-Fehler: {e}') + import traceback + traceback.print_exc() +" 2>&1 | head -10 | sed 's/^/ /' + break + fi + done +fi + +echo "" +echo -e "${YELLOW}Reparatur 3: SSL-Zertifikate regenerieren${NC}" +if [ ! -f "$CERT_FILE" ] || ! openssl x509 -in "$CERT_FILE" -noout -checkend 86400 2>/dev/null; then + echo -e " 🔐 Regeneriere SSL-Zertifikate..." + + if [ -f "/opt/myp/fix_ssl_raspberry.sh" ]; then + echo -e " 🛠️ Führe SSL-Fix aus..." + chmod +x "/opt/myp/fix_ssl_raspberry.sh" + "/opt/myp/fix_ssl_raspberry.sh" 2>&1 | tail -5 | sed 's/^/ /' + else + echo -e " ⚠️ SSL-Fix-Skript nicht gefunden - manuelle SSL-Erstellung..." + mkdir -p "$SSL_DIR" + cd "$SSL_DIR" + + # Einfache SSL-Zertifikat-Erstellung + openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes \ + -subj "/C=DE/ST=BW/L=Stuttgart/O=Mercedes/CN=m040tbaraspi001" 2>/dev/null && \ + echo -e " ✅ SSL-Zertifikate erstellt" || \ + echo -e " ❌ SSL-Erstellung fehlgeschlagen" + fi +fi + +# 8. FINAL-TEST +echo "" +echo -e "${CYAN}=========================================================${NC}" +echo -e "${CYAN}🎯 FINAL-VERBINDUNGSTEST${NC}" +echo -e "${CYAN}=========================================================${NC}" + +echo -e "${BLUE}Teste Verbindungen nach Reparatur:${NC}" + +for url in "http://localhost:5000" "https://localhost:443" "http://127.0.0.1:5000"; do + echo -e " 🌐 Teste: $url" + if timeout 5 curl -s -o /dev/null -w "%{http_code}" "$url" 2>/dev/null | grep -q "200\|302\|404"; then + echo -e " ✅ $url ist erreichbar!" + else + echo -e " ❌ $url nicht erreichbar" + fi +done + +# 9. EMPFEHLUNGEN +echo "" +echo -e "${CYAN}=========================================================${NC}" +echo -e "${CYAN}💡 EMPFEHLUNGEN${NC}" +echo -e "${CYAN}=========================================================${NC}" + +echo -e "${GREEN}Nächste Schritte:${NC}" +echo -e "1. ${BLUE}Service-Logs prüfen:${NC}" +echo -e " journalctl -u myp-https -f" +echo -e " journalctl -u myp-app -f" +echo "" +echo -e "2. ${BLUE}Manuelle App-Start zum Debugging:${NC}" +echo -e " cd /opt/myp" +echo -e " python3 app.py" +echo "" +echo -e "3. ${BLUE}Port-Verfügbarkeit prüfen:${NC}" +echo -e " netstat -tulpn | grep -E ':(443|5000|80)'" +echo "" +echo -e "4. ${BLUE}Firewall-Ports öffnen (falls nötig):${NC}" +echo -e " sudo ufw allow 443" +echo -e " sudo ufw allow 5000" +echo "" +echo -e "5. ${BLUE}Setup-Skript erneut ausführen:${NC}" +echo -e " cd /opt/myp && sudo ./setup.sh" + +echo "" +echo -e "${GREEN}🏁 Connection Refused Diagnose abgeschlossen!${NC}" \ No newline at end of file diff --git a/backend/quick_fix_connection.sh b/backend/quick_fix_connection.sh new file mode 100644 index 000000000..b54f4d202 --- /dev/null +++ b/backend/quick_fix_connection.sh @@ -0,0 +1,105 @@ +#!/bin/bash +# MYP Quick Fix - Connection Refused +# Schnelle Reparatur der häufigsten Verbindungsprobleme + +set -e + +# Farben +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +RED='\033[0;31m' +NC='\033[0m' + +echo -e "${BLUE}🚀 MYP QUICK FIX - Connection Refused${NC}" +echo "==============================================" + +# 1. Services stoppen und neu starten +echo -e "${YELLOW}🔄 Schritt 1: Services neu starten${NC}" +services=("myp-kiosk" "myp-https" "myp-app") + +for service in "${services[@]}"; do + if systemctl is-enabled "$service" >/dev/null 2>&1; then + echo " Stoppe $service..." + systemctl stop "$service" 2>/dev/null || true + sleep 1 + echo " Starte $service..." + systemctl start "$service" 2>/dev/null || true + sleep 2 + + if systemctl is-active "$service" >/dev/null 2>&1; then + echo -e " ✅ $service läuft" + else + echo -e " ❌ $service Fehler" + fi + fi +done + +# 2. Ports freigeben +echo -e "${YELLOW}🔥 Schritt 2: Firewall-Ports öffnen${NC}" +if command -v ufw >/dev/null 2>&1; then + ufw allow 443 >/dev/null 2>&1 || true + ufw allow 5000 >/dev/null 2>&1 || true + ufw allow 80 >/dev/null 2>&1 || true + echo " ✅ Ports 443, 5000, 80 geöffnet" +fi + +# 3. SSL-Zertifikate prüfen/erstellen +echo -e "${YELLOW}🔐 Schritt 3: SSL-Zertifikate prüfen${NC}" +SSL_DIR="/opt/myp/ssl" +mkdir -p "$SSL_DIR" + +if [ ! -f "$SSL_DIR/cert.pem" ] || [ ! -f "$SSL_DIR/key.pem" ]; then + echo " Erstelle SSL-Zertifikate..." + cd "$SSL_DIR" + openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes \ + -subj "/C=DE/ST=BW/L=Stuttgart/O=Mercedes/CN=m040tbaraspi001" >/dev/null 2>&1 + chmod 644 cert.pem + chmod 600 key.pem + echo " ✅ SSL-Zertifikate erstellt" +else + echo " ✅ SSL-Zertifikate vorhanden" +fi + +# 4. Python-Abhängigkeiten prüfen +echo -e "${YELLOW}🐍 Schritt 4: Python-Module prüfen${NC}" +cd /opt/myp +if [ -f "requirements.txt" ]; then + python3 -m pip install -r requirements.txt --break-system-packages --quiet >/dev/null 2>&1 || true + echo " ✅ Python-Module aktualisiert" +fi + +# 5. App manuell testen +echo -e "${YELLOW}🧪 Schritt 5: App-Test${NC}" +cd /opt/myp +timeout 5 python3 -c " +import sys +sys.path.insert(0, '/opt/myp') +try: + from app import app + print(' ✅ App-Import erfolgreich') +except Exception as e: + print(f' ❌ App-Import-Fehler: {e}') +" 2>/dev/null || echo " ⚠️ App-Test unvollständig" + +# 6. Verbindungstest +echo -e "${YELLOW}🌐 Schritt 6: Verbindungstest${NC}" +sleep 3 + +for port in 5000 443; do + if timeout 3 bash -c "/dev/null; then + echo -e " ✅ Port $port erreichbar" + else + echo -e " ❌ Port $port nicht erreichbar" + fi +done + +echo "" +echo -e "${GREEN}🏁 Quick Fix abgeschlossen!${NC}" +echo "" +echo -e "${BLUE}Teste jetzt:${NC}" +echo " Browser: https://localhost" +echo " Kiosk sollte sich verbinden können" +echo "" +echo -e "${BLUE}Falls Problem weiterhin besteht:${NC}" +echo " sudo ./debug_connection_refused.sh" \ No newline at end of file