diff --git a/deploy.sh b/deploy.sh index 686f9a0..efba771 100755 --- a/deploy.sh +++ b/deploy.sh @@ -186,6 +186,12 @@ ZORAXY_DNS echo "[OK] ZorxAuth SSO configured" + # --- Fix SSO redirect URL in BoltDB (API may not persist it correctly) --- + echo "[*] Ensuring SSO redirect URL is set in BoltDB..." + go build -o /tmp/fix-zoraxy-sso ./tools/fix-zoraxy-sso/ + sudo /tmp/fix-zoraxy-sso /opt/nextworkspace/config/zoraxy/sys.db 2>&1 || echo "[WARN] SSO BoltDB fix failed (non-fatal)" + rm -f /tmp/fix-zoraxy-sso + # --- Generate launcher apps.yaml with actual domain --- cat > "$TARGET_DIR/config/nextworkspace/apps.yaml" <\n") + os.Exit(1) + } + + dbPath := os.Args[1] + bucket := "zorxauth" + key := "options" + + db, err := bbolt.Open(dbPath, 0600, nil) + if err != nil { + log.Fatalf("Failed to open DB %s: %v", dbPath, err) + } + defer db.Close() + + err = db.Update(func(tx *bbolt.Tx) error { + b := tx.Bucket([]byte(bucket)) + if b == nil { + return fmt.Errorf("bucket %q not found", bucket) + } + + val := b.Get([]byte(key)) + if val == nil { + return fmt.Errorf("key %q not found in bucket %q", key, bucket) + } + + var opts map[string]interface{} + if err := json.Unmarshal(val, &opts); err != nil { + return fmt.Errorf("failed to parse JSON: %v", err) + } + + // Update the critical SSO fields + opts["sso_redirect_url"] = fmt.Sprintf("https://app.%s/", getDomain()) + opts["enable_auth_gateway"] = true + + updated, err := json.Marshal(opts) + if err != nil { + return fmt.Errorf("failed to marshal JSON: %v", err) + } + + return b.Put([]byte(key), updated) + }) + + if err != nil { + log.Fatalf("Update failed: %v", err) + } + + fmt.Println("[OK] ZorxAuth SSO config updated in BoltDB") +} + +func getDomain() string { + if d := os.Getenv("DOMAIN"); d != "" { + return d + } + return "nextwks.eu" +}