Add overview, change menu style
pull/19/head
Aidaho12 2018-02-06 10:39:43 +06:00
parent d9e6480169
commit 5d12901a5b
7 changed files with 161 additions and 48 deletions

View File

@ -41,7 +41,7 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
conf = open(cfg, "r") conf = open(cfg, "r")
print('<a name="conf"></a>') print('<a name="conf"></a>')
print("<h3>Config from %s</h3>" % serv) print("<h3>Config from %s</h3>" % serv)
print('<form action="config.py#top" method="get">') print('<form action="config.py#top" method="post">')
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())
@ -70,6 +70,6 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None :
os.system("/bin/diff -ub %s %s >> %slog/config_edit.log" % (oldcfg, cfg, fullpath)) os.system("/bin/diff -ub %s %s >> %slog/config_edit.log" % (oldcfg, cfg, fullpath))
os.system("/bin/sudo /bin/rm -f " + hap_configs_dir + "*.old") os.system("/bin/sudo /bin/rm -f " + hap_configs_dir + "*.old")
print('</br><a href="viewsttats.py" title="View stats">Go to view stats</a> <br />') print('</br><a href="viewsttats.py?serv=%s" target="_blank" title="View stats">Go to view stats</a> <br />' % serv)
funct.footer() funct.footer()

View File

@ -60,7 +60,7 @@ if serv is not None and form.getvalue('open') is not None:
funct.logging(serv, "open old config %s" % configver) funct.logging(serv, "open old config %s" % configver)
print("<h3>Config from %s, and version is: %s</h3>" % (serv, configver)) print("<h3>Config from %s, and version is: %s</h3>" % (serv, configver))
print('<form action="configver.py#conf" method="get">') print('<form action="configver.py#conf" method="post">')
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('<input type="hidden" value="1" name="config">')
@ -81,6 +81,6 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None:
funct.upload_and_restart(serv, configver) funct.upload_and_restart(serv, configver)
print('<center><br /><a href="viewsttats.py" title="View stats">Go to view stats</a> <br /></center>') print('</br><a href="viewsttats.py?serv=%s" target="_blank" title="View stats">Go to view stats</a> <br />' % serv)
funct.footer() funct.footer()

View File

@ -23,7 +23,7 @@ funct.chooseServer("delver.py#conf", "Delete Versions HAproxy config", "n")
if serv is not None and form.getvalue('open') is not None: if serv is not None and form.getvalue('open') is not None:
print('<center><h3>Choose old version</h3>') print('<center><h3>Choose old version</h3>')
print('<form action="delver.py#conf" method="get">') print('<form action="delver.py#conf" method="post">')
import glob import glob
@ -52,8 +52,8 @@ if serv is not None and form.getvalue('open') is not None:
os.remove(form.getvalue(get)) os.remove(form.getvalue(get))
print(form.getvalue(get) + "<br />") print(form.getvalue(get) + "<br />")
funct.logging(serv, "delver.py deleted config: %s" % form.getvalue(get)) funct.logging(serv, "delver.py deleted config: %s" % form.getvalue(get))
except OSError: except OSError:
print ("Error: %s - %s." % (e.filename,e.strerror)) print ("Error: %s - %s." % (e.filename,e.strerror))
print('<meta http-equiv="refresh" content="10; url=delver.py?serv=%s&open=open">' % form.getvalue('serv')) print('<meta http-equiv="refresh" content="10; url=delver.py?serv=%s&open=open">' % form.getvalue('serv'))
funct.footer() funct.footer()

View File

