Overvoew and config show
pull/19/head
Aidaho12 2018-02-10 19:35:48 +06:00
parent bc5bd94467
commit 9896fb1464
9 changed files with 123 additions and 81 deletions

View File

@ -42,6 +42,6 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
funct.show_config(cfg)
os.system("/bin/sudo /bin/rm -f " + cfg)
os.system("/bin/rm -f " + cfg)
funct.footer()

View File

@ -59,7 +59,7 @@ print('<option value=1 %s>Disable server</option>' % selected1)
print('<option value=2 %s>Enable server</option>' % selected2)
print('<option value=3 %s>Show</option>' % selected3)
print('</select></td>')
print('<td><input type="text" name="servbackend" size=40 placeholder="Backend/Server, show info, pools or help" required>')
print('<td><input type="text" name="servbackend" size=40 placeholder="Backend/Server, show info, pools or help" required class="form-control">')
print('</td></tr>'
'<tr style="border:none;">'

View File

@ -125,7 +125,8 @@ def head(title):
print('Content-type: text/html\n')
print('<html><head><title>%s</title>' % title)
print('<link href="/favicon.ico" rel="icon" type="image/png" />'
'<link href="/style.css" rel="stylesheet"><meta charset="UTF-8">'
'<meta charset="UTF-8">'
'<link href="/style.css" rel="stylesheet">'
'<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>'
@ -142,12 +143,12 @@ def head(title):
print('</div></div><div class="conteiner">')
def footer():
print('<center>'
print('</center></div>'
'<center>'
'<h3>'
'<a href="#top" title="UP">UP</a>'
'</h3>'
'</center>'
'</center></div>'
'<div class="footer">'
'<div class="footer-link">'
'<span class="LogoText">HAproxy-WI</span>'
@ -186,40 +187,42 @@ def get_config(serv, cfg):
print("!!! There was an issue, " + str(e))
def show_config(cfg):
print('</center><div class="configShow">')
print('</center><div style="margin-left: 16%" class="configShow">')
conf = open(cfg, "r")
i = 0
for line in conf:
i = i + 1
if not line.find("global"):
print('<div class="param">' + line + '</div>')
print('<span class="param">' + line + '</span><div>')
continue
if not line.find("defaults"):
print('<div class="param">' + line + '</div>')
print('</div><span class="param">' + line + '</span><div>')
continue
if not line.find("listen"):
print('<div class="param">' + line + '</div>')
print('</div><span class="param">' + line + '</span><div>')
continue
if not line.find("frontend"):
print('<div class="param">' + line + '</div>')
print('</div><span class="param">' + line + '</span><div>')
continue
if not line.find("backend"):
print('<div class="param">' + line + '</div>')
print('</div><span class="param">' + line + '</span><div>')
continue
if "acl" in line or "option" in line or "server" in line:
print('<div class="paramInSec"><span class="numRow">')
print('<span class="paramInSec"><span class="numRow">')
print(i)
print('</span>' + line + '</div>')
print('</span>' + line + '</span><br />')
continue
if "#" in line:
print('<div class="comment"><span class="numRow">')
print('<span class="comment"><span class="numRow">')
print(i)
print(line + '</span></div>')
continue
print('<div class="configLine"><span class="numRow">')
print(line + '</span></span><br />')
continue
if line.__len__() < 1:
print('</div>')
print('<span class="configLine"><span class="numRow">')
print(i)
print('</span>' + line + '</div>')
print('</div>')
print('</span>' + line + '</span><br />')
print('</div></div>')
conf.close
def upload_and_restart(serv, cfg):
@ -289,6 +292,7 @@ def compare(stdout):
print('</div></div>')
def show_log(stdout):
#print('<input id="serv" value="%s" hidden><button id="stop" value="tailf_stop">Stop</button>' % serv)
i = 0
for line in stdout:
i = i + 1
@ -296,6 +300,21 @@ def show_log(stdout):
print('<div class="line3">' + line + '</div>')
else:
print('<div class="line">' + line + '</div>')
def show_log_tailf(channel, serv):
import select
print('<input id="serv" value="%s" hidden><button id="stop" value="tailf_stop">Stop</button>' % serv)
print('<pre>')
while 1:
rl, wl, xl = select.select([channel],[],[],0.0)
if len(rl) > 0:
print(channel.recv(200).decode(encoding='UTF-8'))
print('<input id="serv" value="%s" hidden><button id="stop" value="tailf_stop">Stop</button>' % serv)
#i = i + 1
#if i % 2 == 0:
# print('<div class="line3">' + line + '</div>')
#else:
# print('<div class="line">' + line + '</div>')
def show_ip(stdout):
for line in stdout:
@ -309,7 +328,14 @@ def server_status(stdout):
def ssh_command(serv, commands, **kwargs):
ssh = ssh_connect(serv)
if kwargs.get("tailf") == "1":
transport = ssh.get_transport()
channel = transport.open_session()
channel.exec_command('tail -f /var/log/haproxy.log')
show_log_tailf(channel, serv)
for command in commands:
try:
stdin, stdout, stderr = ssh.exec_command(command)
@ -325,7 +351,7 @@ def ssh_command(serv, commands, **kwargs):
if kwargs.get("server_status") == "1":
server_status(stdout)
else:
print(stdout.read().decode(encoding='UTF-8'))
print('<div style="margin: -10px;">'+stdout.read().decode(encoding='UTF-8')+'</div>')
print(stderr.read().decode(encoding='UTF-8'))

View File

@ -54,10 +54,10 @@ else:
if form.getvalue('grep') is not None:
grep = 'value='+form.getvalue('grep')
else:
grep = 'value='
grep = ' '
print('</td><td><input type="text" name="rows" %s required></td>' % rows)
print('<td><input type="text" name="grep" %s>' % grep)
print('</td><td><input type="text" name="rows" %s class="form-control" required></td>' % rows)
print('<td><input type="text" name="grep" class="form-control" %s >' % grep)
print('</td></tr>'
'<tr style="border:none;">'
'<th style="border:none;">'
@ -86,6 +86,6 @@ if form.getvalue('serv') is not None:
commands = [ 'sudo tail -%s /var/log/%s/syslog.log %s %s' % (rows, serv, grep_act, grep) ]
syslog_server = config.get('logs', 'syslog_server')
funct.ssh_command(syslog_server, commands, show_log="1")
funct.ssh_command(syslog_server, commands, show_log="1", tailf="0")
funct.footer()

View File

@ -53,3 +53,8 @@ if form.getvalue('name') is not None:
if s in line and name in line:
print("yes")
break
if form.getvalue('tailf_stop') is not None:
serv = form.getvalue('serv')
commands = [ "ps ax |grep python3 |grep -v grep |awk '{ print $1 }' |xargs kill" ]
funct.ssh_command(serv, commands)

View File

@ -17,19 +17,37 @@ print('<h2>Quick Status </h2><table class="overview">')
commands = [ "ps -Af |grep [h]aproxy |wc -l" ]
print('<tr class="overviewHead"><td class="padding10">Server</td><td class="padding10">HAproxy status</td></tr>')
print('<tr class="overviewHead">'
'<td class="padding10">Server</td>'
'<td class="padding10">'
'HAproxy status'
'<span style="float: right; margin-left: 80&;">'
'<a href="" title="Update status" id="update">'
'<img alt="Update" src="/image/pic/update.png" style="max-width: 20px;">'
'</a>'
'</td>'
'</tr>')
for i in sorted(listhap.listhap):
print('<tr><td class="padding10">' + i + '</td><td>')
funct.ssh_command(listhap.listhap.get(i), commands, server_status="1")
print('</td></tr>')
print('<tr class="overviewHead"><td class="padding10">Server</td><td class="padding10">Server status</td></tr>')
print('<tr class="overviewHead">'
'<td class="padding10">Server</td>'
'<td class="padding10">'
'Server status'
'<span style="float: right; margin-left: 80&;">'
'<a href="" title="Update status" id="update">'
'<img alt="Update" src="/image/pic/update.png" style="max-width: 20px;">'
'</a>'
'</td>'
'</tr>')
print('</td></tr>')
commands = [ "cat /etc/haproxy/haproxy.cfg |grep -E '^listen|^backend|^frontend' |grep -v stats |wc -l", "haproxy -v |head -1", "top -u haproxy -b -n 1" ]
commands = [ "cat /etc/haproxy/haproxy.cfg |grep -E '^listen|^backend|^frontend' |grep -v stats |wc -l", "uname -smor", "haproxy -v |head -1", "top -u haproxy -b -n 1" ]
for i in sorted(listhap.listhap):
print('<tr><td class="overviewTr"><h3 title="IP ' + listhap.listhap.get(i) + '">' + i + ':</h3></td>')
print('<td class="overviewTd">Total listen/frontend/backend:<pre>')
print('<td class="overviewTd"><span style="margin-left: -10px;">Total listen/frontend/backend:</span><pre>')
funct.ssh_command(listhap.listhap.get(i), commands)
print('</pre></td></tr>')
print("</table>")
print('</table>')
funct.footer()

BIN
image/pic/update.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

View File

@ -7,6 +7,11 @@ $( function() {
//$( document ).tooltip();
$( "input[type=submit], button" ).button();
$( "input[type=checkbox]" ).checkboxradio();
$( ".configShow" ).accordion({
collapsible: true,
heightStyle: "content",
icons: { "header": "ui-icon-plus", "activeHeader": "ui-icon-minus" }
});
} );
$( function() {

View File

@ -26,6 +26,9 @@ h3 {
form {
margin: 0;
}
iframe {
width: 33%;
}
.top-menu {
background-color: #222;
min-height: 50px;
@ -104,7 +107,7 @@ form {
}
.param {
font-weight: bold;
background-color: #DCDCDC;
//background-color: #DCDCDC;
padding-left: 13px;
}
.numRow {
@ -261,11 +264,41 @@ form {
.menu li:hover li{
display: block;
}
@keyframes shadow {
from {box-shadow: 0px 0px 0px red inset;}
50% {text-shadow: 0 0 30px black;}
to {box-shadow: 0 -5px 5px -5px rgb(38, 137, 60) inset}
}
@keyframes shadow-red {
from {box-shadow: 0px 0px 0px red inset;}
50% {text-shadow: 0 0 30px black;}
to {box-shadow: 0 -5px 5px -5px #5D9CEB inset}
}
//.form-control:valid {
// animation: shadow 0.3s forwards;
//}
.form-control:hover {
animation: shadow-red 0.3s forwards;
}
.form-control:invalid, .form-control:valid {
background-image: linear-gradient(0deg,#d50000 2px,rgba(213,0,0,0) 0),linear-gradient(0deg,rgba(0,0,0,.26) 1px,transparent 0);
}
.form-control {
background: no-repeat bottom,50% calc(100% - 1px);
background-size: 0 100%,100% 100%;
border: 0;
transition: background 1s ease-out;
padding-left: 0;
padding-right: 0;
}
.ui-state-default {
background-color: #EBF1F1;
}
a {
background-color: transparent;
}
a:active,
a:hover {
a:active, a:hover {
outline: 0;
}
abbr[title] {
@ -283,9 +316,8 @@ textarea {
margin: 0;
font: inherit;
color: inherit;
//background-color: #ccc;
border-radius: 7px;
padding: 5px;
padding: 8px;
}
button {
overflow: visible;
@ -293,9 +325,6 @@ button {
button,
select {
text-transform: none;
//background-color: #eee;
}
select {
color: #000;
@ -324,28 +353,17 @@ input::-moz-focus-inner {
input {
line-height: normal;
border-radius: 4px;
padding: 4px;
}
fieldset {
padding: .35em .625em .75em;
margin: 0 2px;
border: 1px solid #c0c0c0;
}
legend {
padding: 0;
border: 0;
}
optgroup {
font-weight: bold;
}
table {
border-spacing: 0;
border-collapse: collapse;
background-color: transparent;
}
td,
th {
padding: 0;
text-align: left;
}
a,
a:visited {
@ -381,36 +399,6 @@ a:focus {
margin-left: -15px;
}
table {
background-color: transparent;
}
caption {
padding-top: 8px;
padding-bottom: 8px;
color: #777;
text-align: left;
}
th {
text-align: left;
}
fieldset {
min-width: 0;
padding: 0;
margin: 0;
border: 0;
}
legend {
display: block;
width: 100%;
padding: 0;
margin-bottom: 20px;
font-size: 21px;
line-height: inherit;
color: #333;
border: 0;
border-bottom: 1px solid #e5e5e5;
}
label {
display: inline-block;
max-width: 100%;