This commit is contained in:
Alexey Berezhok
2026-07-14 00:29:07 +03:00
parent ea55a7d4ba
commit 9c5792de53

View File

@@ -267,14 +267,14 @@ def set_nginx_rewrite_module(enable: bool):
except Exception as e: except Exception as e:
_log(f"Error disabling module in config file {CONFIG_PATH}: {e}") _log(f"Error disabling module in config file {CONFIG_PATH}: {e}")
def make_nginx_custom_template() -> None: def make_nginx_custom_template() -> bool:
tmpl = "/usr/local/mgr5/etc/templates/nginx-vhosts.template" tmpl = "/usr/local/mgr5/etc/templates/nginx-vhosts.template"
tmpl_ssl = "/usr/local/mgr5/etc/templates/nginx-vhosts-ssl.template" tmpl_ssl = "/usr/local/mgr5/etc/templates/nginx-vhosts-ssl.template"
# If templates already exist, abort # If templates already exist, abort
if os.path.exists(tmpl) or os.path.exists(tmpl_ssl): if os.path.exists(tmpl) or os.path.exists(tmpl_ssl):
_log("Error: Custom templates already exist. Aborting make_nginx_custom_template.") _log("Error: Custom templates already exist. Aborting make_nginx_custom_template.")
return return False
default_dir = "/usr/local/mgr5/etc/templates/default" default_dir = "/usr/local/mgr5/etc/templates/default"
default_tmpl = os.path.join(default_dir, "nginx-vhosts.template") default_tmpl = os.path.join(default_dir, "nginx-vhosts.template")
@@ -296,7 +296,7 @@ def make_nginx_custom_template() -> None:
os.remove(f) os.remove(f)
except Exception: except Exception:
pass pass
return return False
# Ensure copied files exist # Ensure copied files exist
if not os.path.exists(tmpl) or not os.path.exists(tmpl_ssl): if not os.path.exists(tmpl) or not os.path.exists(tmpl_ssl):
@@ -307,7 +307,7 @@ def make_nginx_custom_template() -> None:
os.remove(f) os.remove(f)
except Exception: except Exception:
pass pass
return return False
patches_dir = "/usr/local/ispmanager-mod_rewrite/patches" patches_dir = "/usr/local/ispmanager-mod_rewrite/patches"
patch_tmpl = os.path.join(patches_dir, "nginx-vhosts.template.patch") patch_tmpl = os.path.join(patches_dir, "nginx-vhosts.template.patch")
@@ -346,10 +346,11 @@ def make_nginx_custom_template() -> None:
os.remove(f) os.remove(f)
except Exception: except Exception:
pass pass
return return False
read_global_config({'param_name': 'templates_created', 'param_value': 'on'}) read_global_config({'param_name': 'templates_created', 'param_value': 'on'})
_log("Success: Custom Nginx templates created and patched successfully.") _log("Success: Custom Nginx templates created and patched successfully.")
return True
if __name__ == "__main__": if __name__ == "__main__":
root = etree.parse(stdin).getroot() root = etree.parse(stdin).getroot()
@@ -399,11 +400,15 @@ if __name__ == "__main__":
nginx_mod_rewrite_plugin_menu_global_module_enable = os.getenv("PARAM_nginx_mod_rewrite_plugin_menu_global_module_enable") 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 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"): 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'}) if make_nginx_custom_template():
new_element = etree.Element("nginx_mod_rewrite_plugin_menu_global_module_enable") read_global_config({'param_name': 'global_mod_rewrite_enable', 'param_value': 'on'})
new_element.text = "on" new_element = etree.Element("nginx_mod_rewrite_plugin_menu_global_module_enable")
root.append(new_element) new_element.text = "on"
make_nginx_custom_template() root.append(new_element)
else:
new_element = etree.Element("nginx_mod_rewrite_plugin_menu_global_module_enable")
new_element.text = "off"
root.append(new_element)
elif nginx_mod_rewrite_plugin_menu_global_module_enable == "off" and mod_rewrite_global in ("1", "on"): 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'}) 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 = etree.Element("nginx_mod_rewrite_plugin_menu_global_module_enable")