mirror of https://github.com/Aidaho12/haproxy-wi
v1.10.2.3
parent
fdf259ab6b
commit
2bf13e7975
|
@ -1,14 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
import html
|
||||
import cgi
|
||||
import listserv as listhap
|
||||
import subprocess
|
||||
import os
|
||||
import funct
|
||||
import glob
|
||||
import paramiko
|
||||
import ovw
|
||||
import configparser
|
||||
from paramiko import SSHClient
|
||||
|
||||
form = cgi.FieldStorage()
|
||||
serv = form.getvalue('serv')
|
||||
|
@ -25,53 +20,18 @@ config.read(path_config)
|
|||
|
||||
haproxy_configs_server = config.get('configs', 'haproxy_configs_server')
|
||||
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>')
|
||||
if serv is not None and form.getvalue('open') is not None :
|
||||
ovw.show_compare_configs(serv)
|
||||
|
||||
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><div id=ajax>')
|
||||
print('</div><div id=ajax>')
|
||||
|
||||
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) ]
|
||||
|
||||
funct.ssh_command(haproxy_configs_server, commands, compare="1")
|
||||
ovw.comapre_show()
|
||||
|
||||
print('</div>')
|
||||
funct.footer()
|
|
@ -153,17 +153,17 @@ def head(title):
|
|||
'</div>')
|
||||
if config.get('main', 'logo_enable') == "1":
|
||||
print('<div><img src="%s" title="Logo" class="logo"></div>' % config.get('main', 'logo_path'))
|
||||
print('<div class="top-link">')
|
||||
links()
|
||||
print('</div></div><div class="container">')
|
||||
print('</div><div class="container">')
|
||||
|
||||
def links():
|
||||
print('<nav class="menu">'
|
||||
print('<div class="top-link">'
|
||||
'<nav class="menu">'
|
||||
'<ul>'
|
||||
'<li><a title="Statistics, monitoring and logs" class="stats">Stats</a>'
|
||||
'<ul>'
|
||||
'<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/map.py title="View map" class="map">Map</a></li>'
|
||||
'</ul>'
|
||||
|
@ -191,7 +191,8 @@ def links():
|
|||
show_login_links()
|
||||
print('</ul>'
|
||||
'</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():
|
||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||
|
@ -216,8 +217,8 @@ def get_auto_refresh(h2):
|
|||
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="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="pauseAutoResume()" title="Resume auto-refresh" class="auto-refresh-resume" style="display: none; margin-top: 4px;"></a>'
|
||||
'<a onclick="pauseAutoRefresh()" class="auto-refresh-pause" style="display: none; margin-top: 4px;"></a>'
|
||||
'<a onclick="pauseAutoResume()" class="auto-refresh-resume" style="display: none; margin-top: 4px;"></a>'
|
||||
'</span></h2>'
|
||||
'<div class="auto-refresh-div">'
|
||||
'<div class="auto-refresh-head">'
|
||||
|
|
|
@ -17,6 +17,7 @@ funct.check_config()
|
|||
form = cgi.FieldStorage()
|
||||
req = form.getvalue('req')
|
||||
serv = form.getvalue('serv')
|
||||
act = form.getvalue('act')
|
||||
print('Content-type: text/html\n')
|
||||
|
||||
if req is not None:
|
||||
|
@ -72,10 +73,10 @@ if form.getvalue('action') is not None and serv is not None:
|
|||
else:
|
||||
print("Bad config, check please")
|
||||
|
||||
if form.getvalue('act') == "overview":
|
||||
if act == "overview":
|
||||
ovw.get_overview()
|
||||
|
||||
if serv is not None and form.getvalue('act') == "stats":
|
||||
if serv is not None and act == "stats":
|
||||
import requests
|
||||
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")
|
||||
print('</div>')
|
||||
|
||||
if serv is not None and form.getvalue('act') == "showMap":
|
||||
if serv is not None and act == "showMap":
|
||||
ovw.get_map(serv)
|
||||
|
||||
if form.getvalue('servaction') is not None:
|
||||
|
@ -145,16 +146,13 @@ if form.getvalue('servaction') is not None:
|
|||
action = 'edit.py ' + enable + ' ' + backend
|
||||
funct.logging(serv, action)
|
||||
|
||||
if act == "showCompareConfigs":
|
||||
ovw.show_compare_configs(serv)
|
||||
|
||||
if serv is not None and form.getvalue('right') is not None:
|
||||
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) ]
|
||||
ovw.comapre_show()
|
||||
|
||||
funct.ssh_command(haproxy_configs_server, commands, compare="1")
|
||||
|
||||
if serv is not None and form.getvalue('act') == "configShow":
|
||||
if serv is not None and act == "configShow":
|
||||
import os
|
||||
from datetime import datetime
|
||||
from pytz import timezone
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import funct
|
||||
import configparser
|
||||
import json
|
||||
import os
|
||||
import cgi
|
||||
|
||||
path_config = "haproxy-webintarface.config"
|
||||
config = configparser.ConfigParser()
|
||||
|
@ -13,6 +15,7 @@ stats_port= config.get('haproxy', 'stats_port')
|
|||
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
|
||||
status_command = config.get('haproxy', 'status_command')
|
||||
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||
form = cgi.FieldStorage()
|
||||
|
||||
def get_overview():
|
||||
USERS = cgi_path + '/users'
|
||||
|
@ -114,7 +117,6 @@ def get_overview():
|
|||
print('<tr></table>')
|
||||
|
||||
def get_map(serv):
|
||||
import os
|
||||
from datetime import datetime
|
||||
from pytz import timezone
|
||||
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)) ]
|
||||
funct.ssh_command("localhost", commands)
|
||||
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")
|
|
@ -20,6 +20,7 @@ function autoRefreshStyle(autoRefresh) {
|
|||
$('#1').text(autoRefresh + timeRange);
|
||||
$('#0').text(autoRefresh + timeRange);
|
||||
$('.auto-refresh-pause').css('display', 'inline');
|
||||
$('.auto-refresh-resume').css('display', 'none');
|
||||
$('.auto-refresh-pause').css('margin-left', margin);
|
||||
$('.auto-refresh img').remove();
|
||||
}
|
||||
|
@ -43,6 +44,7 @@ function setRefreshInterval(interval) {
|
|||
}
|
||||
}
|
||||
|
||||
var url = "/inc/script.js";
|
||||
var cur_url = window.location.href.split('/').pop();
|
||||
cur_url = cur_url.split('?');
|
||||
var intervalId;
|
||||
|
@ -56,14 +58,11 @@ function startSetInterval(interval) {
|
|||
} else if (cur_url[0] == "overview.py") {
|
||||
intervalId = setInterval('showOverview()', interval);
|
||||
showOverview();
|
||||
} else {
|
||||
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');
|
||||
});
|
||||
|
@ -94,7 +93,6 @@ function showOverview() {
|
|||
},
|
||||
type: "GET",
|
||||
success: function( data ) {
|
||||
var form = $("#ajax").html();
|
||||
$("#ajax").html(data);
|
||||
}
|
||||
} );
|
||||
|
@ -109,8 +107,8 @@ function showStats() {
|
|||
},
|
||||
type: "GET",
|
||||
success: function( data ) {
|
||||
var form = $("#ajax").html();
|
||||
$("#ajax").html(data);
|
||||
$.getScript(url);
|
||||
window.history.pushState("Stats", "Stats", cur_url[0]+"?serv="+$("#serv").val());
|
||||
}
|
||||
} );
|
||||
|
@ -125,7 +123,6 @@ function showLog() {
|
|||
},
|
||||
type: "GET",
|
||||
success: function( data ) {
|
||||
var form = $("#ajax").html();
|
||||
$("#ajax").html(data);
|
||||
}
|
||||
} );
|
||||
|
@ -140,7 +137,6 @@ function showMap() {
|
|||
},
|
||||
type: "GET",
|
||||
success: function( data ) {
|
||||
var form = $("#ajax").html();
|
||||
$("#ajax").html(data);
|
||||
window.history.pushState("Map", "Map", cur_url[0]+"?serv="+$("#serv").val());
|
||||
}
|
||||
|
@ -163,7 +159,6 @@ function showRuntime() {
|
|||
},
|
||||
type: "GET",
|
||||
success: function( data ) {
|
||||
var form = $("#ajax").html();
|
||||
$("#ajax").html(data);
|
||||
}
|
||||
} );
|
||||
|
@ -178,9 +173,25 @@ function showCompare() {
|
|||
},
|
||||
type: "GET",
|
||||
success: function( data ) {
|
||||
var form = $("#ajax").html();
|
||||
$("#ajax").html(data);
|
||||
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",
|
||||
success: function( data ) {
|
||||
var form = $("#ajax").html();
|
||||
$("#ajax").html(data);
|
||||
window.history.pushState("Show config", "Show config", cur_url[0]+"?serv="+$("#serv").val()+"&open=open");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue