mirror of https://github.com/Aidaho12/haproxy-wi
parent
fc2b657c2e
commit
af62ff0fc2
84
app/funct.py
84
app/funct.py
|
@ -231,53 +231,6 @@ def get_config(serv, cfg, **kwargs):
|
||||||
ssh += str(e)
|
ssh += str(e)
|
||||||
return ssh
|
return ssh
|
||||||
|
|
||||||
def show_config(cfg):
|
|
||||||
print('<div style="margin-left: 16%" class="configShow">')
|
|
||||||
try:
|
|
||||||
conf = open(cfg, "r")
|
|
||||||
except IOError:
|
|
||||||
print('<div class="alert alert-danger">Can\'t read import config file</div>')
|
|
||||||
i = 0
|
|
||||||
for line in conf:
|
|
||||||
i = i + 1
|
|
||||||
if not line.find("global"):
|
|
||||||
print('<span class="param">' + line + '</span><div>')
|
|
||||||
continue
|
|
||||||
if not line.find("defaults"):
|
|
||||||
print('</div><span class="param">' + line + '</span><div>')
|
|
||||||
continue
|
|
||||||
if not line.find("listen"):
|
|
||||||
print('</div><span class="param">' + line + '</span><div>')
|
|
||||||
continue
|
|
||||||
if not line.find("frontend"):
|
|
||||||
print('</div><span class="param">' + line + '</span><div>')
|
|
||||||
continue
|
|
||||||
if not line.find("backend"):
|
|
||||||
print('</div><span class="param">' + line + '</span><div>')
|
|
||||||
continue
|
|
||||||
if not line.find("cache"):
|
|
||||||
print('</div><span class="param">' + line + '</span><div>')
|
|
||||||
continue
|
|
||||||
if "acl" in line or "option" in line or "server" in line:
|
|
||||||
if "timeout" not in line and "default-server" not in line and "#use_backend" not in line:
|
|
||||||
print('<span class="paramInSec"><span class="numRow">')
|
|
||||||
print(i)
|
|
||||||
print('</span>' + line + '</span><br />')
|
|
||||||
continue
|
|
||||||
if "#" in line:
|
|
||||||
print('<span class="comment"><span class="numRow">')
|
|
||||||
print(i)
|
|
||||||
print(line + '</span></span><br />')
|
|
||||||
continue
|
|
||||||
if line.__len__() < 1:
|
|
||||||
print('</div>')
|
|
||||||
if line.__len__() > 1:
|
|
||||||
print('<span class="configLine"><span class="numRow">')
|
|
||||||
print(i)
|
|
||||||
print('</span>' + line + '</span><br />')
|
|
||||||
print('</div></div>')
|
|
||||||
conf.close
|
|
||||||
|
|
||||||
def diff_config(oldcfg, cfg):
|
def diff_config(oldcfg, cfg):
|
||||||
import subprocess
|
import subprocess
|
||||||
log_path = get_config_var('main', 'log_path')
|
log_path = get_config_var('main', 'log_path')
|
||||||
|
@ -317,7 +270,7 @@ def install_haproxy(serv, **kwargs):
|
||||||
" STATS_USER="+stats_user+" STATS_PASS="+stats_password ]
|
" STATS_USER="+stats_user+" STATS_PASS="+stats_password ]
|
||||||
|
|
||||||
upload(serv, tmp_config_path, script)
|
upload(serv, tmp_config_path, script)
|
||||||
ssh_command(serv, commands)
|
ssh_command(serv, commands, print_out="1")
|
||||||
|
|
||||||
if kwargs.get('syn_flood') == "1":
|
if kwargs.get('syn_flood') == "1":
|
||||||
syn_flood_protect(serv)
|
syn_flood_protect(serv)
|
||||||
|
@ -339,7 +292,7 @@ def syn_flood_protect(serv, **kwargs):
|
||||||
commands = [ "chmod +x "+tmp_config_path+script, tmp_config_path+script+ " "+enable ]
|
commands = [ "chmod +x "+tmp_config_path+script, tmp_config_path+script+ " "+enable ]
|
||||||
|
|
||||||
upload(serv, tmp_config_path, script)
|
upload(serv, tmp_config_path, script)
|
||||||
ssh_command(serv, commands)
|
ssh_command(serv, commands, print_out="1")
|
||||||
|
|
||||||
os.system("rm -f %s" % script)
|
os.system("rm -f %s" % script)
|
||||||
|
|
||||||
|
@ -428,37 +381,6 @@ def check_haproxy_config(serv):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
|
||||||
def compare(stdout):
|
|
||||||
i = 0
|
|
||||||
minus = 0
|
|
||||||
plus = 0
|
|
||||||
total_change = 0
|
|
||||||
|
|
||||||
print('</center><div class="out">')
|
|
||||||
print('<div class="diff">')
|
|
||||||
|
|
||||||
for line in stdout:
|
|
||||||
i = i + 1
|
|
||||||
|
|
||||||
if i is 1:
|
|
||||||
print('<div class="diffHead">' + line + '<br />')
|
|
||||||
elif i is 2:
|
|
||||||
print(line + '</div>')
|
|
||||||
elif line.find("-") == 0 and i is not 1:
|
|
||||||
print('<div class="lineDiffMinus">' + line + '</div>')
|
|
||||||
minus = minus + 1
|
|
||||||
elif line.find("+") == 0 and i is not 2:
|
|
||||||
print('<div class="lineDiffPlus">' + line + '</div>')
|
|
||||||
plus = plus + 1
|
|
||||||
elif line.find("@") == 0:
|
|
||||||
print('<div class="lineDog">' + line + '</div>')
|
|
||||||
else:
|
|
||||||
print('<div class="lineDiff">' + line + '</div>')
|
|
||||||
|
|
||||||
total_change = minus + plus
|
|
||||||
print('<div class="diffHead">Total change: %s, additions: %s & deletions: %s </div>' % (total_change, minus, plus))
|
|
||||||
print('</div></div>')
|
|
||||||
|
|
||||||
def show_log(stdout):
|
def show_log(stdout):
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -501,6 +423,8 @@ def ssh_command(serv, commands, **kwargs):
|
||||||
show_log(stdout)
|
show_log(stdout)
|
||||||
elif kwargs.get("server_status") == "1":
|
elif kwargs.get("server_status") == "1":
|
||||||
server_status(stdout)
|
server_status(stdout)
|
||||||
|
elif kwargs.get('print_out'):
|
||||||
|
print(stdout.read().decode(encoding='UTF-8'))
|
||||||
else:
|
else:
|
||||||
return stdout.read().decode(encoding='UTF-8')
|
return stdout.read().decode(encoding='UTF-8')
|
||||||
|
|
||||||
|
|
|
@ -261,10 +261,35 @@ if form.getvalue('servaction') is not None:
|
||||||
funct.logging(serv, action)
|
funct.logging(serv, action)
|
||||||
|
|
||||||
if act == "showCompareConfigs":
|
if act == "showCompareConfigs":
|
||||||
ovw.show_compare_configs(serv)
|
import glob
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
env = Environment(loader=FileSystemLoader('templates/ajax'))
|
||||||
|
template = env.get_template('/show_compare_configs.html')
|
||||||
|
left = form.getvalue('left')
|
||||||
|
right = form.getvalue('right')
|
||||||
|
|
||||||
|
output_from_parsed_template = template.render(serv = serv,
|
||||||
|
right = right,
|
||||||
|
left = left,
|
||||||
|
return_files = funct.get_files())
|
||||||
|
|
||||||
|
print(output_from_parsed_template)
|
||||||
|
|
||||||
if serv is not None and form.getvalue('right') is not None:
|
if serv is not None and form.getvalue('right') is not None:
|
||||||
ovw.comapre_show()
|
import subprocess
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
left = form.getvalue('left')
|
||||||
|
right = form.getvalue('right')
|
||||||
|
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
||||||
|
cmd='diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right)
|
||||||
|
env = Environment(loader=FileSystemLoader('templates/ajax'),extensions=['jinja2.ext.loopcontrols'])
|
||||||
|
template = env.get_template('compare.html')
|
||||||
|
|
||||||
|
output, stderr = funct.subprocess_execute(cmd)
|
||||||
|
template = template.render(stdout=output)
|
||||||
|
|
||||||
|
print(template)
|
||||||
|
print(stderr)
|
||||||
|
|
||||||
if serv is not None and act == "configShow":
|
if serv is not None and act == "configShow":
|
||||||
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
||||||
|
@ -275,27 +300,24 @@ if serv is not None and act == "configShow":
|
||||||
else:
|
else:
|
||||||
cfg = hap_configs_dir + form.getvalue('configver')
|
cfg = hap_configs_dir + form.getvalue('configver')
|
||||||
|
|
||||||
print("<center><h3>Config from %s</h3>" % serv)
|
|
||||||
print('<p class="accordion-expand-holder">'
|
|
||||||
'<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>'
|
|
||||||
'<a class="ui-button ui-widget ui-corner-all" title="Edit this run config" target="_blank" href="config.py?serv='+serv+'&open=open">Edit</a>'
|
|
||||||
'</p>')
|
|
||||||
print('</center>')
|
|
||||||
|
|
||||||
funct.show_config(cfg)
|
try:
|
||||||
|
conf = open(cfg, "r")
|
||||||
|
except IOError:
|
||||||
|
print('<div class="alert alert-danger">Can\'t read import config file</div>')
|
||||||
|
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
env = Environment(loader=FileSystemLoader('templates/ajax'),extensions=['jinja2.ext.loopcontrols'])
|
||||||
|
template = env.get_template('config_show.html')
|
||||||
|
|
||||||
|
template = template.render(conf=conf,
|
||||||
|
view=form.getvalue('view'),
|
||||||
|
serv=serv,
|
||||||
|
configver=form.getvalue('configver'))
|
||||||
|
print(template)
|
||||||
|
|
||||||
if form.getvalue('configver') is None:
|
if form.getvalue('configver') is None:
|
||||||
os.system("/bin/rm -f " + cfg)
|
os.system("/bin/rm -f " + cfg)
|
||||||
else:
|
|
||||||
print('<br><center>')
|
|
||||||
print('<form action="configver.py#conf" method="get">')
|
|
||||||
print('<input type="hidden" value="%s" name="serv">' % serv)
|
|
||||||
print('<input type="hidden" value="%s" name="configver">' % form.getvalue('configver'))
|
|
||||||
print('<input type="hidden" value="1" name="config">')
|
|
||||||
if form.getvalue('view') is None:
|
|
||||||
print("<button type='submit' value='save' name='save' class='btn btn-default'>Just save</button>")
|
|
||||||
print("<button type='submit' value='' name='' class='btn btn-default'>Upload and restart</button>")
|
|
||||||
print('</form></center>')
|
|
||||||
|
|
||||||
if form.getvalue('master'):
|
if form.getvalue('master'):
|
||||||
master = form.getvalue('master')
|
master = form.getvalue('master')
|
||||||
|
|
29
app/ovw.py
29
app/ovw.py
|
@ -163,31 +163,4 @@ def get_map(serv):
|
||||||
output, stderr = funct.subprocess_execute(cmd)
|
output, stderr = funct.subprocess_execute(cmd)
|
||||||
print(stderr)
|
print(stderr)
|
||||||
|
|
||||||
print('<img src="/map%s.png" alt="map">' % date)
|
print('<img src="/map%s.png" alt="map">' % date)
|
||||||
|
|
||||||
def show_compare_configs(serv):
|
|
||||||
import glob
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
|
||||||
env = Environment(loader=FileSystemLoader('templates/ajax'))
|
|
||||||
template = env.get_template('/show_compare_configs.html')
|
|
||||||
left = form.getvalue('left')
|
|
||||||
right = form.getvalue('right')
|
|
||||||
|
|
||||||
output_from_parsed_template = template.render(serv = serv,
|
|
||||||
right = right,
|
|
||||||
left = left,
|
|
||||||
return_files = funct.get_files())
|
|
||||||
|
|
||||||
print(output_from_parsed_template)
|
|
||||||
|
|
||||||
def comapre_show():
|
|
||||||
import subprocess
|
|
||||||
left = form.getvalue('left')
|
|
||||||
right = form.getvalue('right')
|
|
||||||
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
|
||||||
cmd='diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right)
|
|
||||||
|
|
||||||
output, stderr = funct.subprocess_execute(cmd)
|
|
||||||
|
|
||||||
funct.compare(output)
|
|
||||||
print(stderr)
|
|
|
@ -1,17 +1,21 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [[ $1 == "enable" ]]; then
|
if [[ $1 == "enable" ]]; then
|
||||||
sudo bash -c cat <<EOF >> /etc/sysctl.conf
|
if grep -q "net.ipv4.tcp_syncookie = 1" /etc/sysctl.conf; then
|
||||||
|
echo "SYN flood protectd allready enabled"
|
||||||
|
else
|
||||||
|
sudo bash -c cat <<EOF >> /etc/sysctl.conf
|
||||||
# Protection SYN flood
|
# Protection SYN flood
|
||||||
net.ipv4.tcp_syncookies = 1
|
net.ipv4.tcp_syncookies = 1
|
||||||
net.ipv4.conf.all.rp_filter = 1
|
net.ipv4.conf.all.rp_filter = 1
|
||||||
net.ipv4.tcp_max_syn_backlog = 1024
|
net.ipv4.tcp_max_syn_backlog = 1024
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
sudo sysctl -w net.ipv4.tcp_syncookies=1
|
sudo sysctl -w net.ipv4.tcp_syncookies=1
|
||||||
sudo sysctl -w net.ipv4.conf.all.rp_filter=1
|
sudo sysctl -w net.ipv4.conf.all.rp_filter=1
|
||||||
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=1024
|
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=1024
|
||||||
sudo sysctl -w net.ipv4.tcp_synack_retries=3
|
sudo sysctl -w net.ipv4.tcp_synack_retries=3
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 == "disable" ]]; then
|
if [[ $1 == "disable" ]]; then
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
</center>
|
||||||
|
<div class="out">
|
||||||
|
<div class="diff">
|
||||||
|
{% set plus = 0 %}
|
||||||
|
{% set minus = 0 %}
|
||||||
|
{% set total_change = 0 %}
|
||||||
|
{% for line in stdout %}
|
||||||
|
|
||||||
|
{% if loop.index0 == 0 %}
|
||||||
|
<div class="diffHead">{{ line }}<br />
|
||||||
|
{% elif loop.index0 == 1 %}
|
||||||
|
{{ line }}</div>
|
||||||
|
{% elif line.startswith('-') and loop.index0 > 1 %}
|
||||||
|
<div class="lineDiffMinus">{{ line }}</div>
|
||||||
|
{% set minus = minus + 1 %}
|
||||||
|
{% elif line.startswith('+') and loop.index0 > 2 %}
|
||||||
|
<div class="lineDiffPlus">{{ line }}</div>
|
||||||
|
{% set plus = plus + 1 %}
|
||||||
|
{% elif line.startswith('@') %}
|
||||||
|
<div class="lineDog">{{ line }}</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="lineDiff">{{ line }}</div>
|
||||||
|
{% endif %}
|
||||||
|
{% set total_change = minus + plus %}
|
||||||
|
{% if loop.last %}
|
||||||
|
<div class="diffHead">Total change: {{ total_change }}, additions: {{ plus }} & deletions: {{ minus }} </div>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,77 @@
|
||||||
|
<center>
|
||||||
|
<h3>Config from {{serv}}</h3>
|
||||||
|
<p class="accordion-expand-holder">
|
||||||
|
<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>
|
||||||
|
{% if not view %}
|
||||||
|
<a class="ui-button ui-widget ui-corner-all" title="Edit this run config" target="_blank" href="config.py?serv={{serv}}&open=open">Edit</a>
|
||||||
|
{% endif %}
|
||||||
|
</p>
|
||||||
|
</center>
|
||||||
|
<div style="margin-left: 16%" class="configShow">
|
||||||
|
{% set i = 0 -%}
|
||||||
|
{% for line in conf %}
|
||||||
|
{% set i = i + loop.index0 %}
|
||||||
|
{% if line.startswith('global') %}
|
||||||
|
<span class="param"> {{ line }} </span><div>
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% if line.startswith('defaults') %}
|
||||||
|
<span class="param"> {{ line }} </span><div>
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% if line.startswith('listen') %}
|
||||||
|
<span class="param"> {{ line }} </span><div>
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% if line.startswith('frontend') %}
|
||||||
|
<span class="param"> {{ line }} </span><div>
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% if line.startswith('backend') %}
|
||||||
|
<span class="param"> {{ line }} </span><div>
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% if line.startswith('cache') %}
|
||||||
|
<span class="param"> {{ line }} </span><div>
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% if "acl" in line or "option" in line or "server" in line %}
|
||||||
|
{% if "timeout" not in line and "default-server" not in line and "#use_backend" not in line and "#" not in line%}
|
||||||
|
<span class="paramInSec">
|
||||||
|
<span class="numRow">
|
||||||
|
{{ i }}
|
||||||
|
</span>
|
||||||
|
{{ line }}
|
||||||
|
</span><br />
|
||||||
|
{% continue %}
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if line|length == 1 %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if line|length > 1 %}
|
||||||
|
<span class="configLine">
|
||||||
|
<span class="numRow">{{ i }}</span>
|
||||||
|
{{ line }}
|
||||||
|
</span><br />
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% if configver %}
|
||||||
|
<br>
|
||||||
|
<center>
|
||||||
|
<form action="configver.py#conf" method="get">
|
||||||
|
<input type="hidden" value="{{serv}}" name="serv">
|
||||||
|
<input type="hidden" value="{{configver}}" name="configver">
|
||||||
|
<input type="hidden" value="1" name="config">
|
||||||
|
{% if not view %}
|
||||||
|
<button type='submit' value='save' name='save' class='btn btn-default'>Just save</button>
|
||||||
|
<button type='submit' value='' name='' class='btn btn-default'>Upload and restart</button>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
</center>
|
||||||
|
{% endif %}
|
|
@ -40,7 +40,7 @@ echo ""
|
||||||
echo "################################"
|
echo "################################"
|
||||||
|
|
||||||
if hash apt-get 2>/dev/null; then
|
if hash apt-get 2>/dev/null; then
|
||||||
apt-get install git net-tools lshw dos2unix apache2 gcc netcat python3-pip gcc-c++ -y
|
apt-get install git net-tools lshw dos2unix apache2 gcc netcat python3-pip g++ -y
|
||||||
HTTPD_CONFIG="/etc/apache2/apache2.conf"
|
HTTPD_CONFIG="/etc/apache2/apache2.conf"
|
||||||
HAPROXY_WI_VHOST_CONF="/etc/apache2/sites-enabled/haproxy-wi.conf"
|
HAPROXY_WI_VHOST_CONF="/etc/apache2/sites-enabled/haproxy-wi.conf"
|
||||||
HTTPD_NAME="apache2"
|
HTTPD_NAME="apache2"
|
||||||
|
|
Loading…
Reference in New Issue