From f93bdc69bf4c992a0233344894aea179fd879ec4 Mon Sep 17 00:00:00 2001 From: Aidaho Date: Tue, 19 Sep 2023 14:14:46 +0300 Subject: [PATCH] v7.0.0.0 Changelog: https://roxy-wi.org/changelog#7.0.0 --- app/modules/service/action.py | 45 ++++++++++++++++++++++++++++------- app/modules/service/common.py | 3 +-- app/routes/admin/routes.py | 1 + app/routes/server/routes.py | 4 ++-- inc/users.js | 3 ++- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/app/modules/service/action.py b/app/modules/service/action.py index 2aab9cca..5bb3e1df 100644 --- a/app/modules/service/action.py +++ b/app/modules/service/action.py @@ -21,14 +21,20 @@ def common_action(server_ip: str, action: str, service: str) -> str: def action_haproxy(server_ip: str, action: str) -> str: haproxy_service_name = "haproxy" - service_common.is_restarted(server_ip, action) + try: + service_common.is_restarted(server_ip, action) + except Exception as e: + return str(e) if service_common.check_haproxy_config(server_ip): server_id = sql.select_server_id_by_ip(server_ip=server_ip) is_docker = sql.select_service_setting(server_id, 'haproxy', 'dockerized') if action == 'restart': - service_common.is_not_allowed_to_restart(server_id, 'haproxy') + try: + service_common.is_not_allowed_to_restart(server_id, 'haproxy') + except Exception as e: + return str(e) if is_docker == '1': container_name = sql.get_setting('haproxy_container_name') @@ -46,13 +52,19 @@ def action_haproxy(server_ip: str, action: str) -> str: def action_nginx(server_ip: str, action: str) -> str: - service_common.is_restarted(server_ip, action) + try: + service_common.is_restarted(server_ip, action) + except Exception as e: + return str(e) if service_common.check_nginx_config(server_ip): server_id = sql.select_server_id_by_ip(server_ip=server_ip) if action == 'restart': - service_common.is_not_allowed_to_restart(server_id, 'nginx') + try: + service_common.is_not_allowed_to_restart(server_id, 'nginx') + except Exception as e: + return str(e) is_docker = sql.select_service_setting(server_id, 'nginx', 'dockerized') if is_docker == '1': @@ -68,7 +80,10 @@ def action_nginx(server_ip: str, action: str) -> str: def action_keepalived(server_ip: str, action: str) -> str: - service_common.is_restarted(server_ip, action) + try: + service_common.is_restarted(server_ip, action) + except Exception as e: + return str(e) commands = [f"sudo systemctl {action} keepalived"] server_mod.ssh_command(server_ip, commands) @@ -77,12 +92,18 @@ def action_keepalived(server_ip: str, action: str) -> str: def action_apache(server_ip: str, action: str) -> str: - service_common.is_restarted(server_ip, action) + try: + service_common.is_restarted(server_ip, action) + except Exception as e: + return str(e) server_id = sql.select_server_id_by_ip(server_ip) if action == 'restart': - service_common.is_not_allowed_to_restart(server_id, 'apache') + try: + service_common.is_not_allowed_to_restart(server_id, 'apache') + except Exception as e: + return str(e) is_docker = sql.select_service_setting(server_id, 'apache', 'dockerized') if is_docker == '1': @@ -98,7 +119,10 @@ def action_apache(server_ip: str, action: str) -> str: def action_haproxy_waf(server_ip: str, action: str) -> str: - service_common.is_restarted(server_ip, action) + try: + service_common.is_restarted(server_ip, action) + except Exception as e: + return str(e) roxywi_common.logging(server_ip, f'HAProxy WAF service has been {action}ed', roxywi=1, login=1, keep_history=1, service='haproxy') @@ -110,7 +134,10 @@ def action_haproxy_waf(server_ip: str, action: str) -> str: def action_nginx_waf(server_ip: str, action: str) -> str: config_dir = common.return_nice_path(sql.get_setting('nginx_dir')) - service_common.is_restarted(server_ip, action) + try: + service_common.is_restarted(server_ip, action) + except Exception as e: + return str(e) waf_new_state = 'on' if action == 'start' else 'off' waf_old_state = 'off' if action == 'start' else 'on' diff --git a/app/modules/service/common.py b/app/modules/service/common.py index 79b879dc..f719941c 100644 --- a/app/modules/service/common.py +++ b/app/modules/service/common.py @@ -32,8 +32,7 @@ def is_restarted(server_ip: str, action: str) -> None: user_role = sql.get_user_role_by_uuid(user_uuid, group_id) if sql.is_serv_protected(server_ip) and int(user_role) > 2: - print(f'error: This server is protected. You cannot {action} it') - return + raise Exception(f'error: This server is protected. You cannot {action} it') def is_not_allowed_to_restart(server_id: int, service: str) -> None: diff --git a/app/routes/admin/routes.py b/app/routes/admin/routes.py index bf77d14c..4aea0753 100644 --- a/app/routes/admin/routes.py +++ b/app/routes/admin/routes.py @@ -212,6 +212,7 @@ def action_openvpn(action, openvpn): @bp.route('/setting//', methods=['POST']) def update_settings(param, val): + val = val.replace('92', '/') user_group = roxywi_common.get_user_group(id=1) if sql.update_setting(param, val, user_group): roxywi_common.logging('Roxy-WI server', f'The {param} setting has been changed to: {val}', roxywi=1, login=1) diff --git a/app/routes/server/routes.py b/app/routes/server/routes.py index d4142944..d200b728 100644 --- a/app/routes/server/routes.py +++ b/app/routes/server/routes.py @@ -109,7 +109,7 @@ def create_server(): return f'error: {e}' -@bp.route('/create/after', methods=['POST']) +@bp.post('/create/after') def after_add(): hostname = common.checkAjaxInput(request.form.get('servername')) ip = common.is_ip_or_dns(request.form.get('newip')) @@ -121,7 +121,7 @@ def after_add(): return str(e) -@bp.route('/update', methods=['POST']) +@bp.post('/update') def update_server(): roxywi_auth.page_for_admin(level=2) name = request.form.get('updateserver') diff --git a/inc/users.js b/inc/users.js index 99415d52..41195939 100644 --- a/inc/users.js +++ b/inc/users.js @@ -1392,6 +1392,7 @@ function addGit(dialog_id) { } } function updateSettings(param, val) { + val = val.replace(/\//g, "92"); toastr.clear(); $.ajax( { url: "/app/admin/setting/" + param + "/" + val, @@ -1926,7 +1927,7 @@ function updateServer(id) { servergroup = $('#new-server-group-add').val(); } $.ajax({ - url: "/app/admin/update", + url: "/app/server/update", data: { updateserver: $('#hostname-' + id).val(), port: $('#port-' + id).val(),