From 87daddbeb2a00f01c3bf2e6076267431c8055366 Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Sun, 10 Aug 2025 12:52:27 -0500 Subject: [PATCH] web action permission changes --- src/display_manager.py | 6 +++++- web_interface_v2.py | 28 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/display_manager.py b/src/display_manager.py index 47e83a66..43a53d98 100644 --- a/src/display_manager.py +++ b/src/display_manager.py @@ -21,9 +21,10 @@ class DisplayManager: cls._instance = super(DisplayManager, cls).__new__(cls) return cls._instance - def __init__(self, config: Dict[str, Any] = None): + def __init__(self, config: Dict[str, Any] = None, force_fallback: bool = False): start_time = time.time() self.config = config or {} + self._force_fallback = force_fallback self._setup_matrix() logger.info("Matrix setup completed in %.3f seconds", time.time() - start_time) @@ -39,6 +40,9 @@ class DisplayManager: setup_start = time.time() try: + # Allow callers (e.g., web UI) to force non-hardware fallback mode + if getattr(self, '_force_fallback', False): + raise RuntimeError('Forced fallback mode requested') options = RGBMatrixOptions() # Hardware configuration diff --git a/web_interface_v2.py b/web_interface_v2.py index 33825e27..cf32f8ee 100644 --- a/web_interface_v2.py +++ b/web_interface_v2.py @@ -196,8 +196,8 @@ def start_display(): logger.info("DisplayManager initialized successfully") except Exception as dm_error: logger.error(f"Failed to initialize DisplayManager: {dm_error}") - # Re-attempt with minimal config to enable fallback simulation - display_manager = DisplayManager({'display': {'hardware': {}}}) + # Re-attempt with explicit fallback mode for web preview + display_manager = DisplayManager({'display': {'hardware': {}}}, force_fallback=True) logger.info("Using fallback DisplayManager for web simulation") display_monitor.start() @@ -223,7 +223,12 @@ def start_display(): return jsonify({ 'status': 'success', - 'message': 'Display started successfully' + 'message': 'Display started successfully', + 'dimensions': { + 'width': getattr(display_manager, 'width', 0), + 'height': getattr(display_manager, 'height', 0) + }, + 'fallback': display_manager.matrix is None }) except Exception as e: logger.error(f"Error in start_display: {e}", exc_info=True) @@ -616,11 +621,20 @@ def get_logs(): try: # Get logs from journalctl for the ledmatrix service result = subprocess.run( - ['sudo', '-n', 'journalctl', '-u', 'ledmatrix.service', '-n', '500', '--no-pager'], - capture_output=True, text=True, check=True + ['journalctl', '-u', 'ledmatrix.service', '-n', '500', '--no-pager'], + capture_output=True, text=True, check=False ) - logs = result.stdout - return jsonify({'status': 'success', 'logs': logs}) + if result.returncode == 0: + return jsonify({'status': 'success', 'logs': result.stdout}) + # Permission denied or other error: fall back to web UI log and return hint + fallback_logs = '' + try: + with open('/tmp/web_interface_v2.log', 'r') as f: + fallback_logs = f.read() + except Exception: + fallback_logs = '(No fallback web UI logs found)' + hint = 'Insufficient permissions to read system journal. Add the web user to the systemd-journal group or configure sudoers for journalctl.' + return jsonify({'status': 'error', 'message': f'Error fetching logs: {result.stderr or "permission denied"}\n\nHint: {hint}', 'fallback': fallback_logs}), 500 except subprocess.CalledProcessError as e: # If the command fails, return the error error_message = f"Error fetching logs: {e.stderr}"