mirror of https://github.com/Aidaho12/haproxy-wi
parent
55308cc234
commit
7876302313
|
@ -0,0 +1,334 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import html
|
||||||
|
import cgi
|
||||||
|
import listserv as listhap
|
||||||
|
import os
|
||||||
|
import funct
|
||||||
|
import paramiko
|
||||||
|
import configparser
|
||||||
|
import http.cookies
|
||||||
|
from paramiko import SSHClient
|
||||||
|
from datetime import datetime
|
||||||
|
from pytz import timezone
|
||||||
|
|
||||||
|
funct.head("Add")
|
||||||
|
funct.check_config()
|
||||||
|
funct.check_login("add.py")
|
||||||
|
|
||||||
|
path_config = "haproxy-webintarface.config"
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(path_config)
|
||||||
|
|
||||||
|
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
|
||||||
|
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||||
|
form = cgi.FieldStorage()
|
||||||
|
|
||||||
|
if form.getvalue('mode') is not None:
|
||||||
|
serv = form.getvalue('serv')
|
||||||
|
port = form.getvalue('port')
|
||||||
|
mode = " mode " + form.getvalue('mode')
|
||||||
|
|
||||||
|
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 = "listen " + form.getvalue('listner')
|
||||||
|
backend = ""
|
||||||
|
elif form.getvalue('frontend') is not None:
|
||||||
|
name = "\nfrontend " + form.getvalue('frontend')
|
||||||
|
backend = " default_backend " + form.getvalue('backend') + "\n"
|
||||||
|
elif form.getvalue('backend') is not None:
|
||||||
|
name = "backend " + form.getvalue('backend')
|
||||||
|
backend = ""
|
||||||
|
|
||||||
|
if not ip and form.getvalue('port') is not None:
|
||||||
|
bind = " bind *:"+ port + "\n"
|
||||||
|
elif port is not None:
|
||||||
|
bind = " bind " + ip + ":" + port + "\n"
|
||||||
|
else:
|
||||||
|
bind = ""
|
||||||
|
|
||||||
|
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 form.getvalue('servers') is not None:
|
||||||
|
servers = form.getvalue('servers')
|
||||||
|
i = servers.split("\n")
|
||||||
|
servers_split = ""
|
||||||
|
for j in i:
|
||||||
|
servers_split += " " + j + "\n"
|
||||||
|
else:
|
||||||
|
servers_split = ""
|
||||||
|
|
||||||
|
config_add = name + "\n" + bind + mode + "\n" + balance + options_split + backend + servers_split + "\n"
|
||||||
|
|
||||||
|
os.chdir(config.get('configs', 'haproxy_save_configs_dir'))
|
||||||
|
|
||||||
|
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||||
|
now_utc = datetime.now(timezone(config.get('main', 'time_zone')))
|
||||||
|
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
|
||||||
|
|
||||||
|
funct.get_config(serv, cfg)
|
||||||
|
try:
|
||||||
|
with open(cfg, "a") as conf:
|
||||||
|
conf.write(config_add)
|
||||||
|
#print('<meta http-equiv="refresh" content="50; url=add.py?add=%s&conf=%s">' % (name, config_add))
|
||||||
|
except IOError:
|
||||||
|
print("Can't read import config file")
|
||||||
|
|
||||||
|
funct.logging(serv, "add.py add new %s" % name)
|
||||||
|
print('<div class="line3">')
|
||||||
|
if funct.upload_and_restart(serv, cfg):
|
||||||
|
print('<meta http-equiv="refresh" content="30; url=add.py?add=%s&conf=%s">' % (name, config_add))
|
||||||
|
|
||||||
|
print('</div>')
|
||||||
|
|
||||||
|
if form.getvalue('add') is not None:
|
||||||
|
print('<h3 class="addSuc"> ' + form.getvalue('add') + ' was successfully added</h3>')
|
||||||
|
print('<div class="line3">')
|
||||||
|
print(form.getvalue('conf'))
|
||||||
|
print('</div>')
|
||||||
|
|
||||||
|
print('<div id="tabs">'
|
||||||
|
'<ul>'
|
||||||
|
'<li><a href="#listner">Listner</a></li>'
|
||||||
|
'<li><a href="#frontend">Frontend</a></li>'
|
||||||
|
'<li><a href="#backend">Backend</a></li>'
|
||||||
|
'</ul>'
|
||||||
|
'<div id="listner">'
|
||||||
|
'<form name="add-listner" action="add.py">'
|
||||||
|
'<table>'
|
||||||
|
'<caption>Add listner</caption>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Select server: </td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<select required name="serv" id="serv">'
|
||||||
|
'<option disabled selected>Choose server</option>')
|
||||||
|
|
||||||
|
for i in sorted(listhap.listhap):
|
||||||
|
print('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
|
||||||
|
|
||||||
|
print('</select>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Name:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<input type="text" name="listner" id="name" required title="Name Listner" placeholder="web_80">'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">IP and Port:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<input type="text" name="ip" id="ip" title="" size="15" placeholder="172.28.0.1"><b>:</b>'
|
||||||
|
'<input type="text" name="port" required title="Port for bind listner" size="5" placeholder="8080">'
|
||||||
|
'<div class="tooltip tooltipTop">IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.</div>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Mode: </td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<select required name="mode">'
|
||||||
|
'<option value="http" selected>http</option>'
|
||||||
|
'<option value="tcp">tcp</option>'
|
||||||
|
'</select>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Balance: </td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<select required name="balance">'
|
||||||
|
'<option value="roundrobin" selected>roundrobin</option>'
|
||||||
|
'<option value="source">source</option>'
|
||||||
|
'<option value="leastconn">leastconn</option>'
|
||||||
|
'<option value="first">first</option>'
|
||||||
|
'<option value="rdp-cookie">rdp-cookie</option>'
|
||||||
|
'</select>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Optinons:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<div class="tooltip">'
|
||||||
|
'<span style="padding-right: 10px;">Start typing options: </span>'
|
||||||
|
'<input type="text" id="options" >'
|
||||||
|
'<span style="padding-left: 10px;">'
|
||||||
|
'or press down. <a href="http://cbonte.github.io/haproxy-dconv/1.7/configuration.html" target="_blanck" style="color: #23527c" title="HAproxy docs">Read more about options</a>'
|
||||||
|
'</span>'
|
||||||
|
'</div>'
|
||||||
|
'<textarea name="option" title="Options thru" id="optionsInput" cols=80 placeholder="acl test hdr_beg(host) -i some_host"></textarea>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Servers:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<textarea name="servers" required title="Backend servers" cols=80 placeholder="server server.local 172.28.0.1:8080 check"></textarea>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addButton">')
|
||||||
|
funct.mode_admin("Add Listner")
|
||||||
|
print('</td>'
|
||||||
|
'</tr>'
|
||||||
|
'</form>'
|
||||||
|
'</table></div>'
|
||||||
|
|
||||||
|
'<!-- Second tabs -->'
|
||||||
|
|
||||||
|
'<div id="frontend">'
|
||||||
|
'<form name="add-frontend" action="add.py">'
|
||||||
|
'<table>'
|
||||||
|
'<caption>Add frontend</caption>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Select server: </td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<select required name="serv" id="serv2">'
|
||||||
|
'<option disabled selected>Choose server</option>')
|
||||||
|
|
||||||
|
for i in sorted(listhap.listhap):
|
||||||
|
print('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
|
||||||
|
|
||||||
|
print('</select>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Name:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<input type="text" name="frontend" id="frontend" required title="Name frontend" placeholder="web_80" >'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">IP and Port:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<input type="text" name="ip" id="ip1" size="15" placeholder="172.28.0.1"><b>:</b>'
|
||||||
|
'<input type="text" name="port" required title="Port for bind listner" size="5" placeholder="8080">'
|
||||||
|
'<div class="tooltip tooltipTop">IP for bind listner, if empty will be assignet on all IPs. Start typing ip, or press down.</div>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Mode: </td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<select required name="mode">'
|
||||||
|
'<option value="http" selected>http</option>'
|
||||||
|
'<option value="tcp">tcp</option>'
|
||||||
|
'</select>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Optinons:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<div style="font-size: 12px; padding-bottom: 10px;">'
|
||||||
|
'<span style="padding-right: 10px;">Start typing options: </span>'
|
||||||
|
'<input type="text" id="options1" >'
|
||||||
|
'<span style="padding-left: 10px;">'
|
||||||
|
'or press down. <a href="http://cbonte.github.io/haproxy-dconv/1.7/configuration.html" target="_blanck" style="color: #23527c" title="HAproxy docs">Read more about options</a>'
|
||||||
|
'</span>'
|
||||||
|
'</div>'
|
||||||
|
'<textarea name="option" title="Options thru" cols=80 id="optionsInput1" placeholder="acl test hdr_beg(host) -i some_host"></textarea>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Default backend</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<div style="font-size: 12px; padding-bottom: 10px;">Start typing backend, or press down</div>'
|
||||||
|
'<input name="backend" id="backends" required size="30" placeholder="some_backend">'
|
||||||
|
'<span style="font-size: 12px; padding-left: 10px;"> .</span>'
|
||||||
|
'<p style="font-size: 12px"><b>Note:</b> If backend don\'t exist, you must <a href="#" style="color: #23527c" title="Create backend" id="redirectBackend">create backend first</a>.</p>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addButton">')
|
||||||
|
funct.mode_admin("Add Frontend")
|
||||||
|
print('</td>'
|
||||||
|
'</tr>'
|
||||||
|
'</form></table>'
|
||||||
|
'</div>'
|
||||||
|
|
||||||
|
|
||||||
|
'<!-- Third tabs -->'
|
||||||
|
|
||||||
|
'<div id="backend">'
|
||||||
|
'<form name="add-backend" action="add.py">'
|
||||||
|
'<table>'
|
||||||
|
'<caption>Add frontend</caption>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Select server: </td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<select required name="serv">'
|
||||||
|
'<option disabled selected>Choose server</option>')
|
||||||
|
|
||||||
|
for i in sorted(listhap.listhap):
|
||||||
|
print('<option value="%s">%s</option>' % (listhap.listhap.get(i), i))
|
||||||
|
|
||||||
|
print('</select>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Name:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<input type="text" name="backend" id="backend" required title="Name backend" placeholder="web_80" >'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Mode: </td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<select required name="mode">'
|
||||||
|
'<option value="http" selected>http</option>'
|
||||||
|
'<option value="tcp">tcp</option>'
|
||||||
|
'</select>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Balance: </td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<select required name="balance">'
|
||||||
|
'<option value="roundrobin" selected>roundrobin</option>'
|
||||||
|
'<option value="source">source</option>'
|
||||||
|
'<option value="leastconn">leastconn</option>'
|
||||||
|
'<option value="first">first</option>'
|
||||||
|
'<option value="rdp-cookie">rdp-cookie</option>'
|
||||||
|
'</select>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Optinons:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<div style="font-size: 12px; padding-bottom: 10px;">'
|
||||||
|
'<span style="padding-right: 10px;">Start typing options: </span>'
|
||||||
|
'<input type="text" id="options2" >'
|
||||||
|
'<span style="padding-left: 10px;">'
|
||||||
|
'or press down. <a href="http://cbonte.github.io/haproxy-dconv/1.7/configuration.html" target="_blanck" style="color: #23527c" title="HAproxy docs">Read more about options</a>'
|
||||||
|
'</span>'
|
||||||
|
'</div>'
|
||||||
|
'<textarea name="option" title="Options thru" cols=80 id="optionsInput2" placeholder="acl test hdr_beg(host) -i some_host"></textarea>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addName">Servers:</td>'
|
||||||
|
'<td class="addOption">'
|
||||||
|
'<textarea name="servers" title="Backend servers" required cols=80 placeholder="server server.local 172.28.0.1:8080 check"></textarea>'
|
||||||
|
'</td>'
|
||||||
|
'</tr>'
|
||||||
|
'<tr>'
|
||||||
|
'<td class="addButton">')
|
||||||
|
funct.mode_admin("Add Backend")
|
||||||
|
print('</td>'
|
||||||
|
'</tr>'
|
||||||
|
'</form></div></table>'
|
||||||
|
|
||||||
|
'</div></div>')
|
||||||
|
|
||||||
|
funct.footer()
|
|
@ -14,11 +14,10 @@ from pytz import timezone
|
||||||
form = cgi.FieldStorage()
|
form = cgi.FieldStorage()
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
servNew = form.getvalue('serNew')
|
servNew = form.getvalue('serNew')
|
||||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
|
||||||
login = cookie.get('login')
|
|
||||||
|
|
||||||
funct.head("Edit HAproxy config")
|
funct.head("Edit HAproxy config")
|
||||||
funct.check_config()
|
funct.check_config()
|
||||||
|
funct.check_login("config.py")
|
||||||
|
|
||||||
path_config = "haproxy-webintarface.config"
|
path_config = "haproxy-webintarface.config"
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@ -28,9 +27,6 @@ fullpath = config.get('main', 'fullpath')
|
||||||
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||||
time_zone = config.get('main', 'time_zone')
|
time_zone = config.get('main', 'time_zone')
|
||||||
|
|
||||||
if login is None:
|
|
||||||
print('<meta http-equiv="refresh" content="0; url=login.py?ref=config.py">')
|
|
||||||
|
|
||||||
if serv is not None:
|
if serv is not None:
|
||||||
fmt = "%Y-%m-%d.%H:%M:%S"
|
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||||
now_utc = datetime.now(timezone(time_zone))
|
now_utc = datetime.now(timezone(time_zone))
|
||||||
|
@ -49,7 +45,9 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
|
||||||
print('<input type="hidden" value="%s" name="serv">' % serv)
|
print('<input type="hidden" value="%s" name="serv">' % serv)
|
||||||
print('<input type="hidden" value="%s.old" name="oldconfig">' % cfg)
|
print('<input type="hidden" value="%s.old" name="oldconfig">' % cfg)
|
||||||
print('<textarea name="config" rows="35" cols="100">%s</textarea>' % conf.read())
|
print('<textarea name="config" rows="35" cols="100">%s</textarea>' % conf.read())
|
||||||
print('<p><button type="submit" value="save and restart" onclick="return confirm(\'are u shure?\')">save and restart</button></p></form>')
|
print('<p>')
|
||||||
|
funct.mode_admin("Save and restart")
|
||||||
|
print('</p></form>')
|
||||||
conf.close
|
conf.close
|
||||||
|
|
||||||
os.system("/bin/sudo /bin/mv %s %s.old" % (cfg, cfg))
|
os.system("/bin/sudo /bin/mv %s %s.old" % (cfg, cfg))
|
||||||
|
|
|
@ -15,6 +15,7 @@ servNew = form.getvalue('serNew')
|
||||||
|
|
||||||
funct.head("Show HAproxy config")
|
funct.head("Show HAproxy config")
|
||||||
funct.check_config()
|
funct.check_config()
|
||||||
|
funct.check_login("configshow.py")
|
||||||
|
|
||||||
path_config = "haproxy-webintarface.config"
|
path_config = "haproxy-webintarface.config"
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
|
|
@ -14,11 +14,10 @@ from pytz import timezone
|
||||||
form = cgi.FieldStorage()
|
form = cgi.FieldStorage()
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
configver = form.getvalue('configver')
|
configver = form.getvalue('configver')
|
||||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
|
||||||
login = cookie.get('login')
|
|
||||||
|
|
||||||
funct.head("Old Versions HAproxy config")
|
funct.head("Old Versions HAproxy config")
|
||||||
funct.check_config()
|
funct.check_config()
|
||||||
|
funct.check_login("configver.py")
|
||||||
|
|
||||||
path_config = "haproxy-webintarface.config"
|
path_config = "haproxy-webintarface.config"
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@ -26,9 +25,6 @@ config.read(path_config)
|
||||||
|
|
||||||
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||||
|
|
||||||
if login is None:
|
|
||||||
print('<meta http-equiv="refresh" content="0; url=login.py?ref=configver.py">')
|
|
||||||
|
|
||||||
funct.chooseServer("configver.py#conf", "Old Versions HAproxy config", "y")
|
funct.chooseServer("configver.py#conf", "Old Versions HAproxy config", "y")
|
||||||
|
|
||||||
if serv is not None and form.getvalue('open') is not None:
|
if serv is not None and form.getvalue('open') is not None:
|
||||||
|
@ -67,9 +63,12 @@ if serv is not None and form.getvalue('open') is not None:
|
||||||
print('<form action="configver.py#conf" method="get">')
|
print('<form action="configver.py#conf" method="get">')
|
||||||
print('<input type="hidden" value="%s" name="serv">' % serv)
|
print('<input type="hidden" value="%s" name="serv">' % serv)
|
||||||
print('<input type="hidden" value="%s" name="configver">' % configver)
|
print('<input type="hidden" value="%s" name="configver">' % configver)
|
||||||
|
print('<input type="hidden" value="1" name="config">')
|
||||||
print('<a name="conf"></a></center>')
|
print('<a name="conf"></a></center>')
|
||||||
funct.show_config(configver)
|
funct.show_config(configver)
|
||||||
print('<center><p><button type="submit" value="Upload and restart" onclick="return confirm(\'are u shure?\')">Upload and restart</button></p></form></center>')
|
print('<center><p>')
|
||||||
|
funct.mode_admin("Upload and restart")
|
||||||
|
print('</p></form></center>')
|
||||||
|
|
||||||
|
|
||||||
if form.getvalue('serv') is not None and form.getvalue('config') is not None:
|
if form.getvalue('serv') is not None and form.getvalue('config') is not None:
|
||||||
|
|
|
@ -17,6 +17,7 @@ right = form.getvalue('right')
|
||||||
|
|
||||||
funct.head("Compare HAproxy configs")
|
funct.head("Compare HAproxy configs")
|
||||||
funct.check_config()
|
funct.check_config()
|
||||||
|
funct.check_login("diff.py")
|
||||||
|
|
||||||
path_config = "haproxy-webintarface.config"
|
path_config = "haproxy-webintarface.config"
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@ -70,6 +71,6 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
|
||||||
if form.getvalue('serv') is not None and form.getvalue('right') is not None:
|
if form.getvalue('serv') is not None and form.getvalue('right') is not None:
|
||||||
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
|
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
|
||||||
|
|
||||||
funct.ssh_command(haproxy_configs_server, commands)
|
funct.ssh_command(haproxy_configs_server, commands, compare="compare")
|
||||||
|
|
||||||
funct.footer()
|
funct.footer()
|
|
@ -10,14 +10,10 @@ from funct import head as head
|
||||||
|
|
||||||
form = cgi.FieldStorage()
|
form = cgi.FieldStorage()
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
|
||||||
login = cookie.get('login')
|
|
||||||
|
|
||||||
head("Edit & show HAproxy settings")
|
head("Edit & show HAproxy settings")
|
||||||
|
|
||||||
if login is None:
|
funct.check_login("edit.py")
|
||||||
print('<meta http-equiv="refresh" content="0; url=login.py?ref=configver.py">')
|
|
||||||
|
|
||||||
|
|
||||||
print('<center><h2>Edit & show HAproxy settings</h2></center>')
|
print('<center><h2>Edit & show HAproxy settings</h2></center>')
|
||||||
print('<center><h3>Choose server & action: Disable/Enable server or output any information about the server:</h3>')
|
print('<center><h3>Choose server & action: Disable/Enable server or output any information about the server:</h3>')
|
||||||
|
@ -55,7 +51,9 @@ print('<option value=2 %s>Enable server</option>' % selected2)
|
||||||
print('<option value=3 %s>Show</option>' % selected3)
|
print('<option value=3 %s>Show</option>' % selected3)
|
||||||
print('</select>')
|
print('</select>')
|
||||||
print('<input type="text" name="servbackend" size=40 placeholder="Backend/Server, show info, pools or help" required>')
|
print('<input type="text" name="servbackend" size=40 placeholder="Backend/Server, show info, pools or help" required>')
|
||||||
print('<p><button type="submit">Enter</button></p></form>')
|
print('<p>')
|
||||||
|
funct.mode_admin("Enter")
|
||||||
|
print('</p></form>')
|
||||||
|
|
||||||
if form.getvalue('servaction') is not None:
|
if form.getvalue('servaction') is not None:
|
||||||
action = form.getvalue('servaction')
|
action = form.getvalue('servaction')
|
||||||
|
|
140
cgi-bin/funct.py
140
cgi-bin/funct.py
|
@ -28,6 +28,7 @@ ssh_user_name = config.get('ssh', 'ssh_user_name')
|
||||||
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
|
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
|
||||||
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||||
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
|
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
|
||||||
|
tmp_config_path = config.get('haproxy', 'tmp_config_path')
|
||||||
restart_command = config.get('haproxy', 'restart_command')
|
restart_command = config.get('haproxy', 'restart_command')
|
||||||
time_zone = config.get('main', 'time_zone')
|
time_zone = config.get('main', 'time_zone')
|
||||||
|
|
||||||
|
@ -43,16 +44,42 @@ def logging(serv, action):
|
||||||
log.write(mess)
|
log.write(mess)
|
||||||
log.close
|
log.close
|
||||||
|
|
||||||
|
def check_login(ref):
|
||||||
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
|
login = cookie.get('login')
|
||||||
|
|
||||||
|
if login is None:
|
||||||
|
print('<meta http-equiv="refresh" content="0; url=login.py?ref=%s">' % ref)
|
||||||
|
|
||||||
|
def show_login_links():
|
||||||
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
|
login = cookie.get('login')
|
||||||
|
|
||||||
|
if login is None:
|
||||||
|
print('<a href=/cgi-bin/login.py? title="Login" style="size:5">Login</a>')
|
||||||
|
else:
|
||||||
|
print('<a href=/cgi-bin/login.py?logout=logout title="Logout" style="size:5">Logout</a>')
|
||||||
|
|
||||||
|
def mode_admin(button):
|
||||||
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
|
role = cookie.get('role')
|
||||||
|
|
||||||
|
if role.value == "admin":
|
||||||
|
print('<button type="submit">%s</button>' % button)
|
||||||
|
|
||||||
def links():
|
def links():
|
||||||
print('<a href=/ title="Home Page" style="size:5">Home Page</a> ')
|
print('<a href=/ title="Home Page" style="size:5">Home Page</a> ')
|
||||||
print('<a href=/cgi-bin/viewsttats.py title="View Stats" style="size:5">Stats</a> ')
|
print('<a href=/cgi-bin/viewsttats.py title="View Stats" style="size:5">Stats</a> ')
|
||||||
print('<a href=/cgi-bin/logs.py title="Logs" style="size:6">Logs</a>')
|
print('<a href="http://172.28.5.106:3000/dashboard/db/haproxy" title="Mon" target="_blanck">Monitoring</a> ')
|
||||||
|
print('<a href=/cgi-bin/logs.py title="View logs" style="size:6">Logs</a>')
|
||||||
print('<a href=/cgi-bin/edit.py title="Edit settings" style="size:5">Edit settings</a> ')
|
print('<a href=/cgi-bin/edit.py title="Edit settings" style="size:5">Edit settings</a> ')
|
||||||
print('<span style="color: #fff"> | Configs: </span>')
|
print('<span style="color: #fff"> | Configs: </span>')
|
||||||
print('<a href=/cgi-bin/configshow.py title="Show Config">Show</a> ')
|
print('<a href=/cgi-bin/configshow.py title="Show Config">Show</a> ')
|
||||||
print('<a href=/cgi-bin/diff.py title="Compare Configs">Compare</a> ')
|
print('<a href=/cgi-bin/diff.py title="Compare Configs">Compare</a> ')
|
||||||
|
print('<a href=/cgi-bin/add.py title="Add single listen/frontend/backend" style="size:5">Add</a> ')
|
||||||
print('<a href=/cgi-bin/config.py title="Edit Config" style="size:5">Edit</a> ')
|
print('<a href=/cgi-bin/config.py title="Edit Config" style="size:5">Edit</a> ')
|
||||||
print('<a href=/cgi-bin/configver.py title="Upload old config" style="size:5">Upload old</a>')
|
print('<a href=/cgi-bin/configver.py title="Upload old config" style="size:5">Upload old</a>')
|
||||||
|
show_login_links()
|
||||||
|
|
||||||
def head(title):
|
def head(title):
|
||||||
print('Content-type: text/html\n')
|
print('Content-type: text/html\n')
|
||||||
|
@ -62,21 +89,11 @@ def head(title):
|
||||||
'<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">'
|
'<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">'
|
||||||
'<script src="https://code.jquery.com/jquery-1.12.4.js"></script>'
|
'<script src="https://code.jquery.com/jquery-1.12.4.js"></script>'
|
||||||
'<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>'
|
'<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>'
|
||||||
|
'<script src="/script.js"></script>'
|
||||||
'</head>'
|
'</head>'
|
||||||
'<body>'
|
'<body>'
|
||||||
'<script>'
|
'<a name="top"></a>'
|
||||||
'$( function() {'
|
'<div class="top-menu">')
|
||||||
'$( "select" ).selectmenu();'
|
|
||||||
'} );'
|
|
||||||
'$( function() {'
|
|
||||||
'$( "input[type=submit], button" ).button();'
|
|
||||||
'} );'
|
|
||||||
'$( function() {'
|
|
||||||
'$( document ).tooltip();'
|
|
||||||
'} );'
|
|
||||||
'</script>'
|
|
||||||
'<a name="top"></a>')
|
|
||||||
print('<div class="top-menu">')
|
|
||||||
if config.get('main', 'logo_enable') == "1":
|
if config.get('main', 'logo_enable') == "1":
|
||||||
print('<img src="%s" title="Logo" class="logo">' % config.get('main', 'logo_path'))
|
print('<img src="%s" title="Logo" class="logo">' % config.get('main', 'logo_path'))
|
||||||
print('<div class="top-link">')
|
print('<div class="top-link">')
|
||||||
|
@ -146,6 +163,10 @@ def show_config(cfg):
|
||||||
conf.close
|
conf.close
|
||||||
|
|
||||||
def upload_and_restart(serv, cfg):
|
def upload_and_restart(serv, cfg):
|
||||||
|
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||||
|
now_utc = datetime.now(timezone(config.get('main', 'time_zone')))
|
||||||
|
tmp_file = tmp_config_path + "/" + now_utc.strftime(fmt) + ".cfg"
|
||||||
|
|
||||||
ssh = SSHClient()
|
ssh = SSHClient()
|
||||||
ssh.load_system_host_keys()
|
ssh.load_system_host_keys()
|
||||||
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
|
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
|
||||||
|
@ -155,37 +176,45 @@ def upload_and_restart(serv, cfg):
|
||||||
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
|
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
|
||||||
print("connected<br />")
|
print("connected<br />")
|
||||||
sftp = ssh.open_sftp()
|
sftp = ssh.open_sftp()
|
||||||
sftp.put(cfg, haproxy_config_path)
|
sftp.put(cfg, tmp_file)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
commands = [ "service haproxy restart" ]
|
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path, restart_command]
|
||||||
|
i = 0
|
||||||
for command in commands:
|
for command in commands:
|
||||||
|
i = i + 1
|
||||||
print("</br>Executing: {}".format( command ))
|
print("</br>Executing: {}".format( command ))
|
||||||
print("</br>")
|
print("</br>")
|
||||||
stdin , stdout, stderr = ssh.exec_command(command)
|
stdin , stdout, stderr = ssh.exec_command(command)
|
||||||
print(stdout.read().decode(encoding='UTF-8'))
|
print(stdout.read().decode(encoding='UTF-8'))
|
||||||
|
if i == 1:
|
||||||
|
if not stderr.read():
|
||||||
|
print('<h3 style="color: #23527c">Config ok</h3>')
|
||||||
|
else:
|
||||||
|
print('<h3 style="color: red">In your config have errors, please check, and try again</h3>')
|
||||||
|
print(stderr.read().decode(encoding='UTF-8'))
|
||||||
|
return False
|
||||||
|
break
|
||||||
|
if i is not 1:
|
||||||
print("</br>Errors:")
|
print("</br>Errors:")
|
||||||
print(stderr.read().decode(encoding='UTF-8'))
|
print(stderr.read().decode(encoding='UTF-8'))
|
||||||
print("</br>")
|
print("</br>")
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
|
||||||
def ssh_command(serv, commands):
|
def compare(stdout):
|
||||||
ssh = SSHClient()
|
|
||||||
ssh.load_system_host_keys()
|
|
||||||
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
|
|
||||||
ssh = paramiko.SSHClient()
|
|
||||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
||||||
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
|
|
||||||
for command in commands:
|
|
||||||
stdin , stdout, stderr = ssh.exec_command(command)
|
|
||||||
print('</center><div class="out">')
|
|
||||||
if serv == haproxy_configs_server:
|
|
||||||
print('<div class="diff">')
|
|
||||||
i = 0
|
i = 0
|
||||||
minus = 0
|
minus = 0
|
||||||
plus = 0
|
plus = 0
|
||||||
|
total_change = 0
|
||||||
|
|
||||||
|
print('</center><div class="out">')
|
||||||
|
print('<div class="diff">')
|
||||||
|
|
||||||
for line in stdout:
|
for line in stdout:
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if serv == haproxy_configs_server:
|
|
||||||
if i is 1:
|
if i is 1:
|
||||||
print('<div class="diffHead">' + line + '<br />')
|
print('<div class="diffHead">' + line + '<br />')
|
||||||
elif i is 2:
|
elif i is 2:
|
||||||
|
@ -200,14 +229,56 @@ def ssh_command(serv, commands):
|
||||||
print('<div class="lineDog">' + line + '</div>')
|
print('<div class="lineDog">' + line + '</div>')
|
||||||
else:
|
else:
|
||||||
print('<div class="lineDiff">' + line + '</div>')
|
print('<div class="lineDiff">' + line + '</div>')
|
||||||
elif i % 2 == 0:
|
|
||||||
|
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):
|
||||||
|
i = 0
|
||||||
|
for line in stdout:
|
||||||
|
i = i + 1
|
||||||
|
if i % 2 == 0:
|
||||||
print('<div class="line3">' + line + '</div>')
|
print('<div class="line3">' + line + '</div>')
|
||||||
else:
|
else:
|
||||||
print('<div class="line">' + line + '</div>')
|
print('<div class="line">' + line + '</div>')
|
||||||
total_change = minus + plus
|
|
||||||
if serv == haproxy_configs_server:
|
|
||||||
print('<div class="diffHead">Total change: %s, additions: %s & deletions: %s </div>' % (total_change, minus, plus))
|
|
||||||
print('</div></div>')
|
print('</div></div>')
|
||||||
|
|
||||||
|
def show_ip(stdout):
|
||||||
|
for line in stdout:
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
def ssh_command(serv, commands, **kwargs):
|
||||||
|
ssh = SSHClient()
|
||||||
|
ssh.load_system_host_keys()
|
||||||
|
k = paramiko.RSAKey.from_private_key_file(ssh_keys)
|
||||||
|
ssh = paramiko.SSHClient()
|
||||||
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
ssh.connect( hostname = serv, username = ssh_user_name, pkey = k )
|
||||||
|
|
||||||
|
ip = 0
|
||||||
|
compare_funct = 0
|
||||||
|
show_log_funct = 0
|
||||||
|
|
||||||
|
for k in kwargs:
|
||||||
|
if "ip" in kwargs[k]:
|
||||||
|
ip = 1
|
||||||
|
if "compare" in kwargs[k]:
|
||||||
|
compare_funct = 1
|
||||||
|
if "show_log" in kwargs[k]:
|
||||||
|
show_log_funct = 1
|
||||||
|
|
||||||
|
for command in commands:
|
||||||
|
stdin , stdout, stderr = ssh.exec_command(command)
|
||||||
|
|
||||||
|
if ip is 1:
|
||||||
|
show_ip(stdout)
|
||||||
|
if compare_funct is 1:
|
||||||
|
compare(stdout)
|
||||||
|
if show_log_funct is 1:
|
||||||
|
show_log(stdout)
|
||||||
|
|
||||||
print(stderr.read().decode(encoding='UTF-8'))
|
print(stderr.read().decode(encoding='UTF-8'))
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
|
||||||
|
@ -249,3 +320,6 @@ def merge_two_dicts(x, y):
|
||||||
z = x.copy()
|
z = x.copy()
|
||||||
z.update(y)
|
z.update(y)
|
||||||
return z
|
return z
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
listhap= {
|
listhap= {
|
||||||
'kz-webhap01': '172.28.9.159',
|
'haproxy1': '172.28.0.1',
|
||||||
'kz-webhap02': '172.28.9.160',
|
'haproxy2': '172.28.0.2'
|
||||||
'kz-mysqlhap01': '172.28.5.6',
|
|
||||||
'kz-mysqlhap02': '172.28.5.5',
|
|
||||||
}
|
}
|
||||||
list_hap_vip = {
|
list_hap_vip = {
|
||||||
'kz-webhap-vip': '172.28.9.161',
|
'haproxy-vip': '172.28.0.3'
|
||||||
'kz-mysqlhap-vip': '172.28.5.17'
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ login = form.getvalue('login')
|
||||||
password = form.getvalue('pass')
|
password = form.getvalue('pass')
|
||||||
USERS = 'cgi-bin/users'
|
USERS = 'cgi-bin/users'
|
||||||
|
|
||||||
|
funct.check_login("login.py")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(USERS, "r") as user:
|
with open(USERS, "r") as user:
|
||||||
pass
|
pass
|
||||||
|
@ -21,9 +23,13 @@ except IOError:
|
||||||
|
|
||||||
def login_page(error):
|
def login_page(error):
|
||||||
if error == "error":
|
if error == "error":
|
||||||
printError = "<b style='color: red'>Somthing wrong :( I'm sad about this, but try again!</b></br></br>"
|
printError = "<b style='color: red'>Somthing wrong :( I'm sad about this, but try again!</b><br /><br />"
|
||||||
else:
|
else:
|
||||||
printError = "<b style='color: red'>First you need to login.</b></br></br>"
|
printError = "<b style='color: red'>First you need to login.</b><br /><br />"
|
||||||
|
|
||||||
|
ref = form.getvalue('ref')
|
||||||
|
if ref is None:
|
||||||
|
ref = "/index.html"
|
||||||
|
|
||||||
funct.head("Login page")
|
funct.head("Login page")
|
||||||
|
|
||||||
|
@ -35,25 +41,33 @@ def login_page(error):
|
||||||
print('<button type="submit" name="Login" value="Enter">Sign Up</button>')
|
print('<button type="submit" name="Login" value="Enter">Sign Up</button>')
|
||||||
print('</form></center>')
|
print('</form></center>')
|
||||||
|
|
||||||
|
if form.getvalue('logout') is not None:
|
||||||
|
print("Set-cookie: login=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly")
|
||||||
|
print("Set-cookie: FirstName=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly")
|
||||||
|
print("Set-cookie: LastName=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly")
|
||||||
|
print("Set-cookie: role=; expires=Wed May 18 03:33:20 2003; path=/cgi-bin/; httponly")
|
||||||
|
print('<meta http-equiv="refresh" content="0; url=/">')
|
||||||
|
|
||||||
if login is None:
|
if login is None:
|
||||||
login_page("n")
|
login_page("n")
|
||||||
|
|
||||||
if login is not None and password is not None:
|
if login is not None and password is not None:
|
||||||
for f in open(USERS, 'r'):
|
for f in open(USERS, 'r'):
|
||||||
users = json.loads(f)
|
users = json.loads(f)
|
||||||
|
print(users['login'])
|
||||||
if login in users['login'] and password == users['password']:
|
if login in users['login'] and password == users['password']:
|
||||||
print("Set-cookie: login=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % login)
|
print("Set-cookie: login=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % login)
|
||||||
print("Set-cookie: FirstName=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % users['firstName'])
|
print("Set-cookie: FirstName=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % users['firstName'])
|
||||||
print("Set-cookie: LastName=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % users['lastName'])
|
print("Set-cookie: LastName=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % users['lastName'])
|
||||||
if ref is None:
|
print("Set-cookie: role=%s; expires=Wed May 18 03:33:20 2033; path=/cgi-bin/; httponly" % users['role'])
|
||||||
ref = "index.html"
|
if form.getvalue('ref') is None:
|
||||||
|
ref = "/index.html"
|
||||||
print("Content-type: text/html\n")
|
print("Content-type: text/html\n")
|
||||||
print('<html><head><title>Redirecting</title><meta charset="UTF-8">')
|
print('<html><head><title>Redirecting</title><meta charset="UTF-8">')
|
||||||
print('<link href="/style.css" rel="stylesheet">')
|
print('<link href="/style.css" rel="stylesheet">')
|
||||||
print('<meta http-equiv="refresh" content="0; url=%s">' % ref)
|
print('<meta http-equiv="refresh" content="0; url=%s">' % ref)
|
||||||
else:
|
|
||||||
login_page("error")
|
|
||||||
break
|
break
|
||||||
|
login_page("error")
|
||||||
|
|
||||||
funct.footer()
|
funct.footer()
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ serv = form.getvalue('serv')
|
||||||
|
|
||||||
funct.head("HAproxy Logs")
|
funct.head("HAproxy Logs")
|
||||||
funct.check_config()
|
funct.check_config()
|
||||||
|
funct.check_login("config.py")
|
||||||
|
|
||||||
path_config = "haproxy-webintarface.config"
|
path_config = "haproxy-webintarface.config"
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@ -70,6 +71,6 @@ if form.getvalue('serv') is not None:
|
||||||
commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ]
|
commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ]
|
||||||
syslog_server = config.get('logs', 'syslog_server')
|
syslog_server = config.get('logs', 'syslog_server')
|
||||||
|
|
||||||
funct.ssh_command(syslog_server, commands)
|
funct.ssh_command(syslog_server, commands, show_log="show_log")
|
||||||
|
|
||||||
funct.footer()
|
funct.footer()
|
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import html
|
||||||
|
import cgi
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import funct
|
||||||
|
options = [ "acl", "http-request", "http-response", "set-uri", "set-url", "set-header", "add-header", "del-header", "replace-header", "path_beg", "url_beg()", "urlp_sub()", "tcpka", "tcplog", "forwardfor", "option" ]
|
||||||
|
|
||||||
|
form = cgi.FieldStorage()
|
||||||
|
req = form.getvalue('req')
|
||||||
|
serv = form.getvalue('serv')
|
||||||
|
print('Content-type: text/html\n')
|
||||||
|
#print('Content-type: application/json\n')
|
||||||
|
|
||||||
|
if req is not None:
|
||||||
|
if req is 1:
|
||||||
|
for i in options:
|
||||||
|
if req in i:
|
||||||
|
print(i)
|
||||||
|
else:
|
||||||
|
for i in options:
|
||||||
|
print(i)
|
||||||
|
|
||||||
|
backend = form.getvalue('backend')
|
||||||
|
if backend is not None:
|
||||||
|
|
||||||
|
cmd='echo "show backend" |nc %s 1999' % serv
|
||||||
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, universal_newlines=True)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
output = stdout.splitlines()
|
||||||
|
|
||||||
|
for line in output:
|
||||||
|
if "#" in line or "stats" in line:
|
||||||
|
continue
|
||||||
|
if backend != "1":
|
||||||
|
if backend in line:
|
||||||
|
print(json.dumps(line))
|
||||||
|
continue
|
||||||
|
if backend == "1":
|
||||||
|
print(json.dumps(line))
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
if form.getvalue('ip') is not None and serv is not None:
|
||||||
|
commands = [ "ip a |grep inet |egrep -v '::1' |awk '{ print $2 }' |awk -F'/' '{ print $1 }'" ]
|
||||||
|
funct.ssh_command(serv, commands, ip="ip")
|
||||||
|
|
||||||
|
if form.getvalue('name') is not None:
|
||||||
|
name = form.getvalue('name')
|
||||||
|
conf = open("/home/ploginov/haproxy/cgi-bin/hap_config/test.cfg", "r")
|
||||||
|
s = form.getvalue('s')
|
||||||
|
for line in conf:
|
||||||
|
#print(line)
|
||||||
|
if s in line and name in line:
|
||||||
|
# print(line)
|
||||||
|
print("yes")
|
||||||
|
break
|
|
@ -1 +1,2 @@
|
||||||
{ "firstName": "admin", "lastName": "admin", "login": "admin", "password": "admin" }
|
{ "firstName": "admin", "lastName": "admin", "login": "admin", "password": "admin", "role": "admin" }
|
||||||
|
{ "firstName": "Guest", "lastName": "Guest", "login": "Guest", "password": "Guest@123", "role": "guest" }
|
||||||
|
|
|
@ -8,6 +8,7 @@ import configparser
|
||||||
from requests_toolbelt.utils import dump
|
from requests_toolbelt.utils import dump
|
||||||
|
|
||||||
funct.check_config()
|
funct.check_config()
|
||||||
|
funct.check_login("config.py")
|
||||||
|
|
||||||
path_config = "haproxy-webintarface.config"
|
path_config = "haproxy-webintarface.config"
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
|
|
@ -6,7 +6,7 @@ server_port = 8000
|
||||||
log_path = %(fullpath)s/log/
|
log_path = %(fullpath)s/log/
|
||||||
time_zone = UTC
|
time_zone = UTC
|
||||||
#Enable logo on top menu. Default disable
|
#Enable logo on top menu. Default disable
|
||||||
logo_enable = 1
|
logo_enable = 0
|
||||||
logo_path = /logo.png
|
logo_path = /logo.png
|
||||||
|
|
||||||
[configs]
|
[configs]
|
||||||
|
@ -36,5 +36,7 @@ user = admin
|
||||||
password = password
|
password = password
|
||||||
stats_port = 8085
|
stats_port = 8085
|
||||||
haproxy_config_path = /etc/haproxy/haproxy.cfg
|
haproxy_config_path = /etc/haproxy/haproxy.cfg
|
||||||
|
#Temp store configs, for haproxy check
|
||||||
|
tmp_config_path = /tmp
|
||||||
#Time in seconds for auto refresh view stats_port
|
#Time in seconds for auto refresh view stats_port
|
||||||
refresh_time = 30
|
refresh_time = 120
|
|
@ -2,7 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>HAProxy monitoryng</title>
|
<title>HAProxy web manager</title>
|
||||||
<link href="/favicon.ico" rel="icon" type="image/x-icon" />
|
<link href="/favicon.ico" rel="icon" type="image/x-icon" />
|
||||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
|
||||||
<link href="style.css" rel="stylesheet">
|
<link href="style.css" rel="stylesheet">
|
||||||
|
@ -17,6 +17,7 @@
|
||||||
<a href="cgi-bin/logs.py" title="View logs">Logs</a> <br />
|
<a href="cgi-bin/logs.py" title="View logs">Logs</a> <br />
|
||||||
<a href="cgi-bin/diff.py" title="Compare Configs">Compare</a> <br />
|
<a href="cgi-bin/diff.py" title="Compare Configs">Compare</a> <br />
|
||||||
<a href="cgi-bin/configshow.py" title="Show Config">Show</a> <br />
|
<a href="cgi-bin/configshow.py" title="Show Config">Show</a> <br />
|
||||||
|
<a href=/cgi-bin/add.py title="Add single listen/frontend/backend">Add</a> <br />
|
||||||
<a href="cgi-bin/config.py" title="Edit settings">Edit config</a> <br />
|
<a href="cgi-bin/config.py" title="Edit settings">Edit config</a> <br />
|
||||||
<a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br />
|
<a href="cgi-bin/configver.py" title="Upload old config">Upload old config</a> <br />
|
||||||
<div class="copyright">
|
<div class="copyright">
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
$( function() {
|
||||||
|
$( "#tabs" ).tabs();
|
||||||
|
$( "#redirectBackend" ).on( "click", function() {
|
||||||
|
$( "#tabs" ).tabs( "option", "active", 2 );
|
||||||
|
} );
|
||||||
|
$( "select" ).selectmenu();
|
||||||
|
$( document ).tooltip();
|
||||||
|
$( "input[type=submit], button" ).button();
|
||||||
|
} );
|
||||||
|
|
||||||
|
$( function() {
|
||||||
|
var availableTags = [
|
||||||
|
"acl", "http-request", "http-response", "set-uri", "set-url", "set-header", "add-header", "del-header", "replace-header", "path_beg", "url_beg()", "urlp_sub()", "tcpka", "tcplog", "forwardfor", "option"
|
||||||
|
];
|
||||||
|
|
||||||
|
$( "#ip" ).autocomplete({
|
||||||
|
source: function( request, response ) {
|
||||||
|
if ( request.term == "" ) {
|
||||||
|
request.term = 1
|
||||||
|
}
|
||||||
|
$.ajax( {
|
||||||
|
url: "options.py",
|
||||||
|
data: {
|
||||||
|
ip: request.term,
|
||||||
|
serv: $("#serv").val()
|
||||||
|
},
|
||||||
|
success: function( data ) {
|
||||||
|
response(data.split("\n"));
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
autoFocus: true,
|
||||||
|
minLength: -1
|
||||||
|
});
|
||||||
|
$( "#ip1" ).autocomplete({
|
||||||
|
source: function( request, response ) {
|
||||||
|
if ( request.term == "" ) {
|
||||||
|
request.term = 1
|
||||||
|
}
|
||||||
|
$.ajax( {
|
||||||
|
url: "options.py",
|
||||||
|
data: {
|
||||||
|
ip: request.term,
|
||||||
|
serv: $("#serv").val()
|
||||||
|
},
|
||||||
|
success: function( data ) {
|
||||||
|
response(data.split("\n"));
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
autoFocus: true,
|
||||||
|
minLength: -1
|
||||||
|
});
|
||||||
|
$( "#backends" ).autocomplete({
|
||||||
|
source: function( request, response ) {
|
||||||
|
if ( request.term == "" ) {
|
||||||
|
request.term = 1
|
||||||
|
}
|
||||||
|
$.ajax( {
|
||||||
|
url: "options.py",
|
||||||
|
data: {
|
||||||
|
backend: request.term,
|
||||||
|
serv: $("#serv2").val()
|
||||||
|
},
|
||||||
|
success: function( data ) {
|
||||||
|
response(data.split('"'));
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
},
|
||||||
|
autoFocus: true,
|
||||||
|
minLength: -1
|
||||||
|
});
|
||||||
|
$( "#options" ).autocomplete({
|
||||||
|
source: availableTags,
|
||||||
|
autoFocus: true,
|
||||||
|
minLength: -1,
|
||||||
|
select: function( event, ui ) {
|
||||||
|
$("#optionsInput").append(ui.item.value + " ");
|
||||||
|
$("#options").empty();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$( "#options1" ).autocomplete({
|
||||||
|
source: availableTags,
|
||||||
|
autoFocus: true,
|
||||||
|
minLength: -1,
|
||||||
|
select: function( event, ui ) {
|
||||||
|
$("#optionsInput1").append(ui.item.value + " ");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$( "#options2" ).autocomplete({
|
||||||
|
source: availableTags,
|
||||||
|
autoFocus: true,
|
||||||
|
minLength: -1,
|
||||||
|
select: function( event, ui ) {
|
||||||
|
$("#optionsInput2").append(ui.item.value + " ")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} );
|
24
style.css
24
style.css
|
@ -119,6 +119,30 @@ body {
|
||||||
.comment {
|
.comment {
|
||||||
color: #aaa;
|
color: #aaa;
|
||||||
}
|
}
|
||||||
|
.addName {
|
||||||
|
background-color: #eee;
|
||||||
|
width: 120px;
|
||||||
|
}
|
||||||
|
.addOption, .addName {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
.addButton {
|
||||||
|
padding-top: 15px;
|
||||||
|
}
|
||||||
|
.addSuc {
|
||||||
|
padding-left: 20px;
|
||||||
|
padding-top: 20px;
|
||||||
|
color: #23527c;
|
||||||
|
}
|
||||||
|
.tooltip {
|
||||||
|
font-size: 12px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
.tooltipTop {
|
||||||
|
margin-bottom: -20px;
|
||||||
|
padding-top: 10px;
|
||||||
|
}
|
||||||
.footer {
|
.footer {
|
||||||
background-color: #222;
|
background-color: #222;
|
||||||
min-height: 50px;
|
min-height: 50px;
|
||||||
|
|
Loading…
Reference in New Issue