mirror of https://github.com/Aidaho12/haproxy-wi
parent
b6624d91f8
commit
1e53c561ea
|
@ -24,7 +24,7 @@ path_config = "haproxy-webintarface.config"
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(path_config)
|
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')
|
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||||
time_zone = config.get('main', 'time_zone')
|
time_zone = config.get('main', 'time_zone')
|
||||||
|
|
||||||
|
@ -33,16 +33,16 @@ if serv is not None:
|
||||||
now_utc = datetime.now(timezone(time_zone))
|
now_utc = datetime.now(timezone(time_zone))
|
||||||
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
|
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 :
|
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
|
||||||
funct.logging(serv, "config.py open config")
|
funct.logging(serv, "config.py open config")
|
||||||
funct.get_config(serv, cfg)
|
funct.get_config(serv, cfg)
|
||||||
|
|
||||||
conf = open(cfg, "r")
|
conf = open(cfg, "r")
|
||||||
print('<a name="conf"></a>')
|
|
||||||
print("<h3>Config from %s</h3>" % serv)
|
print("<center><h3>Config from %s</h3>" % serv)
|
||||||
print('<form action="config.py#top" method="post">')
|
print('<form action="config.py" method="get">')
|
||||||
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())
|
||||||
|
@ -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))
|
os.system("/bin/mv %s %s.old" % (cfg, cfg))
|
||||||
|
|
||||||
if form.getvalue('serv') is not None and form.getvalue('config') is not None :
|
if form.getvalue('serv') is not None and form.getvalue('config') is not None:
|
||||||
funct.logging(serv, "config.py edited config and restarted service")
|
funct.logging(serv, "config.py edited config")
|
||||||
config = form.getvalue('config')
|
config = form.getvalue('config')
|
||||||
oldcfg = form.getvalue('oldconfig')
|
oldcfg = form.getvalue('oldconfig')
|
||||||
save = form.getvalue('save')
|
save = form.getvalue('save')
|
||||||
|
@ -66,11 +66,11 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None :
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Can't read import config file")
|
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)
|
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")
|
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)
|
print('</br><a href="viewsttats.py?serv=%s" target="_blank" title="View stats">Go to view stats</a> <br />' % serv)
|
||||||
|
|
|
@ -5,8 +5,6 @@ import os
|
||||||
import funct
|
import funct
|
||||||
import paramiko
|
import paramiko
|
||||||
import configparser
|
import configparser
|
||||||
from paramiko import SSHClient
|
|
||||||
from datetime import datetime
|
|
||||||
from pytz import timezone
|
from pytz import timezone
|
||||||
|
|
||||||
form = cgi.FieldStorage()
|
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')
|
haproxy_config_path = config.get('haproxy', 'haproxy_config_path')
|
||||||
time_zone = config.get('main', 'time_zone')
|
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"
|
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||||
now_utc = datetime.now(timezone(time_zone))
|
now_utc = datetime.now(timezone(time_zone))
|
||||||
cfg = hap_configs_dir + serv + "-" + now_utc.strftime(fmt) + ".cfg"
|
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)
|
funct.get_config(serv, cfg)
|
||||||
|
|
||||||
print('<a name="conf"></a>')
|
print("<center><h3>Config from %s</h3>" % serv)
|
||||||
print("<h3>Config from %s</h3>" % serv)
|
|
||||||
print('<p class="accordion-expand-holder">'
|
print('<p class="accordion-expand-holder">'
|
||||||
'<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>'
|
'<a class="accordion-expand-all ui-button ui-widget ui-corner-all" href="#">Expand all</a>'
|
||||||
'</p>')
|
'</p>')
|
||||||
|
print('</center>')
|
||||||
funct.show_config(cfg)
|
funct.show_config(cfg)
|
||||||
|
|
||||||
os.system("/bin/rm -f " + cfg)
|
os.system("/bin/rm -f " + cfg)
|
||||||
|
|
||||||
|
print('</div>')
|
||||||
funct.footer()
|
funct.footer()
|
|
@ -4,6 +4,7 @@ import cgi
|
||||||
import os
|
import os
|
||||||
import funct
|
import funct
|
||||||
import configparser
|
import configparser
|
||||||
|
import glob
|
||||||
|
|
||||||
form = cgi.FieldStorage()
|
form = cgi.FieldStorage()
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
|
@ -19,18 +20,15 @@ config.read(path_config)
|
||||||
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
hap_configs_dir = config.get('configs', 'haproxy_save_configs_dir')
|
||||||
|
|
||||||
funct.page_for_admin(level = 2)
|
funct.page_for_admin(level = 2)
|
||||||
|
funct.chooseServer("delver.py", "Delete Versions HAproxy config", "n")
|
||||||
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="post">'
|
print('<form action="delver.py#conf" method="get">'
|
||||||
'<label for="select_all" id="label_select_all"><b>Select all</b></label>'
|
'<label for="select_all" id="label_select_all"><b>Select all</b></label>'
|
||||||
'<input type="checkbox" id="select_all"><br />')
|
'<input type="checkbox" id="select_all"><br />')
|
||||||
|
|
||||||
import glob
|
|
||||||
|
|
||||||
os.chdir(hap_configs_dir)
|
os.chdir(hap_configs_dir)
|
||||||
|
|
||||||
for files in sorted(glob.glob('*.cfg')):
|
for files in sorted(glob.glob('*.cfg')):
|
||||||
|
|
|
@ -25,7 +25,9 @@ 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")
|
||||||
|
|
||||||
if form.getvalue('serv') is not None and form.getvalue('open') is not None :
|
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('</select>')
|
||||||
print('<input type="hidden" value="%s" name="serv">' % serv)
|
print('<input type="hidden" value="%s" name="serv">' % serv)
|
||||||
print('<input type="hidden" value="open" name="open">')
|
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()
|
funct.footer()
|
|
@ -312,7 +312,7 @@ def get_config(serv, cfg):
|
||||||
print("!!! There was an issue, " + str(e))
|
print("!!! There was an issue, " + str(e))
|
||||||
|
|
||||||
def show_config(cfg):
|
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")
|
conf = open(cfg, "r")
|
||||||
i = 0
|
i = 0
|
||||||
for line in conf:
|
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"
|
tmp_file = tmp_config_path + "/" + now_utc.strftime(fmt) + ".cfg"
|
||||||
|
|
||||||
ssh = ssh_connect(serv)
|
ssh = ssh_connect(serv)
|
||||||
print("connected<br />")
|
print("<center>connected<br />")
|
||||||
sftp = ssh.open_sftp()
|
sftp = ssh.open_sftp()
|
||||||
sftp.put(cfg, tmp_file)
|
sftp.put(cfg, tmp_file)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
@ -389,7 +389,8 @@ def upload_and_restart(serv, cfg, **kwargs):
|
||||||
print("</br>")
|
print("</br>")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
print('</center>')
|
||||||
ssh.close()
|
ssh.close()
|
||||||
|
|
||||||
def check_haproxy_config(serv):
|
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))
|
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')
|
servNew = form.getvalue('serNew')
|
||||||
|
|
||||||
print('<h2>' + title + '</h2><center>')
|
print('<h2>' + title + '</h2><center>')
|
||||||
|
@ -561,10 +562,17 @@ def chooseServer(formName, title, note):
|
||||||
choose_only_select(serv, servNew=servNew)
|
choose_only_select(serv, servNew=servNew)
|
||||||
|
|
||||||
print('</select>')
|
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>')
|
print('</p></form>')
|
||||||
|
|
||||||
if note == "y":
|
if note == "y":
|
||||||
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p>')
|
print('<p><b>Note:</b> If you reconfigure First server, second will reconfigured automatically</p>')
|
||||||
|
print('</center>')
|
||||||
|
|
||||||
def choose_server_with_vip(serv):
|
def choose_server_with_vip(serv):
|
||||||
listhap.listhap = merge_two_dicts(listhap.listhap, listhap.listhap_vip)
|
listhap.listhap = merge_two_dicts(listhap.listhap, listhap.listhap_vip)
|
||||||
|
|
|
@ -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")
|
funct.ssh_command(syslog_server, commands, show_log="1")
|
||||||
print('</div>')
|
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
|
import requests
|
||||||
from requests_toolbelt.utils import dump
|
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) ]
|
commands = [ 'diff -ub %s%s %s%s' % (hap_configs_dir, left, hap_configs_dir, right) ]
|
||||||
|
|
||||||
funct.ssh_command(haproxy_configs_server, commands, compare="1")
|
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:
|
if form.getvalue('tailf_stop') is not None:
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
|
|
|
@ -117,6 +117,7 @@ function showStats() {
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
var form = $("#ajax").html();
|
var form = $("#ajax").html();
|
||||||
$("#ajax").html(data);
|
$("#ajax").html(data);
|
||||||
|
window.history.pushState("Stats", "Stats", cur_url[0]+"?serv="+$("#serv").val());
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -186,6 +187,28 @@ function showCompare() {
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
var form = $("#ajax").html();
|
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());
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue