Aidaho 2021-01-22 10:01:08 +06:00
parent 3c8ab621fd
commit 2664479d1c
8 changed files with 42 additions and 34 deletions

View File

@ -399,13 +399,10 @@ if form.getvalue('action_hap') is not None and serv is not None:
if form.getvalue('action_nginx') is not None and serv is not None:
action = form.getvalue('action_nginx')
if funct.check_haproxy_config(serv):
commands = ["sudo systemctl %s nginx" % action]
funct.ssh_command(serv, commands)
funct.logging(serv, 'Nginx was ' + action + 'ed', haproxywi=1, login=1)
print("success: Nginx was %s" % action)
else:
print("error: Bad config, check please")
if form.getvalue('action_waf') is not None and serv is not None:
serv = form.getvalue('serv')
@ -1626,7 +1623,7 @@ if form.getvalue('newserver') is not None:
page=page,
adding=1)
print(template)
funct.logging('a new server ' + hostname, ' has created ', haproxywi=1, login=1)
funct.logging('a new server ' + hostname, ' has been created ', haproxywi=1, login=1)
if form.getvalue('updatehapwiserver') is not None:
hapwi_id = form.getvalue('updatehapwiserver')
@ -1636,7 +1633,7 @@ if form.getvalue('updatehapwiserver') is not None:
metrics = form.getvalue('metrics')
service_name = form.getvalue('service_name')
sql.update_hapwi_server(hapwi_id, alert, metrics, active, service_name)
funct.logging('the server ' + name, ' has updated ', haproxywi=1, login=1)
funct.logging('the server ' + name, ' has been updated ', haproxywi=1, login=1)
if form.getvalue('updateserver') is not None:
name = form.getvalue('updateserver')
@ -1656,7 +1653,7 @@ if form.getvalue('updateserver') is not None:
print(error_mess)
else:
sql.update_server(name, group, typeip, enable, master, serv_id, cred, port, desc, haproxy, nginx, firewall)
funct.logging('the server ' + name, ' has updated ', haproxywi=1, login=1)
funct.logging('the server ' + name, ' has been updated ', haproxywi=1, login=1)
if form.getvalue('serverdel') is not None:
serverdel = form.getvalue('serverdel')
@ -1670,7 +1667,7 @@ if form.getvalue('serverdel') is not None:
if sql.delete_server(serverdel):
sql.delete_waf_server(serverdel)
print("Ok")
funct.logging(hostname, ' has deleted server with ', haproxywi=1, login=1)
funct.logging(hostname, ' has been deleted server with ', haproxywi=1, login=1)
if form.getvalue('newgroup') is not None:
newgroup = form.getvalue('groupname')
@ -2231,6 +2228,15 @@ if form.getvalue('viewFirewallRules') is not None:
cmd2 = ["sudo iptables -L OUTPUT -n --line-numbers|sed 's/ */ /g'|grep -v -E 'Chain|target'"]
input_chain = funct.ssh_command(serv, cmd, raw=1)
input_chain2 = []
for each_line in input_chain:
input_chain2.append(each_line.strip('\n'))
if 'error:' in input_chain:
print(input_chain)
sys.exit()
IN_public_allow = funct.ssh_command(serv, cmd1, raw=1)
output_chain = funct.ssh_command(serv, cmd2, raw=1)
@ -2238,7 +2244,7 @@ if form.getvalue('viewFirewallRules') is not None:
env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('ajax/firewall_rules.html')
template = template.render(input=input_chain, IN_public_allow=IN_public_allow, output=output_chain)
template = template.render(input=input_chain2, IN_public_allow=IN_public_allow, output=output_chain)
print(template)
if form.getvalue('geoipserv') is not None:
@ -2273,7 +2279,7 @@ if form.getvalue('geoip_install'):
commands = ["chmod +x " + script + " && ./" + script + " PROXY=" + proxy_serv + " SSH_PORT=" + ssh_port +
" UPDATE=" + str(geoip_update) + " maxmind_key=" + maxmind_key + " haproxy_dir=" + haproxy_dir +
" HOST=" + str(serv) +" USER=" + str(ssh_user_name) + " PASS=" + str(ssh_user_password) +
" HOST=" + str(serv) + " USER=" + str(ssh_user_name) + " PASS=" + str(ssh_user_password) +
" KEY=" + str(ssh_key_name)]
output, error = funct.subprocess_execute(commands[0])
@ -2281,3 +2287,11 @@ if form.getvalue('geoip_install'):
funct.show_installation_output(error, output, 'GeoLite2 Database')
os.system("rm -f %s" % script)
if form.getvalue('show_versions'):
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('ajax/check_version.html')
template = template.render(versions=funct.versions())
print(template)

View File

