v1.10.2.2

More AJAX!!!! Fixed bugs
pull/19/head
Aidaho12 2018-04-10 12:10:07 +06:00
parent b6624d91f8
commit 1e53c561ea
7 changed files with 97 additions and 34 deletions

View File

@ -24,7 +24,7 @@ path_config = "haproxy-webintarface.config"
config = configparser.ConfigParser()
config.read(path_config)
fullpath = config.get('main', 'fullpath')
log_path = config.get('main', 'log_path')
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
time_zone = config.get('main', 'time_zone')
@ -33,16 +33,16 @@ if serv is not None:
now_utc = datetime.now(timezone(time_zone))
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
funct.chooseServer("config.py#conf", "Edit HAproxy config", "y")
funct.chooseServer("config.py", "Edit HAproxy config", "y")
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
funct.logging(serv, "config.py open config")
funct.get_config(serv, cfg)
conf = open(cfg, "r")
print('<a name="conf"></a>')
print("<h3>Config from %s</h3>" % serv)
print('<form action="config.py#top" method="post">')
print("<center><h3>Config from %s</h3>" % serv)
print('<form action="config.py" method="get">')
print('<input type="hidden" value="%s" name="serv">' % serv)
print('<input type="hidden" value="%s.old" name="oldconfig">' % cfg)
print('<textarea name="config" rows="35" cols="100">%s</textarea>' % conf.read())
@ -54,8 +54,8 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
os.system("/bin/mv %s %s.old" % (cfg, cfg))
if form.getvalue('serv') is not None and form.getvalue('config') is not None :
funct.logging(serv, "config.py edited config and restarted service")
if form.getvalue('serv') is not None and form.getvalue('config') is not None:
funct.logging(serv, "config.py edited config")
config = form.getvalue('config')
oldcfg = form.getvalue('oldconfig')
save = form.getvalue('save')
@ -66,11 +66,11 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None :
except IOError:
print("Can't read import config file")
print("<b>New config was saved as: %s </b></br></br>" % cfg)
print("<center><b>New config was saved as: %s </b></br></br></center>" % cfg)
funct.upload_and_restart(serv, cfg, just_save=save)
os.system("/bin/diff -ub %s %s >> %slog/config_edit.log" % (oldcfg, cfg, fullpath))
os.system("/bin/diff -ub %s %s >> %s/config_edit.log" % (oldcfg, cfg, log_path))
os.system("/bin/rm -f " + hap_configs_dir + "*.old")
print('</br><a href="viewsttats.py?serv=%s" target="_blank" title="View stats">Go to view stats</a> <br />' % serv)

View File

@ -5,8 +5,6 @@ import os
import funct
import paramiko
import configparser
from paramiko import SSHClient
from datetime import datetime
from pytz import timezone
form = cgi.FieldStorage()
@ -27,23 +25,24 @@ hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
time_zone = config.get('main', 'time_zone')
if serv is not None:
funct.chooseServer("configshow.py", "Show HAproxy config", "n", onclick="showConfig()")
print('<div id="ajax">')
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
fmt = "%Y-%m-%d.%H:%M:%S"
now_utc = datetime.now(timezone(time_zone))
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
funct.chooseServer("configshow.py#conf", "Show HAproxy config", "n")
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
funct.get_config(serv, cfg)
print('<a name="conf"></a>')
print("<h3>Config from %s</h3>" % serv)
print("<center><h3>Config from %s</h3>" % serv)
print('<p class="accordion-expand-holder">'
'<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>'
'</p>')
print('</center>')
funct.show_config(cfg)
os.system("/bin/rm -f " + cfg)
print('</div>')
funct.footer()

View File

