diff --git a/README.md b/README.md index ca09bdb..8584a1f 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,8 @@ Supports EL7 and EL8 #### Before uses RPM repository you should donate to support project on [Patreon](https://www.patreon.com/haproxy_wi/overview) or on [PayPal](https://www.paypal.me/loginovpavel) and I will send you credentials for access. Actual prices you can see on [Patreon](https://www.patreon.com/haproxy_wi/overview) +### More information on the official [site](https://haproxy-wi.org/installation.py#rpm) + ## Manual install For install just clone: ``` @@ -178,6 +180,8 @@ For Apache do virtualhost with cgi-bin. Like this: ``` +### More information on the official [site](https://haproxy-wi.org/installation.py#manual) + # OS support HAProxy-WI was tested on EL7, EL8 and all scripts too. Debian/Ubuntu OS support at 'beta' stage, may work not correct @@ -192,6 +196,9 @@ MariaDB [(none)]> create database haproxywi; MariaDB [(none)]> grant all on haproxywi.* to 'haproxy-wi'@'%' IDENTIFIED BY 'haproxy-wi'; MariaDB [(none)]> grant all on haproxywi.* to 'haproxy-wi'@'localhost' IDENTIFIED BY 'haproxy-wi'; ``` + +### More information on the official [site](https://haproxy-wi.org/settings.py#db_settings) + ![alt text](image/haproxy-wi-overview.png "Overview page") # Settings diff --git a/app/create_db.py b/app/create_db.py index 5b364da..33457d2 100644 --- a/app/create_db.py +++ b/app/create_db.py @@ -459,7 +459,7 @@ def update_db_v_3_8_1(**kwargs): def update_ver(**kwargs): con, cur = get_cur() - sql = """update version set version = '3.9.4'; """ + sql = """update version set version = '3.10.0.0'; """ try: cur.execute(sql) con.commit() diff --git a/app/funct.py b/app/funct.py index ed83fbf..4c2353b 100644 --- a/app/funct.py +++ b/app/funct.py @@ -99,7 +99,7 @@ def telegram_send_mess(mess, **kwargs): token_bot = telegram[1] channel_name = telegram[2] - if proxy is not None: + if proxy is not None and proxy != '' and proxy != 'None': apihelper.proxy = {'https': proxy} try: bot = telebot.TeleBot(token=token_bot) @@ -359,8 +359,12 @@ def install_haproxy(serv, **kwargs): if hapver is None: hapver = '2.0.7-1' + + if proxy is not None and proxy != '' and proxy != 'None': + proxy_serv = proxy + else: + proxy_serv = '' - proxy_serv = proxy if proxy is not None else '' syn_flood_protect = '1' if kwargs.get('syn_flood') == "1" else '' commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv+ @@ -400,7 +404,12 @@ def waf_install(serv, **kwargs): os.system("cp scripts/%s ." % script) - commands = [ "sudo chmod +x "+tmp_config_path+script+" && " +tmp_config_path+script +" PROXY=" + proxy+ + if proxy is not None and proxy != '' and proxy != 'None': + proxy_serv = proxy + else: + proxy_serv = '' + + commands = [ "sudo chmod +x "+tmp_config_path+script+" && " +tmp_config_path+script +" PROXY=" + proxy_serv+ " HAPROXY_PATH="+haproxy_dir +" VERSION="+ver ] error = str(upload(serv, tmp_config_path, script)) @@ -651,8 +660,8 @@ def ssh_command(serv, commands, **kwargs): try: ssh.close() except: - print("
"+str(ssh)+"X
") logging('localhost', ' '+str(ssh), haproxywi=1) + return "
"+str(ssh)+"X
" pass @@ -731,13 +740,12 @@ def check_ver(): def check_new_version(): import requests - import ssl import sql proxy = sql.get_setting('proxy') try: - if proxy: + if proxy is not None and proxy != '' and proxy != 'None': proxyDict = { "https" : proxy, "http" : proxy } response = requests.get('https://haproxy-wi.org/update.py?last_ver=1', timeout=1, proxies=proxyDict) else: diff --git a/app/hapservers.py b/app/hapservers.py index 93c4075..17bcc8c 100644 --- a/app/hapservers.py +++ b/app/hapservers.py @@ -27,14 +27,11 @@ serv = form.getvalue('serv') if serv: servers = sql.select_servers(server=serv) autorefresh = 1 - hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') else: servers = sql.get_dick_permit() autorefresh = 0 haproxy_sock_port = sql.get_setting('haproxy_sock_port') -haproxy_config_path = sql.get_setting('haproxy_config_path') -commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ] servers_with_status1 = [] out1 = "" for s in servers: @@ -52,22 +49,6 @@ for s in servers: out1 = False servers_with_status.append(out1) servers_with_status.append(s[12]) - try: - servers_with_status.append(funct.ssh_command(s[2], commands)) - except: - servers_with_status.append('Cannot get last date') - - if serv: - try: - sections = funct.get_sections(hap_configs_dir +funct.get_files()[0]) - except: - try: - cfg = hap_configs_dir + s[2] + "-" + funct.get_data('config') + ".cfg" - error = funct.get_config(s[2], cfg) - sections = funct.get_sections(cfg) - except: - pass - servers_with_status.append(sections) servers_with_status1.append(servers_with_status) diff --git a/app/options.py b/app/options.py index 8f9b485..b2c3836 100644 --- a/app/options.py +++ b/app/options.py @@ -146,6 +146,42 @@ if form.getvalue('action_waf') is not None and serv is not None: funct.ssh_command(serv, commands) +if act == "overviewHapserverBackends": + from jinja2 import Environment, FileSystemLoader + env = Environment(loader=FileSystemLoader('templates/ajax')) + template = env.get_template('haproxyservers_backends.html') + + hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir') + try: + sections = funct.get_sections(hap_configs_dir +funct.get_files()[0]) + except: + try: + cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg" + except: + funct.logging('localhost', ' Cannot generate cfg path', haproxywi=1) + try: + error = funct.get_config(serv, cfg) + except: + funct.logging('localhost', ' Cannot download config', haproxywi=1) + try: + sections = funct.get_sections(cfg) + except: + funct.logging('localhost', ' Cannot get sections from config file', haproxywi=1) + sections = 'Cannot get backends' + + template = template.render(backends=sections, serv=serv) + print(template) + + +if act == "overviewHapservers": + haproxy_config_path = sql.get_setting('haproxy_config_path') + commands = [ "ls -l %s |awk '{ print $6\" \"$7\" \"$8}'" % haproxy_config_path ] + try: + print(funct.ssh_command(serv, commands)) + except: + print('Cannot get last date') + + if act == "overview": import asyncio async def async_get_overview(serv1, serv2): @@ -170,7 +206,7 @@ if act == "overview": template = env.get_template('overview.html') cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) user_id = cookie.get('uuid') - futures = [async_get_overview(server[1], server[2]) for server in sql.get_dick_permit()] + futures = [async_get_overview(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) @@ -587,7 +623,10 @@ if form.getvalue('master'): if ssh_enable == 0: ssh_key_name = '' - proxy_serv = proxy if proxy is not None else "" + if proxy is not None and proxy != '' and proxy != 'None': + proxy_serv = proxy + else: + proxy_serv = '' os.system("cp scripts/%s ." % script) @@ -663,7 +702,10 @@ if form.getvalue('masteradd'): if ssh_enable == 0: ssh_key_name = '' - proxy_serv = proxy if proxy is not None else "" + if proxy is not None and proxy != '' and proxy != 'None': + proxy_serv = proxy + else: + proxy_serv = '' os.system("cp scripts/%s ." % script) diff --git a/app/overview.py b/app/overview.py index 197ecf5..ad2a88e 100644 --- a/app/overview.py +++ b/app/overview.py @@ -33,6 +33,7 @@ try: keep_alive, stderr = funct.subprocess_execute(cmd) cmd = "ps ax |grep '(wsgi:api)'|grep -v grep|wc -l" api, stderr = funct.subprocess_execute(cmd) + servers = sql.get_dick_permit() except: pass @@ -55,5 +56,6 @@ template = template.render(h2 = 1, error = stderr, versions = funct.versions(), haproxy_wi_log = funct.haproxy_wi_log(), + servers = servers, token = token) print(template) diff --git a/app/templates/ajax/haproxyservers_backends.html b/app/templates/ajax/haproxyservers_backends.html new file mode 100644 index 0000000..ba97986 --- /dev/null +++ b/app/templates/ajax/haproxyservers_backends.html @@ -0,0 +1,14 @@ + +{% if backends == 'Cannot get backends' %} + {{backends}} +{% else %} + {% for b in backends %} + + {{b}} + + {% endfor %} +{% endif %} \ No newline at end of file diff --git a/app/templates/ajax/overview.html b/app/templates/ajax/overview.html index f1db51f..969f498 100644 --- a/app/templates/ajax/overview.html +++ b/app/templates/ajax/overview.html @@ -1,26 +1,24 @@ -{% for service in service_status %} - - - - {{ service.0 }} - - - - {% if service.2|int() >= 1 %} - - {% else %} - - {% endif %} - - - {% if service.5.0|length() == 0 %} - - {% elif service.5.0 != '' and service.4|int() == 0 %} - - {% elif service.5.0 != '' and service.4|int() >= 1 %} - - {% endif %} - - - +{% for service in service_status %} + + + {{ service.0 }} + + + + {% if service.2|int() >= 1 %} + + {% else %} + + {% endif %} + + + {% if service.5.0|length() == 0 %} + + {% elif service.5.0 != '' and service.4|int() == 0 %} + + {% elif service.5.0 != '' and service.4|int() >= 1 %} + + {% endif %} + + {% endfor %} diff --git a/app/templates/hapservers.html b/app/templates/hapservers.html index f4e7698..be27f79 100644 --- a/app/templates/hapservers.html +++ b/app/templates/hapservers.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% block content %} + {% if serv %} {% endif %} +
{% for s in servers %} + {% if serv %} @@ -69,16 +85,9 @@ {{s.5.0.0}} {{s.5.0.1}} {{s.5.0.2}} {% endif %}
- - {% if s.7 != None %} - {% if "ls: cannot access" in s.7 %} - Cannot find HAProxy config - {% else %} - Last edit: {{s.7}} - {% endif %} - {% else %} - Cannot connect to HAProxy server - {% endif %} + + Last edit: +
IP: {{s.2}} @@ -97,20 +106,12 @@
{% if serv %} - {% if s.8 is defined %}
Backends:
-
- {% for b in s.8 %} - - {{b}} - - {% endfor %} -
+
- {% endif %} {% endif %}
{% endfor %} @@ -131,5 +132,10 @@ - + {% endblock %} \ No newline at end of file diff --git a/app/templates/ovw.html b/app/templates/ovw.html index 06d86b7..7a8fec8 100644 --- a/app/templates/ovw.html +++ b/app/templates/ovw.html @@ -1,7 +1,14 @@ {% extends "base.html" %} {% block content %} + @@ -19,10 +26,12 @@ - + {% for s in servers %} + + {% endfor %}
- restart + hostname
@@ -283,7 +292,7 @@

