from flask import Flask, request, redirect, url_for, jsonify, Response, send_from_directory import json import logging import mimetypes import os import queue import re import gzip import shutil import sys import subprocess import threading import time from pathlib import Path from datetime import datetime, timedelta # Add parent directory to path for imports sys.path.insert(0, str(Path(__file__).parent.parent)) # Configure logging before anything below logs: the same setup as the display # service (run.py), so this process's journal lines carry their real syslog # priority too (`journalctl -p err -u ledmatrix-web`). LEDMATRIX_DEBUG=true # turns on DEBUG, which includes the routine per-request lines. from src.logging_config import setup_logging setup_logging(format_type=( 'json' if os.environ.get('LEDMATRIX_JSON_LOGGING', 'false').lower() == 'true' else 'readable')) logging.getLogger('werkzeug').setLevel(logging.WARNING) # request_logging covers requests logging.getLogger('urllib3').setLevel(logging.WARNING) from src.config_manager import ConfigManager from src.web_interface.error_handler import describe_exception from src.common.path_safety import ( resolve_under, safe_path_component, safe_relative_parts, ) from werkzeug.exceptions import HTTPException from src.exceptions import ConfigError from src.plugin_system.plugin_catalog import PluginCatalog from src.plugin_system.store_manager import PluginStoreManager from src.plugin_system.saved_repositories import SavedRepositoriesManager from src.plugin_system.schema_manager import SchemaManager from src.plugin_system.operation_queue import PluginOperationQueue from src.plugin_system.operation_history import OperationHistory _JOURNALCTL = shutil.which('journalctl') _SYSTEMCTL = shutil.which('systemctl') _NMCLI = shutil.which('nmcli') _VCGENCMD = shutil.which('vcgencmd') from web_interface import display_preview from web_interface.system_metrics import collect_system_metrics # Static files get their Content-Type from the mimetypes table, which reads the # host's own files (/etc/mime.types, the Windows registry). Browsers refuse to # run a