Fix: default user config

This commit is contained in:
2026-04-22 11:04:59 +02:00
parent b587669f0c
commit 6c6073b966
2 changed files with 35 additions and 13 deletions
+16 -3
View File
@@ -60,10 +60,23 @@ def init_db():
c.execute("SELECT COUNT(*) FROM users")
if c.fetchone()[0] == 0:
h = generate_password_hash('admin123')
# Default value if missing config file
def_user = "admin"
def_pass = "admin123"
# Try read config.json
try:
with open(CONFIG_PATH, 'r') as f:
cfg = json.load(f)
def_user = cfg.get("web_admin", {}).get("default_user", "admin")
def_pass = cfg.get("web_admin", {}).get("default_pass", "admin123")
except Exception:
pass
h = generate_password_hash(def_pass)
c.execute("INSERT INTO users (username, password_hash, role, allowed_nodes) VALUES (?,?,?,?)",
('admin', h, 'admin', 'all'))
logger.info(">>> DEFAULT USER CREATED - User: admin | Pass: admin123 <<<")
(def_user, h, 'admin', 'all'))
logger.info(f">>> DEFAULT USER CREATED - User: {def_user} | Pass: {def_pass} <<<")
conn.commit()
conn.close()
+17 -8
View File
@@ -1,15 +1,24 @@
{
"_comment": {"Default admin username and password"
"mqtt": {
"broker": "your_mqtt_broker_address",
"port": 1883,
"user": "your_username",
"password": "your_password"
},
"web_admin": {
"user": "admin",
"pass": "admin123"
"default_user": "admin",
"default_pass": "admin123"
},
"mqtt": {
"broker": "127.0.0.1",
"port": 1883,
"user": "mmdvm",
"password": "password"
"webpush": {
"vapid_public_key": "INSERT_GENERATED_PUBLIC_KEY_HERE",
"vapid_private_key": "INSERT_GENERATED_PRIVATE_KEY_HERE",
"vapid_claim_email": "mailto:your@email.com"
},
"ui": {
"profileA_Name": "PROFILE A",
"profileA_Color": "#3b82f6",
"profileB_Name": "PROFILE B",
"profileB_Color": "#eab308"
},
"update_schedule": "03:00",
"id_urls": {