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('<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())
|
||||||
print('<p>')
|
print('<p>')
|
||||||
|
funct.get_button("Just save", value="save")
|
||||||
funct.get_button("Save and restart")
|
funct.get_button("Save and restart")
|
||||||
print('</p></form>')
|
print('</p></form>')
|
||||||
conf.close
|
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 :
|
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 and restarted service")
|
||||||
config = form.getvalue('config')
|
config = form.getvalue('config')
|
||||||
oldcfg = form.getvalue('oldconfig')
|
oldcfg = form.getvalue('oldconfig')
|
||||||
|
save = form.getvalue('save')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(cfg, "a") as conf:
|
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)
|
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/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)
|
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>')
|
print('<a name="conf"></a></center>')
|
||||||
funct.show_config(configver)
|
funct.show_config(configver)
|
||||||
print('<center><p>')
|
print('<center><p>')
|
||||||
|
funct.get_button("Just save", value="save")
|
||||||
funct.get_button("Upload and restart")
|
funct.get_button("Upload and restart")
|
||||||
print('</p></form></center>')
|
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:
|
if form.getvalue('serv') is not None and form.getvalue('config') is not None:
|
||||||
configver = form.getvalue('configver')
|
configver = form.getvalue('configver')
|
||||||
configver = hap_configs_dir + configver
|
configver = hap_configs_dir + configver
|
||||||
|
save = form.getvalue('save')
|
||||||
|
|
||||||
funct.logging(serv, "configver.py upload old config %s" % configver)
|
funct.logging(serv, "configver.py upload old config %s" % configver)
|
||||||
|
|
||||||
print("<b>Uploaded old config ver: %s </b></br></br>" % 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)
|
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:
|
if login is None:
|
||||||
print('<meta http-equiv="refresh" content="0; url=login.py?ref=%s">' % ref)
|
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):
|
def is_admin(**kwargs):
|
||||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
role = cookie.get('role')
|
role = cookie.get('role')
|
||||||
|
@ -165,7 +156,7 @@ def links():
|
||||||
'<li><a href=/cgi-bin/map.py title="View map">Map</a></li>'
|
'<li><a href=/cgi-bin/map.py title="View map">Map</a></li>'
|
||||||
'</ul>'
|
'</ul>'
|
||||||
'</li>'
|
'</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>'
|
'<li><a href="#">Configs</a>'
|
||||||
'<ul>'
|
'<ul>'
|
||||||
'<li><a href=/cgi-bin/configshow.py title="Show Config">Show</a></li> '
|
'<li><a href=/cgi-bin/configshow.py title="Show Config">Show</a></li> '
|
||||||
|
@ -187,11 +178,21 @@ def links():
|
||||||
'</li>')
|
'</li>')
|
||||||
show_login_links()
|
show_login_links()
|
||||||
print('</ul>'
|
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():
|
def footer():
|
||||||
print('</center></div>'
|
print('</center></div>'
|
||||||
'<center style="margin-left: 12%;">'
|
'<center style="margin-left: 8%;">'
|
||||||
'<h3>'
|
'<h3>'
|
||||||
'<a class="ui-button ui-widget ui-corner-all" href="#top" title="Move up">UP</a>'
|
'<a class="ui-button ui-widget ui-corner-all" href="#top" title="Move up">UP</a>'
|
||||||
'</h3><br />'
|
'</h3><br />'
|
||||||
|
@ -274,7 +275,7 @@ def show_config(cfg):
|
||||||
print('</div></div>')
|
print('</div></div>')
|
||||||
conf.close
|
conf.close
|
||||||
|
|
||||||
def upload_and_restart(serv, cfg):
|
def upload_and_restart(serv, cfg, **kwargs):
|
||||||
fmt = "%Y-%m-%d.%H:%M:%S"
|
fmt = "%Y-%m-%d.%H:%M:%S"
|
||||||
now_utc = datetime.now(timezone(config.get('main', 'time_zone')))
|
now_utc = datetime.now(timezone(config.get('main', 'time_zone')))
|
||||||
tmp_file = tmp_config_path + "/" + now_utc.strftime(fmt) + ".cfg"
|
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 = ssh.open_sftp()
|
||||||
sftp.put(cfg, tmp_file)
|
sftp.put(cfg, tmp_file)
|
||||||
sftp.close()
|
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
|
i = 0
|
||||||
for command in commands:
|
for command in commands:
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
@ -308,7 +314,17 @@ def upload_and_restart(serv, cfg):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
ssh.close()
|
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):
|
def compare(stdout):
|
||||||
i = 0
|
i = 0
|
||||||
minus = 0
|
minus = 0
|
||||||
|
@ -355,13 +371,17 @@ def show_ip(stdout):
|
||||||
|
|
||||||
def server_status(stdout):
|
def server_status(stdout):
|
||||||
proc_count = ""
|
proc_count = ""
|
||||||
|
i = 0
|
||||||
for line in stdout.read().decode(encoding='UTF-8'):
|
for line in stdout.read().decode(encoding='UTF-8'):
|
||||||
proc_count += line
|
i = i + 1
|
||||||
if "0" != line:
|
if i == 1:
|
||||||
err = 0
|
proc_count += line
|
||||||
else:
|
if line.find("0"):
|
||||||
err = 1
|
err = 1
|
||||||
if err == 0:
|
else:
|
||||||
|
err = 0
|
||||||
|
|
||||||
|
if err != 0:
|
||||||
print('<span class="serverUp"> UP</span> running %s processes' % proc_count)
|
print('<span class="serverUp"> UP</span> running %s processes' % proc_count)
|
||||||
else:
|
else:
|
||||||
print('<span class="serverDown"> DOWN</span> running %s processes' % proc_count)
|
print('<span class="serverDown"> DOWN</span> running %s processes' % proc_count)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
[main]
|
[main]
|
||||||
#Path to files destination
|
#Path to files destination
|
||||||
fullpath = /var/www/haproxy-wi/
|
fullpath = /var/www/haproxy-wi/
|
||||||
|
cgi_path = %(fullpath)s/cgi-bin/
|
||||||
server_bind_ip = 0.0.0.0
|
server_bind_ip = 0.0.0.0
|
||||||
server_port = 8000
|
server_port = 8000
|
||||||
log_path = %(fullpath)s/log/
|
log_path = %(fullpath)s/log/
|
||||||
|
|
|
@ -54,6 +54,16 @@ if form.getvalue('name') is not None:
|
||||||
print("yes")
|
print("yes")
|
||||||
break
|
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:
|
if form.getvalue('tailf_stop') is not None:
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
commands = [ "ps ax |grep python3 |grep -v grep |awk '{ print $1 }' |xargs kill" ]
|
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))
|
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")
|
funct.ssh_command(listhap.get(i), commands, server_status="1")
|
||||||
print('</td><td>')
|
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/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/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))
|
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'
|
'Server status'
|
||||||
'<span style="float: right; margin-left: 80&;">'
|
'<span style="float: right; margin-left: 80&;">'
|
||||||
'<a href="" title="Update status" id="update">'
|
'<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>'
|
'</a>'
|
||||||
'</span>'
|
'</span>'
|
||||||
'</td>'
|
'</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);
|
.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 location = window.location.href;
|
||||||
var cur_url = '/cgi-bin/' + location.split('/').pop();
|
var cur_url = '/cgi-bin/' + location.split('/').pop();
|
||||||
|
|
|
@ -84,7 +84,7 @@ pre {
|
||||||
}
|
}
|
||||||
.container {
|
.container {
|
||||||
min-height: calc(100vh - 115px);
|
min-height: calc(100vh - 115px);
|
||||||
max-width: 91%;
|
max-width: 89%;
|
||||||
min-width: 40%;
|
min-width: 40%;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
margin-left: 207px;
|
margin-left: 207px;
|
||||||
|
@ -143,6 +143,12 @@ pre {
|
||||||
color: #23527c;
|
color: #23527c;
|
||||||
margin-left: 15px;
|
margin-left: 15px;
|
||||||
}
|
}
|
||||||
|
.copyright-menu {
|
||||||
|
font-weight: bold;
|
||||||
|
font-style: italic;
|
||||||
|
color: #fff;
|
||||||
|
margin-left: 30px;
|
||||||
|
}
|
||||||
.line {
|
.line {
|
||||||
background-color: #EBF1F1;
|
background-color: #EBF1F1;
|
||||||
border: 1px solid #ddd;
|
border: 1px solid #ddd;
|
||||||
|
@ -264,6 +270,7 @@ pre {
|
||||||
.menu {
|
.menu {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
|
min-height: calc(100vh - 90px);
|
||||||
}
|
}
|
||||||
.menu ul li{
|
.menu ul li{
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
@ -275,7 +282,7 @@ pre {
|
||||||
}
|
}
|
||||||
.menu ul{
|
.menu ul{
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
background-color: #33414E;
|
background-color: #33414E;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
|
|