Add function "auto-refresh" for pages: overview, logs, stats
Imptoved design
Fixed bugs
pull/19/head
Aidaho12 2018-04-08 13:33:09 +06:00
parent 761a38f2fe
commit d63b5867de
12 changed files with 352 additions and 69 deletions

View File

@ -58,9 +58,7 @@ else:
selected3 = ''
selected4 = ''
print('<center>'
'<h2>Edit & show HAproxy settings</h2>'
'</center>'
print('<h2>Runtime API</h2>'
'<table class="overview">'
'<tr class="overviewHead">'
'<td class="padding10">Server</td>'

View File

@ -112,8 +112,14 @@ 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" />'
'<script>'
'FontAwesomeConfig = { searchPseudoElements: true, observeMutations: false };'
'</script>'
'<script defer src="/inc/fa-solid.min.js"></script>'
'<script defer src="/inc/fontawesome.min.js"></script>'
'<meta charset="UTF-8">'
'<link href="/inc/style.css" rel="stylesheet">'
'<link href="/inc/awesome.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>'
@ -147,48 +153,47 @@ def head(title):
def links():
print('<nav class="menu">'
'<ul>'
'<li><a href=/ title="Home Page" style="size:5">Home Page</a></li>'
'<li><a href="#" title="Statistics, monitoring and logs">Stats</a>'
'<li><a title="Statistics, monitoring and logs" class="stats">Stats</a>'
'<ul>'
'<li><a href=/cgi-bin/overview.py title="Server and service status">Overview</a> </li>'
'<li><a href=/cgi-bin/viewsttats.py title="View Stats">Stats</a> </li>'
'<li><a href=/cgi-bin/logs.py title="View logs">Logs</a></li>'
'<li><a href=/cgi-bin/map.py title="View map">Map</a></li>'
'<li><a href=/cgi-bin/overview.py title="Server and service status" class="overview-link">Overview</a> </li>'
'<li><a href=/cgi-bin/viewsttats.py title="View Stats" class="stats">Stats</a> </li>'
'<li><a href=/cgi-bin/logs.py title="View logs" class="logs">Logs</a></li>'
'<li><a href=/cgi-bin/map.py title="View map" class="map">Map</a></li>'
'</ul>'
'</li>'
'<li><a href=/cgi-bin/edit.py title="Runtime API">Runtime API</a> </li>'
'<li><a href="#">Configs</a>'
'<li><a href=/cgi-bin/edit.py title="Runtime API" class="runtime">Runtime API</a> </li>'
'<li><a class="config-show">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/configshow.py title="Show Config" class="config-show">Show</a></li> '
'<li><a href=/cgi-bin/diff.py title="Compare Configs" class="compare">Compare</a></li>')
if is_admin(level = 1):
print('<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">Edit</a> </li>')
print('<li><a href=/cgi-bin/add.py#listner title="Add single listen" class="add">Add listen</a></li>'
'<li><a href=/cgi-bin/add.py#frontend title="Add single frontend" class="add">Add frontend</a></li>'
'<li><a href=/cgi-bin/add.py#backend title="Add single backend" class="add">Add backend</a></li>'
'<li><a href=/cgi-bin/config.py title="Edit Config" class="edit">Edit</a> </li>')
print('</ul></li>')
if is_admin(level = 1):
print('<li><a href="#">Versions</a>'
print('<li><a class="version">Versions</a>'
'<ul>'
'<li><a href=/cgi-bin/configver.py title="Upload old versions configs">Upload</a></li>')
'<li><a href=/cgi-bin/configver.py title="Upload old versions configs" class="upload">Upload</a></li>')
if is_admin():
print('<li><a href=/cgi-bin/delver.py title="Delete old versions configs">Delete</a></li>')
print('<li><a href=/cgi-bin/delver.py title="Delete old versions configs" class="delete">Delete</a></li>')
if is_admin(level = 1):
print('</ul>'
'</li>')
show_login_links()
print('</ul>'
'</nav>'
'<div class="copyright-menu">HAproxy-WI v1.10.1</div>')
'<div class="copyright-menu">HAproxy-WI v1.10.2</div>')
def show_login_links():
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
login = cookie.get('login')
if login is None:
print('<li><a href=/cgi-bin/login.py? title="Login">Login</a></li>')
print('<li><a href=/cgi-bin/login.py? title="Login" class="login">Login</a></li>')
else:
print('<li><a href=/cgi-bin/login.py?logout=logout title="Logout, user name: %s">Logout</a></li>' % login.value)
print('<li><a href=/cgi-bin/login.py?logout=logout title="Logout, user name: %s" class="login">Logout</a></li>' % login.value)
def footer():
print('</center></div>'
@ -202,7 +207,77 @@ def footer():
'<span class="LogoText">HAproxy-WI</span>'
'</div>'
'</div>--></body></html>')
def get_auto_refresh(h2):
print('<h2>')
print('<span>%s</span>' % h2)
print('<span class="auto-refresh">'
'<a id="0"><img style="margin-top: 10px; margin-left: -23px; position: fixed;" src=/image/pic/update.png alt="restart" class="icon"> Auto-refresh</a>'
'<a id="1" style="display: none;"><img style="margin-top: 10px; margin-left: -23px; position: fixed;" src=/image/pic/update.png alt="restart" class="icon"> Auto-refresh</a>'
'<a onclick="pauseAutoRefresh()" title="Pause auto-refresh" class="auto-refresh-pause" style="display: none;"></a>'
'<a onclick="pauseAutoResume()" title="Resume auto-refresh" class="auto-refresh-resume" style="display: none;"></a>'
'</span></h2>'
'<div class="auto-refresh-div">'
'<div class="auto-refresh-head">'
'Refresh Interval'
'</div>'
'<div class="auto-refresh-interval">'
'<div class="auto-refresh-ul">'
'<ul>'
'<li>'
'<a class="ui-button ui-widget ui-corner-all" onclick="setRefreshInterval(0)" title="Turn off auto-refresh">Off</a> '
'</li>'
'</ul>'
'</div>'
'<div class="auto-refresh-ul">'
'<ul>'
'<li>'
'<a title="Auto-refresh every 5 seconds" onclick="setRefreshInterval(5000)">5 seconds</a>'
'</li>'
'<li>'
'<a title="Auto-refresh every 10 seconds" onclick="setRefreshInterval(10000)">10 seconds</a>'
'</li>'
'<li>'
'<a title="Auto-refresh every 30 seconds" onclick="setRefreshInterval(30000)">30 seconds</a>'
'</li>'
'<li>'
'<a title="Auto-refresh ever 45 seconds" onclick="setRefreshInterval(45000)">45 seconds</a>'
'</li>'
'</ul>'
'</div>'
'<div class="auto-refresh-ul">'
'<ul>'
'<li>'
'<a title="Auto-refresh every 1 minute" onclick="setRefreshInterval(60000)">1 minute</a>'
'</li>'
'<li>'
'<a title="Auto-refresh every 5 minutes" onclick="setRefreshInterval(300000)">5 minutes</a>'
'</li>'
'<li>'
'<a title="Auto-refresh every 15 minutes" onclick="setRefreshInterval(900000)">15 minutes</a>'
'</li>'
'<li>'
'<a title="Auto-refresh ever 30 minutes" onclick="setRefreshInterval(1800000)">30 minutes</a>'
'</li>'
'</ul>'
'</div>'
'<div class="auto-refresh-ul">'
'<ul>'
'<li>'
'<a title="Auto-refresh every 1 hour" onclick="setRefreshInterval(3600000)">1 hour</a>'
'</li>'
'<li>'
'<a title="Auto-refresh every 2 hour" onclick="setRefreshInterval(7200000)">2 hour</a>'
'</li>'
'<li>'
'<a title="Auto-refresh every 12 hour" onclick="setRefreshInterval(43200000)">12 hour</a>'
'</li>'
'<li>'
'<a title="Auto-refresh ever 1 day" onclick="setRefreshInterval(86400000)">1 day</a>'
'</li>'
'</ul>'
'</div>'
'</div>'
'</div>')
def ssh_connect(serv):
ssh = SSHClient()
ssh.load_system_host_keys()

View File

@ -54,5 +54,3 @@ server_state_file = /etc/haproxy/haproxy.state
haproxy_sock = /var/run/haproxy.sock
#Temp store configs, for haproxy check
tmp_config_path = /tmp
#Time in seconds for auto refresh view stats_port
refresh_time = 120

View File

@ -17,9 +17,9 @@ funct.check_login()
path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
config.read(path_config)
print('<h2>HAproxy Logs</h2>'
'<table class="overview">'
funct.get_auto_refresh("HAproxy logs")
print('<table class="overview">'
'<tr class="overviewHead">'
'<td class="padding10">Server</td>'
'<td>Number rows</td>'

View File

@ -23,11 +23,11 @@ try:
except IOError:
print("Can't load users DB")
print('<h2>Quick Status </h2>'
'<table class="overview">')
funct.get_auto_refresh("Overview")
print('<table class="overview">')
if funct.is_admin():
print('<tr class="overviewHead">'
'<td class="padding10">Login</td>'
'<td>Group</td>'
@ -83,9 +83,9 @@ for i in sorted(listhap):
funct.ssh_command(listhap.get(i), commands, server_status="1")
print('</td><td>')
if funct.is_admin():
print('<a href="/cgi-bin/overview.py#" class="start" id="%s" title="Start HAproxy service" onclick = "if (! confirm(\'Start service?\')) return false;"><img src=/image/pic/start.png alt="start" class="icon" ></a>' % listhap.get(i))
print('<a href="/cgi-bin/overview.py#" class="stop" id="%s" title="Stop HAproxy service" onclick = "if (! confirm(\'Stop service?\')) return false;"><img src=/image/pic/stop.png alt="start" class="icon"></a>' % listhap.get(i))
print('<a href="/cgi-bin/overview.py#" class="restart" id="%s" title="Restart HAproxy service" onclick = "if (! confirm(\'Restart service?\')) return false;"><img src=/image/pic/update.png alt="restart" class="icon"></a>' % listhap.get(i))
print('<a id="%s" title="Start HAproxy service" onclick = "if (! confirm(\'Start service?\')) return false;"><img src=/image/pic/start.png alt="start" class="icon"></a>' % listhap.get(i))
print('<a id="%s" title="Stop HAproxy service" onclick = "if (! confirm(\'Stop service?\')) return false;"><img src=/image/pic/stop.png alt="start" class="icon"></a>' % listhap.get(i))
print('<a id="%s" title="Restart HAproxy service" onclick = "if (! confirm(\'Restart service?\')) return false;"><img src=/image/pic/update.png alt="restart" class="icon"></a>' % listhap.get(i))
print('<a href="/cgi-bin/configshow.py?serv=%s&open=open#conf" title="Show config"><img src=/image/pic/show.png alt="show" class="icon"></a>' % listhap.get(i))
print('<a href="/cgi-bin/config.py?serv=%s&open=open#conf" title="Edit config"><img src=/image/pic/edit.png alt="edit" class="icon"></a>' % listhap.get(i))
print('<a href="/cgi-bin/diff.py?serv=%s&open=open#diff" title="Compare config"><img src=/image/pic/compare.png alt="compare" class="icon"></a>' % listhap.get(i))

View File

@ -42,16 +42,20 @@ except requests.exceptions.Timeout as errt:
except requests.exceptions.RequestException as err:
print ("OOps: Something Else",err)
print('<meta http-equiv="refresh" content="%s; url=viewsttats.py?serv=%s">' % (config.get('haproxy', 'refresh_time') ,serv))
#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:
servname = i
print('<div class="container"><h3 style="padding-left: 20px; margin-top: 20px;">Choose server!</h3><br />'
'<form style="padding-left: 20px;" action="viewsttats.py" method="get">'
'<select autofocus required name="serv">'
'<option disabled>Choose server</option>')
print('<div class="container">')
funct.get_auto_refresh("HAproxy statistics")
print('<br />'
'<form style="padding-left: 20px;" action="viewsttats.py" method="get">'
'<select autofocus required name="serv">'
'<option disabled>Choose server</option>')
funct.choose_server_with_vip(serv)
@ -62,4 +66,4 @@ print('<a name="conf"></a><div style="margin-left: 10px;">')
print(data.decode('utf-8'))
funct.head("Stats HAproxy configs")
print('</div>')
#print('<style>.container{display:none}</style>')

78
inc/awesome.css Normal file
View File

@ -0,0 +1,78 @@
.menu .svg-inline--fa {
margin-right: 0.5em;
}
.auto-refresh-pause::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\F04C";
}
.auto-refresh-resume::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f04b";
}
.overview-link::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f21e";
}
.stats::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f06e";
}
.logs::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f02d";
}
.map::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f279";
}
.runtime::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f233";
}
.config-show::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f10a";
}
.compare::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f0c5";
}
.add::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f067";
}
.edit::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f044";
}
.version::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f021";
}
.upload::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f093";
}
.delete::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f00d";
}
.login::before {
display: none;
font-family: "Font Awesome 5 Solid";
content: "\f007";
}