@ -7,18 +7,18 @@
<th class="ip-field" style="width: 5%">IP</th>
<th class="checkbox-head" style="width: 5%"><span title="SSH port">Port</span></th>
{% if page != "servers.py" %}
<th class="group-field" style="width: 10%">Group</th>
<th style="width: 10%">Group</th>
{% endif %}
<th class="checkbox-head" style="width: 5%">Enabled</th>
<th class="checkbox-head" style="width: 5%">
<th style="width: 5%; padding-left: 5px;">
<span title="Virtual IP, something like VRRP">Virt</span>
</th>
<th class="checkbox-head" style="width: 5%">HAProxy</th>
<th class="checkbox-head" style="width: 5%">Nginx</th>
<th class="checkbox-head" style="width: 15%">
<th style="width: 5%">Nginx</th>
<th style="width: 15%;">
<span title="If the server has a firewall enabled, enable this option">Firewalld</span>
</th>
<th class="slave-field" style="width: 10%">
<th style="width: 10%">
<span title="Actions with the master config will automatically apply on the slave">Slave for</span>
</th>
<th class="cred-field">Credentials</th>
@ -83,7 +83,7 @@
{{ checkbox(id) }}
{% endif %}
</td>
<td class="checkbox">
<td class="checkbox" style="padding-left: 5px;">
{% set id = 'nginx-' + server.0|string() %}
{% if server.14 == 1 %}
{{ checkbox(id, checked='checked') }}
@ -91,7 +91,7 @@
{{ checkbox(id) }}
{% endif %}
</td>
<td class="checkbox">
<td class="checkbox" style="padding-left: 0">
<div class="controlgroup">
{% set id = 'firewall-' + server.0|string() %}
{% if server.18 == 1 %}

View File

@ -651,6 +651,7 @@ $( function() {
$( ".second-server" ).hide( "fast" );
$( ".backend_server" ).hide( "fast" );
$( ".send_proxy" ).hide( "fast" );
$( "input[name=server_maxconn]" ).hide( "fast" );
$( ".prefix" ).attr('required',true);
} else {
$( ".prefix" ).hide( "fast" );
@ -658,6 +659,7 @@ $( function() {
$( ".second-server" ).show( "fast" );
$( ".backend_server" ).show( "fast" )
$( ".send_proxy" ).show( "fast" )
$( "input[name=server_maxconn]" ).show( "fast" );
}
});
var location = window.location.href;
@ -888,8 +890,8 @@ $( function() {
toastr.error('Wrong e-mail format');
}
});
var add_server_var = '<br /><input name="servers" title="Backend IP" size=14 placeholder="xxx.xxx.xxx.xxx" class="form-control">: ' +
'<input name="server_port" required title="Backend IP" size=3 placeholder="yyy" class="form-control add_server_number" type="number">' +
var add_server_var = '<br /><input name="servers" title="Backend IP" size=14 placeholder="xxx.xxx.xxx.xxx" class="form-control second-server">: ' +
'<input name="server_port" required title="Backend IP" size=3 placeholder="yyy" class="form-control second-server add_server_number" type="number">' +
'<input name="server_maxconn" required title="Maxconn. Default 200" size=5 value="200" class="form-control add_server_number" type="number">'
$('[name=add-server-input]').click(function() {
$("[name=add_servers]").append(add_server_var);

View File

@ -72,5 +72,4 @@ $( function() {
});
event.preventDefault();
});
})

View File

@ -318,7 +318,6 @@ function updateHapWIServer(id, service_name) {
toastr.error(data);
} else {
toastr.clear();
console.log("#server-"+id+"-"+service_name)
$("#server-"+id+"-"+service_name).addClass( "update", 1000 );
setTimeout(function() {
$( "#server-"+id+"-"+service_name).removeClass( "update" );

View File

@ -959,7 +959,7 @@ $( function() {
$(this).children(".settings").css('padding-left', '30px');
$(this).children(".settings").css('border-left', '4px solid #5D9CEB');
});
$( "#tabs" ).tabs( "option", "active", 5 );
$( "#tabs" ).tabs( "option", "active", 6 );
} );
$( ".services" ).on( "click", function() {
$('.menu li ul li').each(function () {
@ -968,7 +968,7 @@ $( function() {
$(this).children(".services").css('padding-left', '30px');
$(this).children(".services").css('border-left', '4px solid #5D9CEB');
});
$( "#tabs" ).tabs( "option", "active", 6 );
$( "#tabs" ).tabs( "option", "active", 7 );
} );
$( ".updatehapwi" ).on( "click", function() {
$('.menu li ul li').each(function () {
@ -977,7 +977,7 @@ $( function() {
$(this).children(".updatehapwi").css('padding-left', '30px');
$(this).children(".updatehapwi").css('border-left', '4px solid #5D9CEB');
});
$( "#tabs" ).tabs( "option", "active", 7 );
$( "#tabs" ).tabs( "option", "active", 8 );
} );
} else {
$( ".runtime" ).on( "click", function() {

View File

@ -373,12 +373,6 @@ pre {
.ip-field {
width: 100px;
}
.group-field, .slave-field {
//min-width: 5%;
}
.slave-field {
padding-left: 10px;
}
.cred-field {
min-width: 225px;
}

View File

@ -2173,7 +2173,7 @@ function viewFirewallRules(id) {
type: "POST",
success: function (data) {
data = data.replace(/\s+/g, ' ');
if (data.indexOf('danger') != '-1' || data.indexOf('unique') != '-1' || data.indexOf('error:') != '-1') {
if (data.indexOf('danger') != '-1' || data.indexOf('unique') != '-1' || data.indexOf('error: ') != '-1') {
toastr.error(data);
} else {
toastr.clear();