linuxrouter/docker/routlin-dash/app/main.py
2026-05-30 16:25:46 -04:00

84 lines
3.4 KiB
Python

import os, json, sys
from flask import Flask
from config_utils import ACCOUNTS_FILE
from view_page import bp as view_page_bp
from pages.actions.action import bp as actions_bp
from pages.bannedips.action import bp as bannedips_bp
from pages.ddns.action import bp as ddns_bp
from pages.dhcp.action import bp as dhcp_bp
from pages.dnsblocking.action import bp as dnsblocking_bp
from pages.dnsserver.action import bp as dnsserver_bp
from pages.hostoverrides.action import bp as hostoverrides_bp
from pages.intervlan.action import bp as intervlan_bp
from pages.accountlogin.action import bp as accountlogin_bp
from pages.networklayout.action import bp as networklayout_bp
from pages.physicalinterfaces.action import bp as physicalinterfaces_bp
from pages.portforwarding.action import bp as portforwarding_bp
from pages.preferences.action import bp as preferences_bp
from pages.accountverifyemail.action import bp as accountverifyemail_bp
from pages.vpn.action import bp as vpn_bp
from pages.accountcreate.action import bp as accountcreate_bp
from pages.accountmanage.action import bp as accountmanage_bp
from pages.mdns.action import bp as mdns_bp
from pages.radius.action import bp as radius_bp
from action_accountlogout import bp as accountlogout_bp
from api_apply_health import bp as api_apply_health_bp
app = Flask(__name__)
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(24))
app.register_blueprint(view_page_bp)
app.register_blueprint(actions_bp)
app.register_blueprint(bannedips_bp)
app.register_blueprint(ddns_bp)
app.register_blueprint(dhcp_bp)
app.register_blueprint(dnsblocking_bp)
app.register_blueprint(dnsserver_bp)
app.register_blueprint(hostoverrides_bp)
app.register_blueprint(intervlan_bp)
app.register_blueprint(accountlogin_bp)
app.register_blueprint(networklayout_bp)
app.register_blueprint(physicalinterfaces_bp)
app.register_blueprint(portforwarding_bp)
app.register_blueprint(preferences_bp)
app.register_blueprint(accountverifyemail_bp)
app.register_blueprint(vpn_bp)
app.register_blueprint(accountcreate_bp)
app.register_blueprint(accountmanage_bp)
app.register_blueprint(accountlogout_bp)
app.register_blueprint(mdns_bp)
app.register_blueprint(radius_bp)
app.register_blueprint(api_apply_health_bp)
def _seed_initial_account():
email = os.environ.get('INITIAL_MANAGER_EMAIL', '').strip().lower()
if not email:
try:
with open(ACCOUNTS_FILE) as f:
data = json.load(f)
except Exception:
data = {'accounts': []}
if not data.get('accounts'):
print('[main] WARNING: No accounts exist and INITIAL_MANAGER_EMAIL is not set. '
'Set it in docker-compose.yml to seed the initial manager account.', file=sys.stderr)
return
try:
with open(ACCOUNTS_FILE) as f:
data = json.load(f)
except Exception:
data = {'accounts': []}
if data.get('accounts'):
return
data['accounts'] = [{
'email_address': email,
'access_level': 'manager',
'hashed_password': '',
'timezone': '',
}]
with open(ACCOUNTS_FILE, 'w') as f:
json.dump(data, f, indent=2)
print(f'[main] Seeded initial manager account: {email}', file=sys.stderr)
_seed_initial_account()
if __name__ == "__main__":
app.run(host="0.0.0.0", port=25327)