From 810a9d9460ea44a9aac6f93c65d76f9a440dc6e1 Mon Sep 17 00:00:00 2001 From: Aidaho Date: Fri, 17 Feb 2023 20:21:19 +0300 Subject: [PATCH] v6.3.6.0 Changelog: https://roxy-wi.org/changelog#6_3_6 --- app/create_db.py | 2 +- app/modules/db/db_model.py | 12 +++++++- app/modules/db/sql.py | 28 ++++++++++++++++--- .../roles/haproxy/templates/haproxy.cfg.j2 | 5 ++-- .../haproxy/templates/haproxy_rsyslog.conf.j2 | 2 -- app/templates/ajax/show_system_info.html | 8 +++++- app/templates/base.html | 2 +- app/templates/include/mon_installation.html | 2 +- app/templates/languages/en.html | 4 ++- app/templates/languages/ru.html | 3 ++ inc/users.js | 13 +++++---- 11 files changed, 61 insertions(+), 20 deletions(-) diff --git a/app/create_db.py b/app/create_db.py index ed29383a..e65e0d74 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -998,7 +998,7 @@ def update_db_v_6_3_5(): def update_ver(): try: - Version.update(version='6.3.5.0').execute() + Version.update(version='6.3.6.0').execute() except Exception: print('Cannot update version') diff --git a/app/modules/db/db_model.py b/app/modules/db/db_model.py index 013f6ea8..1797f2aa 100644 --- a/app/modules/db/db_model.py +++ b/app/modules/db/db_model.py @@ -578,6 +578,16 @@ class ServiceStatus(BaseModel): constraints = [SQL('UNIQUE (server_id, service_id, service_check)')] +class KeepaliveRestart(BaseModel): + server_id = ForeignKeyField(Server, on_delete='Cascade') + service = CharField() + restarted = IntegerField(constraints=[SQL('DEFAULT 1')]) + + class Meta: + table_name = 'keepaplive_restarted' + constraints = [SQL('UNIQUE (server_id, service)')] + + def create_tables(): with conn: conn.create_tables([User, Server, Role, Telegram, Slack, UUID, Token, ApiToken, Groups, UserGroups, ConfigVersion, @@ -585,4 +595,4 @@ def create_tables(): PortScannerSettings, PortScannerPorts, PortScannerHistory, ProvidersCreds, ServiceSetting, ProvisionedServers, MetricsHttpStatus, SMON, WafRules, Alerts, GeoipCodes, NginxMetrics, SystemInfo, Services, UserName, GitSetting, CheckerSetting, ApacheMetrics, ProvisionParam, - WafNginx, ServiceStatus]) + WafNginx, ServiceStatus, KeepaliveRestart]) diff --git a/app/modules/db/sql.py b/app/modules/db/sql.py index b048f148..a85e2781 100755 --- a/app/modules/db/sql.py +++ b/app/modules/db/sql.py @@ -2242,7 +2242,7 @@ def select_keepalived_alert(**kwargs): def select_keep_alive(): - query = Server.select(Server.ip, Server.groups).where(Server.active == 1) + query = Server.select(Server.ip, Server.groups, Server.server_id).where(Server.active == 1) try: query_res = query.execute() except Exception as e: @@ -2252,7 +2252,7 @@ def select_keep_alive(): def select_nginx_keep_alive(): - query = Server.select(Server.ip, Server.groups).where(Server.nginx_active == 1) + query = Server.select(Server.ip, Server.groups, Server.server_id).where(Server.nginx_active == 1) try: query_res = query.execute() except Exception as e: @@ -2262,7 +2262,7 @@ def select_nginx_keep_alive(): def select_apache_keep_alive(): - query = Server.select(Server.ip, Server.groups).where(Server.apache_active == 1) + query = Server.select(Server.ip, Server.groups, Server.server_id).where(Server.apache_active == 1) try: query_res = query.execute() except Exception as e: @@ -2272,7 +2272,7 @@ def select_apache_keep_alive(): def select_keepalived_keep_alive(): - query = Server.select(Server.ip, Server.port, Server.groups).where(Server.keepalived_active == 1) + query = Server.select(Server.ip, Server.port, Server.groups, Server.server_id).where(Server.keepalived_active == 1) try: query_res = query.execute() except Exception as e: @@ -2290,6 +2290,26 @@ def select_keepalived(serv): return keepalived +def select_update_keep_alive_restart(server_id: int, service: str) -> int: + try: + restarted = KeepaliveRestart.get( + (KeepaliveRestart.server_id == server_id) & + (KeepaliveRestart.service == service) + ).restarted + except Exception as e: + out_error(e) + else: + return restarted or 0 + + +def update_keep_alive_restart(server_id: int, service: str, restarted: int) -> None: + query = KeepaliveRestart.insert(server_id=server_id, service=service, restarted=restarted).on_conflict('replace') + try: + query.execute() + except Exception as e: + out_error(e) + + def update_keepalived(serv): query = Server.update(keepalived='1').where(Server.ip == serv) try: diff --git a/app/scripts/ansible/roles/haproxy/templates/haproxy.cfg.j2 b/app/scripts/ansible/roles/haproxy/templates/haproxy.cfg.j2 index de9a53ad..454b8130 100644 --- a/app/scripts/ansible/roles/haproxy/templates/haproxy.cfg.j2 +++ b/app/scripts/ansible/roles/haproxy/templates/haproxy.cfg.j2 @@ -1,5 +1,6 @@ global - log 127.0.0.1 local2 + log 127.0.0.2 local0 + log 127.0.0.1 local1 notice chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 @@ -31,9 +32,7 @@ defaults listen stats bind *:{{STAT_PORT}} - {% if ansible_os_family == "RedHat" %} http-request use-service prometheus-exporter if { path /metrics } - {% endif %} stats enable stats uri /stats stats realm HAProxy-04\ Statistics diff --git a/app/scripts/ansible/roles/haproxy/templates/haproxy_rsyslog.conf.j2 b/app/scripts/ansible/roles/haproxy/templates/haproxy_rsyslog.conf.j2 index 212449d8..e152cefe 100644 --- a/app/scripts/ansible/roles/haproxy/templates/haproxy_rsyslog.conf.j2 +++ b/app/scripts/ansible/roles/haproxy/templates/haproxy_rsyslog.conf.j2 @@ -7,10 +7,8 @@ module(load="builtin:omfile") if $programname startswith 'haproxy' then { if $syslogseverity == 6 then action(type="omfile" file="/var/log/haproxy/access.log") - stop if $syslogseverity <= 3 then action(type="omfile" file="/var/log/haproxy/error.log") - stop if $syslogseverity <= 5 then action(type="omfile" file="/var/log/haproxy/status.log") stop diff --git a/app/templates/ajax/show_system_info.html b/app/templates/ajax/show_system_info.html index dbc543a6..d75ccda2 100644 --- a/app/templates/ajax/show_system_info.html +++ b/app/templates/ajax/show_system_info.html @@ -156,4 +156,10 @@ {% endfor %} {% endfor %} -{% endif %} \ No newline at end of file +{% endif %} + diff --git a/app/templates/base.html b/app/templates/base.html index 1659b773..b78bcf75 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -13,7 +13,7 @@ data-something_wrong="{{lang.words.something_wrong}}" data-check_logs="{{lang.words.check_logs}}" data-wait_mess="{{lang.phrases.wait_mess}}" data-just_save="{{lang.words.just|title()}} {{lang.words.save}}" data-upload_and_restart="{{lang.phrases.upload_and_restart|title()}}" data-are_you_sure="{{lang.phrases.are_you_sure}}" data-upload_and_reload="{{lang.phrases.upload_and_reload|title()}}" data-select_server="{{lang.errors.select_server}}" - data-empty_name="{{lang.errors.empty_name}}" data-edit="{{lang.words.edit|title()}}" data-close="{{lang.words.close|title()}}" + data-empty_name="{{lang.errors.empty_name}}" data-edit="{{lang.words.edit|title()}}" data-close="{{lang.words.close|title()}}" data-server_info="{{lang.phrases.server_info}}" data-generated_config="{{lang.words.generated|title()}} {{lang.words.config}}" /> {% if title == 'Login page' %} diff --git a/app/templates/include/mon_installation.html b/app/templates/include/mon_installation.html index dfa8aecf..712fa93f 100644 --- a/app/templates/include/mon_installation.html +++ b/app/templates/include/mon_installation.html @@ -54,7 +54,7 @@ {% set values = dict() %} - {% set values = {'0.8.0':'0.8.0', '0.9.0':'0.9.0', '0.10.0':'0.10.0', '0.11.0':'0.11.0', '0.12.0':'0.12.0', '0.13.0':'0.13.0', '0.14.0':'0.14.0'} %} + {% set values = {'0.9.0':'0.9.0', '0.10.0':'0.10.0', '0.11.0':'0.11.0', '0.12.0':'0.12.0', '0.13.0':'0.13.0', '0.14.0':'0.14.0', '0.15.0':'0.15.0'} %} {{ select('hapexpver', values=values, selected='0.14.0') }} diff --git a/app/templates/languages/en.html b/app/templates/languages/en.html index ca2a31aa..c0fac72e 100644 --- a/app/templates/languages/en.html +++ b/app/templates/languages/en.html @@ -231,6 +231,7 @@ %} {% set phrases = dict() %} {% set phrases = { + "config_file_name": "Config file name", "no_events_added": "No events added yet.", "upload_and_restart": "Upload and restart", "upload_and_reload": "Upload and reload", @@ -290,6 +291,7 @@ "how_to_install": "how to install", "port_check": "port check", "possible_service_name": "Possible service name", + "server_info": "Server info", } %} {% set roles = { @@ -503,7 +505,7 @@ "creds2": "credentials", "settings": "settings", "settings2": "settings", - "installat": "installat", + "install": "install", "installation": "installation", "installing": "installing", "proxy": "proxy", diff --git a/app/templates/languages/ru.html b/app/templates/languages/ru.html index c6de78ce..f2b8b9e6 100644 --- a/app/templates/languages/ru.html +++ b/app/templates/languages/ru.html @@ -231,6 +231,7 @@ %} {% set phrases = dict() %} {% set phrases = { + "config_file_name": "Имя конфиг файла", "no_events_added": "События еще не добавлены.", "upload_and_restart": "Загрузить и перезагрузить", "upload_and_reload": "Загрузить и перезапустить", @@ -292,6 +293,7 @@ "how_to_install": "как установить", "port_check": "проверка порта", "possible_service_name": "Возможное название службы", + "server_info": "Информация о сервере", } %} {% set roles = { @@ -817,5 +819,6 @@ "rule_name": "Название правила", "rule": "правило", "rules": "правила", + "send": "отправить", } %} diff --git a/inc/users.js b/inc/users.js index 939c2a2b..84c10ca6 100644 --- a/inc/users.js +++ b/inc/users.js @@ -2833,6 +2833,8 @@ function updateServerInfo(ip, id) { } ); } function showServerInfo(id, ip) { + var close_word = $('#translate').attr('data-close'); + var server_info = $('#translate').attr('data-server_info'); $.ajax({ url: "options.py", data: { @@ -2851,14 +2853,15 @@ function showServerInfo(id, ip) { $("#dialog-server-info").dialog({ resizable: false, height: "auto", - width: 1250, + width: 1000, modal: true, - title: "Server info (" + ip + ")", - buttons: { - Close: function () { + title: server_info + " (" + ip + ")", + buttons: [{ + text: close_word, + click: function () { $(this).dialog("close"); } - } + }] }); $.getScript(awesome); }