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} Dashboard') def is_production(): return not os.environ.get('DEV_MODE', '').lower() in ('1', 'true', 'yes') def routlin_location(): return os.environ.get('ROUTLIN_LOCATION', '/routlin_location') def is_pro(): try: return bool(open(f'{routlin_location()}/.license').read().strip()) except OSError: return False 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_client_utc_offset(timezone_str): """Return signed integer UTC offset in seconds for the given IANA timezone string.""" try: from zoneinfo import ZoneInfo from datetime import datetime return int(datetime.now(ZoneInfo(timezone_str)).utcoffset().total_seconds()) except Exception: return get_host_utc_offset() def get_host_timezone(): """Return the host timezone name (e.g. 'America/New_York'), or '' if unknown.""" tz = os.environ.get('TZ', '').strip() if tz: return tz try: with open('/etc/timezone') as f: return f.read().strip() except OSError: pass return '' 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)