linuxrouter/docker/routlin-dash/app/settings.py
2026-06-11 01:49:59 -04:00

37 lines
1.1 KiB
Python

import os
def product_name():
return os.environ.get('PRODUCT_NAME', 'routlin')
def web_app_display_name():
edition = 'Pro' if is_pro() else 'CE'
return os.environ.get('WEB_APP_DISPLAY_NAME', f'{product_name().capitalize()}-{edition}')
def is_production():
return not os.environ.get('DEV_MODE', '').lower() in ('1', 'true', 'yes')
def is_pro():
return bool(os.environ.get('LICENSE', '').strip())
def get_host_utc_offset():
# Returns signed integer seconds east of UTC (e.g. -21600 for UTC-6, +19800 for UTC+5:30).
import time
return time.localtime().tm_gmtoff
def get_credentials_key():
"""Return a Fernet-compatible key derived from the CREDENTIALS_KEY environment variable,
or None if not set. SHA-256 hashes the raw string to produce 32 bytes, which are then
URL-safe base64-encoded as required by Fernet."""
import base64
import hashlib
key_str = os.environ.get('CREDENTIALS_KEY', '')
if not key_str:
return None
raw = hashlib.sha256(key_str.encode()).digest()
return base64.urlsafe_b64encode(raw)