From d19eb8a3a373f5cd4b144b52b30ba95f8e40ca1e Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Mon, 30 Dec 2019 19:41:16 +0300 Subject: [PATCH] v3.10.1.0 Changelog: https://haproxy-wi.org/changelog.py#3_10_1 --- app/create_db.py | 36 ++-------------- app/funct.py | 2 + app/options.py | 8 ++-- .../ansible/roles/haproxy/tasks/main.yml | 22 +++------- app/templates/ajax/config_show.html | 10 +++++ app/templates/ajax/overivewWaf.html | 11 +++-- app/templates/ajax/show_compare_configs.html | 2 +- app/templates/waf.html | 26 ++++++++++-- inc/script.js | 41 ++----------------- inc/waf.js | 31 ++++++++++++++ 10 files changed, 90 insertions(+), 99 deletions(-) diff --git a/app/create_db.py b/app/create_db.py index c9e30331..a3b702ff 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -73,9 +73,9 @@ def create_table(**kwargs): `groups` VARCHAR ( 120 ), PRIMARY KEY(`id`) ); - INSERT INTO user (username, email, password, role, groups) VALUES ('admin','admin@localhost','admin','admin','1'), - ('editor','editor@localhost','editor','editor','1'), - ('guest','guest@localhost','guest','guest','1'); + INSERT INTO user (username, email, password, role, groups) VALUES ('admin','admin@localhost','21232f297a57a5a743894a0e4a801fc3','admin','1'), + ('editor','editor@localhost','5aee9dbd2a188839105073571bee1b1f','editor','1'), + ('guest','guest@localhost','084e0343a0486ff05530df6c705c8bb4','guest','1'); CREATE TABLE IF NOT EXISTS `servers` ( `id` INTEGER NOT NULL, `hostname` VARCHAR ( 64 ) UNIQUE, @@ -465,34 +465,6 @@ def update_ver(**kwargs): print('Cannot update version') cur.close() con.close() - - -def update_to_hash(): - cur_ver = funct.check_ver() - cur_ver = cur_ver.replace('.','') - i = 1 - ver = '' - for l in cur_ver: - ver += l - i += 1 - if len(ver) < 4: - ver += '00' - if cur_ver <= '3.4.9': - con, cur = get_cur() - sql = """select id, password from user """ - try: - cur.execute(sql) - except sqltool.Error as e: - out_error(e) - else: - for u in cur.fetchall(): - sql = """ update user set password = '%s' where id = '%s' """ % (funct.get_hash(u[1]), u[0]) - try: - cur.execute(sql) - con.commit() - except sqltool.Error as e: - if kwargs.get('silent') != 1: - print("An error occurred:", e) def update_all(): @@ -511,7 +483,6 @@ def update_all(): update_db_v_3_4_9_5() update_db_v_3_5_3() update_db_v_3_8_1() - update_to_hash() update_ver() @@ -531,7 +502,6 @@ def update_all_silent(): update_db_v_3_4_9_5(silent=1) update_db_v_3_5_3(silent=1) update_db_v_3_8_1(silent=1) - update_to_hash() update_ver() diff --git a/app/funct.py b/app/funct.py index cd46d5ac..556e9d7f 100644 --- a/app/funct.py +++ b/app/funct.py @@ -270,6 +270,7 @@ def get_sections(config): line.startswith('#HideBlockEnd') or line.startswith('#HideBlockStart') or line.startswith('peers') or + line.startswith('resolvers') or line.startswith('userlist') ): line = line.strip() @@ -302,6 +303,7 @@ def get_section_from_config(config, section): line.startswith('#HideBlockEnd') or line.startswith('#HideBlockStart') or line.startswith('peers') or + line.startswith('resolvers') or line.startswith('userlist') ): record = False diff --git a/app/options.py b/app/options.py index 2827a828..3802e128 100644 --- a/app/options.py +++ b/app/options.py @@ -234,7 +234,7 @@ if act == "overviewwaf": return server_status - async def get_runner_overviewWaf(url): + async def get_runner_overviewWaf(): import http.cookies from jinja2 import Environment, FileSystemLoader env = Environment(loader=FileSystemLoader('templates/ajax'),extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do']) @@ -243,16 +243,16 @@ if act == "overviewwaf": servers = [] cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) user_id = cookie.get('uuid') - futures = [async_get_overviewWaf(server[1], server[2]) for server in sql.get_dick_permit()] + futures = [async_get_overviewWaf(server[1], server[2]) for server in sql.select_servers(server=serv)] for i, future in enumerate(asyncio.as_completed(futures)): result = await future servers.append(result) servers_sorted = sorted(servers, key=funct.get_key) - template = template.render(service_status=servers_sorted, role=sql.get_user_role_by_uuid(user_id.value), url=url) + template = template.render(service_status=servers_sorted, role=sql.get_user_role_by_uuid(user_id.value)) print(template) ioloop = asyncio.get_event_loop() - ioloop.run_until_complete(get_runner_overviewWaf(form.getvalue('page'))) + ioloop.run_until_complete(get_runner_overviewWaf()) ioloop.close() diff --git a/app/scripts/ansible/roles/haproxy/tasks/main.yml b/app/scripts/ansible/roles/haproxy/tasks/main.yml index 5c85ccc0..13a84364 100644 --- a/app/scripts/ansible/roles/haproxy/tasks/main.yml +++ b/app/scripts/ansible/roles/haproxy/tasks/main.yml @@ -19,35 +19,23 @@ https_proxy: "{{PROXY}}" -- name: install HAProxy {{HAPVER}} on EL6 +- name: install HAProxy {{HAPVER}} on EL{{ansible_facts['distribution_major_version']}} yum: name: - - http://repo.haproxy-wi.org/haproxy-{{HAPVER}}.el6.x86_64.rpm + - http://repo.haproxy-wi.org/haproxy-{{HAPVER}}.el{{ansible_facts['distribution_major_version']}}.x86_64.rpm - socat state: present - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ansible_facts['distribution_major_version']|int == 6 and HAPVER|length > 0 + when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0 register: install_result environment: http_proxy: "{{PROXY}}" https_proxy: "{{PROXY}}" -- name: install HAProxy {{HAPVER}} on EL7 - yum: - name: - - http://repo.haproxy-wi.org/haproxy-{{HAPVER}}.el7.x86_64.rpm - - socat - state: present - when: ((ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ansible_facts['distribution_major_version']|int == 7) and HAPVER|length > 0 - environment: - http_proxy: "{{PROXY}}" - https_proxy: "{{PROXY}}" - - - name: set_fact from wi` set_fact: haproxy_from_wi: "yes" - when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ansible_facts['distribution_major_version']|int == 7 and HAPVER|length > 0 + when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and HAPVER|length > 0 - name: install the latest version of HAProxy @@ -56,7 +44,7 @@ - haproxy - socat state: latest - when: ((ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ansible_facts['distribution_major_version']|int != 7) or ("'FAILED' in install_result.stderr") + when: (ansible_facts['os_family'] == "RedHat" or ansible_facts['os_family'] == 'CentOS') and ("'FAILED' in install_result.stderr") environment: http_proxy: "{{PROXY}}" https_proxy: "{{PROXY}}" diff --git a/app/templates/ajax/config_show.html b/app/templates/ajax/config_show.html index b83e0236..4f50ba1a 100644 --- a/app/templates/ajax/config_show.html +++ b/app/templates/ajax/config_show.html @@ -112,6 +112,16 @@
{% continue %} {% endif %} + {% if line.startswith('resolvers') %} +
{{ line }} + {% if role %} + + Edit + + {% endif %} +
+ {% continue %} + {% endif %} {% if line.startswith('userlist') %}
{{ line }} {% if role %} diff --git a/app/templates/ajax/overivewWaf.html b/app/templates/ajax/overivewWaf.html index 4ea75e20..338fda65 100644 --- a/app/templates/ajax/overivewWaf.html +++ b/app/templates/ajax/overivewWaf.html @@ -1,6 +1,5 @@ {% for service in service_status %} - {% if service.3 == "On" or service.3 == "Off" or service.3 == "DetectionOnly" or url == "waf.py" %} - + {% if service.3 == "On" or service.3 == "Off" or service.3 == "DetectionOnly" %} {% if service.2|int() >= 1 %} @@ -57,7 +56,13 @@ {% endif %} - + {% else %} + + {{ service.0 }} + + + {{ service.3 }} + {% endif %} {% endfor %} - + {% for s in servers_all %} + + {% endfor %}
@@ -15,16 +32,19 @@ Metrics - Refresh + Refresh
+
Refresh
@@ -43,6 +63,6 @@ {% endfor %} } showWafMetrics() - showOverviewWaf() + showOverviewWaf(ip, hostnamea) {% endblock %} \ No newline at end of file diff --git a/inc/script.js b/inc/script.js index e46489f7..a752c33d 100644 --- a/inc/script.js +++ b/inc/script.js @@ -134,7 +134,7 @@ function startSetInterval(interval) { if(interval < 60000) { interval = 60000; } - intervalId = setInterval('showOverview()', interval); + intervalId = setInterval('showOverview(ip, hostnamea)', interval); showOverview(ip, hostnamea); } else if (cur_url[0] == "viewlogs.py") { intervalId = setInterval('viewLogs()', interval); @@ -149,8 +149,8 @@ function startSetInterval(interval) { if(interval < 60000) { interval = 60000; } - intervalId = setInterval('showOverviewWaf()', interval); - showOverviewWaf(); + intervalId = setInterval('showOverviewWaf(ip, hostnamea)', interval); + showOverviewWaf(ip, hostnamea); showWafMetrics(); } else if (cur_url[0] == "hapservers.py") { if(interval < 60000) { @@ -192,41 +192,6 @@ $( document ).ajaxComplete(function( event, request, settings ) { $('#cover').fadeOut('fast'); NProgress.done(); }); -function showOverviewWaf() { - if (cur_url[0] == "waf.py") { - $.getScript('/inc/chart.min.js'); - showWafMetrics() - } - $.ajax( { - url: "options.py", - data: { - act: "overviewwaf", - page: cur_url[0], - token: $('#token').val() - }, - beforeSend: function() { - if (cur_url[0] == "waf.py") { - var load_class = 'loading_full_page' - } else { - var load_class = 'loading' - } - $('#ajaxwafstatus').html('') - }, - type: "POST", - success: function( data ) { - $("#ajaxwafstatus").empty(); - $("#ajaxwafstatus").html(data); - $.getScript('/inc/overview.js'); - if (cur_url[0] == "waf.py") { - $.getScript('/inc/waf.js'); - $( "input[type=submit], button" ).button(); - $( "input[type=checkbox]" ).checkboxradio(); - } else { - $('.first-collumn-wi').css('padding', '10px'); - } - } - } ); -} function showStats() { $.ajax( { url: "options.py", diff --git a/inc/waf.js b/inc/waf.js index ed03e76f..64463317 100644 --- a/inc/waf.js +++ b/inc/waf.js @@ -4,6 +4,37 @@ $( function() { metrics_waf(id); }); } ); +function showOverviewWaf(serv, hostnamea) { + $.getScript('/inc/chart.min.js'); + showWafMetrics(); + console.log(serv) + var i; + for (i = 0; i < serv.length; i++) { + showOverviewWafCallBack(serv[i], hostnamea[i]) + } + $.getScript('/inc/overview.js'); + $.getScript('/inc/waf.js'); +} +function showOverviewWafCallBack(serv, hostnamea) { + $.ajax( { + url: "options.py", + data: { + act: "overviewwaf", + serv: serv, + token: $('#token').val() + }, + beforeSend: function() { + $("#"+hostnamea).html(''); + }, + type: "POST", + success: function( data ) { + $("#"+hostnamea).empty(); + $("#"+hostnamea).html(data) + $( "input[type=submit], button" ).button(); + $( "input[type=checkbox]" ).checkboxradio(); + } + } ); +} function metrics_waf(name) { var enable = 0; if ($('#'+name).is(':checked')) {