mirror of https://github.com/Aidaho12/haproxy-wi
parent
6303f92269
commit
548d61db59
49
app/funct.py
49
app/funct.py
|
@ -445,6 +445,55 @@ def waf_install(serv, **kwargs):
|
|||
if stderr is None:
|
||||
sql.insert_waf_metrics_enable(serv, "0")
|
||||
|
||||
|
||||
def install_nginx():
|
||||
script = "install_nginx.sh"
|
||||
stats_user = sql.get_setting('nginx_stats_user')
|
||||
stats_password = sql.get_setting('nginx_stats_password')
|
||||
stats_port = sql.get_setting('nginx_stats_port')
|
||||
stats_page = sql.get_setting('nginx_stats_page')
|
||||
config_path = sql.get_setting('nginx_config_path')
|
||||
proxy = sql.get_setting('proxy')
|
||||
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = return_ssh_keys_path(serv)
|
||||
|
||||
if ssh_enable == 0:
|
||||
ssh_key_name = ''
|
||||
|
||||
os.system("cp scripts/%s ." % script)
|
||||
|
||||
if proxy is not None and proxy != '' and proxy != 'None':
|
||||
proxy_serv = proxy
|
||||
else:
|
||||
proxy_serv = ''
|
||||
|
||||
syn_flood_protect = '1' if form.getvalue('syn_flood') == "1" else ''
|
||||
|
||||
commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv+" STATS_USER="+stats_user+" STATS_PASS="+stats_password+
|
||||
" CONFIG_PATH="+config_path+" STAT_PORT="+stats_port+" STAT_PAGE="+stats_page+" SYN_FLOOD="+syn_flood_protect+" HOST="+serv+
|
||||
" USER="+ssh_user_name+" PASS="+ssh_user_password+" KEY="+ssh_key_name ]
|
||||
|
||||
output, error = subprocess_execute(commands[0])
|
||||
|
||||
if error:
|
||||
logging('localhost', error, haproxywi=1)
|
||||
print('error: '+error)
|
||||
else:
|
||||
for l in output:
|
||||
if "msg" in l or "FAILED" in l:
|
||||
try:
|
||||
l = l.split(':')[1]
|
||||
l = l.split('"')[1]
|
||||
print(l+"<br>")
|
||||
break
|
||||
except:
|
||||
print(output)
|
||||
break
|
||||
else:
|
||||
print('success: Nginx was installed<br>')
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
sql.update_nginx(serv)
|
||||
|
||||
|
||||
def update_haproxy_wi():
|
||||
cmd = 'sudo -S yum -y update haproxy-wi'
|
||||
|
|
|
@ -50,7 +50,6 @@ if form.getvalue('getcert') is not None and serv is not None:
|
|||
|
||||
|
||||
if serv and form.getvalue('ssl_cert'):
|
||||
#cert_local_dir = funct.get_config_var('main', 'cert_local_dir')
|
||||
cert_local_dir = os.path.dirname(os.getcwd())+"/"+sql.get_setting('ssl_local_path')
|
||||
cert_path = sql.get_setting('cert_path')
|
||||
|
||||
|
@ -347,10 +346,16 @@ if form.getvalue('action'):
|
|||
if serv is not None and act == "stats":
|
||||
import requests
|
||||
|
||||
haproxy_user = sql.get_setting('stats_user')
|
||||
haproxy_pass = sql.get_setting('stats_password')
|
||||
stats_port = sql.get_setting('stats_port')
|
||||
stats_page = sql.get_setting('stats_page')
|
||||
if form.getvalue('service') == 'nginx':
|
||||
haproxy_user = sql.get_setting('nginx_stats_user')
|
||||
haproxy_pass = sql.get_setting('nginx_stats_password')
|
||||
stats_port = sql.get_setting('nginx_stats_port')
|
||||
stats_page = sql.get_setting('nginx_stats_page')
|
||||
else:
|
||||
haproxy_user = sql.get_setting('stats_user')
|
||||
haproxy_pass = sql.get_setting('stats_password')
|
||||
stats_port = sql.get_setting('stats_port')
|
||||
stats_page = sql.get_setting('stats_page')
|
||||
try:
|
||||
response = requests.get('http://%s:%s/%s' % (serv, stats_port, stats_page), auth=(haproxy_user, haproxy_pass))
|
||||
except requests.exceptions.ConnectTimeout:
|
||||
|
@ -367,7 +372,25 @@ if serv is not None and act == "stats":
|
|||
print ("OOps: Something Else",err)
|
||||
|
||||
data = response.content
|
||||
print(data.decode('utf-8'))
|
||||
if form.getvalue('service') == 'nginx':
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
env = Environment(loader=FileSystemLoader('templates/'))
|
||||
template = env.get_template('ajax/nginx_stats.html')
|
||||
|
||||
servers_with_status = list()
|
||||
h = ()
|
||||
out1 = []
|
||||
for k in data.decode('utf-8').split():
|
||||
out1.append(k)
|
||||
h = (out1, )
|
||||
servers_with_status.append(h)
|
||||
|
||||
template = template.render(out=servers_with_status)
|
||||
print(template)
|
||||
|
||||
|
||||
else:
|
||||
print(data.decode('utf-8'))
|
||||
|
||||
|
||||
if serv is not None and form.getvalue('rows') is not None:
|
||||
|
@ -660,6 +683,10 @@ if form.getvalue('master'):
|
|||
funct.install_haproxy(master)
|
||||
funct.install_haproxy(slave)
|
||||
|
||||
if form.getvalue('nginx') == "1":
|
||||
funct.install_nginx(master)
|
||||
funct.install_nginx(slave)
|
||||
|
||||
commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv+
|
||||
" ETH="+ETH+" IP="+str(IP)+" MASTER=MASTER"+" SYN_FLOOD="+syn_flood+" HOST="+str(master)+
|
||||
" USER="+str(ssh_user_name)+" PASS="+str(ssh_user_password)+" KEY="+str(ssh_key_name) ]
|
||||
|
@ -862,53 +889,7 @@ if form.getvalue('backup') or form.getvalue('deljob') or form.getvalue('backupup
|
|||
|
||||
|
||||
if form.getvalue('install_nginx'):
|
||||
script = "install_nginx.sh"
|
||||
serv = form.getvalue('install_nginx')
|
||||
stats_user = sql.get_setting('nginx_stats_user')
|
||||
stats_password = sql.get_setting('nginx_stats_password')
|
||||
stats_port = sql.get_setting('nginx_stats_port')
|
||||
stats_page = sql.get_setting('nginx_stats_page')
|
||||
config_path = sql.get_setting('nginx_config_path')
|
||||
proxy = sql.get_setting('proxy')
|
||||
ssh_enable, ssh_user_name, ssh_user_password, ssh_key_name = funct.return_ssh_keys_path(serv)
|
||||
|
||||
if ssh_enable == 0:
|
||||
ssh_key_name = ''
|
||||
|
||||
os.system("cp scripts/%s ." % script)
|
||||
|
||||
if proxy is not None and proxy != '' and proxy != 'None':
|
||||
proxy_serv = proxy
|
||||
else:
|
||||
proxy_serv = ''
|
||||
|
||||
syn_flood_protect = '1' if form.getvalue('syn_flood') == "1" else ''
|
||||
|
||||
commands = [ "chmod +x "+script +" && ./"+script +" PROXY=" + proxy_serv+" STATS_USER="+stats_user+" STATS_PASS="+stats_password+
|
||||
" CONFIG_PATH="+config_path+" STAT_PORT="+stats_port+" STAT_PAGE="+stats_page+" SYN_FLOOD="+syn_flood_protect+" HOST="+serv+
|
||||
" USER="+ssh_user_name+" PASS="+ssh_user_password+" KEY="+ssh_key_name ]
|
||||
|
||||
output, error = funct.subprocess_execute(commands[0])
|
||||
|
||||
if error:
|
||||
funct.logging('localhost', error, haproxywi=1)
|
||||
print('error: '+error)
|
||||
else:
|
||||
for l in output:
|
||||
if "msg" in l or "FAILED" in l:
|
||||
try:
|
||||
l = l.split(':')[1]
|
||||
l = l.split('"')[1]
|
||||
print(l+"<br>")
|
||||
break
|
||||
except:
|
||||
print(output)
|
||||
break
|
||||
else:
|
||||
print('success: Nginx was installed<br>')
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
sql.update_nginx(serv)
|
||||
funct.install_nginx(form.getvalue('install_nginx'))
|
||||
|
||||
|
||||
if form.getvalue('haproxyaddserv'):
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
{% if MASTER == 'BACKUP' %}
|
||||
{% set ID = '101' %}
|
||||
{% else %}
|
||||
{% set ID = '100' %}
|
||||
{% endif %}
|
||||
|
||||
vrrp_instance VI_{{ID}} {
|
||||
vrrp_instance VI_{{IP}} {
|
||||
state {{MASTER}}
|
||||
interface {{ETH}}
|
||||
virtual_router_id 101
|
||||
|
|
|
@ -57,16 +57,14 @@
|
|||
<ul class="v_menu">
|
||||
<li><a href="/app/hapservers.py" title="Overview HAProxy servers" class="overview-link head-submenu">Overview</a> </li>
|
||||
<li><a href="/app/config.py" title="Working with HAProxy configs" class="edit head-submenu">Configs</a></li>
|
||||
<li><a href="/app/viewsttats.py" title="Show stats" class="stats head-submenu">Stats</a></li>
|
||||
<li><a href="/app/edit.py" title="Runtime API" class="runtime head-submenu">Runtime API</a></li>
|
||||
<li><a href="/app/metrics.py" title="Metrics" class="metrics head-submenu">Metrics</a></li>
|
||||
{% if role <= 2 %}
|
||||
<li><a href="/app/add.py#proxy" title="Add proxy" class="add head-submenu" id="add1">Add proxy</a></li>
|
||||
<li><a href="/app/versions.py" title="Actions with configs versions" class="version head-submenu">Versions</a></li>
|
||||
<li><a href="/app/add.py#ssl" title="Upload SSL cert" class="cert head-submenu" id="add4">SSL</a></li>
|
||||
<li><a href="/app/add.py#option" title="Save custom options" class="option head-submenu" id="add5">Options</a></li>
|
||||
<li><a href="/app/add.py#add-servers" title="Save servers" class="runtime head-submenu" id="add6">Servers</a></li>
|
||||
<li><a href="/app/add.py#userlist" title="Add userlist" class="add-userlist head-submenu" id="add7">User lists</a></li>
|
||||
<li><a href="/app/add.py#lists" title="Manage black and white lists" class="lists head-submenu" id="add8">Lists</a></li>
|
||||
<li><a href="/app/add.py#ssl" title="Upload SSL cert" class="cert head-submenu" id="add3">SSL</a></li>
|
||||
<li><a href="/app/add.py#lists" title="Manage black and white lists" class="lists head-submenu" id="add7">Lists</a></li>
|
||||
<li><a href="/app/waf.py" title="Web application firewall" class="waf head-submenu">WAF</a> </li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<td><span title="Interface for VRRP addreess">Interface(?)</span></td>
|
||||
<td>VRRP IP</td>
|
||||
<td><span title="HAProxy-WI will try install HAProxy">HAProxy(?)</span></td>
|
||||
<td><span title="HAProxy-WI will try install Nginx">Nginx(?)</span></td>
|
||||
<td>SYN flood protect</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
@ -33,6 +34,7 @@
|
|||
<td>{{ input('interface', size='7') }}</td>
|
||||
<td>{{ input('vrrp-ip', size='14') }}</td>
|
||||
<td>{{ checkbox('hap') }}</td>
|
||||
<td>{{ checkbox('nginx') }}</td>
|
||||
<td>{{ checkbox('syn_flood') }}</td>
|
||||
<td>
|
||||
<a class="ui-button ui-widget ui-corner-all" id="create" title="Create HA configuration">Create</a>
|
||||
|
@ -48,7 +50,8 @@
|
|||
<td><span title="Interface for VRRP addreess">Interface(?)</span></td>
|
||||
<td>VRRP IP</td>
|
||||
<td><span title="If checked HAProxy-WI will restart Keepalived">Restart(?)</span></td>
|
||||
<td style="width: 20%;"></td>
|
||||
<td style="width: 23%;"></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -72,6 +75,7 @@
|
|||
<td>{{ input('vrrp-ip-add', size='14') }}</td>
|
||||
<td>{{ checkbox('kp') }}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td>
|
||||
<a class="ui-button ui-widget ui-corner-all" id="add-vrrp" title="Add HA configuration">Add</a>
|
||||
</td>
|
||||
|
|
|
@ -50,6 +50,16 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="div-pannel">
|
||||
<div class="div-server">
|
||||
<div class="server-name">
|
||||
<span title="Create presaved options" class="span-link" id="add4">Create presaved options</span>
|
||||
</div>
|
||||
<div class="server-desc">
|
||||
Create, edit and delete options with given parameters. And after use them as autocomplete in the "Add" sections
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="middle-collumn">
|
||||
<div class="div-pannel">
|
||||
|
@ -92,6 +102,16 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="div-pannel">
|
||||
<div class="div-server">
|
||||
<div class="server-name">
|
||||
<span title="Create presaved servers" class="span-link" id="add5">Create presaved servers</span>
|
||||
</div>
|
||||
<div class="server-desc">
|
||||
Create, edit and delete servers. And after use them as autocomplete in the "Add" sections
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="right-collumn">
|
||||
<div class="div-pannel">
|
||||
|
@ -134,5 +154,15 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="div-pannel">
|
||||
<div class="div-server">
|
||||
<div class="server-name">
|
||||
<span title="Create userlists" class="span-link" id="add6">Create userlists</span>
|
||||
</div>
|
||||
<div class="server-desc">
|
||||
Create userlists. And use it in the "Add" sections
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
34
inc/add.js
34
inc/add.js
|
@ -680,33 +680,24 @@ $( function() {
|
|||
});
|
||||
$( "#tabs" ).tabs( "option", "active", 0 );
|
||||
} );
|
||||
$( "#add4" ).on( "click", function() {
|
||||
$( "#add3" ).on( "click", function() {
|
||||
$('.menu li ul li').each(function () {
|
||||
$(this).find('a').css('padding-left', '20px')
|
||||
$(this).find('a').css('border-left', '0px solid #5D9CEB');
|
||||
$(this).children("#add4").css('padding-left', '30px');;
|
||||
$(this).children("#add4").css('border-left', '4px solid #5D9CEB');
|
||||
$(this).children("#add3").css('padding-left', '30px');
|
||||
$(this).children("#add3").css('border-left', '4px solid #5D9CEB');
|
||||
});
|
||||
$( "#tabs" ).tabs( "option", "active", 4 );
|
||||
} );
|
||||
$( "#add5" ).on( "click", function() {
|
||||
$('.menu li ul li').each(function () {
|
||||
$(this).find('a').css('padding-left', '20px')
|
||||
$(this).find('a').css('border-left', '0px solid #5D9CEB');
|
||||
$(this).children("#add5").css('padding-left', '30px');;
|
||||
$(this).children("#add5").css('border-left', '4px solid #5D9CEB');
|
||||
});
|
||||
$( "#add4" ).on( "click", function() {
|
||||
$( "#tabs" ).tabs( "option", "active", 5 );
|
||||
} );
|
||||
$( "#add6" ).on( "click", function() {
|
||||
$('.menu li ul li').each(function () {
|
||||
$(this).find('a').css('padding-left', '20px')
|
||||
$(this).find('a').css('border-left', '0px solid #5D9CEB');
|
||||
$(this).children("#add6").css('padding-left', '30px');
|
||||
$(this).children("#add6").css('border-left', '4px solid #5D9CEB');
|
||||
});
|
||||
$( "#add5" ).on( "click", function() {
|
||||
$( "#tabs" ).tabs( "option", "active", 6 );
|
||||
} );
|
||||
$( "#add6" ).on( "click", function() {
|
||||
$( "#tabs" ).tabs( "option", "active", 7 );
|
||||
} );
|
||||
$( "#add7" ).on( "click", function() {
|
||||
$('.menu li ul li').each(function () {
|
||||
$(this).find('a').css('padding-left', '20px')
|
||||
|
@ -714,15 +705,6 @@ $( function() {
|
|||
$(this).children("#add7").css('padding-left', '30px');
|
||||
$(this).children("#add7").css('border-left', '4px solid #5D9CEB');
|
||||
});
|
||||
$( "#tabs" ).tabs( "option", "active", 7 );
|
||||
} );
|
||||
$( "#add8" ).on( "click", function() {
|
||||
$('.menu li ul li').each(function () {
|
||||
$(this).find('a').css('padding-left', '20px')
|
||||
$(this).find('a').css('border-left', '0px solid #5D9CEB');
|
||||
$(this).children("#add8").css('padding-left', '30px');
|
||||
$(this).children("#add8").css('border-left', '4px solid #5D9CEB');
|
||||
});
|
||||
$( "#tabs" ).tabs( "option", "active", 8 );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -53,9 +53,13 @@ $( function() {
|
|||
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;
|
||||
var nginx = 0;
|
||||
var syn_flood = 0;
|
||||
if ($('#hap').is(':checked')) {
|
||||
hap = '1';
|
||||
}
|
||||
if ($('#nginx').is(':checked')) {
|
||||
nginx = '1';
|
||||
}
|
||||
if ($('#syn_flood').is(':checked')) {
|
||||
syn_flood = '1';
|
||||
|
@ -78,6 +82,7 @@ $( function() {
|
|||
interface: $("#interface").val(),
|
||||
vrrpip: $('#vrrp-ip').val(),
|
||||
hap: hap,
|
||||
nginx: nginx,
|
||||
syn_flood: syn_flood,
|
||||
token: $('#token').val()
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue