Development

This commit is contained in:
Matthew Grotke 2026-06-13 00:03:11 -04:00
parent 5b1f905ed0
commit 44261e5b5c
6 changed files with 87 additions and 33 deletions

View file

@ -11,6 +11,7 @@ Usage:
"""
import argparse
import json
import os
import re
import shutil
@ -40,6 +41,7 @@ HEALTH_FILE = SCRIPT_DIR / ".health"
SNAPSHOTS_DIR = SCRIPT_DIR / ".snapshots"
CAPTIVE_QUEUE_FILE = SCRIPT_DIR / ".captive-queue"
DASH_DATA_DIR = COMPOSE_FILE.parent / "data"
APP_CONFIG_FILE = DASH_DATA_DIR / "app_config.json"
# Dashboard systemd timer
DASHB_TIMER_NAME = f"{PRODUCT_NAME}-dashboard-queue"
@ -286,9 +288,14 @@ def _set_env_var(content, key, value):
def _dash_already_configured():
if not COMPOSE_FILE.exists():
if not APP_CONFIG_FILE.exists():
return False
return bool(re.search(r"^\s*- INITIAL_MANAGER_EMAIL=\S", COMPOSE_FILE.read_text(), re.MULTILINE))
try:
cfg = json.loads(APP_CONFIG_FILE.read_text())
return bool(cfg.get('initial_manager_email'))
except Exception:
return False
def setup_docker_compose(reuse_config=False):
header("Dashboard Configuration")
@ -320,8 +327,6 @@ def setup_docker_compose(reuse_config=False):
print(" Dashboard container started.")
return
content = COMPOSE_FILE.read_text()
print()
print(" SMTP is used to send email verification codes for new accounts.")
print(" (Gmail users: use an App Password, not your account password.)")
@ -332,21 +337,35 @@ def setup_docker_compose(reuse_config=False):
print(" Please enter a valid email address.")
manager_email = prompt_str("Initial manager account email")
credentials_key = prompt_str(
"Credentials encryption key (press Enter to auto-generate)", default=""
)
if not credentials_key:
import secrets as _sec
credentials_key = _sec.token_urlsafe(48)
print(f" Generated key: {credentials_key}")
smtp_host = prompt_str("SMTP host", default="smtp.gmail.com")
smtp_port = prompt_str("SMTP port", default="587")
smtp_user = prompt_str("SMTP username (email)")
smtp_password = prompt_str("SMTP password", secret=True)
smtp_from = prompt_str("SMTP From address", default=smtp_user)
content = _set_env_var(content, "INITIAL_MANAGER_EMAIL", manager_email)
content = _set_env_var(content, "SMTP_HOST", smtp_host)
content = _set_env_var(content, "SMTP_PORT", smtp_port)
content = _set_env_var(content, "SMTP_USER", smtp_user)
content = _set_env_var(content, "SMTP_PASSWORD", smtp_password)
content = _set_env_var(content, "SMTP_FROM", smtp_from)
app_config = {
"initial_manager_email": manager_email,
"credentials_key": credentials_key,
"smtp": {
"host": smtp_host,
"port": int(smtp_port),
"user": smtp_user,
"password": smtp_password,
"from": smtp_from,
},
}
COMPOSE_FILE.write_text(content)
print(f"\n Written: {COMPOSE_FILE}")
APP_CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True)
APP_CONFIG_FILE.write_text(json.dumps(app_config, indent=2) + "\n")
print(f"\n Written: {APP_CONFIG_FILE}")
env = _compose_env()
print("\n Stopping existing container...")
@ -675,7 +694,7 @@ def main():
reuse_config = False
if dash_installed:
reuse_config = prompt_yn(
"Re-use existing Docker configuration? (Keeps CREDENTIALS_KEY and SMTP credentials)",
"Re-use existing app_config.json? (Keeps credentials key and SMTP settings)",
default="y"
)