5
inc/fa-solid.min.js vendored Normal file

File diff suppressed because one or more lines are too long

5
inc/fontawesome.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,44 @@
function setRefreshInterval(interval) {
if (interval == "0") {
Cookies.remove('auto-refresh');
pauseAutoRefresh();
$('.auto-refresh').append('<img style="margin-top: 10px; margin-left: -110px; position: fixed;" src=/image/pic/update.png alt="restart" class="icon">');
$('#1').text('Auto-refresh');
$('#0').text('Auto-refresh');
$('.auto-refresh-pause').css('display', 'none');
$('.auto-refresh-resume').css('display', 'none');
hideAutoRefreshDiv();
} else {
Cookies.set('auto-refresh', interval, { expires: 365 });
startSetInterval(interval);
hideAutoRefreshDiv();
document.location.reload();
}
}
var intervalId;
function startSetInterval(interval) {
intervalId = setInterval('document.location.reload()', interval);
}
function pauseAutoRefresh() {
clearInterval(intervalId);
$(function() {
$('.auto-refresh-pause').attr('onclick', 'pauseAutoResume()');
$('.auto-refresh-pause').css('display', 'none');
$('.auto-refresh-resume').css('display', 'inline');
});
}
function pauseAutoResume(){
var autoRefresh = Cookies.get('auto-refresh');
setRefreshInterval(autoRefresh);
}
function hideAutoRefreshDiv() {
$(function() {
$('.auto-refresh-div').hide("blind", "fast");
$('#1').css("display", "none");
$('#0').css("display", "inline");
});
}
$( function() {
$( "#tabs" ).tabs();
$( "#redirectBackend" ).on( "click", function() {
@ -86,16 +127,60 @@ $( function() {
var location = window.location.href;
var cur_url = '/cgi-bin/' + location.split('/').pop();
cur_url = cur_url.split('?');
$('.menu li').each(function () {
var link = $(this).find('a').attr('href');
if (cur_url == link)
if (cur_url[0] == link)
{
$(this).addClass('current');
}
});
$('#0').click(function() {
$('.auto-refresh-div').show("blind", "fast");
$('#0').css("display", "none");
$('#1').css("display", "inline");
});
$('#1').click(function() {
$('.auto-refresh-div').hide("blind", "fast");
$('#1').css("display", "none");
$('#0').css("display", "inline");
});
var autoRefresh = Cookies.get('auto-refresh');
var pause = '<a onclick="pauseAutoRefresh()" title="Pause auto-refresh" class="auto-refresh-pause"></a>'
if ($('.auto-refresh')) {
var margin;
if(autoRefresh) {
startSetInterval(autoRefresh)
autoRefresh = autoRefresh / 1000;
if ( autoRefresh == 60) {
timeRange = " minute"
autoRefresh = autoRefresh / 60;
margin = '-80px';
} else if ( autoRefresh > 60 && autoRefresh < 3600 ) {
timeRange = " minutes"
autoRefresh = autoRefresh / 60;
margin = '-93px';
} else if ( autoRefresh >= 3600 && autoRefresh < 86401 ) {
timeRange = " hours"
autoRefresh = autoRefresh / 3600;
margin = '-80px';
} else {
timeRange = " seconds";
margin = '-100px';
}
$('#1').text(autoRefresh + timeRange);
$('#0').text(autoRefresh + timeRange);
$('.auto-refresh-pause').css('display', 'inline');
$('.auto-refresh-pause').css('margin-left', margin);
}
}
$('#select_all').click(function(){
var checkboxes = $(this).closest('form').find(':checkbox');

View File

@ -13,7 +13,6 @@ body {
h2 {
background: #5D9CEB;
border: 1px solid #5D9CEB;
//border-radius: 5px 5px 0px 0px;
padding: 10px;
padding-left: 3%;
color: #fff;
@ -73,23 +72,73 @@ pre {
padding-left: 7px;
padding-right: 7px;
}
/*.top-link {
margin-top: 115px;
}
.top-link {
margin-left: 28%;
}*/
.footer-link {
margin-left: 44%;
}
.container {
min-height: calc(100vh - 115px);
max-width: 89%;
max-width: 91%;
min-width: 40%;
background-color: #fff;
margin-left: 207px;
padding-bottom: 10px;
}
.auto-refresh {
margin-left: 86%;
}
.auto-refresh a {
color: #fff !important;
cursor: pointer;
font-size: 15px;
}
.auto-refresh-div {
display: none;
position: relative;
padding: 10px 10px 14px;
background-color: #F5F5F5;
border-bottom: solid 1px #D9D9D9;
border-top: solid 1px #D9D9D9;
margin-bottom: 10px;
line-height: 20px;
}
.auto-refresh-div a {
color: #000;
cursor: pointer;
}
.auto-refresh-head {
margin-top: 0;
font-size: 16px;
color: #2d2d2d;
font-weight: bold;
margin-left: 77%;
}
.auto-refresh-interval {
float: left;
padding: 0px 15px;
margin-left: 75%;
}
.auto-refresh-ul{
float: left;
padding-left: 0;
list-style: none;
margin-top: 10px;
}
.auto-refresh-ul ul li {
margin: 0;
padding: 0;
border: 0;
font-family: inherit;
vertical-align: baseline;
list-style: none;
}
.auto-refresh-pause, .auto-refresh-resume {
margin-top: 10px;
margin-left: -100px;
position: fixed;
color: #000;
font-size: 12px;
height: 15;
}
.configShow, .diff {
margin-left: 16%;
height: 78%;
@ -275,6 +324,7 @@ pre {
.menu ul li{
padding: 10px;
padding-left: 20px;
margin-right: 0px !important;
}
.menu ul ul > li:hover{

View File

@ -6,26 +6,11 @@
<link href="/favicon.ico" rel="icon" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link href="/inc/style.css" rel="stylesheet">
<meta http-equiv="refresh" content="0; url=/cgi-bin/overview.py">
</head>
<body>
<center>
<div class="conteinerIndex">
<h2>Welcome to HAproxy-WI!</h2>
<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/logs.py" title="View logs">Logs</a> <br />
<a href="cgi-bin/map.py" title="View map">Map</a> <br />
<a href="cgi-bin/edit.py" title="Runtime API">Runtime API</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/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/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 />
<div class="copyright">
HAproxy Web Interface v1.10
</div>
</div>
<p>
Redirecting... Please wait
</p>
</body>
</html>