From af25700ede37ee0c08e382404485204c49bab570 Mon Sep 17 00:00:00 2001 From: Aidaho Date: Sat, 17 Feb 2024 15:28:34 +0300 Subject: [PATCH] v7.2.0.0 Small logging fixes --- app/modules/db/sql.py | 2 +- app/modules/roxywi/common.py | 11 ++++---- app/modules/roxywi/user.py | 4 +-- app/modules/service/ha_cluster.py | 26 ++++++++++-------- app/modules/service/installation.py | 10 +++---- app/modules/tools/smon.py | 2 +- app/modules/tools/smon_agent.py | 6 ++-- app/routes/ha/routes.py | 14 +++++----- .../keepalived/templates/keepalived.conf.j2 | 4 ++- {inc => app/static}/images/sort_asc.png | Bin .../static}/images/sort_asc_disabled.png | Bin {inc => app/static}/images/sort_both.png | Bin {inc => app/static}/images/sort_desc.png | Bin .../images/sort_desc_disabled copy.png | Bin .../static}/images/sort_desc_disabled.png | Bin .../images/ui-icons_444444_256x240.png | Bin .../images/ui-icons_555555_256x240.png | Bin .../images/ui-icons_777777_256x240.png | Bin .../images/ui-icons_ffffff_256x240.png | Bin inc/users.js | 10 +++---- 20 files changed, 47 insertions(+), 42 deletions(-) rename {inc => app/static}/images/sort_asc.png (100%) rename {inc => app/static}/images/sort_asc_disabled.png (100%) rename {inc => app/static}/images/sort_both.png (100%) rename {inc => app/static}/images/sort_desc.png (100%) rename {inc => app/static}/images/sort_desc_disabled copy.png (100%) rename {inc => app/static}/images/sort_desc_disabled.png (100%) rename {inc => app/static}/images/ui-icons_444444_256x240.png (100%) rename {inc => app/static}/images/ui-icons_555555_256x240.png (100%) rename {inc => app/static}/images/ui-icons_777777_256x240.png (100%) rename {inc => app/static}/images/ui-icons_ffffff_256x240.png (100%) diff --git a/app/modules/db/sql.py b/app/modules/db/sql.py index 630efbbb..af2d791a 100755 --- a/app/modules/db/sql.py +++ b/app/modules/db/sql.py @@ -2872,7 +2872,7 @@ def select_restart_services_settings(service: str) -> str: return query_res -def select_service_setting(server_id: int, service: str, setting: str) -> int: +def select_service_setting(server_id: int, service: str, setting: str) -> str: try: result = ServiceSetting.get( (ServiceSetting.server_id == server_id) diff --git a/app/modules/roxywi/common.py b/app/modules/roxywi/common.py index 73e3d100..40f2b395 100644 --- a/app/modules/roxywi/common.py +++ b/app/modules/roxywi/common.py @@ -149,7 +149,7 @@ def logging(server_ip: str, action: str, **kwargs) -> None: with open(log_file, 'a') as log: log.write(mess) except IOError as e: - print(f'
Cannot write log. Please check log_path in config {e}
') + print(f'Cannot write log. Please check log_path in config {e}') def keep_action_history(service: str, action: str, server_ip: str, login: str, user_ip: str): @@ -161,8 +161,9 @@ def keep_action_history(service: str, action: str, server_ip: str, login: str, u user_ip = 'localhost' if service == 'HA cluster': - cluster_name = sql.select_cluster_name(server_ip) - sql.insert_action_history(service, action, server_ip, user_id, user_ip, server_ip, cluster_name) + cluster_id = server_ip + cluster_name = sql.select_cluster_name(int(cluster_id)) + sql.insert_action_history(service, action, int(cluster_id), user_id, user_ip, cluster_id, cluster_name) else: try: server_id = sql.select_server_id_by_ip(server_ip=server_ip) @@ -303,5 +304,5 @@ def handle_exceptions(ex: Exception, server_ip: str, message: str, **kwargs: Any :return: None """ - logging(server_ip, f'{message}: {ex}', **kwargs) - raise Exception(f'{message}: {ex}') + logging(server_ip, f'error: {message}: {ex}', **kwargs) + raise Exception(f'error: {message}: {ex}') diff --git a/app/modules/roxywi/user.py b/app/modules/roxywi/user.py index 212c6853..bbaa7be1 100644 --- a/app/modules/roxywi/user.py +++ b/app/modules/roxywi/user.py @@ -28,7 +28,7 @@ def create_user(new_user: str, email: str, password: str, role: str, activeuser: except Exception as e: roxywi_common.logging('error: Cannot send email for a new user', e, roxywi=1, login=1) except Exception as e: - roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot create a new user: {e}', roxywi=1, login=1) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot create a new user', roxywi=1, login=1) def delete_user(user_id: int) -> str: @@ -50,7 +50,7 @@ def update_user(email, new_user, user_id, enabled, group_id, role_id): try: sql.update_user(new_user, email, role_id, user_id, enabled) except Exception as e: - print(e) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot update user {new_user}', roxywi=1, login=1) sql.update_user_role(user_id, group_id, role_id) roxywi_common.logging(new_user, ' has been updated user ', roxywi=1, login=1) diff --git a/app/modules/service/ha_cluster.py b/app/modules/service/ha_cluster.py index e11b0ade..29a0a916 100644 --- a/app/modules/service/ha_cluster.py +++ b/app/modules/service/ha_cluster.py @@ -1,12 +1,14 @@ -import modules.db.sql as sql -from modules.db.db_model import HaCluster, HaClusterRouter, HaClusterVip, HaClusterVirt -import modules.common.common as common -import modules.server.server as server_mod -import modules.roxywi.common as roxywi_common -from modules.server.ssh import return_ssh_keys_path +import json + +import app.modules.db.sql as sql +from app.modules.db.db_model import HaCluster, HaClusterRouter, HaClusterVip, HaClusterVirt +import app.modules.common.common as common +import app.modules.server.server as server_mod +import app.modules.roxywi.common as roxywi_common +from app.modules.server.ssh import return_ssh_keys_path -def create_cluster(cluster: object, group_id: int) -> str: +def create_cluster(cluster: json, group_id: int) -> str: master_ip = None vip = common.is_ip_or_dns(cluster['vip']) syn_flood = int(cluster['syn_flood']) @@ -68,7 +70,7 @@ def create_cluster(cluster: object, group_id: int) -> str: return str(cluster_id) -def update_cluster(cluster: object, group_id: int) -> str: +def update_cluster(cluster: json, group_id: int) -> str: cluster_id = int(cluster['cluster_id']) syn_flood = int(cluster['syn_flood']) cluster_name = common.checkAjaxInput(cluster['name']) @@ -130,7 +132,7 @@ def delete_cluster(cluster_id: int) -> str: return 'ok' -def update_vip(cluster_id: int, router_id: int, json_data: object, group_id: int) -> None: +def update_vip(cluster_id: int, router_id: int, json_data: json, group_id: int) -> None: return_master = int(json_data['return_to_master']) vip = common.is_ip_or_dns(json_data['vip']) vip_id = sql.select_clusters_vip_id(cluster_id, router_id) @@ -159,7 +161,7 @@ def update_vip(cluster_id: int, router_id: int, json_data: object, group_id: int roxywi_common.logging(cluster_id, f'Cluster VIP {vip} has been updated', keep_history=1, roxywi=1, service='HA cluster') -def insert_vip(cluster_id: int, json_data: object, group_id: int) -> None: +def insert_vip(cluster_id: int, json_data: json, group_id: int) -> None: vip = common.is_ip_or_dns(json_data['vip']) return_master = int(json_data['return_to_master']) @@ -185,7 +187,7 @@ def insert_vip(cluster_id: int, json_data: object, group_id: int) -> None: roxywi_common.logging(cluster_id, f'New cluster VIP: {vip} has been created', keep_history=1, roxywi=1, service='HA cluster') -def update_slaves(json_data: object, router_id: int) -> None: +def update_slaves(json_data: json, router_id: int) -> None: master_ip = None cluster = json_data cluster_id = int(json_data['cluster_id']) @@ -243,7 +245,7 @@ def update_slaves(json_data: object, router_id: int) -> None: raise Exception(f'error: Cannot update server {value["ip"]}: {e}') -def add_or_update_virt(cluster: object, cluster_id: int, vip_id: int, group_id: int) -> None: +def add_or_update_virt(cluster: json, cluster_id: int, vip_id: int, group_id: int) -> None: haproxy = 0 nginx = 0 apache = 0 diff --git a/app/modules/service/installation.py b/app/modules/service/installation.py index b7f6a725..c72088ca 100644 --- a/app/modules/service/installation.py +++ b/app/modules/service/installation.py @@ -390,13 +390,13 @@ def run_ansible(inv: dict, server_ips: str, ansible_role: str) -> object: invent.write(str(inv)) except Exception as e: server_mod.stop_ssh_agent(agent_pid) - roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'error: Cannot save inventory file', roxywi=1) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot save inventory file', roxywi=1) try: result = ansible_runner.run(**kwargs) except Exception as e: server_mod.stop_ssh_agent(agent_pid) - roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'error: Cannot run Ansible', roxywi=1) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot run Ansible', roxywi=1) try: server_mod.stop_ssh_agent(agent_pid) @@ -425,7 +425,7 @@ def service_actions_after_install(server_ips: str, service: str, json_data) -> N try: update_functions[service](server_ip) except Exception as e: - roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot activate {service} on server {server_ip}', roxywi=1) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot activate {service} on server {server_ip}', roxywi=1) if service != 'keepalived': is_docker = json_data['services'][service]['docker'] @@ -439,7 +439,7 @@ def install_service(service: str, json_data: str) -> object: try: json_data = json.loads(json_data) except Exception as e: - roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'error: Cannot parse JSON', roxywi=1) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot parse JSON', roxywi=1) generate_functions = { 'haproxy': generate_haproxy_inv, @@ -453,7 +453,7 @@ def install_service(service: str, json_data: str) -> object: service_actions_after_install(server_ips, service, json_data) return run_ansible(inv, server_ips, service), 201 except Exception as e: - roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot install {service}', roxywi=1) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot install {service}', roxywi=1) def _install_ansible_collections(): diff --git a/app/modules/tools/smon.py b/app/modules/tools/smon.py index 48f3121c..1b4dfe0e 100644 --- a/app/modules/tools/smon.py +++ b/app/modules/tools/smon.py @@ -175,7 +175,7 @@ def delete_smon(smon_id, user_group) -> str: server_ip = smon_sql.get_agent_ip_by_id(agent_id) smon_agent.delete_check(agent_id, server_ip, smon_id) except Exception as e: - roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot delete check: {e}', roxywi=1, login=1) + roxywi_common.handle_exceptions(e, 'Roxy-WI server', f'Cannot delete check', roxywi=1, login=1) try: if smon_sql.delete_smon(smon_id, user_group): roxywi_common.logging('SMON', ' The server from SMON has been delete ', roxywi=1, login=1) diff --git a/app/modules/tools/smon_agent.py b/app/modules/tools/smon_agent.py index b8591a86..41d354d9 100644 --- a/app/modules/tools/smon_agent.py +++ b/app/modules/tools/smon_agent.py @@ -47,7 +47,7 @@ def add_agent(data) -> int: common_roxywi.logging(server_ip, 'A new SMON agent has been created', roxywi=1, login=1, keep_history=1, service='SMON') return last_id except Exception as e: - common_roxywi.handle_exceptions(e, 'Roxy-WI server', 'error: Cannot create Agent', roxywi=1, login=1) + common_roxywi.handle_exceptions(e, 'Roxy-WI server', 'Cannot create Agent', roxywi=1, login=1) def delete_agent(agent_id: int): @@ -57,7 +57,7 @@ def delete_agent(agent_id: int): inv, server_ips = generate_agent_inc(server_ip, 'uninstall', agent_uuid) run_ansible(inv, server_ips, 'smon_agent') except Exception as e: - common_roxywi.handle_exceptions(e, server_ip, 'error: Cannot uninstall SMON agent', roxywi=1, login=1) + common_roxywi.handle_exceptions(e, server_ip, 'Cannot uninstall SMON agent', roxywi=1, login=1) def update_agent(json_data): @@ -69,7 +69,7 @@ def update_agent(json_data): try: smon_sql.update_agent(agent_id, name, desc, enabled) except Exception as e: - common_roxywi.handle_exceptions(e, 'Roxy-WI server', f'error: Cannot update SMON agent: {agent_id}', roxywi=1, login=1) + common_roxywi.handle_exceptions(e, 'Roxy-WI server', f'Cannot update SMON agent: {agent_id}', roxywi=1, login=1) def get_agent_headers(agent_id: int) -> dict: diff --git a/app/routes/ha/routes.py b/app/routes/ha/routes.py index b45f055c..cf813fd7 100644 --- a/app/routes/ha/routes.py +++ b/app/routes/ha/routes.py @@ -5,18 +5,18 @@ from flask_login import login_required from app.routes.ha import bp from middleware import get_user_params, check_services -import modules.db.sql as sql -import modules.common.common as common -import modules.server.server as server_mod -import modules.roxywi.common as roxywi_common -import modules.service.keepalived as keepalived -import modules.service.ha_cluster as ha_cluster +import app.modules.db.sql as sql +import app.modules.common.common as common +import app.modules.server.server as server_mod +import app.modules.roxywi.common as roxywi_common +import app.modules.service.keepalived as keepalived +import app.modules.service.ha_cluster as ha_cluster @bp.before_request @login_required def before_request(): - """ Protect all of the admin endpoints. """ + """ Protect all the admin endpoints. """ pass diff --git a/app/scripts/ansible/roles/keepalived/templates/keepalived.conf.j2 b/app/scripts/ansible/roles/keepalived/templates/keepalived.conf.j2 index e93ca020..aacd2699 100644 --- a/app/scripts/ansible/roles/keepalived/templates/keepalived.conf.j2 +++ b/app/scripts/ansible/roles/keepalived/templates/keepalived.conf.j2 @@ -1,6 +1,7 @@ global_defs { # Managed by Roxy-WI do not edit this file. Use HA cluster configuration instead router_id LVS_DEVEL + enable_script_security } @@ -13,6 +14,7 @@ vrrp_script chk_nginx { } {% endif %} + {%- if HAPROXY %} #HAProxy health-check for keepalive vrrp_script chk_haproxy { @@ -52,7 +54,7 @@ vrrp_instance VI_{{router}} { advert_int 1 authentication { auth_type PASS - auth_pass VerySecretPass + auth_pass VerySecr } virtual_ipaddress { {{vip.vip}} diff --git a/inc/images/sort_asc.png b/app/static/images/sort_asc.png similarity index 100% rename from inc/images/sort_asc.png rename to app/static/images/sort_asc.png diff --git a/inc/images/sort_asc_disabled.png b/app/static/images/sort_asc_disabled.png similarity index 100% rename from inc/images/sort_asc_disabled.png rename to app/static/images/sort_asc_disabled.png diff --git a/inc/images/sort_both.png b/app/static/images/sort_both.png similarity index 100% rename from inc/images/sort_both.png rename to app/static/images/sort_both.png diff --git a/inc/images/sort_desc.png b/app/static/images/sort_desc.png similarity index 100% rename from inc/images/sort_desc.png rename to app/static/images/sort_desc.png diff --git a/inc/images/sort_desc_disabled copy.png b/app/static/images/sort_desc_disabled copy.png similarity index 100% rename from inc/images/sort_desc_disabled copy.png rename to app/static/images/sort_desc_disabled copy.png diff --git a/inc/images/sort_desc_disabled.png b/app/static/images/sort_desc_disabled.png similarity index 100% rename from inc/images/sort_desc_disabled.png rename to app/static/images/sort_desc_disabled.png diff --git a/inc/images/ui-icons_444444_256x240.png b/app/static/images/ui-icons_444444_256x240.png similarity index 100% rename from inc/images/ui-icons_444444_256x240.png rename to app/static/images/ui-icons_444444_256x240.png diff --git a/inc/images/ui-icons_555555_256x240.png b/app/static/images/ui-icons_555555_256x240.png similarity index 100% rename from inc/images/ui-icons_555555_256x240.png rename to app/static/images/ui-icons_555555_256x240.png diff --git a/inc/images/ui-icons_777777_256x240.png b/app/static/images/ui-icons_777777_256x240.png similarity index 100% rename from inc/images/ui-icons_777777_256x240.png rename to app/static/images/ui-icons_777777_256x240.png diff --git a/inc/images/ui-icons_ffffff_256x240.png b/app/static/images/ui-icons_ffffff_256x240.png similarity index 100% rename from inc/images/ui-icons_ffffff_256x240.png rename to app/static/images/ui-icons_ffffff_256x240.png diff --git a/inc/users.js b/inc/users.js index 687d21b6..9083e290 100644 --- a/inc/users.js +++ b/inc/users.js @@ -1775,25 +1775,25 @@ function showApacheLog(serv) { } ); } function checkSshConnect(ip) { - $.ajax( { + $.ajax({ url: "/app/server/check/ssh/" + ip, // data: { // token: $('#token').val() // }, // type: "POST", - success: function( data ) { + success: function (data) { if (data.indexOf('error:') != '-1') { toastr.error(data) - } else if(data.indexOf('failed') != '-1') { + } else if (data.indexOf('failed') != '-1') { toastr.error(data) - } else if(data.indexOf('Errno') != '-1') { + } else if (data.indexOf('Errno') != '-1') { toastr.error(data) } else { toastr.clear(); toastr.success('Connect is accepted'); } } - } ); + }); } function openChangeUserPasswordDialog(id) { changeUserPasswordDialog(id);