2026-06-06 14:55:29 -04:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
2026-06-11 01:49:59 -04:00
|
|
|
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}')
|
|
|
|
|
|
|
|
|
|
|
2026-06-06 14:55:29 -04:00
|
|
|
def is_production():
|
2026-06-07 14:21:40 -04:00
|
|
|
return not os.environ.get('DEV_MODE', '').lower() in ('1', 'true', 'yes')
|
2026-06-06 14:55:29 -04:00
|
|
|
|
|
|
|
|
|
2026-06-11 01:55:15 -04:00
|
|
|
def routlin_location():
|
|
|
|
|
return os.environ.get('ROUTLIN_LOCATION', '/routlin_location')
|
|
|
|
|
|
|
|
|
|
|
2026-06-06 14:55:29 -04:00
|
|
|
def is_pro():
|
2026-06-11 01:55:15 -04:00
|
|
|
try:
|
|
|
|
|
return bool(open(f'{routlin_location()}/.license').read().strip())
|
|
|
|
|
except OSError:
|
|
|
|
|
return False
|
2026-06-07 00:50:49 -04:00
|
|
|
|
|
|
|
|
|
2026-06-10 14:23:47 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2026-06-07 00:50:49 -04:00
|
|
|
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)
|