Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,31 @@
BACKGROUND_EFFECT = os.getenv("FPP_BACKGROUND_EFFECT", "background")
POLL_INTERVAL_SECONDS = max(5, int(os.getenv("FPP_POLL_INTERVAL_MS", "15000")) // 1000)
REQUEST_TIMEOUT = 8
ACCESS_CODE = os.getenv("ACCESS_CODE", "").strip()
def _load_access_code_from_config() -> str:
"""Return access code from generated frontend config if available."""

config_path = os.path.join(os.path.dirname(__file__), "config.js")
if not os.path.exists(config_path):
return ""

try:
with open(config_path, "r", encoding="utf-8") as f:
raw = f.read().strip()
prefix = "window.FPP_CONFIG ="
if not raw.startswith(prefix):
return ""
Comment on lines +33 to +35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle config.js files with leading comments

When ACCESS_CODE is unset but only provided in the bundled frontend config, the new fallback always returns an empty string because it requires config.js to start directly with "window.FPP_CONFIG =". The default config.js and template in this repo both begin with a comment, so the prefix check fails and control endpoints stay unprotected even though the frontend is configured with an access code. This affects deployments that rely on the checked-in config instead of the docker-generated one.

Useful? React with 👍 / 👎.


json_part = raw[len(prefix) :].strip()
if json_part.endswith(";"):
json_part = json_part[:-1]

config = json.loads(json_part)
return str(config.get("accessCode", "")).strip()
except Exception:
return ""


ACCESS_CODE = os.getenv("ACCESS_CODE", "").strip() or _load_access_code_from_config()

state_lock = threading.RLock()
state: Dict[str, Any] = {
Expand Down