# n8n Customer Provisioning System ## Status: ✅ Phase 1 Complete, Phase 2 In Progress --- # Phase 1: Debug-Option Implementation ## Status: ✅ Completed (v2 - mit Log-Datei) ### Schritte: - [x] **libsupabase.sh anpassen** - [x] `DEBUG="${DEBUG:-0}"` Variable hinzufügen - [x] `info()` nur bei DEBUG=1 ausgeben - [x] `warn()` nur bei DEBUG=1 ausgeben - [x] `die()` anpassen: JSON-Fehler auf fd 3 bei DEBUG=0 - [x] `setup_traps()` anpassen für JSON-Fehlerausgabe auf fd 3 - [x] **install.sh anpassen** - [x] `DEBUG=0` als Default setzen - [x] `--debug` Option im Argument-Parsing hinzufügen - [x] `echo off` Zeile entfernen - [x] Usage-Text aktualisieren - [x] Log-Verzeichnis erstellen (`logs/`) - [x] Alle Ausgaben in Log-Datei umleiten - [x] Log-Datei nach Container-Hostname benennen - [x] JSON-Ausgabe enthält Pfad zur Log-Datei ### Erwartetes Verhalten: **Ohne `--debug` (Normal-Modus):** - Alle Ausgaben (apt, docker, etc.) → Log-Datei `logs/.log` - Nur JSON auf stdout - Bei Fehlern: JSON mit `{"error": "..."}` **Mit `--debug`:** - Alle Ausgaben auf stderr UND in Log-Datei - JSON auf stdout (auch im Log) ### Änderungen: **libsupabase.sh:** - `DEBUG="${DEBUG:-0}"` Variable - `info()` und `warn()` nur bei `DEBUG=1` - `die()` und `setup_traps()` geben JSON auf fd 3 aus (falls verfügbar) **install.sh:** - Log-Verzeichnis: `${SCRIPT_DIR}/logs/` - Temporäre Log-Datei während Installation - Umbenennung zu `.log` nach Hostname-Generierung - fd 3 reserviert für JSON-Ausgabe - JSON enthält `"log_file"` Pfad - `--debug` Option für Konsolen-Ausgabe ### JSON-Ausgabe enthält jetzt: ```json { "ctid": ..., "hostname": "sb-...", ... "log_file": "/path/to/logs/sb-....log" } ``` --- # Phase 2: NGINX Reverse Proxy Setup ## Status: 🔄 In Progress ### Neues Script: `setup_nginx_proxy.sh` Konfiguriert automatisch einen NGINX Reverse Proxy auf OPNsense für neue n8n-Instanzen. ### Verwendung: ```bash # Mit Daten aus dem Installer-Output: bash setup_nginx_proxy.sh \ --ctid 768736636 \ --hostname sb-1768736636 \ --fqdn sb-1768736636.userman.de \ --backend-ip 192.168.45.135 \ --backend-port 5678 # Mit Debug-Ausgabe: bash setup_nginx_proxy.sh --debug \ --ctid 768736636 \ --hostname sb-1768736636 \ --fqdn sb-1768736636.userman.de \ --backend-ip 192.168.45.135 ``` ### Was das Script macht: 1. **Upstream Server** erstellen (Backend-Server mit IP:Port) 2. **Upstream** erstellen (Load-Balancer-Gruppe) 3. **Location** erstellen (URL-Pfad-Konfiguration mit WebSocket-Support) 4. **HTTP Server** erstellen (Virtual Host mit HTTPS + ACME/Let's Encrypt) 5. **NGINX neu laden** (Konfiguration anwenden) ### API-Endpunkte (OPNsense NGINX Plugin): - `POST /api/nginx/settings/addUpstreamServer` - `POST /api/nginx/settings/addUpstream` - `POST /api/nginx/settings/addLocation` - `POST /api/nginx/settings/addHttpServer` - `POST /api/nginx/service/reconfigure` ### JSON-Ausgabe: ```json { "success": true, "ctid": "768736636", "fqdn": "sb-1768736636.userman.de", "backend": "192.168.45.135:5678", "nginx": { "upstream_server_uuid": "...", "upstream_uuid": "...", "location_uuid": "...", "http_server_uuid": "..." } } ``` ### Noch zu testen: - [ ] API-Verbindung zu OPNsense - [ ] Upstream Server erstellen - [ ] Upstream erstellen - [ ] Location erstellen - [ ] HTTP Server erstellen - [ ] NGINX Konfiguration anwenden - [ ] SSL-Zertifikat (Let's Encrypt/ACME) --- # Phase 3: Integration in n8n Workflow (Geplant) ### Workflow-Erweiterung: 1. `install.sh` → LXC + n8n erstellen 2. `setup_nginx_proxy.sh` → Reverse Proxy konfigurieren 3. E-Mail an Kunden mit Zugangsdaten ### n8n Workflow Nodes: ``` [Webhook Trigger] → [SSH: install.sh] → [Parse JSON] → [SSH: setup_nginx_proxy.sh] → [Parse JSON] → [Send Email] ```