Skip to content

Commit

Permalink
modules.admin: Second Restauration attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
msinn committed Jun 21, 2024
1 parent 2aeea50 commit 8bd9592
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions modules/admin/api_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import json
import cherrypy

from lib.module import Modules
import lib.shyaml as shyaml

from .rest import RESTResource
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions modules/admin/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
9 changes: 5 additions & 4 deletions modules/admin/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 8bd9592

Please sign in to comment.