Fixes
This commit is contained in:
@@ -29,6 +29,68 @@ def nginx_restart():
|
||||
except Exception as e:
|
||||
_log(f"Error restarting nginx: {e}")
|
||||
|
||||
def read_global_config(params):
|
||||
"""
|
||||
Reads or writes a parameter in the global settings configuration file.
|
||||
:param params: dict with keys 'param_name' and 'param_value'.
|
||||
:return: param_value as string if reading; None otherwise.
|
||||
"""
|
||||
param_name = params.get('param_name')
|
||||
if not param_name:
|
||||
return None
|
||||
param_value = params.get('param_value')
|
||||
config_path = "/usr/local/ispmanager-mod_rewrite/settings/global_settings.cfg"
|
||||
|
||||
if param_value is None:
|
||||
# Read mode
|
||||
if not os.path.exists(config_path):
|
||||
return None
|
||||
try:
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
stripped = line.strip()
|
||||
if stripped.startswith('#'):
|
||||
continue
|
||||
pattern = rf'^\s*{re.escape(param_name)}\s*=\s*(.*)$'
|
||||
m = re.match(pattern, line)
|
||||
if m:
|
||||
return m.group(1).strip()
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
else:
|
||||
# Write mode
|
||||
dir_path = os.path.dirname(config_path)
|
||||
try:
|
||||
os.makedirs(dir_path, exist_ok=True)
|
||||
except Exception:
|
||||
return None
|
||||
lines = []
|
||||
found = False
|
||||
if os.path.exists(config_path):
|
||||
try:
|
||||
with open(config_path, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
except Exception:
|
||||
return None
|
||||
for idx, line in enumerate(lines):
|
||||
stripped = line.strip()
|
||||
if stripped.startswith('#'):
|
||||
continue
|
||||
pattern = rf'^\s*{re.escape(param_name)}\s*=\s*.*$'
|
||||
if re.match(pattern, line):
|
||||
lines[idx] = f"{param_name}={param_value}\n"
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
lines.append(f"{param_name}={param_value}\n")
|
||||
try:
|
||||
with open(config_path, 'w', encoding='utf-8') as f:
|
||||
f.writelines(lines)
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
def check_nginx_rewrite_module():
|
||||
_log("check_nginx_rewrite_module called")
|
||||
if not os.path.exists(CONFIG_PATH):
|
||||
@@ -134,6 +196,7 @@ if __name__ == "__main__":
|
||||
nginx_mod_rewrite_plugin_menu_module_enable = os.getenv("PARAM_nginx_mod_rewrite_plugin_menu_module_enable")
|
||||
mod_enabled = check_nginx_rewrite_module()
|
||||
_log(f"Current module state: {'enabled' if mod_enabled else 'disabled'}")
|
||||
mod_rewrite_global = read_global_config({'param_name': 'global_mod_rewrite_enable'})
|
||||
|
||||
if os.getenv('PARAM_clicked_button') == 'ok' and nginx_mod_rewrite_plugin_menu_module_enable is not None:
|
||||
if nginx_mod_rewrite_plugin_menu_module_enable == "on" and not mod_enabled:
|
||||
@@ -157,6 +220,27 @@ if __name__ == "__main__":
|
||||
new_element.text = "on" if mod_enabled else "off"
|
||||
root.append(new_element)
|
||||
|
||||
nginx_mod_rewrite_plugin_menu_global_module_enable = os.getenv("PARAM_nginx_mod_rewrite_plugin_menu_global_module_enable")
|
||||
if os.getenv('PARAM_clicked_button') == 'ok' and nginx_mod_rewrite_plugin_menu_global_module_enable is not None:
|
||||
if nginx_mod_rewrite_plugin_menu_global_module_enable == "on" and mod_rewrite_global not in ("1", "on"):
|
||||
read_global_config({'param_name': 'global_mod_rewrite_enable', 'param_value': 'on'})
|
||||
new_element = etree.Element("nginx_mod_rewrite_plugin_menu_global_module_enable")
|
||||
new_element.text = "on"
|
||||
root.append(new_element)
|
||||
elif nginx_mod_rewrite_plugin_menu_global_module_enable == "off" and mod_rewrite_global in ("1", "on"):
|
||||
read_global_config({'param_name': 'global_mod_rewrite_enable', 'param_value': 'off'})
|
||||
new_element = etree.Element("nginx_mod_rewrite_plugin_menu_global_module_enable")
|
||||
new_element.text = "off"
|
||||
root.append(new_element)
|
||||
else:
|
||||
new_element = etree.Element("nginx_mod_rewrite_plugin_menu_global_module_enable")
|
||||
new_element.text = "on" if mod_rewrite_global in ("1", "on") else "off"
|
||||
root.append(new_element)
|
||||
else:
|
||||
new_element = etree.Element("nginx_mod_rewrite_plugin_menu_global_module_enable")
|
||||
new_element.text = "on" if mod_rewrite_global in ("1", "on") else "off"
|
||||
root.append(new_element)
|
||||
|
||||
elif func == "webdomain.edit":
|
||||
_log("webdomain.edit handler")
|
||||
elif func == "site.edit":
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
Reference in New Issue
Block a user