pull/42/head
Aidaho12 2018-08-28 16:45:09 +06:00
parent 3f8a687176
commit d4b36019e1
7 changed files with 87 additions and 24 deletions

View File

@ -10,6 +10,11 @@ env = Environment(loader=FileSystemLoader('templates/'))
template = env.get_template('add.html')
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')
funct.check_login()
funct.page_for_admin(level = 2)
@ -24,21 +29,20 @@ try:
except:
pass
output_from_parsed_template = template.render(title = "Add",
role = sql.get_user_role_by_uuid(user_id.value),
user = user,
selects = servers,
add = form.getvalue('add'),
conf_add = form.getvalue('conf'),
group = user_group,
token = token)
print(output_from_parsed_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')
template = template.render(title = "Add",
role = sql.get_user_role_by_uuid(user_id.value),
user = user,
selects = servers,
add = form.getvalue('add'),
conf_add = form.getvalue('conf'),
group = user_group,
token = token)
print(template)
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')
port = form.getvalue('port')
force_close = form.getvalue('force_close')
@ -189,11 +193,11 @@ if form.getvalue('mode') is not None:
if master[0] != None:
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:
print('<div class="alert alert-danger">%s</div>' % stderr)
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>')

View File

@ -15,10 +15,18 @@ backend = form.getvalue('backend')
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:
print("What the fuck?! U r hacker Oo?!")
sys.exit()
if form.getvalue('getcerts') is not None and serv is not None:
cert_path = sql.get_setting('cert_path')
commands = [ "ls -1t "+cert_path+" |grep pem" ]

View File

@ -457,6 +457,8 @@ def get_dick_permit(**kwargs):
import os
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_id = cookie.get('uuid')
disable = ''
ip = ''
con, cur = create_db.get_cur()
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"
if kwargs.get('disable') == 0:
disable = 'or enable = 0'
else:
disable = ''
if kwargs.get('ip'):
ip = "and ip = '%s'" % kwargs.get('ip')
try:
cur.execute(sql)
@ -478,7 +481,7 @@ def get_dick_permit(**kwargs):
if group[5] == '1':
sql = """ select * from servers where enable = 1 %s %s """ % (disable, type_ip)
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:
cur.execute(sql)
except sqltool.Error as e:

View File

@ -192,6 +192,13 @@
</div>
</div>
{% 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 %}
<div id="ajax-compare"></div>
<div id="ajax"></div>

View File

@ -81,6 +81,10 @@ $( function() {
}
});
$('#secIntervals').css('display', 'none');
$('#apply_close').click( function() {
$("#apply").css('display', 'none');
Cookies.remove('restart', { path: '' });
});
});
function confirmAjaxAction(action, service, id) {
$( "#dialog-confirm" ).dialog({
@ -94,6 +98,12 @@ function confirmAjaxAction(action, service, id) {
$( this ).dialog( "close" );
if(service == "hap") {
ajaxActionServers(action, id);
if(action == "restart") {
if(Cookies.get('restart')) {
Cookies.remove('restart', { path: '' });
$("#apply").css('display', 'none');
}
}
} else if (service == "waf") {
ajaxActionWafServers(action, id)
}

View File

@ -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) {
var margin;
if (cur_url[0] == "overview.py") {
@ -64,7 +89,7 @@ function autoRefreshStyle(autoRefresh) {
function setRefreshInterval(interval) {
if (interval == "0") {
Cookies.remove('auto-refresh');
Cookies.remove('auto-refresh', { path: '' });
pauseAutoRefresh();
$('.auto-refresh').prepend('<img src=/image/pic/update.png alt="restart" class="icon">');
$('.auto-refresh').css('margin-top', '-3px');
@ -156,7 +181,6 @@ function showOverview() {
success: function( data ) {
$("#ajaxstatus").empty();
$("#ajaxstatus").html(data);
$.getScript('/inc/overview.js');
}
} );
}
@ -188,7 +212,6 @@ function showOverviewServers() {
type: "GET",
success: function( data ) {
$("#ajaxservers").html(data);
$.getScript('/inc/overview.js');
}
} );
}

View File

@ -222,7 +222,7 @@ pre {
padding-left: 10px;
padding-right: 10px;
}
.line:hover, .line3:hover, tr:hover {
.line:hover, .line3:hover {
background-color: #f6f8fa;
}
.time-range {
@ -239,6 +239,9 @@ pre {
.comment {
color: #aaa;
}
.add-table {
width: 100%;
}
.addName {
background-color: #f6f6f6;
width: 120px;
@ -269,6 +272,11 @@ pre {
padding-top: 20px;
color: #23527c;
}
.add-note {
width: 30%;
padding-left: 10px;
font-style: italic;
}
.tooltip {
font-size: 12px;
padding-bottom: 10px;