From b6bf804f73d007dacd548afeff195e2fa24d2512 Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Sun, 22 May 2022 12:09:04 +0300 Subject: [PATCH] v6.0.2.0 Changelog: https://roxy-wi.org/changelog.py#6_0_2 --- app/create_db.py | 16 +++++++ app/funct.py | 58 ++++++++++------------- app/sections.py | 7 ++- app/sql.py | 14 ++---- app/templates/include/admin_settings.html | 16 +++---- app/templates/sections.html | 6 ++- 6 files changed, 61 insertions(+), 56 deletions(-) diff --git a/app/create_db.py b/app/create_db.py index e87099c8..dab7601e 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -571,6 +571,22 @@ def update_db_v_5_3_0(**kwargs): {'param': 'haproxy_container_name', 'value': 'haproxy', 'section': 'haproxy', 'desc': 'Docker container name for HAProxy service', 'group': g.group_id}, + {'param': 'apache_path_logs', 'value': '/var/log/httpd/', 'section': 'apache', + 'desc': 'The path for Apache logs', 'group': g.group_id}, + {'param': 'apache_stats_user', 'value': 'admin', 'section': 'apache', + 'desc': 'Username for accessing Apache stats page', 'group': g.group_id}, + {'param': 'apache_stats_password', 'value': 'password', 'section': 'apache', + 'desc': 'Password for Apache stats webpage', 'group': g.group_id}, + {'param': 'apache_stats_port', 'value': '8087', 'section': 'apache', 'desc': 'Stats port for webpage Apache', + 'group': g.group_id}, + {'param': 'apache_stats_page', 'value': 'stats', 'section': 'apache', 'desc': 'URI Stats for webpage Apache', + 'group': g.group_id}, + {'param': 'apache_dir', 'value': '/etc/httpd/', 'section': 'apache', + 'desc': 'Path to the Apache directory with config files', 'group': g.group_id}, + {'param': 'apache_config_path', 'value': '/etc/httpd/conf/httpd.conf', 'section': 'apache', + 'desc': 'Path to the main Apache configuration file', 'group': g.group_id}, + {'param': 'apache_container_name', 'value': 'apache', 'section': 'apache', + 'desc': 'Docker container name for Apache service', 'group': g.group_id}, ] try: diff --git a/app/funct.py b/app/funct.py index 803582b2..0f2fcc88 100644 --- a/app/funct.py +++ b/app/funct.py @@ -9,11 +9,7 @@ def is_ip_or_dns(server_from_request: str) -> str: ip_regex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" dns_regex = "^(?!-)[A-Za-z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,6}$" try: - if ('roxy-wi' in server_from_request or - 'fail2ban' in server_from_request or - 'prometheus' in server_from_request or - 'all' in server_from_request or - 'grafana-server' in server_from_request): + if server_from_request in ('roxy-wi', 'fail2ban', 'prometheus', 'all', 'grafana-server', 'rabbitmq-server'): return server_from_request if re.match(ip_regex, server_from_request): return server_from_request @@ -522,20 +518,18 @@ def get_sections(config, **kwargs): if find_ip: return_config.append(find_ip[0]) else: - if ( - line.startswith('listen') or - line.startswith('frontend') or - line.startswith('backend') or - line.startswith('cache') or - line.startswith('defaults') or - line.startswith('global') or - line.startswith('#HideBlockEnd') or - line.startswith('#HideBlockStart') or - line.startswith('peers') or - line.startswith('resolvers') or - line.startswith('userlist') or - line.startswith('http-errors') - ): + if line.startswith(('global', + 'listen', + 'frontend', + 'backend', + 'cache', + 'defaults', + '#HideBlockStart', + '#HideBlockEnd', + 'peers', + 'resolvers', + 'userlist', + 'http-errors')): line = line.strip() return_config.append(line) @@ -555,20 +549,18 @@ def get_section_from_config(config, section): record = True continue if record: - if ( - line.startswith('listen') or - line.startswith('frontend') or - line.startswith('backend') or - line.startswith('cache') or - line.startswith('defaults') or - line.startswith('global') or - line.startswith('#HideBlockEnd') or - line.startswith('#HideBlockStart') or - line.startswith('peers') or - line.startswith('resolvers') or - line.startswith('userlist') or - line.startswith('http-errors') - ): + if line.startswith(('global', + 'listen', + 'frontend', + 'backend', + 'cache', + 'defaults', + '#HideBlockStart', + '#HideBlockEnd', + 'peers', + 'resolvers', + 'userlist', + 'http-errors')): record = False end_line = index end_line = end_line - 1 diff --git a/app/sections.py b/app/sections.py index 0019157c..a3297d1b 100644 --- a/app/sections.py +++ b/app/sections.py @@ -47,7 +47,7 @@ if serv is not None and section is not None: if serv is not None and form.getvalue('config') is not None: try: - funct.logging(serv, "config.py edited config") + funct.logging(serv, "sections.py edited config") except Exception: pass @@ -69,7 +69,10 @@ if serv is not None and form.getvalue('config') is not None: except IOError: error = "Can't read import config file" - stderr = funct.master_slave_upload_and_restart(serv, cfg, just_save=save) + stderr = funct.master_slave_upload_and_restart(serv, cfg, just_save=save, oldcfg=oldcfg) + + if "is valid" in stderr: + stderr = '' funct.diff_config(oldcfg, cfg) diff --git a/app/sql.py b/app/sql.py index 0d80bb38..a43274bc 100755 --- a/app/sql.py +++ b/app/sql.py @@ -1798,16 +1798,10 @@ def get_setting(param, **kwargs): return query_res else: for setting in query_res: - if ( - param == 'nginx_stats_port' or param == 'session_ttl' or param == 'token_ttl' or - param == 'stats_port' or param == 'haproxy_sock_port' or param == 'ldap_type' or - param == 'ldap_port' or param == 'ldap_enable' or param == 'log_time_storage' or - param == 'syslog_server_enable' or param == 'smon_check_interval' or - param == 'checker_check_interval' or param == 'port_scan_interval' or - param == 'smon_keep_history_range' or param == 'checker_keep_history_range' or - param == 'portscanner_keep_history_range' or param == 'checker_maxconn_threshold' or - param == 'apache_stats_port' - ): + if param in ('nginx_stats_port', 'session_ttl', 'token_ttl', 'stats_port', 'haproxy_sock_port', 'ldap_type', + 'ldap_port', 'ldap_enable', 'log_time_storage', 'syslog_server_enable', 'smon_check_interval', + 'checker_check_interval', 'port_scan_interval', 'smon_keep_history_range', 'checker_keep_history_range', + 'portscanner_keep_history_range', 'checker_maxconn_threshold', 'apache_stats_port'): return int(setting.value) else: return setting.value diff --git a/app/templates/include/admin_settings.html b/app/templates/include/admin_settings.html index e6f05db5..3c8a6bc9 100644 --- a/app/templates/include/admin_settings.html +++ b/app/templates/include/admin_settings.html @@ -27,20 +27,16 @@ {{set.param}} - {% if set.param == 'ldap_password' or set.param == 'stats_password' or set.param == 'nginx_stats_password' %} + {% if set.param in ('ldap_password', 'stats_password', 'nginx_stats_password', 'apache_stats_password', 'rabbitmq_password') %} {% if set.value is none %} {{ input(set.param, size='25', type='password') }} {% else %} {{ input(set.param, size='25', type='password', placeholder='*****') }} {% endif %} - {% elif set.param == 'nginx_stats_port' or set.param == 'session_ttl' or set.param == 'token_ttl' or - set.param == 'stats_port' or set.param == 'haproxy_sock_port' or set.param == 'ldap_type' or - set.param == 'ldap_port' or set.param == 'ldap_enable' or set.param == 'log_time_storage' or - set.param == 'syslog_server_enable' or set.param == 'smon_check_interval' or - set.param == 'checker_check_interval' or set.param == 'port_scan_interval' or - set.param == 'smon_keep_history_range' or set.param == 'checker_keep_history_range' or - set.param == 'portscanner_keep_history_range' or set.param == 'haproxy_enterprise' or - set.param == 'checker_maxconn_threshold' %} + {% elif set.param in ('nginx_stats_port', 'session_ttl', 'token_ttl', 'stats_port', 'haproxy_sock_port', + 'ldap_type', 'ldap_port', 'ldap_enable', 'log_time_storage', 'syslog_server_enable', 'smon_check_interval', + 'checker_check_interval', 'port_scan_interval', 'smon_keep_history_range', 'checker_keep_history_range', + 'portscanner_keep_history_range', 'haproxy_enterprise', 'checker_maxconn_threshold', 'apache_stats_port') %} {{ input(set.param, value=set.value, style='width: 210px;', type='number') }} {% else %} @@ -58,4 +54,4 @@ {% endif %} {% endfor %} - \ No newline at end of file + diff --git a/app/templates/sections.html b/app/templates/sections.html index 920a0f5d..35179228 100644 --- a/app/templates/sections.html +++ b/app/templates/sections.html @@ -1,5 +1,8 @@ {% extends "base.html" %} {% block content %} +{% if is_serv_protected and role > 2 %} + +{% else %} @@ -74,4 +77,5 @@ {% endif %} -{% endblock %} \ No newline at end of file +{% endif %} +{% endblock %}