From 548d61db59cb50aff3ef190707bd0981ce1fc274 Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Thu, 6 Feb 2020 22:06:12 +0300 Subject: [PATCH] v4.0.0.0 Changelog: https://haproxy-wi.org/changelog.py#4 --- app/funct.py | 49 +++++++++++ app/options.py | 87 ++++++++----------- .../keepalived/templates/add_vrrp.conf.j2 | 8 +- app/templates/base.html | 8 +- app/templates/ha.html | 6 +- app/templates/include/add_proxy.html | 30 +++++++ inc/add.js | 34 ++------ inc/users.js | 5 ++ 8 files changed, 135 insertions(+), 92 deletions(-) diff --git a/app/funct.py b/app/funct.py index d5120c08..d9d22f59 100644 --- a/app/funct.py +++ b/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+"
") + break + except: + print(output) + break + else: + print('success: Nginx was installed
') + + os.system("rm -f %s" % script) + sql.update_nginx(serv) + def update_haproxy_wi(): cmd = 'sudo -S yum -y update haproxy-wi' diff --git a/app/options.py b/app/options.py index 6220379c..40d16ee1 100644 --- a/app/options.py +++ b/app/options.py @@ -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+"
") - break - except: - print(output) - break - else: - print('success: Nginx was installed
') - - os.system("rm -f %s" % script) - sql.update_nginx(serv) + funct.install_nginx(form.getvalue('install_nginx')) if form.getvalue('haproxyaddserv'): diff --git a/app/scripts/ansible/roles/keepalived/templates/add_vrrp.conf.j2 b/app/scripts/ansible/roles/keepalived/templates/add_vrrp.conf.j2 index 0b1f68e8..aad660ca 100644 --- a/app/scripts/ansible/roles/keepalived/templates/add_vrrp.conf.j2 +++ b/app/scripts/ansible/roles/keepalived/templates/add_vrrp.conf.j2 @@ -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 diff --git a/app/templates/base.html b/app/templates/base.html index ad6acb27..c27af555 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -57,16 +57,14 @@ diff --git a/app/templates/ha.html b/app/templates/ha.html index 0cfc3604..6de15a36 100644 --- a/app/templates/ha.html +++ b/app/templates/ha.html @@ -10,6 +10,7 @@ Interface(?) VRRP IP HAProxy(?) + Nginx(?) SYN flood protect @@ -33,6 +34,7 @@ {{ input('interface', size='7') }} {{ input('vrrp-ip', size='14') }} {{ checkbox('hap') }} + {{ checkbox('nginx') }} {{ checkbox('syn_flood') }} Create @@ -48,7 +50,8 @@ Interface(?) VRRP IP Restart(?) - + + @@ -72,6 +75,7 @@ {{ input('vrrp-ip-add', size='14') }} {{ checkbox('kp') }} + Add diff --git a/app/templates/include/add_proxy.html b/app/templates/include/add_proxy.html index a1f23e86..fa149f3f 100644 --- a/app/templates/include/add_proxy.html +++ b/app/templates/include/add_proxy.html @@ -50,6 +50,16 @@ +
+
+
+ Create presaved options +
+
+ Create, edit and delete options with given parameters. And after use them as autocomplete in the "Add" sections +
+
+
@@ -92,6 +102,16 @@
+
+
+
+ Create presaved servers +
+
+ Create, edit and delete servers. And after use them as autocomplete in the "Add" sections +
+
+
@@ -134,5 +154,15 @@
+
+
+
+ Create userlists +
+
+ Create userlists. And use it in the "Add" sections +
+
+
\ No newline at end of file diff --git a/inc/add.js b/inc/add.js index 736c8d60..a73b01e5 100644 --- a/inc/add.js +++ b/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 ); } ); } diff --git a/inc/users.js b/inc/users.js index 6464d515..f6cd8d2c 100644 --- a/inc/users.js +++ b/inc/users.js @@ -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() },