mirror of https://github.com/Aidaho12/haproxy-wi
parent
1212285a20
commit
0f1c889165
19
app/funct.py
19
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:
|
||||
|
|
|
@ -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'):
|
||||
|
|
|
@ -141,22 +141,90 @@
|
|||
{% set new_ver_without_dots = versions.3 %}
|
||||
<table class="overview">
|
||||
<tr class="overviewHead">
|
||||
<td class="padding10 first-collumn" style="width: 25%;">Currnet version</td>
|
||||
<td class="padding10 first-collumn" style="width: 25%;">Service</td>
|
||||
<td>Currnet version</td>
|
||||
<td class="padding10">Last version</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="padding10 first-collumn">
|
||||
<b>{{current_ver}}</b>
|
||||
</td>
|
||||
<td class="padding10">
|
||||
<b>{{new_ver}}</b>
|
||||
</td>
|
||||
<td>
|
||||
{% if new_ver_without_dots > current_ver_without_dots and new_ver != "Sorry cannot get current version" %}
|
||||
<a class="ui-button ui-widget ui-corner-all" id="update_haproxy_wi" title="Update HAProxy">Update</a>
|
||||
<td class="padding10 first-collumn">
|
||||
HAProxy-WI
|
||||
</td>
|
||||
<td>
|
||||
<b>{{current_ver}}</b>
|
||||
</td>
|
||||
<td class="padding10">
|
||||
<b>{{new_ver}}</b>
|
||||
</td>
|
||||
<td>
|
||||
{% if new_ver_without_dots > current_ver_without_dots and new_ver != "Sorry cannot get current version" %}
|
||||
<a class="ui-button ui-widget ui-corner-all" onclick="updateService('haproxy-wi')" title="Update HAProxy-WI">Update</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% for s in services %}
|
||||
{% if s.0 == 'smon' or s.0 == 'checker_haproxy' or s.0 == 'keep_alive' or s.0 == 'metrics_haproxy' %}
|
||||
<tr>
|
||||
{% 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 %}
|
||||
</td>
|
||||
<td class="padding10 first-collumn">
|
||||
{{service_name}}
|
||||
</td>
|
||||
<td>
|
||||
{% if s.3 != '* is not installed' %}
|
||||
<b>{{s.3}}</b>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="padding10">
|
||||
<b>
|
||||
{% 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 %}
|
||||
</b>
|
||||
</td>
|
||||
<td>
|
||||
{% if s.3 != '* is not installed' %}
|
||||
{% if is_need_update %}
|
||||
<a class="ui-button ui-widget ui-corner-all" onclick="updateService('{{s.0}}')" title="Update {{service_name}}">Update</a>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{service_name}} service is not installed
|
||||
<a href="https://haproxy-wi.org/services.py?service={{service_link}}#installation" title="{{service_name}} installtion" target="_blank" style="color: #5d9ceb;">Read about installation</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
<div class="add-note addName alert-info" style="width: inherit; margin-right: 15px;">
|
||||
<b style="font-size: 20px; display: block; padding-bottom: 10px;">Note:</b>
|
||||
|
|
26
app/users.py
26
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,
|
||||
|
|
102
inc/users.js
102
inc/users.js
|
@ -58,7 +58,6 @@ $( function() {
|
|||
autoFocus: true,
|
||||
minLength: -1
|
||||
});
|
||||
var wait_mess = '<div class="alert alert-warning">Please don\'t close and don\'t represh page. Wait until the work is completed. This may take some time </div>'
|
||||
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('<div class="alert alert-warning">Please don\'t close and don\'t represh page. Wait until the work is completed. This may take some time </div>');
|
||||
$.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 <a href="https://haproxy-wi.org/installation.py" title="How to get HAProxy-WI auth">hear</a>');
|
||||
} 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 <a href="https://haproxy-wi.org/updates.py">detail</a>');
|
||||
} 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 for<a href="https://haproxy-wi.org/updates.py">detail</a>');
|
||||
} 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('<div class="alert alert-warning">Please don\'t close and don\'t represh page. Wait until the work is completed. This may take some time </div>');
|
||||
$.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 <a href="https://haproxy-wi.org/installation.py" title="How to get HAProxy-WI auth">hear</a>');
|
||||
} 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 <a href="https://haproxy-wi.org/updates.py">detail</a>');
|
||||
} 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 for<a href="https://haproxy-wi.org/updates.py">detail</a>');
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
Loading…
Reference in New Issue