mirror of https://github.com/Aidaho12/haproxy-wi
v3.2.2
parent
3f8a687176
commit
d4b36019e1
34
app/add.py
34
app/add.py
|
@ -10,6 +10,11 @@ env = Environment(loader=FileSystemLoader('templates/'))
|
||||||
template = env.get_template('add.html')
|
template = env.get_template('add.html')
|
||||||
form = cgi.FieldStorage()
|
form = cgi.FieldStorage()
|
||||||
|
|
||||||
|
if form.getvalue('add'):
|
||||||
|
c = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
|
c["restart"] = form.getvalue('serv')
|
||||||
|
print(c)
|
||||||
|
|
||||||
print('Content-type: text/html\n')
|
print('Content-type: text/html\n')
|
||||||
funct.check_login()
|
funct.check_login()
|
||||||
funct.page_for_admin(level = 2)
|
funct.page_for_admin(level = 2)
|
||||||
|
@ -24,21 +29,20 @@ try:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
output_from_parsed_template = template.render(title = "Add",
|
template = template.render(title = "Add",
|
||||||
role = sql.get_user_role_by_uuid(user_id.value),
|
role = sql.get_user_role_by_uuid(user_id.value),
|
||||||
user = user,
|
user = user,
|
||||||
selects = servers,
|
selects = servers,
|
||||||
add = form.getvalue('add'),
|
add = form.getvalue('add'),
|
||||||
conf_add = form.getvalue('conf'),
|
conf_add = form.getvalue('conf'),
|
||||||
group = user_group,
|
group = user_group,
|
||||||
token = token)
|
token = token)
|
||||||
print(output_from_parsed_template)
|
print(template)
|
||||||
|
|
||||||
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
|
||||||
cert_path = sql.get_setting('cert_path')
|
|
||||||
haproxy_dir = sql.get_setting('haproxy_dir')
|
|
||||||
|
|
||||||
if form.getvalue('mode') is not None:
|
if form.getvalue('mode') is not None:
|
||||||
|
hap_configs_dir = funct.get_config_var('configs', 'haproxy_save_configs_dir')
|
||||||
|
cert_path = sql.get_setting('cert_path')
|
||||||
|
haproxy_dir = sql.get_setting('haproxy_dir')
|
||||||
serv = form.getvalue('serv')
|
serv = form.getvalue('serv')
|
||||||
port = form.getvalue('port')
|
port = form.getvalue('port')
|
||||||
force_close = form.getvalue('force_close')
|
force_close = form.getvalue('force_close')
|
||||||
|
@ -189,11 +193,11 @@ if form.getvalue('mode') is not None:
|
||||||
if master[0] != None:
|
if master[0] != None:
|
||||||
funct.upload_and_restart(master[0], cfg)
|
funct.upload_and_restart(master[0], cfg)
|
||||||
|
|
||||||
stderr = funct.upload_and_restart(serv, cfg)
|
stderr = funct.upload_and_restart(serv, cfg, just_save="save")
|
||||||
if stderr:
|
if stderr:
|
||||||
print('<div class="alert alert-danger">%s</div>' % stderr)
|
print('<div class="alert alert-danger">%s</div>' % stderr)
|
||||||
else:
|
else:
|
||||||
print('<meta http-equiv="refresh" content="0; url=add.py?add=%s&conf=%s">' % (name, config_add))
|
print('<meta http-equiv="refresh" content="0; url=add.py?add=%s&conf=%s&serv=%s">' % (name, config_add, serv))
|
||||||
|
|
||||||
print('</div>')
|
print('</div>')
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,18 @@ backend = form.getvalue('backend')
|
||||||
|
|
||||||
print('Content-type: text/html\n')
|
print('Content-type: text/html\n')
|
||||||
|
|
||||||
|
if act == "checkrestart":
|
||||||
|
servers = sql.get_dick_permit(ip=serv)
|
||||||
|
for server in servers:
|
||||||
|
if server != "":
|
||||||
|
print("ok")
|
||||||
|
sys.exit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
if form.getvalue('token') is None:
|
if form.getvalue('token') is None:
|
||||||
print("What the fuck?! U r hacker Oo?!")
|
print("What the fuck?! U r hacker Oo?!")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if form.getvalue('getcerts') is not None and serv is not None:
|
if form.getvalue('getcerts') is not None and serv is not None:
|
||||||
cert_path = sql.get_setting('cert_path')
|
cert_path = sql.get_setting('cert_path')
|
||||||
commands = [ "ls -1t "+cert_path+" |grep pem" ]
|
commands = [ "ls -1t "+cert_path+" |grep pem" ]
|
||||||
|
|
|
@ -457,6 +457,8 @@ def get_dick_permit(**kwargs):
|
||||||
import os
|
import os
|
||||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
user_id = cookie.get('uuid')
|
user_id = cookie.get('uuid')
|
||||||
|
disable = ''
|
||||||
|
ip = ''
|
||||||
|
|
||||||
con, cur = create_db.get_cur()
|
con, cur = create_db.get_cur()
|
||||||
sql = """ select * from user where username = '%s' """ % get_user_name_by_uuid(user_id.value)
|
sql = """ select * from user where username = '%s' """ % get_user_name_by_uuid(user_id.value)
|
||||||
|
@ -466,8 +468,9 @@ def get_dick_permit(**kwargs):
|
||||||
type_ip = "and type_ip = 0"
|
type_ip = "and type_ip = 0"
|
||||||
if kwargs.get('disable') == 0:
|
if kwargs.get('disable') == 0:
|
||||||
disable = 'or enable = 0'
|
disable = 'or enable = 0'
|
||||||
else:
|
if kwargs.get('ip'):
|
||||||
disable = ''
|
ip = "and ip = '%s'" % kwargs.get('ip')
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
|
@ -478,7 +481,7 @@ def get_dick_permit(**kwargs):
|
||||||
if group[5] == '1':
|
if group[5] == '1':
|
||||||
sql = """ select * from servers where enable = 1 %s %s """ % (disable, type_ip)
|
sql = """ select * from servers where enable = 1 %s %s """ % (disable, type_ip)
|
||||||
else:
|
else:
|
||||||
sql = """ select * from servers where groups like '%{group}%' and (enable = 1 {disable}) {type_ip} """.format(group=group[5], disable=disable, type_ip=type_ip)
|
sql = """ select * from servers where groups like '%{group}%' and (enable = 1 {disable}) {type_ip} {ip} """.format(group=group[5], disable=disable, type_ip=type_ip, ip=ip)
|
||||||
try:
|
try:
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
except sqltool.Error as e:
|
except sqltool.Error as e:
|
||||||
|
|
|
@ -192,6 +192,13 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if role %}
|
||||||
|
{% if role <= 2 %}
|
||||||
|
<div id="apply" style="display: none;">
|
||||||
|
<div class="alert alert-warning" id="apply_div"></div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
<div id="ajax-compare"></div>
|
<div id="ajax-compare"></div>
|
||||||
<div id="ajax"></div>
|
<div id="ajax"></div>
|
||||||
|
|
|
@ -81,6 +81,10 @@ $( function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#secIntervals').css('display', 'none');
|
$('#secIntervals').css('display', 'none');
|
||||||
|
$('#apply_close').click( function() {
|
||||||
|
$("#apply").css('display', 'none');
|
||||||
|
Cookies.remove('restart', { path: '' });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
function confirmAjaxAction(action, service, id) {
|
function confirmAjaxAction(action, service, id) {
|
||||||
$( "#dialog-confirm" ).dialog({
|
$( "#dialog-confirm" ).dialog({
|
||||||
|
@ -94,6 +98,12 @@ function confirmAjaxAction(action, service, id) {
|
||||||
$( this ).dialog( "close" );
|
$( this ).dialog( "close" );
|
||||||
if(service == "hap") {
|
if(service == "hap") {
|
||||||
ajaxActionServers(action, id);
|
ajaxActionServers(action, id);
|
||||||
|
if(action == "restart") {
|
||||||
|
if(Cookies.get('restart')) {
|
||||||
|
Cookies.remove('restart', { path: '' });
|
||||||
|
$("#apply").css('display', 'none');
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (service == "waf") {
|
} else if (service == "waf") {
|
||||||
ajaxActionWafServers(action, id)
|
ajaxActionWafServers(action, id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,32 @@ window.onblur= function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if(Cookies.get('restart')) {
|
||||||
|
var ip = Cookies.get('restart');
|
||||||
|
$.ajax( {
|
||||||
|
url: "options.py",
|
||||||
|
data: {
|
||||||
|
act: "checkrestart",
|
||||||
|
serv: ip,
|
||||||
|
token: $('#token').val()
|
||||||
|
},
|
||||||
|
type: "GET",
|
||||||
|
success: function( data ) {
|
||||||
|
if(data.indexOf('ok') != '-1') {
|
||||||
|
$("#apply").css('display', 'block');
|
||||||
|
$("#apply_div").css('width', '850px');
|
||||||
|
if (cur_url[0] == "overview.py") {
|
||||||
|
$("#apply_div").css('width', '650px');
|
||||||
|
$("#apply_div").html("You made changes to the server: "+ip+". Changes will take effect only after<a id='"+ip+"' class='restart' title='Restart HAproxy service'>restart</a><a href='#' title='close' id='apply_close' style='float: right'><b>X</b></a>");
|
||||||
|
$.getScript('/inc/overview.js');
|
||||||
|
} else {
|
||||||
|
$("#apply_div").html("You made changes to the server: "+ip+". Changes will take effect only after restart. <a href='overview.py' title='Overview'>Go to Overview page and restart</a><a href='#' title='close' id='apply_close' style='float: right'><b>X</b></a>");
|
||||||
|
$.getScript('/inc/overview.js');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
function autoRefreshStyle(autoRefresh) {
|
function autoRefreshStyle(autoRefresh) {
|
||||||
var margin;
|
var margin;
|
||||||
if (cur_url[0] == "overview.py") {
|
if (cur_url[0] == "overview.py") {
|
||||||
|
@ -64,7 +89,7 @@ function autoRefreshStyle(autoRefresh) {
|
||||||
|
|
||||||
function setRefreshInterval(interval) {
|
function setRefreshInterval(interval) {
|
||||||
if (interval == "0") {
|
if (interval == "0") {
|
||||||
Cookies.remove('auto-refresh');
|
Cookies.remove('auto-refresh', { path: '' });
|
||||||
pauseAutoRefresh();
|
pauseAutoRefresh();
|
||||||
$('.auto-refresh').prepend('<img src=/image/pic/update.png alt="restart" class="icon">');
|
$('.auto-refresh').prepend('<img src=/image/pic/update.png alt="restart" class="icon">');
|
||||||
$('.auto-refresh').css('margin-top', '-3px');
|
$('.auto-refresh').css('margin-top', '-3px');
|
||||||
|
@ -156,7 +181,6 @@ function showOverview() {
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
$("#ajaxstatus").empty();
|
$("#ajaxstatus").empty();
|
||||||
$("#ajaxstatus").html(data);
|
$("#ajaxstatus").html(data);
|
||||||
$.getScript('/inc/overview.js');
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -188,7 +212,6 @@ function showOverviewServers() {
|
||||||
type: "GET",
|
type: "GET",
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
$("#ajaxservers").html(data);
|
$("#ajaxservers").html(data);
|
||||||
$.getScript('/inc/overview.js');
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ pre {
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
padding-right: 10px;
|
padding-right: 10px;
|
||||||
}
|
}
|
||||||
.line:hover, .line3:hover, tr:hover {
|
.line:hover, .line3:hover {
|
||||||
background-color: #f6f8fa;
|
background-color: #f6f8fa;
|
||||||
}
|
}
|
||||||
.time-range {
|
.time-range {
|
||||||
|
@ -239,6 +239,9 @@ pre {
|
||||||
.comment {
|
.comment {
|
||||||
color: #aaa;
|
color: #aaa;
|
||||||
}
|
}
|
||||||
|
.add-table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
.addName {
|
.addName {
|
||||||
background-color: #f6f6f6;
|
background-color: #f6f6f6;
|
||||||
width: 120px;
|
width: 120px;
|
||||||
|
@ -269,6 +272,11 @@ pre {
|
||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
color: #23527c;
|
color: #23527c;
|
||||||
}
|
}
|
||||||
|
.add-note {
|
||||||
|
width: 30%;
|
||||||
|
padding-left: 10px;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
.tooltip {
|
.tooltip {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
|
|
Loading…
Reference in New Issue