You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
1.5 KiB

#!/usr/bin/env python3
"""Initialisation du backend pySonnerie.
Cree backend/data/conf.json avec des valeurs par defaut si le fichier
n'existe pas encore. Le mot de passe admin est genere aleatoirement.
"""
from __future__ import annotations
import json
import secrets
import sys
from pathlib import Path
CONF_PATH = Path(__file__).resolve().parent / "data" / "conf.json"
DEFAULT_CONF = {
"server": {
"host": "0.0.0.0",
"port": 8443,
"tls_cert": "certs/cert.pem",
"tls_key": "certs/key.pem",
},
"auth": {
"username": "admin",
"password": None, # remplace par un mot de passe aleatoire
},
"serial": {
"enabled": False,
"port": "/dev/ttyACM0",
"baudrate": 115200,
"timeout": 1,
},
"triggers": {},
}
def main() -> None:
if CONF_PATH.exists():
print(f"[info] {CONF_PATH} existe deja, aucune modification.")
sys.exit(0)
CONF_PATH.parent.mkdir(parents=True, exist_ok=True)
(CONF_PATH.parent / "musiques").mkdir(parents=True, exist_ok=True)
conf = DEFAULT_CONF.copy()
password = secrets.token_urlsafe(16)
conf["auth"] = {"username": "admin", "password": password}
CONF_PATH.write_text(json.dumps(conf, indent=2) + "\n", encoding="utf-8")
CONF_PATH.chmod(0o600)
print(f"[ok] {CONF_PATH} cree (permissions 600).")
print(f"[ok] Identifiants par defaut : admin / {password}")
print("[!] Notez ce mot de passe, il ne sera pas reaffiche.")
if __name__ == "__main__":
main()