diff --git a/FLOWISE_SETUP.md b/FLOWISE_SETUP.md index 83ef84a..e340b20 100644 --- a/FLOWISE_SETUP.md +++ b/FLOWISE_SETUP.md @@ -182,8 +182,68 @@ pct exec -- docker logs flowise pct exec -- docker logs flowise-postgres ``` +## Account Setup Script + +Nach der Installation muss der Administrator-Account über die Web-UI oder das Script erstellt werden. + +### Verwendung + +```bash +# Account erstellen +bash setup_flowise_account.sh \ + --url https://fw-1768829679.userman.de \ + --name "Admin User" \ + --email admin@example.com \ + --password "SecurePass1!" + +# Mit Debug-Ausgabe +bash setup_flowise_account.sh --debug \ + --url https://fw-1768829679.userman.de \ + --name "Admin User" \ + --email admin@example.com \ + --password "SecurePass1!" +``` + +### Parameter + +| Parameter | Beschreibung | Erforderlich | +|-----------|--------------|--------------| +| `--url ` | Flowise Base-URL | Ja | +| `--name ` | Administrator-Anzeigename | Ja | +| `--email ` | Administrator-E-Mail (Login) | Ja | +| `--password ` | Administrator-Passwort | Ja | +| `--debug` | Debug-Modus aktivieren | Nein | + +### Passwort-Anforderungen + +- Mindestens 8 Zeichen +- Mindestens ein Kleinbuchstabe +- Mindestens ein Großbuchstabe +- Mindestens eine Ziffer +- Mindestens ein Sonderzeichen + +### Ausgabe + +```json +{ + "success": true, + "url": "https://fw-1768829679.userman.de", + "email": "admin@example.com", + "name": "Admin User", + "message": "Account created successfully" +} +``` + ## Versionsverlauf +### install_flowise.sh + +| Version | Änderungen | +|---------|------------| +| 1.0.0 | Initiale Version | + +### setup_flowise_account.sh + | Version | Änderungen | |---------|------------| | 1.0.0 | Initiale Version | diff --git a/setup_flowise_account.sh b/setup_flowise_account.sh new file mode 100644 index 0000000..ec17ad6 --- /dev/null +++ b/setup_flowise_account.sh @@ -0,0 +1,254 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +# ============================================================================= +# Flowise Account Setup Script +# ============================================================================= +# Erstellt den Administrator-Account für eine neue Flowise-Instanz +# über die Flowise API (/api/v1/organization/setup) +# ============================================================================= + +SCRIPT_VERSION="1.0.0" + +# Debug mode: 0 = nur JSON, 1 = Logs auf stderr +DEBUG="${DEBUG:-0}" +export DEBUG + +# Logging functions +log_ts() { date "+[%F %T]"; } +info() { [[ "$DEBUG" == "1" ]] && echo "$(log_ts) INFO: $*" >&2; return 0; } +warn() { [[ "$DEBUG" == "1" ]] && echo "$(log_ts) WARN: $*" >&2; return 0; } +die() { + if [[ "$DEBUG" == "1" ]]; then + echo "$(log_ts) ERROR: $*" >&2 + else + echo "{\"error\": \"$*\"}" + fi + exit 1 +} + +# ============================================================================= +# Usage +# ============================================================================= +usage() { + cat >&2 <<'EOF' +Usage: + bash setup_flowise_account.sh [options] + +Required options: + --url Flowise base URL (e.g., https://fw-1768829679.userman.de) + --name Administrator display name + --email Administrator email (used as login) + --password Administrator password (8+ chars, upper, lower, digit, special) + +Optional: + --debug Enable debug mode (show logs on stderr) + --help Show this help + +Password requirements: + - At least 8 characters + - At least one lowercase letter + - At least one uppercase letter + - At least one digit + - At least one special character + +Examples: + # Setup account: + bash setup_flowise_account.sh \ + --url https://fw-1768829679.userman.de \ + --name "Admin User" \ + --email admin@example.com \ + --password "SecurePass1!" + + # With debug output: + bash setup_flowise_account.sh --debug \ + --url https://fw-1768829679.userman.de \ + --name "Admin User" \ + --email admin@example.com \ + --password "SecurePass1!" +EOF +} + +# ============================================================================= +# Default values +# ============================================================================= +FLOWISE_URL="" +ADMIN_NAME="" +ADMIN_EMAIL="" +ADMIN_PASSWORD="" + +# ============================================================================= +# Argument parsing +# ============================================================================= +while [[ $# -gt 0 ]]; do + case "$1" in + --url) FLOWISE_URL="${2:-}"; shift 2 ;; + --name) ADMIN_NAME="${2:-}"; shift 2 ;; + --email) ADMIN_EMAIL="${2:-}"; shift 2 ;; + --password) ADMIN_PASSWORD="${2:-}"; shift 2 ;; + --debug) DEBUG="1"; export DEBUG; shift 1 ;; + --help|-h) usage; exit 0 ;; + *) die "Unknown option: $1 (use --help)" ;; + esac +done + +# ============================================================================= +# Validation +# ============================================================================= +[[ -n "$FLOWISE_URL" ]] || die "--url is required" +[[ -n "$ADMIN_NAME" ]] || die "--name is required" +[[ -n "$ADMIN_EMAIL" ]] || die "--email is required" +[[ -n "$ADMIN_PASSWORD" ]] || die "--password is required" + +# Validate email format +[[ "$ADMIN_EMAIL" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]] || die "Invalid email format: $ADMIN_EMAIL" + +# Validate password policy (Flowise requirements) +validate_password() { + local p="$1" + [[ ${#p} -ge 8 ]] || return 1 + [[ "$p" =~ [a-z] ]] || return 1 + [[ "$p" =~ [A-Z] ]] || return 1 + [[ "$p" =~ [0-9] ]] || return 1 + [[ "$p" =~ [^a-zA-Z0-9] ]] || return 1 + return 0 +} + +validate_password "$ADMIN_PASSWORD" || die "Password does not meet requirements: 8+ chars, lowercase, uppercase, digit, special character" + +# Remove trailing slash from URL +FLOWISE_URL="${FLOWISE_URL%/}" + +info "Script Version: ${SCRIPT_VERSION}" +info "Configuration:" +info " URL: ${FLOWISE_URL}" +info " Name: ${ADMIN_NAME}" +info " Email: ${ADMIN_EMAIL}" +info " Password: ********" + +# ============================================================================= +# Check if Flowise is reachable +# ============================================================================= +info "Checking if Flowise is reachable..." + +# Try to reach the organization-setup page +HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -k "${FLOWISE_URL}/organization-setup" 2>/dev/null || echo "000") + +if [[ "$HTTP_CODE" == "000" ]]; then + die "Cannot connect to Flowise at ${FLOWISE_URL}" +elif [[ "$HTTP_CODE" == "404" ]]; then + warn "Organization setup page not found (404). Account may already exist." +fi + +info "Flowise is reachable (HTTP ${HTTP_CODE})" + +# ============================================================================= +# Create Account via API +# ============================================================================= +info "Creating administrator account..." + +# Prepare JSON payload +# Note: Flowise expects specific field names +JSON_PAYLOAD=$(cat <&1) + +# Extract HTTP code from last line +HTTP_CODE=$(echo "$RESPONSE" | tail -n1) +RESPONSE_BODY=$(echo "$RESPONSE" | sed '$d') + +info "HTTP Response Code: ${HTTP_CODE}" +info "Response Body: ${RESPONSE_BODY}" + +# ============================================================================= +# Handle Response +# ============================================================================= +if [[ "$HTTP_CODE" == "200" || "$HTTP_CODE" == "201" ]]; then + info "Account created successfully!" + + # Output result as JSON + if [[ "$DEBUG" == "1" ]]; then + cat <&1) + + HTTP_CODE=$(echo "$RESPONSE" | tail -n1) + RESPONSE_BODY=$(echo "$RESPONSE" | sed '$d') + + if [[ "$HTTP_CODE" == "200" || "$HTTP_CODE" == "201" ]]; then + info "Account created successfully via /api/v1/signup!" + if [[ "$DEBUG" == "1" ]]; then + cat <