diff --git a/ispmanager-plugin-nginx_mod_rewrite_plugin.spec b/ispmanager-plugin-nginx_mod_rewrite_plugin.spec index 531cdbc..57d3765 100644 --- a/ispmanager-plugin-nginx_mod_rewrite_plugin.spec +++ b/ispmanager-plugin-nginx_mod_rewrite_plugin.spec @@ -23,6 +23,7 @@ cp -r usr/* %{buildroot}/usr mkdir -p %{buildroot}/usr/local/ispmanager-mod_rewrite/utils wget -O %{buildroot}/usr/local/ispmanager-mod_rewrite/mod_rewrite.zip https://github.com/bayrepo/ngx_http_apache_rewrite_module/archive/refs/heads/main.zip cp utils/build_mod_rewrite.py %{buildroot}/usr/local/ispmanager-mod_rewrite/utils +mkdir -p %{buildroot}/usr/local/ispmanager-mod_rewrite/settings %triggerin -- nginx /usr/local/ispmanager-mod_rewrite/utils/build_mod_rewrite.py @@ -41,9 +42,12 @@ fi %attr(700, root, root) /usr/local/mgr5/addon/nginx_form_rewrite_plugin.py %attr(600, root, root) /usr/local/ispmanager-mod_rewrite/mod_rewrite.zip %attr(700, root, root) /usr/local/ispmanager-mod_rewrite/utils/build_mod_rewrite.py +%attr(700, root, root) %dir /usr/local/ispmanager-mod_rewrite/settings %attr(644, root, root) /usr/local/mgr5/skins/icons/mod_rewrite_menu.svg %attr(644, root, root) /usr/local/mgr5/skins/icons/mod_rewrite_tool.svg -%attr(644, root, root) /usr/local/mgr5/etc/sql/webdomain.addon/nginx_mod_rewrite_plugin +%attr(644, root, root) /usr/local/mgr5/skins/common/plugin-logo/ispmanager-plugin-nginx_mod_rewrite_plugin.png +%attr(600, root, root) /usr/local/mgr5/etc/sql/webdomain.addon/nginx_mod_rewrite_plugin_webdomain_edit_enable + %changelog * Mon Jun 29 2026 Alexey BayRepo - 0.0.1-1 diff --git a/usr/local/mgr5/addon/nginx_form_rewrite_plugin.py b/usr/local/mgr5/addon/nginx_form_rewrite_plugin.py index f3992e0..e281a07 100755 --- a/usr/local/mgr5/addon/nginx_form_rewrite_plugin.py +++ b/usr/local/mgr5/addon/nginx_form_rewrite_plugin.py @@ -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": diff --git a/usr/local/mgr5/skins/common/plugin-logo/ispmanager-plugin-nginx_mod_rewrite_plugin.png b/usr/local/mgr5/skins/common/plugin-logo/ispmanager-plugin-nginx_mod_rewrite_plugin.png new file mode 100644 index 0000000..af75e33 Binary files /dev/null and b/usr/local/mgr5/skins/common/plugin-logo/ispmanager-plugin-nginx_mod_rewrite_plugin.png differ