mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-05 06:45:09 +00:00
fix(web): plugin dir resolver in routes, nmcli AP detection, daemon config reload, upload safety, BDF preview (#655)
* fix(web): plugin dir resolver in routes, nmcli AP detection, daemon config reload, upload safety - Route plugin lookups (installed list, update, recorded version, config form, web UI pages) through the plugin manager's resolver so plugins in ledmatrix-<id> directories work. - Captive-portal detection also sees the nmcli fallback AP (cached). - WiFi monitor daemon re-reads wifi_config.json when its mtime changes. - Drop the AP check in disconnect_from_network that could never fire. - LED status file per WiFiManager; config path falls back to this checkout. - BDF font preview via src.common.bdf_font. - Asset uploads validate every file before saving; metadata and calendar credentials written atomically; no absolute path in the response; asset delete answers 400 for a missing body. - Coerce string booleans in plugin toggle, on-demand start and AP force. - SSE broadcaster clears its thread handle before exiting. - start.py log filter handles every exc_info form. - Cleanups: unused plugins/fonts partial work, duplicate backup catch-alls, raw-config error helper, update-route tidy, redundant imports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(web): request BDF font previews now that the server renders them The Fonts tab skipped the preview request for .bdf files because the server used to refuse them; /fonts/preview now draws BDF with the shared loader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(web): take the update route's plugin directory from a directory listing CodeQL flagged the path built from the request's plugin_id (the id was already validated with safe_path_component, which CodeQL doesn't model; the same flow on main is alerts 738/739). The directory is now the entry of plugins_dir matched by name, so nothing built from user input reaches the filesystem; an id with nothing installed goes to the store manager, which reports it not found as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(web): read the blueprint's plugin_manager defensively in _plugin_directory _get_plugin_version now goes through _plugin_directory, which read api_v3.plugin_manager directly; the attribute exists only once the app sets it, so test_path_traversal_guards::test_a_real_manifest_is_read failed when run on its own (order-dependent in the full suite). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1150,6 +1150,27 @@ def get_secrets_config():
|
||||
# alone so a client can still tell "set" from "not set".
|
||||
return jsonify({'status': 'success',
|
||||
'data': mask_all_secret_values(config)})
|
||||
def _raw_config_save_error(e):
|
||||
"""The 500 both raw-config save routes answer a failed save with.
|
||||
|
||||
A ConfigError that names its file says which one; the rest is the same
|
||||
for every failure. raw_json.html reads only ``message``, which this
|
||||
keeps, alongside ``status`` and ``details`` as before.
|
||||
"""
|
||||
from src.exceptions import ConfigError
|
||||
error_message = 'An error occurred; see logs for details'
|
||||
config_path = getattr(e, 'config_path', None) if isinstance(e, ConfigError) else None
|
||||
if config_path:
|
||||
error_message = f"{error_message} (config_path: {config_path})"
|
||||
return error_response(
|
||||
ErrorCode.CONFIG_SAVE_FAILED if isinstance(e, ConfigError) else ErrorCode.UNKNOWN_ERROR,
|
||||
error_message,
|
||||
details=describe_exception(e),
|
||||
context={'config_path': config_path} if config_path else None,
|
||||
status_code=500
|
||||
)
|
||||
|
||||
|
||||
@api_v3.route('/config/raw/main', methods=['POST'])
|
||||
def save_raw_main_config():
|
||||
"""Save raw main configuration JSON"""
|
||||
@@ -1193,31 +1214,8 @@ def save_raw_main_config():
|
||||
logger.warning("Automatic update setup could not be started", exc_info=True)
|
||||
return jsonify({'status': 'success', 'message': message})
|
||||
except Exception as e:
|
||||
from src.exceptions import ConfigError
|
||||
logger.error("Error saving raw main config", exc_info=True)
|
||||
|
||||
# Extract more specific error message if it's a ConfigError
|
||||
if isinstance(e, ConfigError):
|
||||
error_message = 'An error occurred; see logs for details'
|
||||
if hasattr(e, 'config_path') and e.config_path:
|
||||
error_message = f"{error_message} (config_path: {e.config_path})"
|
||||
return error_response(
|
||||
ErrorCode.CONFIG_SAVE_FAILED,
|
||||
error_message,
|
||||
details=describe_exception(e),
|
||||
|
||||
context={'config_path': e.config_path} if hasattr(e, 'config_path') and e.config_path else None,
|
||||
status_code=500
|
||||
)
|
||||
else:
|
||||
error_message = 'An error occurred; see logs for details'
|
||||
return error_response(
|
||||
ErrorCode.UNKNOWN_ERROR,
|
||||
error_message,
|
||||
details=describe_exception(e),
|
||||
|
||||
status_code=500
|
||||
)
|
||||
return _raw_config_save_error(e)
|
||||
@api_v3.route('/config/raw/secrets', methods=['POST'])
|
||||
def save_raw_secrets_config():
|
||||
"""Save raw secrets configuration JSON"""
|
||||
@@ -1257,17 +1255,5 @@ def save_raw_secrets_config():
|
||||
|
||||
return jsonify({'status': 'success', 'message': 'Secrets configuration saved successfully'})
|
||||
except Exception as e:
|
||||
from src.exceptions import ConfigError
|
||||
logger.error("Error saving raw secrets config", exc_info=True)
|
||||
|
||||
# Extract more specific error message if it's a ConfigError
|
||||
if isinstance(e, ConfigError):
|
||||
# ConfigError has a message attribute and may have context
|
||||
error_message = 'An error occurred; see logs for details'
|
||||
if hasattr(e, 'config_path') and e.config_path:
|
||||
error_message = f"{error_message} (config_path: {e.config_path})"
|
||||
else:
|
||||
error_message = 'An error occurred; see logs for details'
|
||||
|
||||
return jsonify({'status': 'error', 'message': error_message,
|
||||
'details': describe_exception(e)}), 500
|
||||
return _raw_config_save_error(e)
|
||||
|
||||
Reference in New Issue
Block a user