diff --git a/doc/befehle.md b/doc/befehle.md index ee99198..66526fe 100644 --- a/doc/befehle.md +++ b/doc/befehle.md @@ -34,6 +34,18 @@ Beim Update passiert automatisch: 5. Der systemd Service wird per `daemon-reload` neu geladen 6. Der Service wird automatisch neu gestartet (falls er lief) +### API-Verbindungstest nach Installation + +Nach der Installation wird automatisch ein **zweistufiger Verbindungstest** durchgeführt: + +1. **Base-URL Erreichbarkeit** — Prüft ob die konfigurierte `ADGUARD_URL` erreichbar ist (DNS, TCP, HTTP). Bei Fehlern werden spezifische Hinweise angezeigt (z.B. DNS-Fehler, Timeout, SSL-Problem). +2. **API-Authentifizierung** — Testet ob die hinterlegten Zugangsdaten (`ADGUARD_USER` / `ADGUARD_PASS`) korrekt sind, indem der API-Endpunkt `/control/querylog` abgefragt wird. + +> **Hinweis:** Dieser Test kann auch jederzeit manuell ausgeführt werden: +> ```bash +> sudo /opt/adguard-shield/adguard-shield.sh test +> ``` + ### Voraussetzungen Folgende Pakete werden bei der Installation automatisch installiert (via `apt`): diff --git a/doc/tipps-und-troubleshooting.md b/doc/tipps-und-troubleshooting.md index 69d4d31..204dc3b 100644 --- a/doc/tipps-und-troubleshooting.md +++ b/doc/tipps-und-troubleshooting.md @@ -25,10 +25,84 @@ sudo /opt/adguard-shield/adguard-shield.sh test - Falsche Zugangsdaten (`ADGUARD_USER` / `ADGUARD_PASS`) - AdGuard Home läuft nicht - Firewall blockiert lokale Verbindung +- DNS-Auflösung des Hostnames fehlgeschlagen +- SSL/TLS-Zertifikatfehler (bei HTTPS) -**Lösung:** URL manuell testen: +#### Schritt-für-Schritt Diagnose + +**1. Base-URL Erreichbarkeit prüfen (ohne Auth):** ```bash -curl -s -u admin:passwort http://127.0.0.1:3000/control/querylog?limit=1 +# Vollständige Diagnose mit HTTP-Headern und Verbindungsdetails +curl -ikv https://dns1.domain.com 2>&1 + +# Nur HTTP-Statuscode prüfen (schnell) +curl -s -o /dev/null -w "%{http_code}\n" -k https://dns1.domain.com +``` + +> `-i` zeigt HTTP-Response-Header, `-k` ignoriert SSL-Fehler, `-v` zeigt Verbindungsdetails (DNS, TLS-Handshake, etc.) + +**2. DNS-Auflösung testen:** +```bash +# Hostname auflösen +dig +short dns1.domain.com + +# Oder mit nslookup +nslookup dns1.domain.com +``` + +**3. Port-Erreichbarkeit testen:** +```bash +# TCP-Verbindung zum Port prüfen (z.B. Port 3000) +nc -zv 127.0.0.1 3000 + +# Oder mit curl +curl -v telnet://127.0.0.1:3000 +``` + +**4. API-Endpunkt mit Authentifizierung testen:** +```bash +# Query-Log abfragen (mit Auth + Response-Header) +curl -i -u admin:passwort https://dns1.domain.com/control/querylog?limit=1 + +# Nur HTTP-Status zurückgeben +curl -s -o /dev/null -w "%{http_code}\n" -u admin:passwort https://dns1.domain.com/control/querylog?limit=1 +``` + +**5. AdGuard Home Status-API prüfen:** +```bash +# Allgemeinen Status abfragen (benötigt keine Auth) +curl -ik https://dns1.domain.com/control/status +``` + +#### Typische Fehlercodes + +| HTTP-Code | Bedeutung | Lösung | +|-----------|-----------|--------| +| `000` | Keine Verbindung | Host nicht erreichbar, DNS-Fehler oder Firewall | +| `200` | Erfolg | Alles in Ordnung ✅ | +| `301/302` | Weiterleitung | URL prüfen — evtl. fehlt `https://` oder Port | +| `401` | Nicht autorisiert | `ADGUARD_USER` / `ADGUARD_PASS` prüfen | +| `403` | Zugriff verweigert | Zugangsdaten oder IP-Beschränkung in AdGuard Home | +| `404` | Nicht gefunden | URL falsch oder AdGuard Home Version zu alt | +| `502/503` | Service nicht verfügbar | AdGuard Home läuft nicht oder wird gerade neu gestartet | + +#### curl Exit-Codes + +| Exit-Code | Bedeutung | +|-----------|-----------| +| `6` | DNS-Auflösung fehlgeschlagen — Hostname prüfen | +| `7` | Verbindung abgelehnt — Läuft AdGuard Home? Port korrekt? | +| `28` | Timeout — Host nicht erreichbar oder Firewall blockiert | +| `35` | SSL/TLS-Handshake fehlgeschlagen | +| `51` | SSL-Zertifikat: Hostname stimmt nicht überein | +| `60` | SSL-Zertifikat: nicht vertrauenswürdig (selbstsigniert?) | + +> **Tipp:** Bei selbstsignierten Zertifikaten `-k` an curl anhängen, um SSL-Fehler zu ignorieren. AdGuard Shield verwendet intern automatisch `-k` bei der API-Kommunikation. + +**Lösung:** URL und Zugangsdaten in der Konfiguration anpassen: +```bash +sudo nano /opt/adguard-shield/adguard-shield.conf +sudo systemctl restart adguard-shield ``` ### iptables-Fehler: "Permission denied" diff --git a/install.sh b/install.sh index 069acce..856f242 100644 --- a/install.sh +++ b/install.sh @@ -396,17 +396,60 @@ test_connection() { source "$INSTALL_DIR/adguard-shield.conf" - local response - response=$(curl -s -o /dev/null -w "%{http_code}" \ - -u "${ADGUARD_USER}:${ADGUARD_PASS}" \ - --connect-timeout 5 \ - "${ADGUARD_URL}/control/querylog?limit=1" 2>/dev/null) + # ── Schritt 1: Base-URL Erreichbarkeit prüfen ──────────────────────── + echo -e " ${CYAN}1)${NC} Prüfe Erreichbarkeit von ${BOLD}${ADGUARD_URL}${NC} ..." - if [[ "$response" == "200" ]]; then - echo -e " ✅ Verbindung erfolgreich! (HTTP $response)" + local base_http_code + local base_curl_exit + base_http_code=$(curl -s -o /dev/null -w "%{http_code}" \ + --connect-timeout 5 --max-time 10 \ + -k "${ADGUARD_URL}" 2>/dev/null) || base_curl_exit=$? + base_curl_exit=${base_curl_exit:-0} + + if [[ "$base_curl_exit" -ne 0 ]]; then + # curl konnte keine Verbindung aufbauen + echo -e " ❌ Base-URL nicht erreichbar! (curl Exit-Code: $base_curl_exit)" + case "$base_curl_exit" in + 6) echo -e " ${YELLOW}→ DNS-Auflösung fehlgeschlagen. Hostname prüfen!${NC}" ;; + 7) echo -e " ${YELLOW}→ Verbindung abgelehnt. Läuft AdGuard Home? Port korrekt?${NC}" ;; + 28) echo -e " ${YELLOW}→ Timeout. Host nicht erreichbar oder Firewall blockiert.${NC}" ;; + 35|51|60) echo -e " ${YELLOW}→ SSL/TLS-Fehler. Zertifikat oder HTTPS-Konfiguration prüfen.${NC}" ;; + *) echo -e " ${YELLOW}→ Unbekannter Fehler. Manuell testen: curl -v ${ADGUARD_URL}${NC}" ;; + esac + echo "" + echo -e " ${YELLOW}Troubleshooting:${NC}" + echo -e " curl -ikv ${ADGUARD_URL}" + echo "" + return 1 + fi + + if [[ "$base_http_code" == "000" ]]; then + echo -e " ❌ Base-URL nicht erreichbar (keine HTTP-Antwort)" + echo -e " ${YELLOW}→ Manuell testen: curl -ikv ${ADGUARD_URL}${NC}" + echo "" + return 1 + fi + + echo -e " ✅ Base-URL erreichbar (HTTP $base_http_code)" + + # ── Schritt 2: API-Endpunkt mit Authentifizierung testen ───────────── + echo -e " ${CYAN}2)${NC} Teste API-Authentifizierung ..." + + local api_response + api_response=$(curl -s -o /dev/null -w "%{http_code}" \ + -u "${ADGUARD_USER}:${ADGUARD_PASS}" \ + --connect-timeout 5 --max-time 10 \ + -k "${ADGUARD_URL}/control/querylog?limit=1" 2>/dev/null) + + if [[ "$api_response" == "200" ]]; then + echo -e " ✅ API-Authentifizierung erfolgreich! (HTTP $api_response)" + elif [[ "$api_response" == "401" || "$api_response" == "403" ]]; then + echo -e " ❌ Authentifizierung fehlgeschlagen (HTTP $api_response)" + echo -e " ${YELLOW}→ Benutzername oder Passwort falsch!${NC}" + echo -e " ${YELLOW}→ Prüfe ADGUARD_USER und ADGUARD_PASS in: $INSTALL_DIR/adguard-shield.conf${NC}" else - echo -e " ❌ Verbindung fehlgeschlagen (HTTP $response)" - echo -e " ${YELLOW}Bitte prüfe URL und Zugangsdaten in: $INSTALL_DIR/adguard-shield.conf${NC}" + echo -e " ❌ API-Verbindung fehlgeschlagen (HTTP $api_response)" + echo -e " ${YELLOW}→ Bitte prüfe URL und Zugangsdaten in: $INSTALL_DIR/adguard-shield.conf${NC}" fi echo "" }