Are you sure?

{% endblock %} \ No newline at end of file diff --git a/inc/overview.js b/inc/overview.js index 158bf70..366cb3a 100644 --- a/inc/overview.js +++ b/inc/overview.js @@ -1,5 +1,118 @@ var cur_url = window.location.href.split('/').pop(); cur_url = cur_url.split('?'); +function showOverviewHapWI() { + $.ajax( { + url: "options.py", + data: { + act: "overviewHapwi", + token: $('#token').val() + }, + beforeSend: function() { + $('#ajaxHapwi').html('') + }, + type: "POST", + success: function( data ) { + $("#ajaxHapwi").html(data); + } + } ); +} +function showHapservers(serv, hostnamea) { + var i; + for (i = 0; i < serv.length; i++) { + showHapserversCallBack(serv[i], hostnamea[i]) + } +} +function showHapserversCallBack(serv, hostnamea) { + $.ajax( { + url: "options.py", + data: { + act: "overviewHapservers", + serv: serv, + token: $('#token').val() + }, + beforeSend: function() { + $("#"+hostnamea).html(''); + }, + type: "POST", + success: function( data ) { + $("#"+hostnamea).empty(); + $("#"+hostnamea).html(data); + } + } ); +} +function overviewHapserverBackends(serv, hostnamea) { + console.log("#top-"+hostnamea) + $.ajax( { + url: "options.py", + data: { + act: "overviewHapserverBackends", + serv: serv[0], + token: $('#token').val() + }, + beforeSend: function() { + $("#top-"+hostnamea).html(''); + }, + type: "POST", + success: function( data ) { + $("#top-"+hostnamea).empty(); + $("#top-"+hostnamea).html(data); + } + } ); +} +function showOverview(serv, hostnamea) { + showOverviewHapWI() + var i; + for (i = 0; i < serv.length; i++) { + showOverviewCallBack(serv[i], hostnamea[i]) + } + $.getScript('/inc/overview.js'); +} +function showOverviewCallBack(serv, hostnamea) { + $.ajax( { + url: "options.py", + data: { + act: "overview", + serv: serv, + token: $('#token').val() + }, + beforeSend: function() { + $("#"+hostnamea).html(''); + }, + type: "POST", + success: function( data ) { + $("#"+hostnamea).empty(); + $("#"+hostnamea).html(data); + } + } ); +} +function showOverviewServer(name,ip,id) { + $.ajax( { + url: "options.py", + data: { + act: "overviewServers", + name: name, + serv: ip, + id: id, + page: 'hapservers.py', + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + $("#ajax-server-"+id).empty(); + $("#ajax-server-"+id).css('display', 'block'); + $("#ajax-server-"+id).css('background-color', '#fbfbfb'); + $("#ajax-server-"+id).css('border', '1px solid #A4C7F5'); + $(".ajax-server").css('display', 'block'); + $(".div-server").css('clear', 'both'); + $(".div-pannel").css('clear', 'both'); + $(".div-pannel").css('display', 'block'); + $(".div-pannel").css('padding-top', '10px'); + $(".div-pannel").css('height', '70px'); + $("#div-pannel-"+id).insertBefore('#up-pannel') + $("#ajax-server-"+id).html(data); + } + } ); +} function ajaxActionServers(action, id) { var bad_ans = 'Bad config, check please'; $.ajax( { @@ -17,7 +130,7 @@ function ajaxActionServers(action, id) { if (cur_url[0] == "hapservers.py") { location.reload() } else { - setTimeout(showOverview, 2000) + setTimeout(showOverview(ip, hostnamea), 2000) } } }, diff --git a/inc/script.js b/inc/script.js index 5f6062d..a694f9e 100644 --- a/inc/script.js +++ b/inc/script.js @@ -135,7 +135,7 @@ function startSetInterval(interval) { interval = 60000; } intervalId = setInterval('showOverview()', interval); - showOverview(); + showOverview(ip, hostnamea); } else if (cur_url[0] == "viewlogs.py") { intervalId = setInterval('viewLogs()', interval); viewLogs(); @@ -192,53 +192,6 @@ $( document ).ajaxComplete(function( event, request, settings ) { $('#cover').fadeOut('fast'); NProgress.done(); }); -function showOverview() { - showOverviewHapWI() - $.ajax( { - url: "options.py", - data: { - act: "overview", - token: $('#token').val() - }, - beforeSend: function() { - $('#ajaxstatus').html('') - }, - type: "POST", - success: function( data ) { - $("#ajaxstatus").empty(); - $("#ajaxstatus").html(data); - $.getScript('/inc/overview.js'); - } - } ); -} -function showOverviewServer(name,ip,id) { - $.ajax( { - url: "options.py", - data: { - act: "overviewServers", - name: name, - serv: ip, - id: id, - page: 'hapservers.py', - token: $('#token').val() - }, - type: "POST", - success: function( data ) { - $("#ajax-server-"+id).empty(); - $("#ajax-server-"+id).css('display', 'block'); - $("#ajax-server-"+id).css('background-color', '#fbfbfb'); - $("#ajax-server-"+id).css('border', '1px solid #A4C7F5'); - $(".ajax-server").css('display', 'block'); - $(".div-server").css('clear', 'both'); - $(".div-pannel").css('clear', 'both'); - $(".div-pannel").css('display', 'block'); - $(".div-pannel").css('padding-top', '10px'); - $(".div-pannel").css('height', '70px'); - $("#div-pannel-"+id).insertBefore('#up-pannel') - $("#ajax-server-"+id).html(data); - } - } ); -} function showOverviewWaf() { if (cur_url[0] == "waf.py") { $.getScript('/inc/chart.min.js'); @@ -274,22 +227,6 @@ function showOverviewWaf() { } } ); } -function showOverviewHapWI() { - $.ajax( { - url: "options.py", - data: { - act: "overviewHapwi", - token: $('#token').val() - }, - beforeSend: function() { - $('#ajaxHapwi').html('') - }, - type: "POST", - success: function( data ) { - $("#ajaxHapwi").html(data); - } - } ); -} function showStats() { $.ajax( { url: "options.py", @@ -516,6 +453,9 @@ function viewLogs() { } } $( function() { + $('#errorMess').click(function(){ + $('#error').remove(); + }); $( "#serv" ).on('selectmenuchange',function() { $("#show").css("pointer-events", "inherit"); $("#show").css("cursor", "pointer"); diff --git a/inc/style.css b/inc/style.css index 79d6ea6..3b35434 100644 --- a/inc/style.css +++ b/inc/style.css @@ -744,6 +744,7 @@ label { .div-server { background-color: #fbfbfb; border: 1px solid #A4C7F5; + height: 153px; width: 365px; padding: 20px; padding-left: 15px; @@ -780,7 +781,7 @@ label { padding-bottom: 10px; color: #999; padding-top: 10px; - min-height: 60px; + height: 80px; } .server-act-links { margin-left: -2px; @@ -1027,6 +1028,15 @@ label { .loading_hapwi_overview{ margin-left: 40%; } +.loading_small { + width: 39px; + height: 39px; + padding-left: 103%; +} +.loading_small_haproxyservers { + width: 15px; + height: 15px; +} .tooltip { font-size: 12px; padding-bottom: 10px; diff --git a/requirements.txt b/requirements.txt index 809c424..0d83409 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,9 +2,7 @@ configparser==3.5.0 paramiko>=2.5.0 pytz==2017.3 requests>=2.22.0 -requests_toolbelt==0.8.0 pyTelegramBotAPI==3.6.3 -dump==0.0.4 networkx==2.1 matplotlib==2.1.2 future==0.13.1