import os, json, sys from flask import Flask from view_page import bp as view_page_bp from action_general import bp as action_general_bp from action_networkinterfaces import bp as action_networkinterfaces_bp from action_upstreamdns import bp as action_upstreamdns_bp from action_apply_mdns import bp as action_apply_mdns_bp from action_apply_vpn import bp as action_apply_vpn_bp from action_apply_banned_ips import bp as action_apply_banned_ips_bp from action_apply_host_overrides import bp as action_apply_host_overrides_bp from action_dnsblocking import bp as action_dnsblocking_bp from action_apply_vlans import bp as action_apply_vlans_bp from action_apply_inter_vlan import bp as action_apply_inter_vlan_bp from action_apply_port_forwarding import bp as action_apply_port_forwarding_bp from action_apply_dhcp_reservations import bp as action_apply_dhcp_reservations_bp from action_create_account import bp as action_create_account_bp from action_log_in import bp as action_log_in_bp from action_log_out import bp as action_log_out_bp from action_verify_email import bp as action_verify_email_bp from action_add_account import bp as action_add_account_bp from action_delete_account import bp as action_delete_account_bp from action_save_preferences import bp as action_save_preferences_bp from action_change_password import bp as action_change_password_bp from action_ddns import bp as action_ddns_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(action_general_bp) app.register_blueprint(action_networkinterfaces_bp) app.register_blueprint(action_upstreamdns_bp) app.register_blueprint(action_apply_mdns_bp) app.register_blueprint(action_apply_vpn_bp) app.register_blueprint(action_apply_banned_ips_bp) app.register_blueprint(action_apply_host_overrides_bp) app.register_blueprint(action_dnsblocking_bp) app.register_blueprint(action_apply_vlans_bp) app.register_blueprint(action_apply_inter_vlan_bp) app.register_blueprint(action_apply_port_forwarding_bp) app.register_blueprint(action_apply_dhcp_reservations_bp) app.register_blueprint(action_create_account_bp) app.register_blueprint(action_log_in_bp) app.register_blueprint(action_log_out_bp) app.register_blueprint(action_verify_email_bp) app.register_blueprint(action_add_account_bp) app.register_blueprint(action_delete_account_bp) app.register_blueprint(action_save_preferences_bp) app.register_blueprint(action_change_password_bp) app.register_blueprint(action_ddns_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 accounts_file = '/data/authorized_accounts.json' 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)