mirror of https://github.com/Aidaho12/haproxy-wi
parent
cc52ec7779
commit
6a4c597ab8
23
app/add.py
23
app/add.py
|
@ -4,7 +4,7 @@ import cgi
|
|||
import os
|
||||
import funct
|
||||
import sql
|
||||
import http
|
||||
import http.cookies
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
env = Environment(loader=FileSystemLoader('templates/'))
|
||||
template = env.get_template('add.html')
|
||||
|
@ -45,19 +45,21 @@ if form.getvalue('mode') is not None:
|
|||
haproxy_dir = sql.get_setting('haproxy_dir')
|
||||
serv = form.getvalue('serv')
|
||||
port = form.getvalue('port')
|
||||
bind = ""
|
||||
ip = ""
|
||||
force_close = form.getvalue('force_close')
|
||||
mode = " mode " + form.getvalue('mode')
|
||||
balance = ""
|
||||
mode = " mode " + form.getvalue('mode') + "\n"
|
||||
maxconn = " maxconn " + form.getvalue('maxconn') + "\n"
|
||||
options_split = ""
|
||||
ssl = ""
|
||||
ssl_check = ""
|
||||
|
||||
if form.getvalue('balance') is not None:
|
||||
balance = " balance " + form.getvalue('balance') + "\n"
|
||||
else:
|
||||
balance = ""
|
||||
|
||||
if form.getvalue('ip') is not None:
|
||||
ip = form.getvalue('ip')
|
||||
else:
|
||||
ip = ""
|
||||
|
||||
if form.getvalue('listner') is not None:
|
||||
name = "\nlisten " + form.getvalue('listner')
|
||||
|
@ -78,15 +80,11 @@ if form.getvalue('mode') is not None:
|
|||
ssl_check = " ssl verify none"
|
||||
else:
|
||||
ssl_check = " ssl verify"
|
||||
else:
|
||||
ssl_check = ""
|
||||
|
||||
if not ip and port is not None:
|
||||
bind = " bind *:"+ port + " " + ssl + "\n"
|
||||
elif port is not None:
|
||||
bind = " bind " + ip + ":" + port + " " + ssl + "\n"
|
||||
else:
|
||||
bind = ""
|
||||
|
||||
if form.getvalue('default-check') == "1":
|
||||
if form.getvalue('check-servers') == "1":
|
||||
|
@ -102,11 +100,8 @@ if form.getvalue('mode') is not None:
|
|||
if form.getvalue('option') is not None:
|
||||
options = form.getvalue('option')
|
||||
i = options.split("\n")
|
||||
options_split = ""
|
||||
for j in i:
|
||||
options_split += " " + j + "\n"
|
||||
else:
|
||||
options_split = ""
|
||||
|
||||
if force_close == "1":
|
||||
options_split += " option http-server-close\n"
|
||||
|
@ -175,7 +170,7 @@ if form.getvalue('mode') is not None:
|
|||
waf = " filter spoe engine modsecurity config "+haproxy_dir+"/waf.conf\n"
|
||||
waf += " http-request deny if { var(txn.modsec.code) -m int gt 0 }\n"
|
||||
|
||||
config_add = name + "\n" + bind + mode + "\n" + balance + options_split + filter + compression_s + cache_s + waf + backend + servers_split + "\n" + cache_set
|
||||
config_add = name + "\n" + bind + mode + maxconn + balance + options_split + filter + compression_s + cache_s + waf + backend + servers_split + "\n" + cache_set
|
||||
cfg = hap_configs_dir + serv + "-" + funct.get_data('config') + ".cfg"
|
||||
|
||||
funct.get_config(serv, cfg)
|
||||
|
|
70
app/funct.py
70
app/funct.py
|
@ -1,7 +1,6 @@
|
|||
# -*- coding: utf-8 -*-"
|
||||
import cgi
|
||||
import os, sys
|
||||
import http.cookies
|
||||
|
||||
form = cgi.FieldStorage()
|
||||
serv = form.getvalue('serv')
|
||||
|
@ -42,6 +41,7 @@ def get_data(type):
|
|||
|
||||
def logging(serv, action, **kwargs):
|
||||
import sql
|
||||
import http.cookies
|
||||
log_path = get_config_var('main', 'log_path')
|
||||
|
||||
if not os.path.exists(log_path):
|
||||
|
@ -64,12 +64,11 @@ def logging(serv, action, **kwargs):
|
|||
else:
|
||||
mess = get_data('date_in_log') + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n"
|
||||
log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a")
|
||||
|
||||
try:
|
||||
try:
|
||||
log.write(mess)
|
||||
log.close
|
||||
except IOError:
|
||||
print('<center><div class="alert alert-danger">Can\'t read write log. Please chech log_path in config</div></center>')
|
||||
except IOError as e:
|
||||
print('<center><div class="alert alert-danger">Can\'t write log. Please check log_path in config %e</div></center>' % e)
|
||||
pass
|
||||
|
||||
def telegram_send_mess(mess, **kwargs):
|
||||
|
@ -95,6 +94,7 @@ def telegram_send_mess(mess, **kwargs):
|
|||
|
||||
def check_login(**kwargs):
|
||||
import sql
|
||||
import http.cookies
|
||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||
user_uuid = cookie.get('uuid')
|
||||
ref = os.environ.get("SCRIPT_NAME")
|
||||
|
@ -110,6 +110,7 @@ def check_login(**kwargs):
|
|||
|
||||
def is_admin(**kwargs):
|
||||
import sql
|
||||
import http.cookies
|
||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||
user_id = cookie.get('uuid')
|
||||
try:
|
||||
|
@ -134,7 +135,7 @@ def page_for_admin(**kwargs):
|
|||
|
||||
if not is_admin(level = give_level):
|
||||
print('<center><h3 style="color: red">How did you get here?! O_o You do not have need permissions</h>')
|
||||
print('<meta http-equiv="refresh" content="10; url=/">')
|
||||
print('<meta http-equiv="refresh" content="5; url=/">')
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
|
@ -233,7 +234,10 @@ def install_haproxy(serv, **kwargs):
|
|||
" SOCK_PORT="+haproxy_sock_port+" STAT_PORT="+stats_port+" STAT_FILE="+server_state_file+
|
||||
" STATS_USER="+stats_user+" STATS_PASS="+stats_password ]
|
||||
|
||||
upload(serv, tmp_config_path, script)
|
||||
error = str(upload(serv, tmp_config_path, script))
|
||||
if error:
|
||||
print('error: '+error)
|
||||
|
||||
os.system("rm -f %s" % script)
|
||||
ssh_command(serv, commands, print_out="1")
|
||||
|
||||
|
@ -251,7 +255,9 @@ def syn_flood_protect(serv, **kwargs):
|
|||
|
||||
commands = [ "sudo chmod +x "+tmp_config_path+script, tmp_config_path+script+ " "+enable ]
|
||||
|
||||
upload(serv, tmp_config_path, script)
|
||||
error = str(upload(serv, tmp_config_path, script))
|
||||
if error:
|
||||
print('error: '+error)
|
||||
os.system("rm -f %s" % script)
|
||||
ssh_command(serv, commands, print_out="1")
|
||||
|
||||
|
@ -268,7 +274,9 @@ def waf_install(serv, **kwargs):
|
|||
commands = [ "sudo chmod +x "+tmp_config_path+script+" && " +tmp_config_path+script +" PROXY=" + proxy+
|
||||
" HAPROXY_PATH="+haproxy_dir +" VERSION="+ver ]
|
||||
|
||||
upload(serv, tmp_config_path, script)
|
||||
error = str(upload(serv, tmp_config_path, script))
|
||||
if error:
|
||||
print('error: '+error)
|
||||
os.system("rm -f %s" % script)
|
||||
|
||||
stderr = ssh_command(serv, commands, print_out="1")
|
||||
|
@ -286,19 +294,27 @@ def check_haproxy_version(serv):
|
|||
return ver
|
||||
|
||||
def upload(serv, path, file, **kwargs):
|
||||
error = ""
|
||||
full_path = path + file
|
||||
|
||||
if kwargs.get('dir') == "fullpath":
|
||||
full_path = path
|
||||
|
||||
try:
|
||||
ssh = ssh_connect(serv)
|
||||
except Exception as e:
|
||||
print('<div class="alert alert-danger">Connect fail: %s</div>' % e)
|
||||
error = e
|
||||
pass
|
||||
try:
|
||||
sftp = ssh.open_sftp()
|
||||
file = sftp.put(file, full_path)
|
||||
sftp.close()
|
||||
ssh.close()
|
||||
except Exception as e:
|
||||
print('<div class="alert alert-danger">Upload fail: %s</div>' % e)
|
||||
error = e
|
||||
pass
|
||||
|
||||
return error
|
||||
|
||||
def upload_and_restart(serv, cfg, **kwargs):
|
||||
import sql
|
||||
|
@ -310,14 +326,7 @@ def upload_and_restart(serv, cfg, **kwargs):
|
|||
except OSError:
|
||||
return 'Please install dos2unix'
|
||||
pass
|
||||
|
||||
try:
|
||||
ssh = ssh_connect(serv)
|
||||
except:
|
||||
return 'Connect fail'
|
||||
sftp = ssh.open_sftp()
|
||||
sftp.put(cfg, tmp_file)
|
||||
sftp.close()
|
||||
|
||||
if kwargs.get("keepalived") == 1:
|
||||
if kwargs.get("just_save") == "save":
|
||||
commands = [ "sudo mv -f " + tmp_file + " /etc/keepalived/keepalived.conf" ]
|
||||
|
@ -332,13 +341,16 @@ def upload_and_restart(serv, cfg, **kwargs):
|
|||
if sql.get_setting('firewall_enable') == "1":
|
||||
commands.extend(open_port_firewalld(cfg))
|
||||
except:
|
||||
return 'Please check the config for the presence of the parameter - "firewall_enable". Mast be: "0" or "1". Firewalld configure not working now'
|
||||
|
||||
for command in commands:
|
||||
stdin, stdout, stderr = ssh.exec_command(command)
|
||||
error = 'Please check the config for the presence of the parameter - "firewall_enable". Mast be: "0" or "1". Firewalld configure not working now'
|
||||
|
||||
error += str(upload(serv, tmp_file, cfg, dir='fullpath'))
|
||||
|
||||
return stderr.read()
|
||||
ssh.close()
|
||||
try:
|
||||
error += ssh_command(serv, commands, retunr_err=1)
|
||||
except Exception as e:
|
||||
error += e
|
||||
if error:
|
||||
return error
|
||||
|
||||
def open_port_firewalld(cfg):
|
||||
try:
|
||||
|
@ -373,7 +385,6 @@ def check_haproxy_config(serv):
|
|||
|
||||
def show_log(stdout):
|
||||
i = 0
|
||||
|
||||
for line in stdout:
|
||||
i = i + 1
|
||||
line_class = "line3" if i % 2 == 0 else "line"
|
||||
|
@ -412,6 +423,8 @@ def ssh_command(serv, commands, **kwargs):
|
|||
elif kwargs.get('print_out'):
|
||||
print(stdout.read().decode(encoding='UTF-8'))
|
||||
return stdout.read().decode(encoding='UTF-8')
|
||||
elif kwargs.get('retunr_err'):
|
||||
return stderr.read().decode(encoding='UTF-8')
|
||||
else:
|
||||
return stdout.read().decode(encoding='UTF-8')
|
||||
|
||||
|
@ -421,8 +434,7 @@ def ssh_command(serv, commands, **kwargs):
|
|||
try:
|
||||
ssh.close()
|
||||
except:
|
||||
ssh = str(ssh)
|
||||
print("<div class='alert alert-danger' style='margin: 0;'>"+ssh+"</div>")
|
||||
print("<div class='alert alert-danger' style='margin: 0;'>"+str(ssh)+"</div>")
|
||||
pass
|
||||
|
||||
def escape_html(text):
|
||||
|
@ -452,7 +464,7 @@ def show_backends(serv, **kwargs):
|
|||
ret += back[1]
|
||||
ret += "<br />"
|
||||
else:
|
||||
print(back[1]+"<br>")
|
||||
print(back[1], end="<br>")
|
||||
|
||||
if kwargs.get('ret'):
|
||||
return ret
|
||||
|
|
|
@ -307,7 +307,6 @@ if act == "showCompareConfigs":
|
|||
print(output_from_parsed_template)
|
||||
|
||||
if serv is not None and form.getvalue('right') is not None:
|
||||
import subprocess
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
left = form.getvalue('left')
|
||||
right = form.getvalue('right')
|
||||
|
@ -370,7 +369,10 @@ if form.getvalue('master'):
|
|||
|
||||
os.system("cp scripts/%s ." % script)
|
||||
|
||||
funct.upload(master, tmp_config_path, script)
|
||||
error = str(funct.upload(master, tmp_config_path, script))
|
||||
if error:
|
||||
print('error: '+error)
|
||||
sys.exit()
|
||||
funct.upload(slave, tmp_config_path, script)
|
||||
|
||||
commands = [ "sudo chmod +x "+tmp_config_path+script, tmp_config_path+script+" MASTER "+interface+" "+vrrpip ]
|
||||
|
@ -393,7 +395,10 @@ if form.getvalue('masteradd'):
|
|||
|
||||
os.system("cp scripts/%s ." % script)
|
||||
|
||||
funct.upload(master, tmp_config_path, script)
|
||||
error = str(funct.upload(master, tmp_config_path, script))
|
||||
if error:
|
||||
print('error: '+error)
|
||||
sys.exit()
|
||||
funct.upload(slave, tmp_config_path, script)
|
||||
|
||||
commands = [ "sudo chmod +x "+tmp_config_path+script, tmp_config_path+script+" MASTER "+interface+" "+vrrpip+" "+kp]
|
||||
|
|
|
@ -3,7 +3,7 @@ import os
|
|||
import sql
|
||||
import http.cookies
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
env = Environment(loader=FileSystemLoader('templates/ajax'))
|
||||
env = Environment(loader=FileSystemLoader('templates/ajax'),extensions=['jinja2.ext.loopcontrols', 'jinja2.ext.do'])
|
||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||
user_id = cookie.get('uuid')
|
||||
haproxy_sock_port = sql.get_setting('haproxy_sock_port')
|
||||
|
@ -41,8 +41,7 @@ def get_overviewWaf(url):
|
|||
print(template)
|
||||
|
||||
def get_overviewServers():
|
||||
template = env.get_template('overviewServers.html')
|
||||
|
||||
template = env.get_template('overviewServers.html')
|
||||
commands = [ "top -u haproxy -b -n 1" ]
|
||||
|
||||
for server in sorted(listhap):
|
||||
|
|
|
@ -73,6 +73,13 @@
|
|||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="advance">
|
||||
<td class="addName">Maxconn: </td>
|
||||
<td class="addOption">
|
||||
<input type="number" name="maxconn" required title="Fix the maximum number of concurrent connections on a frontend" size="5" value="2000" class="form-control">
|
||||
<div class="tooltip tooltipTop">This value should not exceed the global maxconn. Default global maxconn value: 2000</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="advance">
|
||||
<td class="addName">Balance: </td>
|
||||
<td class="addOption">
|
||||
|
@ -287,6 +294,13 @@
|
|||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="advance">
|
||||
<td class="addName">Maxconn: </td>
|
||||
<td class="addOption">
|
||||
<input type="number" name="maxconn" required title="Fix the maximum number of concurrent connections on a frontend" size="5" value="2000" class="form-control">
|
||||
<div class="tooltip tooltipTop">This value should not exceed the global maxconn. Default global maxconn value: 2000</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="advance">
|
||||
<td class="addName"><span title="Cache support start 1.8 and latter">Web acceleration(?):</span></td>
|
||||
<td class="addOption">
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
<div class="lineDiff">{{ line }}</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% set total_change = minus + plus %}
|
||||
|
||||
|
||||
{% set total_change = minus + plus %}
|
||||
<div class="diffHead">Total change: {{ total_change|length }}, additions: {{ plus|length }} & deletions: {{ minus|length }} </div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -1,48 +1,58 @@
|
|||
{% set waf_servers = [] %}
|
||||
{% for service in service_status %}
|
||||
{% if service.3 or url == "waf.py" %}
|
||||
<tr class="{{ loop.cycle('odd', 'even') }}">
|
||||
<td class="padding10 first-collumn">
|
||||
<a href="#{{ service.0 }}" title="Go to {{ service.0 }} status" style="color: #000">{{ service.0 }}</a>
|
||||
</td>
|
||||
<td class="second-collumn">
|
||||
{% if service.2|int() >= 1 %}
|
||||
<span class="serverUp"> UP</span> running {{service.2 }} processes
|
||||
{% else %}
|
||||
<span class="serverDown"> DOWN</span> running {{service.2 }} processes
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if role <= 1 %}
|
||||
<a id="{{ service.1 }}" class="start-waf" title="Start WAF service">
|
||||
<img src=/image/pic/start.png alt="start" class="icon">
|
||||
</a>
|
||||
<a id="{{ service.1 }}" class="stop-waf" title="Stop WAF service">
|
||||
<img src=/image/pic/stop.png alt="start" class="icon">
|
||||
</a>
|
||||
<a id="{{ service.1 }}" class="restart-waf" title="Restart WAF service">
|
||||
<img src=/image/pic/update.png alt="restart" class="icon">
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if service.3 %}
|
||||
{{ service.3 }}
|
||||
{%else %}
|
||||
<a title="Install WAF"><button onclick="installWaf('{{ service.1 }}')">Install</button></a>
|
||||
{% do waf_servers.append(1) %}
|
||||
<tr class="{{ loop.cycle('odd', 'even') }}">
|
||||
<td class="padding10 first-collumn">
|
||||
<a href="#{{ service.0 }}" title="Go to {{ service.0 }} status" style="color: #000">{{ service.0 }}</a>
|
||||
</td>
|
||||
<td class="second-collumn">
|
||||
{% if service.2|int() >= 1 %}
|
||||
<span class="serverUp"> UP</span> running {{service.2 }} processes
|
||||
{% else %}
|
||||
<span class="serverDown"> DOWN</span> running {{service.2 }} processes
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if url == "waf.py" %}
|
||||
<td>
|
||||
{% if service.3 %}
|
||||
{% if service.4|int() == 1 %}
|
||||
<label for="{{ service.0 }}"></label><input type="checkbox" id="{{ service.0 }}" checked>
|
||||
{% else %}
|
||||
<label for="{{ service.0 }}"></label><input type="checkbox" id="{{ service.0 }}">
|
||||
</td>
|
||||
<td>
|
||||
{% if role <= 1 %}
|
||||
<a id="{{ service.1 }}" class="start-waf" title="Start WAF service">
|
||||
<img src=/image/pic/start.png alt="start" class="icon">
|
||||
</a>
|
||||
<a id="{{ service.1 }}" class="stop-waf" title="Stop WAF service">
|
||||
<img src=/image/pic/stop.png alt="start" class="icon">
|
||||
</a>
|
||||
<a id="{{ service.1 }}" class="restart-waf" title="Restart WAF service">
|
||||
<img src=/image/pic/update.png alt="restart" class="icon">
|
||||
</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if service.3 %}
|
||||
{{ service.3 }}
|
||||
{%else %}
|
||||
<a title="Install WAF"><button onclick="installWaf('{{ service.1 }}')">Install</button></a>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% if url == "waf.py" %}
|
||||
<td>
|
||||
{% if service.3 %}
|
||||
{% if service.4|int() == 1 %}
|
||||
<label for="{{ service.0 }}"></label><input type="checkbox" id="{{ service.0 }}" checked>
|
||||
{% else %}
|
||||
<label for="{{ service.0 }}"></label><input type="checkbox" id="{{ service.0 }}">
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
<td></td>
|
||||
</tr>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% if waf_servers|count == 0 and url != "waf.py" %}
|
||||
<tr>
|
||||
<td class="padding10 first-collumn">
|
||||
You have not installed the WAF server yet
|
||||
{{ waf_servers|length }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
|
@ -101,7 +101,7 @@
|
|||
</ul>
|
||||
</nav>
|
||||
<div class="copyright-menu">
|
||||
HAproxy-WI v3.2.5
|
||||
HAproxy-WI v3.2.6
|
||||
<br>
|
||||
<a href="https://www.patreon.com/haproxy_wi" title="Donate" target="_blank" style="color: #fff; margin-left: 30px; color: red;" class="patreon"> Patreon</a>
|
||||
</div>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td class="padding10 first-collumn" style="width: 10%;">
|
||||
<form action="logs.py" method="get">
|
||||
<form action="" method="get">
|
||||
<select autofocus required name="serv" id="{{ select_id }}">
|
||||
{% if onclick == 'viewLogs()' %}
|
||||
<option disabled selected>Choose log</option>
|
||||
|
|
Loading…
Reference in New Issue