From 8bd95925d59da24fbed66e4cbc7d769859b5a458 Mon Sep 17 00:00:00 2001 From: msinn Date: Fri, 21 Jun 2024 17:42:39 +0200 Subject: [PATCH] modules.admin: Second Restauration attempt --- modules/admin/api_config.py | 6 ++++++ modules/admin/api_server.py | 3 +++ modules/admin/rest.py | 9 +++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/admin/api_config.py b/modules/admin/api_config.py index 1ba8bb93fd..1d00fa5ede 100644 --- a/modules/admin/api_config.py +++ b/modules/admin/api_config.py @@ -25,6 +25,7 @@ import json import cherrypy +from lib.module import Modules import lib.shyaml as shyaml from .rest import RESTResource @@ -245,6 +246,11 @@ def update(self, id=None): # update etc/module.yaml with data from admin frontend self.module_confdata = shyaml.yaml_load_roundtrip(os.path.join(self.etc_dir, 'module.yaml')) self.update_configdict(self.module_confdata['http'], data, 'http') + self.mod_http = Modules.get_instance().get_module('http') + hashed_password = data.get('http', {}).get('data', {}).get('hashed_password', '') + if hashed_password is None: + hashed_password = '' + self.mod_http._hashed_password = hashed_password self.update_configdict(self.module_confdata['admin'], data, 'admin') if self.module_confdata.get('websocket', None) is None: diff --git a/modules/admin/api_server.py b/modules/admin/api_server.py index 5b564ebf33..fe8853d69a 100644 --- a/modules/admin/api_server.py +++ b/modules/admin/api_server.py @@ -94,6 +94,9 @@ def root(self): response = {} response['default_language'] = self._sh.get_defaultlanguage() response['client_ip'] = client_ip + http_user_dict = self.module.mod_http.get_user_dict() + response['login_required'] = http_user_dict.get('admin', {"password_hash": ""}).get("password_hash", "") != "" + return json.dumps(response) diff --git a/modules/admin/rest.py b/modules/admin/rest.py index 447221805b..81b3d2239c 100644 --- a/modules/admin/rest.py +++ b/modules/admin/rest.py @@ -252,14 +252,15 @@ def set_response_headers(self, vpath=''): """ Set http response headers for CORS support """ - # if vpath != 'status': - # self.logger.notice(f"set_response_headers ({vpath=}): request headers: {cherrypy.request.headers}") +# if vpath != 'status': +# self.logger.notice(f"set_response_headers ({vpath=}): request headers: {cherrypy.request.headers}") cherrypy.response.headers['Access-Control-Allow-Headers'] = '*' + #cherrypy.response.headers['Access-Control-Allow-Origin'] = '*' origin = cherrypy.request.headers.get('Origin', '*') cherrypy.response.headers['Access-Control-Allow-Origin'] = origin cherrypy.response.headers['Access-Control-Allow-Credentials'] = 'true' - # if vpath != 'status': - # self.logger.notice(f"set_response_headers: response headers for: {cherrypy.response.headers}") +# if vpath != 'status': +# self.logger.notice(f"set_response_headers: response headers for: {cherrypy.response.headers}") @cherrypy.expose def index(self, *vpath, **params):