v1.10.1
Add functions: "Juast save", start, stop, restart Haproxy service from overview page. Bugs fixedpull/19/head v1.10.1
|
@ -47,16 +47,18 @@ if form.getvalue('serv') is not None and form.getvalue('open') is not None :
|
|||
print('<input type="hidden" value="%s.old" name="oldconfig">' % cfg)
|
||||
print('<textarea name="config" rows="35" cols="100">%s</textarea>' % conf.read())
|
||||
print('<p>')
|
||||
funct.get_button("Just save", value="save")
|
||||
funct.get_button("Save and restart")
|
||||
print('</p></form>')
|
||||
conf.close
|
||||
|
||||
os.system("/bin/sudo /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 :
|
||||
funct.logging(serv, "config.py edited config and restarted service")
|
||||
config = form.getvalue('config')
|
||||
oldcfg = form.getvalue('oldconfig')
|
||||
save = form.getvalue('save')
|
||||
|
||||
try:
|
||||
with open(cfg, "a") as conf:
|
||||
|
@ -66,10 +68,10 @@ if form.getvalue('serv') is not None and form.getvalue('config') is not None :
|
|||
|
||||
print("<b>New config was saved as: %s </b></br></br>" % cfg)
|
||||
|
||||
funct.upload_and_restart(serv, 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/sudo /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)
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ if serv is not None and form.getvalue('open') is not None:
|
|||
print('<a name="conf"></a></center>')
|
||||
funct.show_config(configver)
|
||||
print('<center><p>')
|
||||
funct.get_button("Just save", value="save")
|
||||
funct.get_button("Upload and restart")
|
||||
print('</p></form></center>')
|
||||
|
||||
|
@ -75,12 +76,13 @@ if serv is not None and form.getvalue('open') is not None:
|
|||
if form.getvalue('serv') is not None and form.getvalue('config') is not None:
|
||||
configver = form.getvalue('configver')
|
||||
configver = hap_configs_dir + configver
|
||||
save = form.getvalue('save')
|
||||
|
||||
funct.logging(serv, "configver.py upload old config %s" % configver)
|
||||
|
||||
print("<b>Uploaded old config ver: %s </b></br></br>" % configver)
|
||||
|
||||
funct.upload_and_restart(serv, configver)
|
||||
funct.upload_and_restart(serv, configver, just_save=save)
|
||||
|
||||
print('</br><a href="viewsttats.py?serv=%s" target="_blank" title="View stats">Go to view stats</a> <br />' % serv)
|
||||
|
||||
|
|
|
@ -67,16 +67,7 @@ def check_login(**kwargs):
|
|||
|
||||
if login is None:
|
||||
print('<meta http-equiv="refresh" content="0; url=login.py?ref=%s">' % ref)
|
||||
|
||||
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>')
|
||||
else:
|
||||
print('<li><a href=/cgi-bin/login.py?logout=logout title="Logout, user name: %s">Logout</a></li>' % login.value)
|
||||
|
||||
|
||||
def is_admin(**kwargs):
|
||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||
role = cookie.get('role')
|
||||
|
@ -165,7 +156,7 @@ def links():
|
|||
'<li><a href=/cgi-bin/map.py title="View map">Map</a></li>'
|
||||
'</ul>'
|
||||
'</li>'
|
||||
'<li><a href=/cgi-bin/edit.py title="Runtime API" style="size:5">Runtime API</a> </li>'
|
||||
'<li><a href=/cgi-bin/edit.py title="Runtime API">Runtime API</a> </li>'
|
||||
'<li><a href="#">Configs</a>'
|
||||
'<ul>'
|
||||
'<li><a href=/cgi-bin/configshow.py title="Show Config">Show</a></li> '
|
||||
|
@ -187,11 +178,21 @@ def links():
|
|||
'</li>')
|
||||
show_login_links()
|
||||
print('</ul>'
|
||||
'</nav>')
|
||||
'</nav>'
|
||||
'<div class="copyright-menu">HAproxy-WI v1.10.1</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>')
|
||||
else:
|
||||
print('<li><a href=/cgi-bin/login.py?logout=logout title="Logout, user name: %s">Logout</a></li>' % login.value)
|
||||
|
||||
def footer():
|
||||
print('</center></div>'
|
||||
'<center style="margin-left: 12%;">'
|
||||
'<center style="margin-left: 8%;">'
|
||||
'<h3>'
|
||||
'<a class="ui-button ui-widget ui-corner-all" href="#top" title="Move up">UP</a>'
|
||||
'</h3><br />'
|
||||
|
@ -274,7 +275,7 @@ def show_config(cfg):
|
|||
print('</div></div>')
|
||||
conf.close
|
||||
|
||||
def upload_and_restart(serv, cfg):
|
||||
def upload_and_restart(serv, cfg, **kwargs):
|
||||
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||
now_utc = datetime.now(timezone(config.get('main', 'time_zone')))
|
||||
tmp_file = tmp_config_path + "/" + now_utc.strftime(fmt) + ".cfg"
|
||||
|
@ -284,7 +285,12 @@ def upload_and_restart(serv, cfg):
|
|||
sftp = ssh.open_sftp()
|
||||
sftp.put(cfg, tmp_file)
|
||||
sftp.close()
|
||||
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path, restart_command ]
|
||||
|
||||
if kwargs.get("just_save") == "save":
|
||||
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path ]
|
||||
else:
|
||||
commands = [ "/sbin/haproxy -q -c -f " + tmp_file, "mv -f " + tmp_file + " " + haproxy_config_path, restart_command ]
|
||||
|
||||
i = 0
|
||||
for command in commands:
|
||||
i = i + 1
|
||||
|
@ -308,7 +314,17 @@ def upload_and_restart(serv, cfg):
|
|||
return True
|
||||
|
||||
ssh.close()
|
||||
|
||||
|
||||
def check_haproxy_config(serv):
|
||||
commands = [ "/sbin/haproxy -q -c -f %s" % haproxy_config_path ]
|
||||
ssh = ssh_connect(serv)
|
||||
for command in commands:
|
||||
stdin , stdout, stderr = ssh.exec_command(command)
|
||||
if not stderr.read():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def compare(stdout):
|
||||
i = 0
|
||||
minus = 0
|
||||
|
@ -355,13 +371,17 @@ def show_ip(stdout):
|
|||
|
||||
def server_status(stdout):
|
||||
proc_count = ""
|
||||
i = 0
|
||||
for line in stdout.read().decode(encoding='UTF-8'):
|
||||
proc_count += line
|
||||
if "0" != line:
|
||||
err = 0
|
||||
else:
|
||||
err = 1
|
||||
if err == 0:
|
||||
i = i + 1
|
||||
if i == 1:
|
||||
proc_count += line
|
||||
if line.find("0"):
|
||||
err = 1
|
||||
else:
|
||||
err = 0
|
||||
|
||||
if err != 0:
|
||||
print('<span class="serverUp"> UP</span> running %s processes' % proc_count)
|
||||
else:
|
||||
print('<span class="serverDown"> DOWN</span> running %s processes' % proc_count)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[main]
|
||||
#Path to files destination
|
||||
fullpath = /var/www/haproxy-wi/
|
||||
cgi_path = %(fullpath)s/cgi-bin/
|
||||
server_bind_ip = 0.0.0.0
|
||||
server_port = 8000
|
||||
log_path = %(fullpath)s/log/
|
||||
|
|
|
@ -54,6 +54,16 @@ if form.getvalue('name') is not None:
|
|||
print("yes")
|
||||
break
|
||||
|
||||
if form.getvalue('action') is not None and serv is not None:
|
||||
serv = form.getvalue('serv')
|
||||
action = form.getvalue('action')
|
||||
|
||||
if funct.check_haproxy_config(serv):
|
||||
commands = [ "systemctl %s haproxy" % action ]
|
||||
funct.ssh_command(serv, commands)
|
||||
else:
|
||||
print("Bad config, check please")
|
||||
|
||||
if form.getvalue('tailf_stop') is not None:
|
||||
serv = form.getvalue('serv')
|
||||
commands = [ "ps ax |grep python3 |grep -v grep |awk '{ print $1 }' |xargs kill" ]
|
||||
|
|
|
@ -82,6 +82,10 @@ for i in sorted(listhap):
|
|||
print('<tr><td class="padding10 first-collumn"><a href="#%s" title="Go to %s status" style="color: #000">%s</a></td><td class="second-collumn">' % (i, i, i))
|
||||
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 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))
|
||||
|
@ -99,7 +103,7 @@ print('</table><table class="overview"><tr class="overviewHead">'
|
|||
'Server status'
|
||||
'<span style="float: right; margin-left: 80&;">'
|
||||
'<a href="" title="Update status" id="update">'
|
||||
'<img alt="Update" src="/image/pic/update.png" style="max-width: 20px;">'
|
||||
'<img alt="Update" src="/image/pic/update.png" class="icon" style="padding-right: 8px; float: right">'
|
||||
'</a>'
|
||||
'</span>'
|
||||
'</td>'
|
||||
|
|
BIN
image/5.jpeg
Before Width: | Height: | Size: 249 KiB After Width: | Height: | Size: 255 KiB |
BIN
image/7.jpeg
Before Width: | Height: | Size: 583 KiB After Width: | Height: | Size: 573 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 674 B |
|
@ -49,6 +49,40 @@ $( function() {
|
|||
.data('isAllOpen', isAllOpen);
|
||||
});
|
||||
|
||||
function ajaxActionServers(action, id) {
|
||||
var bad_ans = 'Bad config, check please';
|
||||
$.ajax( {
|
||||
url: "options.py",
|
||||
data: {
|
||||
action: action,
|
||||
serv: id
|
||||
},
|
||||
success: function( data ) {
|
||||
data = data.replace(/\s+/g,' ');
|
||||
if( data == 'Bad config, check please ' ) {
|
||||
alert(data);
|
||||
} else {
|
||||
document.location.reload();
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
alert(w.data_error);
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
$('.start').click(function() {
|
||||
var id = $(this).attr('id');
|
||||
ajaxActionServers("start", id);
|
||||
});
|
||||
$('.stop').click(function() {
|
||||
var id = $(this).attr('id');
|
||||
ajaxActionServers("stop", id);
|
||||
});
|
||||
$('.restart').click(function() {
|
||||
var id = $(this).attr('id');
|
||||
ajaxActionServers("restart", id);
|
||||
});
|
||||
|
||||
var location = window.location.href;
|
||||
var cur_url = '/cgi-bin/' + location.split('/').pop();
|
||||
|
|
|
@ -84,7 +84,7 @@ pre {
|
|||
}
|
||||
.container {
|
||||
min-height: calc(100vh - 115px);
|
||||
max-width: 91%;
|
||||
max-width: 89%;
|
||||
min-width: 40%;
|
||||
background-color: #fff;
|
||||
margin-left: 207px;
|
||||
|
@ -143,6 +143,12 @@ pre {
|
|||
color: #23527c;
|
||||
margin-left: 15px;
|
||||
}
|
||||
.copyright-menu {
|
||||
font-weight: bold;
|
||||
font-style: italic;
|
||||
color: #fff;
|
||||
margin-left: 30px;
|
||||
}
|
||||
.line {
|
||||
background-color: #EBF1F1;
|
||||
border: 1px solid #ddd;
|
||||
|
@ -264,6 +270,7 @@ pre {
|
|||
.menu {
|
||||
font-weight: bold;
|
||||
font-style: italic;
|
||||
min-height: calc(100vh - 90px);
|
||||
}
|
||||
.menu ul li{
|
||||
padding: 10px;
|
||||
|
@ -275,7 +282,7 @@ pre {
|
|||
}
|
||||
.menu ul{
|
||||
position: relative;
|
||||
margin: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #33414E;
|
||||
list-style-type: none;
|
||||
|
|