1.  Improved appearance, for more visual output of configs and logs
2. Was add jQuery
3. Code is improved
pull/19/head v1.3
Aidaho12 2018-01-22 09:55:07 +06:00
parent 60a0f5db33
commit fe0026077a
11 changed files with 194 additions and 57 deletions

1
.gitignore vendored
View File

@ -99,3 +99,4 @@ ENV/
# mypy
.mypy_cache/
cgi-bin/hap_config/172.28.5.5-2018-01-10.13\:56\:02.cfg

View File

@ -34,12 +34,12 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
print('<form action="diff.py#diff" method="get">')
print('<center><h3><span style="padding: 75px;">Choose left</span><span style="padding: 100px;">Choose right</span></h3>')
print('<p><select autofocus required name="left">')
print('<p><select autofocus required name="left" id="left">')
print('<option disabled selected>Choose version</option>')
os.chdir(hap_configs_dir)
for files in glob.glob('*.cfg'):
for files in sorted(glob.glob('*.cfg')):
ip = files.split("-")
if serv == ip[0]:
if left == files:
@ -50,10 +50,10 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
print('</select>')
print('<select autofocus required name="right">')
print('<select autofocus required name="right" id="right">')
print('<option disabled selected>Choose version</option>')
for files in glob.glob('*.cfg'):
for files in sorted(glob.glob('*.cfg')):
ip = files.split("-")
if serv == ip[0]:
if right == files:
@ -65,13 +65,11 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
print('</select>')
print('<input type="hidden" value="%s" name="serv">' % serv)
print('<input type="hidden" value="open" name="open">')
print('<p><button type="submit" value="Compare" name="Compare">Compare</button></p></form>')
print('<p><button type="submit" value="Compare" name="Compare">Compare</button></p></form></center>')
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) ]
funct.ssh_command(haproxy_configs_server, commands)
print('<h3><a href="#top" title="UP">UP</a></center>')
funct.footer()

View File

@ -22,7 +22,7 @@ if login is None:
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('<form action="edit.py" method="get">')
print('<p><select autofocus required name="serv">')
print('<p><select autofocus required name="serv" id="serv">')
print('<option disabled selected>Choose server</option>')
funct.choose_server_with_vip(serv)
@ -48,7 +48,7 @@ else:
selected3 = ''
print('</select>')
print('<select autofocus required name="servaction">')
print('<select autofocus required name="servaction" id="chooseServer">')
print('<option disabled selected>Choose action</option>')
print('<option value=1 %s>Disable server</option>' % selected1)
print('<option value=2 %s>Enable server</option>' % selected2)

View File

@ -12,8 +12,7 @@ def check_config():
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
config.read(path_config)
for section in [ 'main', 'configs', 'ssh', 'logs', 'haproxy' ]:
if not config.has_section(section):
print('<b style="color: red">Check config file, no %s section</b>' % section)
@ -56,18 +55,43 @@ def links():
print('<a href=/cgi-bin/configver.py title="Upload old config" style="size:5">Upload old</a>')
def head(title):
print("Content-type: text/html\n")
print('Content-type: text/html\n')
print('<html><head><title>%s</title>' % title)
print('<link href="/favicon.ico" rel="icon" type="image/png" />')
print('<link href="/style.css" rel="stylesheet"><meta charset="UTF-8"></head><body>')
print('<a name="top"></a>')
print('<div class="top-menu"><div class="top-link">')
print('<link href="/favicon.ico" rel="icon" type="image/png" />'
'<link href="/style.css" rel="stylesheet"><meta charset="UTF-8">'
'<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/ui/1.12.1/jquery-ui.js"></script>'
'</head>'
'<body>'
'<script>'
'$( function() {'
'$( "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":
print('<img src="%s" title="Logo" class="logo">' % config.get('main', 'logo_path'))
print('<div class="top-link">')
links()
print('</div></div><div class="conteiner">')
def footer():
print('<center><h3><a href="#top" title="UP">UP</a></center>')
print('</center></div><div class="footer"><div class="footer-link">')
print('<center>'
'<h3>'
'<a href="#top" title="UP">UP</a>'
'</h3>'
'</center>'
'</center></div>'
'<div class="footer">'
'<div class="footer-link">')
links()
print('</div></div></body></html>')
@ -111,9 +135,9 @@ def show_config(cfg):
print('</span>' + line + '</div>')
continue
if "#" in line:
print('<div class="comment">')
print('<div class="comment"><span class="numRow">')
print(i)
print(line + '</div>')
print(line + '</span></div>')
continue
print('<div class="configLine"><span class="numRow">')
print(i)
@ -143,7 +167,7 @@ def upload_and_restart(serv, cfg):
print(stderr.read().decode(encoding='UTF-8'))
print("</br>")
ssh.close()
def ssh_command(serv, commands):
ssh = SSHClient()
ssh.load_system_host_keys()
@ -154,21 +178,44 @@ def ssh_command(serv, commands):
for command in commands:
stdin , stdout, stderr = ssh.exec_command(command)
print('</center><div class="out">')
i = 1
if serv == haproxy_configs_server:
print('<div class="diff">')
i = 0
minus = 0
plus = 0
for line in stdout:
i = i + 1
if i % 2 == 0:
print('<div class="line">' + line + '</div>')
if serv == haproxy_configs_server:
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>')
elif i % 2 == 0:
print('<div class="line3">' + line + '</div>')
else:
print('<div class="line2">' + line + '</div>')
print('</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(stderr.read().decode(encoding='UTF-8'))
ssh.close()
def chooseServer(formName, title, note):
print('<center><h2>' + title + '</h2>')
print('<h3>Choose server</h3>')
print('<form action=' + formName + ' method="get">')
print('<p><select autofocus required name="serv">')
print('<p><select autofocus required name="serv" id="chooseServer">')
print('<option disabled>Choose server</option>')
form = cgi.FieldStorage()
@ -186,7 +233,7 @@ def chooseServer(formName, title, note):
print('</select>')
print('<p><button type="submit" value="open" name="open">Open</button></p></form>')
if note == "y":
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p><br />')
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p>')
def choose_server_with_vip(serv):
import listserv as listhap

View File

@ -1,7 +1,10 @@
listhap= {
'haproxy1': '172.28.0.1',
'haproxy2': '172.28.0.2'
'kz-webhap01': '172.28.9.159',
'kz-webhap02': '172.28.9.160',
'kz-mysqlhap01': '172.28.5.6',
'kz-mysqlhap02': '172.28.5.5',
}
list_hap_vip = {
'haproxy-vip': '172.28.0.3'
'kz-webhap-vip': '172.28.9.161',
'kz-mysqlhap-vip': '172.28.5.17'
}

View File

@ -27,13 +27,13 @@ def login_page(error):
funct.head("Login page")
print('<center><div class="conteiner"><form name="auth" action="login.py" class="form-horizontal" method="post">')
print('<center><form name="auth" action="login.py" class="form-horizontal" method="post">')
print(printError)
print('<label for="login"> Login: </label> <input type="text" name="login" class="form-control">')
print('<label for="pass"> Pass: </label> <input type="password" name="pass" class="form-control">')
print('<input type="hidden" value="%s" name="ref">' % ref)
print('<button type="submit" name="Login" value="Enter">Sign</button>')
print('</form></div></center>')
print('<button type="submit" name="Login" value="Enter">Sign Up</button>')
print('</form></center>')
if login is None:
login_page("n")

View File

@ -20,7 +20,7 @@ config.read(path_config)
print('<center><h2>HAproxy Logs</h2></center>')
print('<center><h3>Choose server & number rows</h3>')
print('<form action="logs.py" method="get">')
print('<p><select autofocus required name="serv">')
print('<p><select autofocus required name="serv" id="serv">')
print('<option disabled>Choose server</option>')
for i in sorted(listhap.listhap):

View File

@ -24,7 +24,7 @@ serv = form.getvalue('serv')
if serv is None:
first_serv = list(listhap.list_hap_vip.values())
serv = first_serv[0]
try:
response = requests.get('http://%s:%s/stats' % (serv, stats_port), auth=(haproxy_user, haproxy_pass))
except requests.exceptions.ConnectTimeout:
@ -33,6 +33,7 @@ except requests.exceptions.ReadTimeout:
print('Oops. Read timeout occured')
print("Content-type: text/html\n")
print('<meta http-equiv="refresh" content="%s; url=viewsttats.py?serv=%s">' % (config.get('haproxy', 'refresh_time') ,serv))
for i in listhap.listhap:
if listhap.listhap.get(i) == serv:

View File

@ -3,13 +3,15 @@
fullpath = /opt/haproxy/
server_bind_ip = 0.0.0.0
server_port = 8000
#Log for server.py
log_path = %(fullpath)s/log/
time_zone = UTC
#Enable logo on top menu. Default disable
logo_enable = 1
logo_path = /logo.png
[configs]
#Server for save configs from HAproxy servers
haproxy_configs_server =
haproxy_configs_server = kz-web14
#Dir where configs will be save
haproxy_save_configs_dir = /opt/haproxy/cgi-bin/hap_config/
@ -20,9 +22,9 @@ ssh_keys = /opt/haproxy/cgi-bin/id_rsa.pem
ssh_user_name = root
[logs]
#Logs save localy, disable by default
#Logs save locally, disable by default
local_path_logs = /var/log/haproxy.log
#
#If exist syslog server for HAproxy logs
syslog_server_enable = enable
syslog_server = 172.28.5.112
@ -34,3 +36,5 @@ user = admin
password = password
stats_port = 8085
haproxy_config_path = /etc/haproxy/haproxy.cfg
#Time in seconds for auto refresh view stats_port
refresh_time = 30

View File

@ -8,17 +8,21 @@
<link href="style.css" rel="stylesheet">
</head>
<body>
<center>
<h2>Welcome! HAproxy Web intarface</h2>
<h3>Choose your destiny!</h3>
<a href="cgi-bin/viewsttats.py" title="View stats">View stats</a> <br />
<a href="cgi-bin/edit.py" title="Edit settings">Edit settings</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/configshow.py" title="Show Config">Show</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 />
</center>
<center>
<div class="conteinerIndex">
<h2>Welcome! HAproxy Web Intarface</h2>
<h3>Choose your destiny!</h3>
<a href="cgi-bin/viewsttats.py" title="View stats">View stats</a> <br />
<a href="cgi-bin/edit.py" title="Edit settings">Edit settings</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/configshow.py" title="Show Config">Show</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 />
<div class="copyright">
HAproxy Web Interface v1.3
</div>
</div>
</center>
</body>
</html>

View File

@ -6,7 +6,7 @@ body {
font-size: 14px;
line-height: 1.42857143;
color: #000;
background-color: #fff;
background-color: #eee;
margin: 0;
padding: 0;
}
@ -18,6 +18,12 @@ body {
position: fixed;
right: 0;
left: 0;
z-index: 1000;
}
.top-menu img {
max-width: 125px;
float: left;
padding-left: 100px;
}
.top-menu a, .footer a {
padding: 10px;
@ -39,9 +45,79 @@ body {
margin-left: 35%;
}
.conteiner {
clear: both;
margin-top: 65px;
min-height: calc(100vh - 115px);
clear: both;
margin-top: 65px;
min-height: calc(100vh - 115px);
width: 45%;
background-color: #fff;
margin-left: 27%;
}
.configShow, .diff {
margin-left: 16%;
height: 70%;
overflow: auto;
width: 70%;
border: 1px solid #DCDCDC;
border-radius: 5px;
}
.diffHead {
background-color: #F5F5F5;
padding: 10px;
}
.lineDog {
background-color: #dbedff;
margin-bottom: 10px;
}
.lineDiffMinus, .lineDiffPlus {
padding-left: 5px;
}
.lineDiffMinus {
background-color: #ffdce0;
}
.lineDiffPlus {
background-color: #cdffd8;
}
.lineDiff {
padding-left: 5px;
}
.param {
font-weight: bold;
background-color: #DCDCDC;
padding-left: 13px;
}
.numRow {
padding-left: 10px;
padding-right: 20px;
}
.paramInSec {
font-weight: bold;
}
.conteinerIndex {
width: 20%;
background-color: #fff;
padding: 20px;
border-radius: 10px;
margin-top: 2%;
}
.conteinerIndex img {
max-width: 250px;
}
.copyright {
color: #23527c;
margin-left: 15px;
}
.line {
background-color: #eee;
border: 1px solid #000;
}
.line, .line3 {
padding-top:5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
}
.comment {
color: #aaa;
}
.footer {
background-color: #222;
@ -118,7 +194,9 @@ input::-moz-focus-inner {
border: 0;
}
input {
line-height: normal;
line-height: normal;
border-radius: 4px;
padding: 4px;
}
fieldset {
@ -174,6 +252,7 @@ a:focus {
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.container-fluid {
padding-right: 15px;
padding-left: 15px;