From 0f1c8891654974b978f1a803bd3980244a53429e Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Thu, 24 Sep 2020 11:01:48 +0600 Subject: [PATCH] v4.5.0.0 Changelog: https://haproxy-wi.org/changelog.py#4_5 --- app/funct.py | 19 +++++--- app/options.py | 7 ++- app/templates/admin.html | 90 +++++++++++++++++++++++++++++----- app/users.py | 26 +++++++--- inc/users.js | 102 +++++++++++++++++++-------------------- 5 files changed, 166 insertions(+), 78 deletions(-) diff --git a/app/funct.py b/app/funct.py index 8a9859db..b1512958 100644 --- a/app/funct.py +++ b/app/funct.py @@ -617,8 +617,10 @@ def install_nginx(serv): sql.update_nginx(serv) -def update_haproxy_wi(): - cmd = 'sudo -S yum -y update haproxy-wi' +def update_haproxy_wi(service): + if service != 'haproxy-wi': + service = 'haprxoy-wi-'+service + cmd = 'sudo -S yum -y update '+service output, stderr = subprocess_execute(cmd) print(output) print(stderr) @@ -1062,18 +1064,23 @@ def check_ver(): return sql.get_ver() -def check_new_version(): +def check_new_version(**kwargs): import requests import sql proxy = sql.get_setting('proxy') - + + if kwargs.get('service'): + last_ver = '_'+kwargs.get('service') + else: + last_ver = '' + try: 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) + response = requests.get('https://haproxy-wi.org/update.py?last_ver'+last_ver+'=1', timeout=1, proxies=proxyDict) else: - response = requests.get('https://haproxy-wi.org/update.py?last_ver=1', timeout=1) + response = requests.get('https://haproxy-wi.org/update.py?last_ver'+last_ver+'=1', timeout=1) res = response.content.decode(encoding='UTF-8') except requests.exceptions.RequestException as e: diff --git a/app/options.py b/app/options.py index 0b230e74..0b98b4da 100644 --- a/app/options.py +++ b/app/options.py @@ -1346,7 +1346,12 @@ if form.getvalue('installwaf'): if form.getvalue('update_haproxy_wi'): - funct.update_haproxy_wi() + service = form.getvalue('service') + services = ['checker_haproxy', 'haproxy-wi', 'keep_alive', 'smon', 'metrics_haproxy'] + if service not in services: + print('error: '+service+' is not part of HAProxy-WI') + sys.exit() + funct.update_haproxy_wi(service) if form.getvalue('metrics_waf'): diff --git a/app/templates/admin.html b/app/templates/admin.html index 843dd671..a3bbc8e7 100644 --- a/app/templates/admin.html +++ b/app/templates/admin.html @@ -141,22 +141,90 @@ {% set new_ver_without_dots = versions.3 %} - + + - - - + + + + + {% for s in services %} + {% if s.0 == 'smon' or s.0 == 'checker_haproxy' or s.0 == 'keep_alive' or s.0 == 'metrics_haproxy' %} + + {% set is_need_update = 0 %} + {% if s.0 == 'smon' %} + {% set service_name = 'SMON' %} + {% set service_link = 'smon' %} + {% if s.3|int() < smon_ver|int() %} + {% set is_need_update = 1 %} + {% endif %} + {% elif s.0 == 'checker_haproxy' %} + {% set service_name = 'Checker' %} + {% set service_link = 'checker' %} + {% if s.3|int() < checker_ver|int() %} + {% set is_need_update = 1 %} + {% endif %} + {% elif s.0 == 'keep_alive' %} + {% set service_name = 'Auto start' %} + {% set service_link = 'auto_start' %} + {% if s.3|int() < keep_ver|int() %} + {% set is_need_update = 1 %} + {% endif %} + {% elif s.0 == 'metrics_haproxy' %} + {% set service_name = 'Metrics' %} + {% set service_link = 'metrics' %} + {% if s.3|int() < metrics_ver|int() %} + {% set is_need_update = 1 %} + {% endif %} {% endif %} - + + + + + + {% endif %} + {% endfor %}
Currnet versionServiceCurrnet version Last version
- {{current_ver}} - - {{new_ver}} - - {% if new_ver_without_dots > current_ver_without_dots and new_ver != "Sorry cannot get current version" %} - Update + + HAProxy-WI + + {{current_ver}} + + {{new_ver}} + + {% if new_ver_without_dots > current_ver_without_dots and new_ver != "Sorry cannot get current version" %} + Update + {% endif %} +
+ {{service_name}} + + {% if s.3 != '* is not installed' %} + {{s.3}} + {% endif %} + + + {% if s.0 == 'smon' %} + {{smon_ver}} + {% elif s.0 == 'checker_haproxy' %} + {{checker_ver}} + {% elif s.0 == 'keep_alive' %} + {{keep_ver}} + {% elif s.0 == 'metrics_haproxy' %} + {{metrics_ver}} + {% endif %} + + + {% if s.3 != '* is not installed' %} + {% if is_need_update %} + Update + {% endif %} + {% else %} + {{service_name}} service is not installed + Read about installation + {% endif %} +
Note: diff --git a/app/users.py b/app/users.py index d4daf495..3a616e37 100644 --- a/app/users.py +++ b/app/users.py @@ -18,17 +18,23 @@ try: ldap_enable = sql.get_setting('ldap_enable') grafana, stderr = funct.subprocess_execute("service grafana-server status |grep Active |awk '{print $1}'") services = [] - services_name = {"checker_haproxy":"Master backends checker service", - "keep_alive":"Auto start service", - "metrics_haproxy":"Master metrics service", - "prometheus":"Prometheus service", - "grafana-server":"Grafana service", - "smon":"Simple monitoring network ports", - "fail2ban": "Fail2ban service"} + services_name = {'checker_haproxy':'Master backends checker service', + 'keep_alive':'Auto start service', + 'metrics_haproxy':'Master metrics service', + 'prometheus':'Prometheus service', + 'grafana-server':'Grafana service', + 'smon':'Simple monitoring network ports', + 'fail2ban': 'Fail2ban service'} for s, v in services_name.items(): cmd = "systemctl status %s |grep Act |awk '{print $2}'" %s status, stderr = funct.subprocess_execute(cmd) - services.append([s, status, v]) + if s != 'keep_alive': + service_name = s.split('_')[0] + else: + service_name = s + cmd = "rpm --query haproxy-wi-"+service_name+"-* |awk -F\""+service_name+"\" '{print $2}' |awk -F\".noa\" '{print $1}' |sed 's/-//1' |sed 's/-/./'" + service_ver, stderr = funct.subprocess_execute(cmd) + services.append([s, status, v, service_ver[0]]) except: pass @@ -45,6 +51,10 @@ template = template.render(title = "Admin area: Manage users", telegrams = sql.select_telegram(), token = token, versions = funct.versions(), + checker_ver = funct.check_new_version(service='checker'), + smon_ver = funct.check_new_version(service='smon'), + metrics_ver = funct.check_new_version(service='metrics'), + keep_ver = funct.check_new_version(service='keep'), settings = settings, backups = sql.select_backups(), services = services, diff --git a/inc/users.js b/inc/users.js index be5f7428..188e6259 100644 --- a/inc/users.js +++ b/inc/users.js @@ -58,7 +58,6 @@ $( function() { autoFocus: true, minLength: -1 }); - var wait_mess = '
Please don\'t close and don\'t represh page. Wait until the work is completed. This may take some time
' var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; $('#create').click(function() { var hap = 0; @@ -402,57 +401,6 @@ $( function() { } } ); }); - $('#update_haproxy_wi').click(function() { - $("#ajax-update").html('') - $("#ajax-update").html('
Please don\'t close and don\'t represh page. Wait until the work is completed. This may take some time
'); - $.ajax( { - url: "options.py", - data: { - update_haproxy_wi: 1, - token: $('#token').val() - }, - type: "POST", - success: function( data ) { - data = data.replace(/\s+/g,' '); - if (data.indexOf('error:') != '-1' || data.indexOf('Failed') != '-1') { - toastr.error(data); - } else if (data.indexOf('Complete!') != '-1'){ - toastr.clear(); - toastr.success('Update was success!'); - } else if (data.indexOf('Unauthorized') != '-1') { - toastr.clear(); - toastr.error('It is seems like you Unauthorized in the HAProxy-WI repository. How to get HAProxy-WI auth you can read hear'); - } else if (data.indexOf('but not installed') != '-1') { - toastr.clear(); - toastr.error('You have settings for HAProxy-WI repository, but installed HAProxy-WI without repository. Please reinstall with yum'); - } else if (data.indexOf('No Match for argument') != '-1') { - toastr.clear(); - toastr.error('It is seems like you do not have HAProxy-WI repository settings. Please read docs for detail'); - } else if (data.indexOf('password for') != '-1') { - toastr.clear(); - toastr.error('It is seems like you need add Apache user to sudoers. Please read docs fordetail'); - } else if (data.indexOf('No packages marked for update') != '-1') { - toastr.clear(); - toastr.error('It is seems like you have the lastest version HAProxy-WI'); - } else if (data.indexOf('Connection timed out') != '-1') { - toastr.clear(); - toastr.error('Cannot connect to HAProxy-WI repository. Connection timed out'); - } else if (data.indexOf('--disable') != '-1') { - toastr.clear(); - toastr.error('It is seems like you have problem with your repositorys'); - } else if (data.indexOf('Unauthorized') != '-1') { - toastr.clear(); - toastr.error('It is seems like you Unauthorized in the HAProxy-WI repository'); - } else if (data.indexOf('Error: Package') != '-1') { - toastr.clear(); - toastr.error(data); - } else if (data.indexOf('conflicts with file from') != '-1') { - toastr.clear(); - toastr.error(data); - } - } - } ); - }); $('#add-group-button').click(function() { addGroupDialog.dialog('open'); }); @@ -1958,4 +1906,54 @@ function ajaxActionServies(action, service) { alert(w.data_error); } } ); +} +function updateService(service) { + $("#ajax-update").html('') + $("#ajax-update").html('
Please don\'t close and don\'t represh page. Wait until the work is completed. This may take some time
'); + $.ajax( { + url: "options.py", + data: { + update_haproxy_wi: 1, + service: service, + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + console.log(data) + data = data.replace(/\s+/g,' '); + if (data.indexOf('error:') != '-1' || data.indexOf('Failed') != '-1') { + toastr.error(data); + } else if (data.indexOf('Complete!') != '-1'){ + toastr.clear(); + toastr.success('Update was success!'); + } else if (data.indexOf('Unauthorized') != '-1') { + toastr.clear(); + toastr.error('It is seems like you Unauthorized in the HAProxy-WI repository. How to get HAProxy-WI auth you can read hear'); + } else if (data.indexOf('but not installed') != '-1') { + toastr.clear(); + toastr.error('You have settings for HAProxy-WI repository, but installed HAProxy-WI without repository. Please reinstall with yum'); + } else if (data.indexOf('No Match for argument') != '-1') { + toastr.clear(); + toastr.error('It is seems like you do not have HAProxy-WI repository settings. Please read docs for detail'); + } else if (data.indexOf('password for') != '-1') { + toastr.clear(); + toastr.error('It is seems like you need add Apache user to sudoers. Please read docs fordetail'); + } else if (data.indexOf('No packages marked for update') != '-1') { + toastr.clear(); + toastr.info('It is seems like you have the lastest version HAProxy-WI'); + } else if (data.indexOf('Connection timed out') != '-1') { + toastr.clear(); + toastr.error('Cannot connect to HAProxy-WI repository. Connection timed out'); + } else if (data.indexOf('--disable') != '-1') { + toastr.clear(); + toastr.error('It is seems like you have problem with your repositories'); + } else if (data.indexOf('Error: Package') != '-1') { + toastr.clear(); + toastr.error(data); + } else if (data.indexOf('conflicts with file from') != '-1') { + toastr.clear(); + toastr.error(data); + } + } + } ); } \ No newline at end of file