v1.10.2.3

pull/19/head
Aidaho12 2018-04-11 15:27:57 +06:00
parent fdf259ab6b
commit 2bf13e7975
6 changed files with 102 additions and 82 deletions

View File

@ -1,14 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import html import html
import cgi import cgi
import listserv as listhap
import subprocess
import os
import funct import funct
import glob import ovw
import paramiko
import configparser import configparser
from paramiko import SSHClient
form = cgi.FieldStorage() form = cgi.FieldStorage()
serv = form.getvalue('serv') serv = form.getvalue('serv')
@ -25,53 +20,18 @@ config.read(path_config)
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')
left = form.getvalue('left')
right = form.getvalue('right')
funct.chooseServer("diff.py#diff", "Compare HAproxy configs", "n") funct.chooseServer("diff.py#diff", "Compare HAproxy configs", "n", onclick="showCompareConfigs()")
if form.getvalue('serv') is not None and form.getvalue('open') is not None : print('<div id="ajax-compare">')
print('<form action="diff.py#diff" method="get">')
print('<center><h3><span style="padding: 20px;">Choose left</span><span style="padding: 110px;">Choose right</span></h3>')
print('<p><select autofocus required name="left" id="left">')
print('<option disabled selected>Choose version</option>')
os.chdir(hap_configs_dir)
for files in sorted(glob.glob('*.cfg')):
ip = files.split("-")
if serv == ip[0]:
if left == files:
selected = 'selected'
else:
selected = ''
print('<option value="%s" %s>%s</option>' % (files, selected, files))
print('</select>') if serv is not None and form.getvalue('open') is not None :
ovw.show_compare_configs(serv)
print('<select autofocus required name="right" id="right">')
print('<option disabled selected>Choose version</option>')
for files in sorted(glob.glob('*.cfg')): print('</div><div id=ajax>')
ip = files.split("-")
if serv == ip[0]:
if right == files:
selected = 'selected'
else:
selected = ''
print('<option value="%s" %s>%s</option>' % (files, selected, files))
print('</select>')
print('<input type="hidden" value="%s" name="serv">' % serv)
print('<input type="hidden" value="open" name="open">')
print('<a class="ui-button ui-widget ui-corner-all" id="show" title="Compare" onclick="showCompare()">Show</a></p></form></center></center><div id=ajax>')
if serv is not None and form.getvalue('right') is not None: if 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) ] ovw.comapre_show()
funct.ssh_command(haproxy_configs_server, commands, compare="1")
print('</div>') print('</div>')
funct.footer() funct.footer()

View File

@ -153,17 +153,17 @@ def head(title):
'</div>') '</div>')
if config.get('main', 'logo_enable') == "1": if config.get('main', 'logo_enable') == "1":
print('<div><img src="%s" title="Logo" class="logo"></div>' % config.get('main', 'logo_path')) print('<div><img src="%s" title="Logo" class="logo"></div>' % config.get('main', 'logo_path'))
print('<div class="top-link">')
links() links()
print('</div></div><div class="container">') print('</div><div class="container">')
def links(): def links():
print('<nav class="menu">' print('<div class="top-link">'
'<nav class="menu">'
'<ul>' '<ul>'
'<li><a title="Statistics, monitoring and logs" class="stats">Stats</a>' '<li><a title="Statistics, monitoring and logs" class="stats">Stats</a>'
'<ul>' '<ul>'
'<li><a href=/cgi-bin/overview.py title="Server and service status" class="overview-link">Overview</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/viewsttats.py title"Show 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/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>' '<li><a href=/cgi-bin/map.py title="View map" class="map">Map</a></li>'
'</ul>' '</ul>'
@ -191,7 +191,8 @@ def links():
show_login_links() show_login_links()
print('</ul>' print('</ul>'
'</nav>' '</nav>'
'<div class="copyright-menu">HAproxy-WI v1.10.2.3</div>') '<div class="copyright-menu">HAproxy-WI v1.10.2.3</div>'
'</div>')
def show_login_links(): def show_login_links():
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE")) cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
@ -216,8 +217,8 @@ def get_auto_refresh(h2):
print('<span class="auto-refresh">' print('<span class="auto-refresh">'
'<a id="0"><img style="margin-top: 3px; margin-left: -23px; position: fixed;" src=/image/pic/update.png alt="restart" class="icon"> Auto-refresh</a>' '<a id="0"><img style="margin-top: 3px; 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: 3px; 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: 3px; 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; margin-top: 4px;"></a>' '<a onclick="pauseAutoRefresh()" class="auto-refresh-pause" style="display: none; margin-top: 4px;"></a>'
'<a onclick="pauseAutoResume()" title="Resume auto-refresh" class="auto-refresh-resume" style="display: none; margin-top: 4px;"></a>' '<a onclick="pauseAutoResume()" class="auto-refresh-resume" style="display: none; margin-top: 4px;"></a>'
'</span></h2>' '</span></h2>'
'<div class="auto-refresh-div">' '<div class="auto-refresh-div">'
'<div class="auto-refresh-head">' '<div class="auto-refresh-head">'

View File

@ -17,6 +17,7 @@ funct.check_config()
form = cgi.FieldStorage() form = cgi.FieldStorage()
req = form.getvalue('req') req = form.getvalue('req')
serv = form.getvalue('serv') serv = form.getvalue('serv')
act = form.getvalue('act')
print('Content-type: text/html\n') print('Content-type: text/html\n')
if req is not None: if req is not None:
@ -72,10 +73,10 @@ if form.getvalue('action') is not None and serv is not None:
else: else:
print("Bad config, check please") print("Bad config, check please")
if form.getvalue('act') == "overview": if act == "overview":
ovw.get_overview() ovw.get_overview()
if serv is not None and form.getvalue('act') == "stats": if serv is not None and act == "stats":
import requests import requests
from requests_toolbelt.utils import dump from requests_toolbelt.utils import dump
@ -123,7 +124,7 @@ if serv is not None and form.getvalue('rows') is not None:
funct.ssh_command(syslog_server, commands, show_log="1") funct.ssh_command(syslog_server, commands, show_log="1")
print('</div>') print('</div>')
if serv is not None and form.getvalue('act') == "showMap": if serv is not None and act == "showMap":
ovw.get_map(serv) ovw.get_map(serv)
if form.getvalue('servaction') is not None: if form.getvalue('servaction') is not None:
@ -144,17 +145,14 @@ if form.getvalue('servaction') is not None:
funct.ssh_command(serv, command, show_log="1") funct.ssh_command(serv, command, show_log="1")
action = 'edit.py ' + enable + ' ' + backend action = 'edit.py ' + enable + ' ' + backend
funct.logging(serv, action) funct.logging(serv, action)
if act == "showCompareConfigs":
ovw.show_compare_configs(serv)
if serv is not None and form.getvalue('right') is not None: if serv is not None and form.getvalue('right') is not None:
left = form.getvalue('left') ovw.comapre_show()
right = form.getvalue('right')
haproxy_configs_server = config.get('configs', 'haproxy_configs_server') if serv is not None and act == "configShow":
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
funct.ssh_command(haproxy_configs_server, commands, compare="1")
if serv is not None and form.getvalue('act') == "configShow":
import os import os
from datetime import datetime from datetime import datetime
from pytz import timezone from pytz import timezone

View File

@ -1,6 +1,8 @@
import funct import funct
import configparser import configparser
import json import json
import os
import cgi
path_config = "haproxy-webintarface.config" path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser() config = configparser.ConfigParser()
@ -13,6 +15,7 @@ stats_port= config.get('haproxy', 'stats_port')
haproxy_config_path = config.get('haproxy', 'haproxy_config_path') haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
status_command = config.get('haproxy', 'status_command') status_command = config.get('haproxy', 'status_command')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir') hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
form = cgi.FieldStorage()
def get_overview(): def get_overview():
USERS = cgi_path + '/users' USERS = cgi_path + '/users'
@ -114,7 +117,6 @@ def get_overview():
print('<tr></table>') print('<tr></table>')
def get_map(serv): def get_map(serv):
import os
from datetime import datetime from datetime import datetime
from pytz import timezone from pytz import timezone
import networkx as nx import networkx as nx
@ -209,5 +211,54 @@ def get_map(serv):
commands = [ "rm -f "+fullpath+"/map*.png", "mv %s/map.png %s/map%s.png" % (cgi_path, fullpath, now_utc.strftime(fmt)) ] commands = [ "rm -f "+fullpath+"/map*.png", "mv %s/map.png %s/map%s.png" % (cgi_path, fullpath, now_utc.strftime(fmt)) ]
funct.ssh_command("localhost", commands) funct.ssh_command("localhost", commands)
print('<img src="/map%s.png" alt="map">' % now_utc.strftime(fmt)) print('<img src="/map%s.png" alt="map">' % now_utc.strftime(fmt))
#commands = [ "rm -f %s/map%s.png" % (fullpath, now_utc.strftime(fmt))]
#funct.ssh_command("localhost", commands) def show_compare_configs(serv):
import glob
left = form.getvalue('left')
right = form.getvalue('right')
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
print('<form action="diff.py#diff" method="get">')
print('<center><h3><span style="padding: 20px;">Choose left</span><span style="padding: 110px;">Choose right</span></h3>')
print('<p><select autofocus required name="left" id="left">')
print('<option disabled selected>Choose version</option>')
os.chdir(hap_configs_dir)
for files in sorted(glob.glob('*.cfg')):
ip = files.split("-")
if serv == ip[0]:
if left == files:
selected = 'selected'
else:
selected = ''
print('<option value="%s" %s>%s</option>' % (files, selected, files))
print('</select>')
print('<select autofocus required name="right" id="right">')
print('<option disabled selected>Choose version</option>')
for files in sorted(glob.glob('*.cfg')):
ip = files.split("-")
if serv == ip[0]:
if right == files:
selected = 'selected'
else:
selected = ''
print('<option value="%s" %s>%s</option>' % (files, selected, files))
print('</select>')
print('<input type="hidden" value="%s" name="serv">' % serv)
print('<input type="hidden" value="open" name="open">')
print('<a class="ui-button ui-widget ui-corner-all" id="show" title="Compare" onclick="showCompare()">Show</a></p></form></center></center>')
def comapre_show():
left = form.getvalue('left')
right = form.getvalue('right')
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
funct.ssh_command(haproxy_configs_server, commands, compare="1")

View File

@ -45,7 +45,7 @@ except requests.exceptions.RequestException as err:
for i in listhap.listhap: for i in listhap.listhap:
if listhap.listhap.get(i) == serv: if listhap.listhap.get(i) == serv:
servname = i servname = i
print('<div class="container">') print('<div class="container">')
funct.get_auto_refresh("HAproxy statistics") funct.get_auto_refresh("HAproxy statistics")

View File

@ -20,6 +20,7 @@ function autoRefreshStyle(autoRefresh) {
$('#1').text(autoRefresh + timeRange); $('#1').text(autoRefresh + timeRange);
$('#0').text(autoRefresh + timeRange); $('#0').text(autoRefresh + timeRange);
$('.auto-refresh-pause').css('display', 'inline'); $('.auto-refresh-pause').css('display', 'inline');
$('.auto-refresh-resume').css('display', 'none');
$('.auto-refresh-pause').css('margin-left', margin); $('.auto-refresh-pause').css('margin-left', margin);
$('.auto-refresh img').remove(); $('.auto-refresh img').remove();
} }
@ -43,6 +44,7 @@ function setRefreshInterval(interval) {
} }
} }
var url = "/inc/script.js";
var cur_url = window.location.href.split('/').pop(); var cur_url = window.location.href.split('/').pop();
cur_url = cur_url.split('?'); cur_url = cur_url.split('?');
var intervalId; var intervalId;
@ -56,14 +58,11 @@ function startSetInterval(interval) {
} else if (cur_url[0] == "overview.py") { } else if (cur_url[0] == "overview.py") {
intervalId = setInterval('showOverview()', interval); intervalId = setInterval('showOverview()', interval);
showOverview(); showOverview();
} else { }
intervalId = setInterval('document.location.reload()', interval);
}
} }
function pauseAutoRefresh() { function pauseAutoRefresh() {
clearInterval(intervalId); clearInterval(intervalId);
$(function() { $(function() {
$('.auto-refresh-pause').attr('onclick', 'pauseAutoResume()');
$('.auto-refresh-pause').css('display', 'none'); $('.auto-refresh-pause').css('display', 'none');
$('.auto-refresh-resume').css('display', 'inline'); $('.auto-refresh-resume').css('display', 'inline');
}); });
@ -94,7 +93,6 @@ function showOverview() {
}, },
type: "GET", type: "GET",
success: function( data ) { success: function( data ) {
var form = $("#ajax").html();
$("#ajax").html(data); $("#ajax").html(data);
} }
} ); } );
@ -109,8 +107,8 @@ function showStats() {
}, },
type: "GET", type: "GET",
success: function( data ) { success: function( data ) {
var form = $("#ajax").html(); $("#ajax").html(data);
$("#ajax").html(data); $.getScript(url);
window.history.pushState("Stats", "Stats", cur_url[0]+"?serv="+$("#serv").val()); window.history.pushState("Stats", "Stats", cur_url[0]+"?serv="+$("#serv").val());
} }
} ); } );
@ -125,7 +123,6 @@ function showLog() {
}, },
type: "GET", type: "GET",
success: function( data ) { success: function( data ) {
var form = $("#ajax").html();
$("#ajax").html(data); $("#ajax").html(data);
} }
} ); } );
@ -140,7 +137,6 @@ function showMap() {
}, },
type: "GET", type: "GET",
success: function( data ) { success: function( data ) {
var form = $("#ajax").html();
$("#ajax").html(data); $("#ajax").html(data);
window.history.pushState("Map", "Map", cur_url[0]+"?serv="+$("#serv").val()); window.history.pushState("Map", "Map", cur_url[0]+"?serv="+$("#serv").val());
} }
@ -163,7 +159,6 @@ function showRuntime() {
}, },
type: "GET", type: "GET",
success: function( data ) { success: function( data ) {
var form = $("#ajax").html();
$("#ajax").html(data); $("#ajax").html(data);
} }
} ); } );
@ -178,9 +173,25 @@ function showCompare() {
}, },
type: "GET", type: "GET",
success: function( data ) { success: function( data ) {
var form = $("#ajax").html();
$("#ajax").html(data); $("#ajax").html(data);
window.history.pushState("Compare", "Compare", cur_url[0]+"?serv="+$("#serv").val()+"&open=open&left="+$("#left").val()+"&right="+$("#right").val()); window.history.pushState("Compare", "Compare", cur_url[0]+"?serv="+$("#serv").val()+"&open=open&left="+$("#left").val()+"&right="+$("#right").val());
$.getScript(url);
}
} );
}
function showCompareConfigs() {
$.ajax( {
url: "options.py",
data: {
serv: $("#serv").val(),
act: "showCompareConfigs",
open: "open"
},
type: "GET",
success: function( data ) {
$("#ajax-compare").html(data);
window.history.pushState("Compare", "Compare", cur_url[0]+"?serv="+$("#serv").val()+"&open=open");
$.getScript(url);
} }
} ); } );
} }
@ -193,7 +204,6 @@ function showConfig() {
}, },
type: "GET", type: "GET",
success: function( data ) { success: function( data ) {
var form = $("#ajax").html();
$("#ajax").html(data); $("#ajax").html(data);
window.history.pushState("Show config", "Show config", cur_url[0]+"?serv="+$("#serv").val()+"&open=open"); window.history.pushState("Show config", "Show config", cur_url[0]+"?serv="+$("#serv").val()+"&open=open");
} }