""" MIT License Copyright (C) 2023 ROCKY4546 https://github.com/rocky4546 This file is part of Cabernet Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. """ from lib.web.pages.templates import web_templates from lib.common.decorators import getrequest from lib.common.decorators import postrequest @getrequest.route('/api/configform') def get_configform_html(_webserver): if 'area' in _webserver.query_data: configform = ConfigFormHTML() form = configform.get(_webserver.plugins.config_obj.defn_json.get_defn( _webserver.query_data['area']), _webserver.query_data['area'], _webserver.plugins.config_obj.data) _webserver.do_mime_response(200, 'text/html', form) else: _webserver.do_mime_response(404, 'text/html', web_templates['htmlError'].format('404 - Area Not Found')) @postrequest.route('/api/configform') def post_configform_html(_webserver): if _webserver.config['web']['disable_web_config']: _webserver.do_mime_response( 501, 'text/html', web_templates['htmlError'] .format('501 - Config pages disabled. ' 'Set [web][disable_web_config] to False in the config file to enable')) else: # Take each key and make a [section][key] to store the value config_changes = {} area = _webserver.query_data['area'][0] del _webserver.query_data['area'] del _webserver.query_data['name'] del _webserver.query_data['instance'] for key in _webserver.query_data: key_pair = key.split('-', 1) if key_pair[0] not in config_changes: config_changes[key_pair[0]] = {} config_changes[key_pair[0]][key_pair[1]] = _webserver.query_data[key] results = _webserver.plugins.config_obj.update_config(area, config_changes) _webserver.do_mime_response(200, 'text/html', results) class ConfigFormHTML: def __init__(self): self.area = None self.config_defn = None self.config = None def get(self, _config_defn, _area, _config): self.area = _area self.config = _config self.config_defn = _config_defn return ''.join([self.header, self.body]) @property def header(self): return ''.join([ '
', '', '', '