@ -4,6 +4,7 @@ import cgi
import os
import funct
import configparser
import glob
form = cgi.FieldStorage()
serv = form.getvalue('serv')
@ -19,18 +20,15 @@ config.read(path_config)
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
funct.page_for_admin(level = 2)
funct.chooseServer("delver.py#conf", "Delete Versions HAproxy config", "n")
funct.chooseServer("delver.py", "Delete Versions HAproxy config", "n")
if serv is not None and form.getvalue('open') is not None:
print('<center><h3>Choose old version</h3>')
print('<form action="delver.py#conf" method="post">'
print('<form action="delver.py#conf" method="get">'
'<label for="select_all" id="label_select_all"><b>Select all</b></label>'
'<input type="checkbox" id="select_all"><br />')
import glob
os.chdir(hap_configs_dir)
for files in sorted(glob.glob('*.cfg')):

View File

@ -25,7 +25,9 @@ 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")
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
@ -64,8 +66,12 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
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></div>')
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:
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
funct.ssh_command(haproxy_configs_server, commands, compare="1")
print('</div>')
funct.footer()

View File

@ -312,7 +312,7 @@ def get_config(serv, cfg):
print("!!! There was an issue, " + str(e))
def show_config(cfg):
print('</center><div style="margin-left: 16%" class="configShow">')
print('<div style="margin-left: 16%" class="configShow">')
conf = open(cfg, "r")
i = 0
for line in conf:
@ -358,7 +358,7 @@ def upload_and_restart(serv, cfg, **kwargs):
tmp_file = tmp_config_path + "/" + now_utc.strftime(fmt) + ".cfg"
ssh = ssh_connect(serv)
print("connected<br />")
print("<center>connected<br />")
sftp = ssh.open_sftp()
sftp.put(cfg, tmp_file)
sftp.close()
@ -389,7 +389,8 @@ def upload_and_restart(serv, cfg, **kwargs):
print("</br>")
return True
print('</center>')
ssh.close()
def check_haproxy_config(serv):
@ -549,7 +550,7 @@ def choose_only_select(serv, **kwargs):
print('<option value="%s" %s>%s</option>' % (listhap.get(i), selected, i))
def chooseServer(formName, title, note):
def chooseServer(formName, title, note, **kwargs):
servNew = form.getvalue('serNew')
print('<h2>' + title + '</h2><center>')
@ -561,10 +562,17 @@ def chooseServer(formName, title, note):
choose_only_select(serv, servNew=servNew)
print('</select>')
get_button("Open", value="open")
if kwargs.get("onclick") is not None:
print('<a class="ui-button ui-widget ui-corner-all" id="show" title="Show config" onclick="%s">Show</a>' % kwargs.get("onclick"))
else:
get_button("Open", value="open")
print('</p></form>')
if note == "y":
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p>')
print('</center>')
def choose_server_with_vip(serv):
listhap.listhap = merge_two_dicts(listhap.listhap, listhap.listhap_vip)

View File

@ -93,7 +93,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') is not None:
if serv is not None and form.getvalue('act') == "stats":
import requests
from requests_toolbelt.utils import dump
@ -150,6 +150,35 @@ 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")
if serv is not None and form.getvalue('act') == "configShow":
import os
from paramiko import SSHClient
from datetime import datetime
from pytz import timezone
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
time_zone = config.get('main', 'time_zone')
fmt = "%Y-%m-%d.%H:%M:%S"
now_utc = datetime.now(timezone(time_zone))
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
funct.get_config(serv, cfg)
print('<script>$( ".configShow" ).accordion({'
'collapsible: true,'
'heightStyle: "content",'
'icons: { "header": "ui-icon-plus", "activeHeader": "ui-icon-minus" }'
'});</script>')
print("<center><h3>Config from %s</h3>" % serv)
print('<p class="accordion-expand-holder">'
'<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>'
'</p>')
print('</center>')
funct.show_config(cfg)
os.system("/bin/rm -f " + cfg)
if form.getvalue('tailf_stop') is not None:
serv = form.getvalue('serv')

View File

@ -117,6 +117,7 @@ function showStats() {
success: function( data ) {
var form = $("#ajax").html();
$("#ajax").html(data);
window.history.pushState("Stats", "Stats", cur_url[0]+"?serv="+$("#serv").val());
}
} );
}
@ -186,6 +187,28 @@ function showCompare() {
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());
}
} );
}
function showConfig() {
$.ajax( {
url: "options.py",
data: {
serv: $("#serv").val(),
act: "configShow"
},
type: "GET",
beforeSend: function () {
NProgress.start();
},
complete: function () {
NProgress.done();
},
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");
}
} );
}