@ -70,9 +70,9 @@ def show_login_links():
login = cookie.get('login') login = cookie.get('login')
if login is None: if login is None:
print('<a style="margin-left: 40px;" href=/cgi-bin/login.py? title="Login" style="size:5">Login</a>') print('<li><a href=/cgi-bin/login.py? title="Login">Login</a></li>')
else: else:
print('<a style="margin-left: 40px;" href=/cgi-bin/login.py?logout=logout title="Logout" style="size:5">Logout</a>') print('<li><a href=/cgi-bin/login.py?logout=logout title="Logout">Logout</a></li>')
def mode_admin(button, **kwargs): def mode_admin(button, **kwargs):
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
@ -88,20 +88,38 @@ def mode_admin(button, **kwargs):
print('<button type="submit">%s</button>' % button) print('<button type="submit">%s</button>' % button)
def links(): def links():
print('<a href=/ title="Home Page" style="size:5">Home Page</a> ') print('<nav class="menu">'
print('<a href=/cgi-bin/viewsttats.py title="View Stats" style="size:5">Stats</a> ') '<ul>'
print('<a href="http://172.28.5.106:3000/dashboard/db/haproxy" title="Mon" target="_blanck">Monitoring</a> ') '<li><a href=/ title="Home Page" style="size:5">Home Page</a></li>'
print('<a href=/cgi-bin/logs.py title="View logs" style="size:6">Logs</a>') '<li><a href="#" title="Statistics, monitoring and logs">Stats</a>'
print('<a href=/cgi-bin/edit.py title="Edit settings" style="size:5">Edit settings</a> ') '<ul>'
print('<span style="color: #fff"> | Configs: </span>') '<li><a href=/cgi-bin/overview.py title="Server and service status"">Overview</a> </li>'
print('<a href=/cgi-bin/configshow.py title="Show Config">Show</a> ') '<li><a href=/cgi-bin/viewsttats.py title="View Stats"">Stats</a> </li>'
print('<a href=/cgi-bin/diff.py title="Compare Configs">Compare</a> ') '<li><a href="http://172.28.5.106:3000/d/000000002/haproxy?refresh=1m&orgId=1" title="Mon" target="_blanck">Monitoring</a> </li>'
print('<a href=/cgi-bin/add.py title="Add single listen/frontend/backend" style="size:5">Add</a> ') '<li><a href=/cgi-bin/logs.py title="View logs">Logs</a></li>'
print('<a href=/cgi-bin/config.py title="Edit Config" style="size:5">Edit</a> ') '</ul>'
print('<span style="color: #fff"> | Versions: </span>') '</li>'
print('<a href=/cgi-bin/configver.py title="Upload old versions configs" style="size:5">Upload</a>') '<li><a href=/cgi-bin/edit.py title="Edit settings" style="size:5">Edit settings</a> </li>'
print('<a href=/cgi-bin/delver.py title="Delete old versions configs" style="size:5">Delete</a>') '<li><a href="#">Configs</a>'
'<ul>'
'<li><a href=/cgi-bin/configshow.py title="Show Config">Show</a></li> '
'<li><a href=/cgi-bin/diff.py title="Compare Configs">Compare</a></li>'
'<li><a href=/cgi-bin/add.py#listner title="Add single listen">Add listen</a></li>'
'<li><a href=/cgi-bin/add.py#frontend title="Add single frontend">Add frontend</a></li>'
'<li><a href=/cgi-bin/add.py#backend title="Add single backend">Add backend</a></li>'
'<li><a href=/cgi-bin/config.py title="Edit Config" style="size:5">Edit</a> </li>'
'</ul>'
'</li>'
'<li><a href="#">Versions</a>'
'<ul>'
'<li><a href=/cgi-bin/configver.py title="Upload old versions configs" style="size:5">Upload</a></li>'
'<li><a href=/cgi-bin/delver.py title="Delete old versions configs" style="size:5">Delete</a></li>'
'</ul>'
'</li>')
show_login_links() show_login_links()
print('</ul>'
'</nav>')
def head(title): def head(title):
print('Content-type: text/html\n') print('Content-type: text/html\n')
@ -132,7 +150,7 @@ def footer():
'</center></div>' '</center></div>'
'<div class="footer">' '<div class="footer">'
'<div class="footer-link">') '<div class="footer-link">')
links() #links()
print('</div></div></body></html>') print('</div></div></body></html>')
def ssh_connect(serv): def ssh_connect(serv):
@ -295,6 +313,8 @@ def ssh_command(serv, commands, **kwargs):
compare(stdout) compare(stdout)
if show_log_funct is 1: if show_log_funct is 1:
show_log(stdout) show_log(stdout)
else:
print(stdout.read().decode(encoding='UTF-8'))
print(stderr.read().decode(encoding='UTF-8')) print(stderr.read().decode(encoding='UTF-8'))
ssh.close() ssh.close()

26
cgi-bin/overview.py Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python3
import html
import cgi
import funct
import configparser
import listserv as listhap
funct.head("Overview")
funct.check_config()
funct.check_login()
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
config.read(path_config)
commands = [ "top -u haproxy -b -n 1" ]
print('<h2>Quick Status </h2><table class="overview">')
for i in sorted(listhap.listhap):
print('<tr><td class="overviewTr"><h3 title="IP ' + listhap.listhap.get(i) + '">Server ' + i + ':</h3></td>')
print('<td class="overviewTd"><pre>')
funct.ssh_command(listhap.listhap.get(i), commands)
print('</pre></td></tr>')
print("</table>")
funct.footer()

View File

@ -12,9 +12,10 @@
<div class="conteinerIndex"> <div class="conteinerIndex">
<h2>Welcome! HAproxy Web Interface</h2> <h2>Welcome! HAproxy Web Interface</h2>
<h3>Choose your destiny!</h3> <h3>Choose your destiny!</h3>
<a href=/cgi-bin/overview.py title="Server and service status"">Overview</a> <br />
<a href="cgi-bin/viewsttats.py" title="View stats">View stats</a> <br /> <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/logs.py" title="View logs">Logs</a> <br />
<a href="cgi-bin/edit.py" title="Edit settings">Edit settings</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/add.py title="Add single listen/frontend/backend">Add</a> <br />
@ -22,7 +23,7 @@
<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 />
<a href="cgi-bin/delver.py" title="Upload old config">Delete old config</a> <br /> <a href="cgi-bin/delver.py" title="Upload old config">Delete old config</a> <br />
<div class="copyright"> <div class="copyright">
HAproxy Web Interface v1.6 HAproxy Web Interface v1.6.1
</div> </div>
</div> </div>
</body> </body>

110
style.css
View File

@ -10,15 +10,22 @@ body {
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
h2 {
border: 1px solid #aaa;
padding: 10px;
border-radius: 5px;
background: #aaa;
padding-left: 3%;
}
.top-menu { .top-menu {
background-color: #222; background-color: #222;
min-height: 50px; min-height: 50px;
margin-bottom: 20px; margin-bottom: 20px;
top: 0; top: 0;
position: fixed; position: fixed;
right: 0; right: 0;
left: 0; left: 0;
z-index: 1000; z-index: 1000;
} }
.logoText { .logoText {
color: #fff; color: #fff;
@ -40,26 +47,21 @@ body {
padding-left: 7px; padding-left: 7px;
padding-right: 7px; padding-right: 7px;
} }
.top-menu a:focus, .footer a:focus {
color: #000;
}
.top-menu a:hover, .footer a:hover {
color: #fff;
}
.top-menu span, .footer span {
padding-left: 20px;
}
.top-link { .top-link {
margin-top: 15px; margin-top: 15px;
margin-left: 35%; }
.top-link, .footer-link {
margin-left: 30%;
} }
.conteiner { .conteiner {
clear: both; clear: both;
margin-top: 65px; margin-top: 65px;
min-height: calc(100vh - 115px); min-height: calc(100vh - 115px);
width: 45%; max-width: 50%;
min-width: 40%;
background-color: #fff; background-color: #fff;
margin-left: 27%; margin-left: 25%;
} }
.configShow, .diff { .configShow, .diff {
margin-left: 16%; margin-left: 16%;
@ -159,13 +161,77 @@ body {
right: 0; right: 0;
left: 0; left: 0;
} }
.overview {
width: 100%;
}
.overview tr{
border: 1px solid #ddd;
border-radius: 5px;
}
.overviewTd {
padding-left: 5%;
padding-top: 20px;
border-color: #ddd;
}
.overviewTr {
margin: 0;
background-color: #eee;
padding-left: 15px;
font-size: 15px;
}
.footer-link { .footer-link {
padding-top: 15px; padding-top: 15px;
margin-left: 35%;
} }
.ro { .ro {
border: none; border: none;
} }
.menu {
margin-left: 13%;
font-weight: bold;
font-style: italic;
margin-top: -10px;
}
.menu ul li{
padding: 10px;
}
.menu ul > li:hover{
background-color: #333;
}
.menu ul ul > li:hover{
background-color: #69e;
}
.menu ul li, .menu ul{
display: inline-block;
}
.menu ul{
position: relative;
margin: 0;
padding: 0;
background-color: #222222;
}
.menu ul ul{
display: none;
position: absolute;
background-color: #007FFF;
margin-top: 10px;
margin-left: -10px;
}
.menu ul a{
color: #fff;
text-decoration: none;
}
.menu ul ul a{
color: #fff;
text-decoration: none;
}
.menu li:hover ul{
display: block;
}
.menu li:hover li{
display: block;
}
a { a {
background-color: transparent; background-color: transparent;
} }