mirror of https://github.com/Aidaho12/haproxy-wi
parent
3b25ad6de9
commit
b3057628eb
|
@ -709,7 +709,7 @@ def update_db_v_4_5_4(**kwargs):
|
|||
|
||||
def update_ver(**kwargs):
|
||||
con, cur = get_cur()
|
||||
sql = """update version set version = '4.5.4.0'; """
|
||||
sql = """update version set version = '4.5.5.0'; """
|
||||
try:
|
||||
cur.execute(sql)
|
||||
con.commit()
|
||||
|
|
|
@ -627,8 +627,13 @@ def install_nginx(serv):
|
|||
|
||||
def update_haproxy_wi(service):
|
||||
if service != 'haproxy-wi':
|
||||
try:
|
||||
if service != 'keep_alive':
|
||||
service = service.split('_')[0]
|
||||
except Exception:
|
||||
pass
|
||||
service = 'haproxy-wi-'+service
|
||||
cmd = 'sudo -S yum -y update '+service
|
||||
cmd = 'sudo -S yum -y update '+service
|
||||
output, stderr = subprocess_execute(cmd)
|
||||
print(output)
|
||||
print(stderr)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
import sql
|
||||
import funct
|
||||
import sql
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
@ -18,7 +17,7 @@ try:
|
|||
servers = ''
|
||||
else:
|
||||
servers = sql.select_servers_metrics(user_id.value)
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
|
@ -28,6 +27,6 @@ template = template.render(h2=1, title="Metrics",
|
|||
user=user,
|
||||
servers=servers,
|
||||
versions=funct.versions(),
|
||||
services=service_ver[0],
|
||||
services=service_ver[0],
|
||||
token=token)
|
||||
print(template)
|
||||
|
|
|
@ -1526,6 +1526,42 @@ if form.getvalue('bwlists_save'):
|
|||
elif form.getvalue('bwlists_restart') == 'reload':
|
||||
funct.ssh_command(serv, ["sudo systemctl reload " + haproxy_service_name])
|
||||
|
||||
if form.getvalue('bwlists_delete'):
|
||||
color = form.getvalue('color')
|
||||
bwlists_delete = form.getvalue('bwlists_delete')
|
||||
list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + color + "/" + bwlists_delete
|
||||
try:
|
||||
os.remove(list_path)
|
||||
except IOError as e:
|
||||
print('error: Cannot delete ' + color + ' list. %s , ' % e)
|
||||
|
||||
path = sql.get_setting('haproxy_dir') + "/" + color
|
||||
servers = []
|
||||
|
||||
if serv != 'all':
|
||||
servers.append(serv)
|
||||
|
||||
MASTERS = sql.is_master(serv)
|
||||
for master in MASTERS:
|
||||
if master[0] is not None:
|
||||
servers.append(master[0])
|
||||
else:
|
||||
server = sql.get_dick_permit()
|
||||
for s in server:
|
||||
servers.append(s[2])
|
||||
|
||||
for serv in servers:
|
||||
error = funct.ssh_command(serv, ["sudo rm " + path + "/" + bwlists_delete], return_err=1)
|
||||
|
||||
if error:
|
||||
print('error: Deleting fail: %s , ' % error)
|
||||
else:
|
||||
print('success: ' + color + ' list was delete on ' + serv + ' , ')
|
||||
try:
|
||||
funct.logging(serv, 'has deleted ' + color + ' list ' + bwlists_save, haproxywi=1, login=1)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if form.getvalue('get_lists'):
|
||||
list_path = os.path.dirname(os.getcwd()) + "/" + sql.get_setting('lists_path') + "/" + form.getvalue('group') + "/" + form.getvalue('color')
|
||||
lists = funct.get_files(dir=list_path, format="lst")
|
||||
|
@ -2069,6 +2105,34 @@ if form.getvalue('showBytes') is not None:
|
|||
template = template.render(bin_bout=bin_bout, serv=serv)
|
||||
print(template)
|
||||
|
||||
if form.getvalue('nginxConnections'):
|
||||
import requests
|
||||
serv = form.getvalue('nginxConnections')
|
||||
port = sql.get_setting('nginx_stats_port')
|
||||
user = sql.get_setting('nginx_stats_user')
|
||||
password = sql.get_setting('nginx_stats_password')
|
||||
page = sql.get_setting('nginx_stats_page')
|
||||
|
||||
r = requests.get('http://' + serv + ':' + port + '/' + page, auth=(user, password))
|
||||
|
||||
if r.status_code == 200:
|
||||
bin_bout = [0, 0]
|
||||
for num, line in enumerate(r.text.split('\n')):
|
||||
#bin_bout.append(line.encode(encoding='ISO-8859-1'))
|
||||
if num == 0:
|
||||
bin_bout.append(line.split(' ')[2])
|
||||
if num == 2:
|
||||
bin_bout.append(line.split(' ')[3])
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
env = Environment(loader=FileSystemLoader('templates'))
|
||||
template = env.get_template('ajax/bin_bout.html')
|
||||
template = template.render(bin_bout=bin_bout, serv=serv, service='nginx')
|
||||
print(template)
|
||||
else:
|
||||
print('error: cannot connect to Nginx stat page')
|
||||
|
||||
if form.getvalue('alert_consumer'):
|
||||
try:
|
||||
user_group = funct.get_user_group(id=1)
|
||||
|
@ -2231,3 +2295,21 @@ if form.getvalue('scan_ports') is not None:
|
|||
template = env.get_template('ajax/scan_ports.html')
|
||||
template = template.render(ports=stdout, info=stdout1)
|
||||
print(template)
|
||||
|
||||
if form.getvalue('viewFirewallRules') is not None:
|
||||
serv = form.getvalue('viewFirewallRules')
|
||||
|
||||
cmd = ["sudo iptables -L INPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
||||
cmd1 = ["sudo iptables -L IN_public_allow -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
||||
cmd2 = ["sudo iptables -L OUTPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
|
||||
|
||||
input = funct.ssh_command(serv, cmd, raw=1)
|
||||
IN_public_allow = funct.ssh_command(serv, cmd1, raw=1)
|
||||
output = funct.ssh_command(serv, cmd2, raw=1)
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
env = Environment(loader=FileSystemLoader('templates'))
|
||||
template = env.get_template('ajax/firewall_rules.html')
|
||||
template = template.render(input=input, IN_public_allow=IN_public_allow, output=output)
|
||||
print(template)
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
'url_param userid':'url_param userid'} %}
|
||||
{% set checks = dict() %}
|
||||
{% set checks = {'':'Choose custom health check','option tcp-check':'Check a TCP Port',
|
||||
'option ssl-hello-chk':'Check an SSL Port','option httpchk':'Check an HTTP service',
|
||||
'option ldap-check':'Check an LDAP service', 'option mysql-check':'Check a MySql Service',
|
||||
'option ssl-hello-chk':'Check a SSL Port','option httpchk':'Check a HTTP service',
|
||||
'option ldap-check':'Check a LDAP service', 'option mysql-check':'Check a MySql Service',
|
||||
'option pgsql-check':'Check a PgSQL Service', 'option redis-check': 'Check a Redis Service',
|
||||
'option smtpchk':'Check an SMTP service'} %}
|
||||
'option smtpchk':'Check a SMTP service'} %}
|
||||
|
||||
<script src="/inc/add.js"></script>
|
||||
<div id="tabs">
|
||||
|
|
|
@ -20,7 +20,7 @@ th, tr, td {
|
|||
{% if services == '* is not installed' %}
|
||||
<center>
|
||||
<br />
|
||||
<h3>You do not have installed Metrics service
|
||||
<h3>You do not have installed Metrics service.
|
||||
Read <a href="https://haproxy-wi.org/services.py?service=metrics#installation" title="Metrics installation" style="color: #5d9ceb;" target="_blank">hear</a>
|
||||
how to install Metrics service</h3>
|
||||
</center>
|
||||
|
@ -28,6 +28,15 @@ th, tr, td {
|
|||
{% if servers|length == 0 %}
|
||||
{% include 'include/getstarted.html' %}
|
||||
{% else %}
|
||||
<table style="min-width: 40%;">
|
||||
<tr class="overviewHead">
|
||||
<th colspan=13 style="background-color: #d1ecf1">
|
||||
<span id="table_metrics_head" style="position: absolute;margin-left: 43%;">Metrics</span>
|
||||
<span id="en_table_metric" class="add switcher_table_metric" title="Enable showing Average table"></span>
|
||||
<span id="dis_table_metric" class="minus switcher_table_metric" title="Disable showing Average table"></span>
|
||||
</th>
|
||||
</tr>
|
||||
</table>
|
||||
<div id="table_metrics"></div>
|
||||
<div style="padding-left: 25px;float: left;margin-top: 6px;">
|
||||
<b>Time range:</b>
|
||||
|
@ -54,7 +63,12 @@ th, tr, td {
|
|||
{% for s in servers %}
|
||||
getChartData('{{s.0}}')
|
||||
{% endfor %}
|
||||
loadMetrics()
|
||||
if (localStorage.getItem('table_metrics') == 0 || localStorage.getItem('table_metrics') === null) {
|
||||
$('#dis_table_metric').css('display', 'none');
|
||||
} else {
|
||||
$('#en_table_metric').css('display', 'none');
|
||||
loadMetrics();
|
||||
}
|
||||
});
|
||||
metrics.then();
|
||||
}
|
||||
|
@ -71,6 +85,7 @@ th, tr, td {
|
|||
metrics.then();
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
|
36
inc/add.js
36
inc/add.js
|
@ -1344,6 +1344,10 @@ function editList(list, color) {
|
|||
modal: true,
|
||||
title: "Edit "+color+" list "+list,
|
||||
buttons: {
|
||||
"Delete": function() {
|
||||
$( this ).dialog( "close" );
|
||||
deleteList(list, color);
|
||||
},
|
||||
"Just save": function() {
|
||||
$( this ).dialog( "close" );
|
||||
saveList('save', list, color);
|
||||
|
@ -1398,3 +1402,35 @@ function saveList(action, list, color) {
|
|||
});
|
||||
}
|
||||
}
|
||||
function deleteList(list, color) {
|
||||
var serv = $( "#serv-"+color+"-list option:selected" ).val();
|
||||
if (serv == 'Choose server') {
|
||||
toastr.warning('Choose a server before deleting');
|
||||
} else {
|
||||
$.ajax({
|
||||
url: "options.py",
|
||||
data: {
|
||||
bwlists_delete: list,
|
||||
serv: serv,
|
||||
color: color,
|
||||
group: $('#group').val(),
|
||||
token: $('#token').val()
|
||||
},
|
||||
type: "POST",
|
||||
success: function (data) {
|
||||
if (data.indexOf('error:') != '-1' || data.indexOf('Failed') != '-1') {
|
||||
toastr.error(data);
|
||||
} else if (data.indexOf('Info') != '-1' ){
|
||||
toastr.clear();
|
||||
toastr.info(data);
|
||||
} else if (data.indexOf('success') != '-1' ) {
|
||||
toastr.clear();
|
||||
toastr.success('List has been deleted');
|
||||
setTimeout(function () {
|
||||
location.reload();
|
||||
}, 2500);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -254,3 +254,8 @@
|
|||
font-family: "Font Awesome 5 Solid";
|
||||
content: "\f0c9";
|
||||
}
|
||||
.minus::before {
|
||||
display: none;
|
||||
font-family: "Font Awesome 5 Solid";
|
||||
content: "\f068";
|
||||
}
|
||||
|
|
|
@ -170,8 +170,7 @@ function renderWafChart(data, labels, server) {
|
|||
});
|
||||
charts.push(myChart);
|
||||
}
|
||||
console.log(charts);
|
||||
$("#secIntervals").css("display", "none");
|
||||
$("#secIntervals").css("display", "none");
|
||||
|
||||
function loadMetrics() {
|
||||
$.ajax({
|
||||
|
@ -319,4 +318,17 @@ function renderChartHapWiCpu(data) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
$( function() {
|
||||
$('#dis_table_metric').click(function() {
|
||||
localStorage.setItem('table_metrics', 0);
|
||||
$('#body_table_metrics').css('display', 'none');
|
||||
$('#en_table_metric').css('display', 'inline');
|
||||
$('#dis_table_metric').css('display', 'none');
|
||||
});
|
||||
$('#en_table_metric').click(function() {
|
||||
localStorage.setItem('table_metrics', 1);
|
||||
$('#en_table_metric').css('display', 'none');
|
||||
$('#dis_table_metric').css('display', 'inline');
|
||||
loadMetrics();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue