mirror of https://github.com/Aidaho12/haproxy-wi
parent
17edd5c92b
commit
bc38039f61
20
app/funct.py
20
app/funct.py
|
@ -50,6 +50,7 @@ def logging(serv, action, **kwargs):
|
||||||
import sql
|
import sql
|
||||||
import http.cookies
|
import http.cookies
|
||||||
log_path = get_config_var('main', 'log_path')
|
log_path = get_config_var('main', 'log_path')
|
||||||
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
|
|
||||||
if not os.path.exists(log_path):
|
if not os.path.exists(log_path):
|
||||||
os.makedirs(log_path)
|
os.makedirs(log_path)
|
||||||
|
@ -59,12 +60,21 @@ def logging(serv, action, **kwargs):
|
||||||
except:
|
except:
|
||||||
IP = ''
|
IP = ''
|
||||||
try:
|
try:
|
||||||
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
|
||||||
user_uuid = cookie.get('uuid')
|
user_uuid = cookie.get('uuid')
|
||||||
login = sql.get_user_name_by_uuid(user_uuid.value)
|
login = sql.get_user_name_by_uuid(user_uuid.value)
|
||||||
except:
|
except:
|
||||||
login = ''
|
login = ''
|
||||||
|
|
||||||
|
try:
|
||||||
|
user_group_id = cookie.get('group')
|
||||||
|
user_group_id1 = user_group_id.value
|
||||||
|
groups = sql.select_groups(id=user_group_id1)
|
||||||
|
for g in groups:
|
||||||
|
if g[0] == int(user_group_id1):
|
||||||
|
user_group = g[1]
|
||||||
|
except:
|
||||||
|
user_group = ''
|
||||||
|
|
||||||
if kwargs.get('alerting') == 1:
|
if kwargs.get('alerting') == 1:
|
||||||
mess = get_data('date_in_log') + action + "\n"
|
mess = get_data('date_in_log') + action + "\n"
|
||||||
log = open(log_path + "/checker-"+get_data('logs')+".log", "a")
|
log = open(log_path + "/checker-"+get_data('logs')+".log", "a")
|
||||||
|
@ -76,12 +86,14 @@ def logging(serv, action, **kwargs):
|
||||||
log = open(log_path + "/keep_alive-"+get_data('logs')+".log", "a")
|
log = open(log_path + "/keep_alive-"+get_data('logs')+".log", "a")
|
||||||
elif kwargs.get('haproxywi') == 1:
|
elif kwargs.get('haproxywi') == 1:
|
||||||
if kwargs.get('login'):
|
if kwargs.get('login'):
|
||||||
mess = get_data('date_in_log') + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n"
|
mess = get_data('date_in_log') + " from " + IP + " user: " + login + ", group: " +user_group + ", " + \
|
||||||
|
action + " for: " + serv + "\n"
|
||||||
else:
|
else:
|
||||||
mess = get_data('date_in_log') + action + " from " + IP + "\n"
|
mess = get_data('date_in_log') + ", group: " +user_group + ", " + action + " from " + IP + "\n"
|
||||||
log = open(log_path + "/haproxy-wi-"+get_data('logs')+".log", "a")
|
log = open(log_path + "/haproxy-wi-"+get_data('logs')+".log", "a")
|
||||||
else:
|
else:
|
||||||
mess = get_data('date_in_log') + " from " + IP + " user: " + login + " " + action + " for: " + serv + "\n"
|
mess = get_data('date_in_log') + " from " + IP + " user: " + login + ", group: " +user_group + ", " + \
|
||||||
|
action + " for: " + serv + "\n"
|
||||||
log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a")
|
log = open(log_path + "/config_edit-"+get_data('logs')+".log", "a")
|
||||||
try:
|
try:
|
||||||
log.write(mess)
|
log.write(mess)
|
||||||
|
|
29
app/login.py
29
app/login.py
|
@ -24,7 +24,6 @@ error_log = ""
|
||||||
error = ""
|
error = ""
|
||||||
|
|
||||||
def send_cookie(login):
|
def send_cookie(login):
|
||||||
session_ttl = int()
|
|
||||||
session_ttl = sql.get_setting('session_ttl')
|
session_ttl = sql.get_setting('session_ttl')
|
||||||
session_ttl = int(session_ttl)
|
session_ttl = int(session_ttl)
|
||||||
expires = datetime.datetime.utcnow() + datetime.timedelta(days=session_ttl)
|
expires = datetime.datetime.utcnow() + datetime.timedelta(days=session_ttl)
|
||||||
|
@ -34,23 +33,28 @@ def send_cookie(login):
|
||||||
sql.write_user_token(login, user_token)
|
sql.write_user_token(login, user_token)
|
||||||
|
|
||||||
id = sql.get_user_id_by_uuid(user_uuid)
|
id = sql.get_user_id_by_uuid(user_uuid)
|
||||||
user_groups = sql.select_user_groups(id, limit=1)
|
try:
|
||||||
|
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
|
user_groups = cookie.get('group')
|
||||||
|
user_groups = user_groups.value
|
||||||
|
except:
|
||||||
|
user_groups = sql.select_user_groups(id, limit=1)
|
||||||
|
|
||||||
c = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
c = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
|
||||||
c["uuid"] = user_uuid
|
c["uuid"] = user_uuid
|
||||||
c["uuid"]["path"] = "/"
|
c["uuid"]["path"] = "/app"
|
||||||
# c["uuid"]["sameSite"] = "Strict"
|
# c["uuid"]["samesite"] = "Strict"
|
||||||
c["uuid"]["Secure"] = "True"
|
c["uuid"]["Secure"] = "True"
|
||||||
c["uuid"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
c["uuid"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||||
c["group"] = user_groups
|
c["group"] = user_groups
|
||||||
c["group"]["path"] = "/"
|
c["group"]["path"] = "/app"
|
||||||
# c["group"]["sameSite"] = "Strict"
|
# c["group"]["samesite"] = "Strict"
|
||||||
c["group"]["Secure"] = "True"
|
c["group"]["Secure"] = "True"
|
||||||
c["group"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
c["group"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||||
print(c)
|
print(c.output())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
funct.logging('locahost', ' '+sql.get_user_name_by_uuid(user_uuid)+' log in', haproxywi=1)
|
funct.logging('locahost', ' user: '+sql.get_user_name_by_uuid(user_uuid)+' log in', haproxywi=1)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
print("Content-type: text/html\n")
|
print("Content-type: text/html\n")
|
||||||
|
@ -63,14 +67,14 @@ def ban():
|
||||||
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=10)
|
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=10)
|
||||||
c["ban"] = 1
|
c["ban"] = 1
|
||||||
c["ban"]["path"] = "/"
|
c["ban"]["path"] = "/"
|
||||||
# c["ban"]["sameSite"] = "Strict"
|
# c["ban"]["samesite"] = "Strict"
|
||||||
c["ban"]["Secure"] = "True"
|
c["ban"]["Secure"] = "True"
|
||||||
c["ban"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
c["ban"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
||||||
try:
|
try:
|
||||||
funct.logging('locahost', login+' failed log in', haproxywi=1, login=1)
|
funct.logging('locahost', login+' failed log in', haproxywi=1, login=1)
|
||||||
except:
|
except:
|
||||||
funct.logging('locahost', ' Failed log in. Wrong username', haproxywi=1)
|
funct.logging('locahost', ' Failed log in. Wrong username', haproxywi=1)
|
||||||
print(c)
|
print(c.output())
|
||||||
print("Content-type: text/html\n")
|
print("Content-type: text/html\n")
|
||||||
print('ban')
|
print('ban')
|
||||||
|
|
||||||
|
@ -84,7 +88,6 @@ def check_in_ldap(user, password):
|
||||||
root_user = sql.get_setting('ldap_user')
|
root_user = sql.get_setting('ldap_user')
|
||||||
root_password = sql.get_setting('ldap_password')
|
root_password = sql.get_setting('ldap_password')
|
||||||
ldap_base = sql.get_setting('ldap_base')
|
ldap_base = sql.get_setting('ldap_base')
|
||||||
domain = sql.get_setting('ldap_domain')
|
|
||||||
ldap_search_field = sql.get_setting('ldap_search_field')
|
ldap_search_field = sql.get_setting('ldap_search_field')
|
||||||
ldap_user_attribute = sql.get_setting('ldap_user_attribute')
|
ldap_user_attribute = sql.get_setting('ldap_user_attribute')
|
||||||
ldap_type = sql.get_setting('ldap_type')
|
ldap_type = sql.get_setting('ldap_type')
|
||||||
|
@ -109,7 +112,7 @@ def check_in_ldap(user, password):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except ldap.SERVER_DOWN:
|
except ldap.SERVER_DOWN:
|
||||||
print("Content-type: text/html\n")
|
print("Content-type: text/html\n")
|
||||||
print('<center><div class="alert alert-danger">Server down')
|
print('<center><div class="alert alert-danger">Server down</div><br /><br />')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except ldap.LDAPError as e:
|
except ldap.LDAPError as e:
|
||||||
if type(e.message) == dict and e.message.has_key('desc'):
|
if type(e.message) == dict and e.message.has_key('desc'):
|
||||||
|
@ -151,7 +154,7 @@ if form.getvalue('logout'):
|
||||||
sql.delete_uuid(user_id.value)
|
sql.delete_uuid(user_id.value)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
print("Set-cookie: uuid=; expires=Wed, May 18 03:33:20 2003; path=/; httponly")
|
print("Set-cookie: uuid=; expires=Wed, May 18 03:33:20 2003; path=/app; httponly")
|
||||||
print("Content-type: text/html\n")
|
print("Content-type: text/html\n")
|
||||||
print('<meta http-equiv="refresh" content="0; url=/app/login.py">')
|
print('<meta http-equiv="refresh" content="0; url=/app/login.py">')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
|
@ -51,10 +51,9 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if config %}
|
{% if config %}
|
||||||
{% if role <= 2 %}
|
{% if role <= 2 %}
|
||||||
<div id="config">
|
|
||||||
<h4>Config from {{ serv }}</h4>
|
<h4>Config from {{ serv }}</h4>
|
||||||
</center>
|
</center>
|
||||||
<form action="{{ action }}" name="saveconfig" method="post">
|
<form action="{{ action }}" name="saveconfig" id="saveconfig" method="post">
|
||||||
<input type="hidden" value="{{ serv }}" name="serv">
|
<input type="hidden" value="{{ serv }}" name="serv">
|
||||||
<input type="hidden" value="{{ cfg }}.old" name="oldconfig">
|
<input type="hidden" value="{{ cfg }}.old" name="oldconfig">
|
||||||
<div style="margin-left: 23%;width: 60%;">
|
<div style="margin-left: 23%;width: 60%;">
|
||||||
|
@ -75,7 +74,6 @@
|
||||||
{% if note %}
|
{% if note %}
|
||||||
<div class="alert alert-info"><b>Note:</b> If you reconfigure Master server, Slave will reconfigured automatically</div>
|
<div class="alert alert-info"><b>Note:</b> If you reconfigure Master server, Slave will reconfigured automatically</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if aftersave %}
|
{% if aftersave %}
|
||||||
|
|
|
@ -204,8 +204,8 @@ function setRefreshInterval(interval) {
|
||||||
hideAutoRefreshDiv();
|
hideAutoRefreshDiv();
|
||||||
} else {
|
} else {
|
||||||
clearInterval(intervalId);
|
clearInterval(intervalId);
|
||||||
Cookies.set('auto-refresh', interval, { expires: 365 });
|
Cookies.set('auto-refresh', interval, { expires: 365, samesite: 'strict', secure: 'true' });
|
||||||
Cookies.set('auto-refresh-pause', "0", { expires: 365 });
|
Cookies.set('auto-refresh-pause', "0", { expires: 365, samesite: 'strict', secure: 'true' });
|
||||||
startSetInterval(interval);
|
startSetInterval(interval);
|
||||||
hideAutoRefreshDiv();
|
hideAutoRefreshDiv();
|
||||||
autoRefreshStyle(interval);
|
autoRefreshStyle(interval);
|
||||||
|
@ -257,13 +257,13 @@ function pauseAutoRefresh() {
|
||||||
$(function() {
|
$(function() {
|
||||||
$('.auto-refresh-pause').css('display', 'none');
|
$('.auto-refresh-pause').css('display', 'none');
|
||||||
$('.auto-refresh-resume').css('display', 'inline');
|
$('.auto-refresh-resume').css('display', 'inline');
|
||||||
Cookies.set('auto-refresh-pause', "1", { expires: 365 });
|
Cookies.set('auto-refresh-pause', "1", { expires: 365, samesite: 'strict', secure: 'true' });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function pauseAutoResume(){
|
function pauseAutoResume(){
|
||||||
var autoRefresh = Cookies.get('auto-refresh');
|
var autoRefresh = Cookies.get('auto-refresh');
|
||||||
setRefreshInterval(autoRefresh);
|
setRefreshInterval(autoRefresh);
|
||||||
Cookies.set('auto-refresh-pause', "0", { expires: 365 });
|
Cookies.set('auto-refresh-pause', "0", { expires: 365, samesite: 'strict', secure: 'true' });
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideAutoRefreshDiv() {
|
function hideAutoRefreshDiv() {
|
||||||
|
@ -378,6 +378,13 @@ function showLog() {
|
||||||
}
|
}
|
||||||
function showMap() {
|
function showMap() {
|
||||||
$("#ajax").empty();
|
$("#ajax").empty();
|
||||||
|
try {
|
||||||
|
myCodeMirror.toTextArea();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
$("#saveconfig").remove();
|
||||||
|
$("h4").remove();
|
||||||
$("#ajax-compare").empty();
|
$("#ajax-compare").empty();
|
||||||
$("#config").empty();
|
$("#config").empty();
|
||||||
$(".alert-info").empty();
|
$(".alert-info").empty();
|
||||||
|
@ -424,7 +431,13 @@ function showCompare() {
|
||||||
}
|
}
|
||||||
function showCompareConfigs() {
|
function showCompareConfigs() {
|
||||||
$("#ajax").empty();
|
$("#ajax").empty();
|
||||||
$("#config").empty();
|
try {
|
||||||
|
myCodeMirror.toTextArea();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
$("#saveconfig").remove();
|
||||||
|
$("h4").remove();
|
||||||
$(".alert-info").empty();
|
$(".alert-info").empty();
|
||||||
$.ajax( {
|
$.ajax( {
|
||||||
url: "options.py",
|
url: "options.py",
|
||||||
|
@ -452,6 +465,13 @@ function showCompareConfigs() {
|
||||||
function showConfig() {
|
function showConfig() {
|
||||||
var service = $('#service').val();
|
var service = $('#service').val();
|
||||||
$("#ajax").empty();
|
$("#ajax").empty();
|
||||||
|
try {
|
||||||
|
myCodeMirror.toTextArea();
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
$("#saveconfig").remove();
|
||||||
|
$("h4").remove();
|
||||||
$("#ajax-compare").empty();
|
$("#ajax-compare").empty();
|
||||||
$("#config").empty();
|
$("#config").empty();
|
||||||
$(".alert").empty();
|
$(".alert").empty();
|
||||||
|
@ -613,7 +633,7 @@ $( function() {
|
||||||
$(".footer").css("margin-left", "1%");
|
$(".footer").css("margin-left", "1%");
|
||||||
$(".show_menu").show();
|
$(".show_menu").show();
|
||||||
$("#hide_menu").hide();
|
$("#hide_menu").hide();
|
||||||
Cookies.set('hide_menu', 'hide', { expires: 365 });
|
Cookies.set('hide_menu', 'hide', { expires: 365, samesite: 'strict', secure: 'true' });
|
||||||
});
|
});
|
||||||
$( "#show_menu" ).click(function() {
|
$( "#show_menu" ).click(function() {
|
||||||
$(".top-menu").show( "drop", "fast" );
|
$(".top-menu").show( "drop", "fast" );
|
||||||
|
@ -623,7 +643,7 @@ $( function() {
|
||||||
$(".footer").css("margin-left", "207px");
|
$(".footer").css("margin-left", "207px");
|
||||||
$(".show_menu").hide();
|
$(".show_menu").hide();
|
||||||
$("#hide_menu").show();
|
$("#hide_menu").show();
|
||||||
Cookies.set('hide_menu', 'show', { expires: 365 });
|
Cookies.set('hide_menu', 'show', { expires: 365, samesite: 'strict', secure: 'true' });
|
||||||
});
|
});
|
||||||
var hideMenu = Cookies.get('hide_menu');
|
var hideMenu = Cookies.get('hide_menu');
|
||||||
if (hideMenu == "show") {
|
if (hideMenu == "show") {
|
||||||
|
@ -789,6 +809,7 @@ $( function() {
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
if (data.indexOf('ok') != '-1') {
|
if (data.indexOf('ok') != '-1') {
|
||||||
window.location.replace(ref);
|
window.location.replace(ref);
|
||||||
|
console.log(data)
|
||||||
} else if (data.indexOf('disabled') != '-1') {
|
} else if (data.indexOf('disabled') != '-1') {
|
||||||
$('.alert').show();
|
$('.alert').show();
|
||||||
$('.alert').html(data);
|
$('.alert').html(data);
|
||||||
|
@ -989,7 +1010,7 @@ function createHistroy() {
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
var get_history_array = ['login.py', 'login.py','login.py'];
|
var get_history_array = ['login.py', 'login.py','login.py'];
|
||||||
Cookies.set('history', JSON.stringify(get_history_array), { expires: 1, path: '/app', sameSite: 'Strict', Secure: 'True' });
|
Cookies.set('history', JSON.stringify(get_history_array), { expires: 10, path: '/app', samesite: 'strict', secure: 'true' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function listHistroy() {
|
function listHistroy() {
|
||||||
|
@ -1029,14 +1050,14 @@ function listHistroy() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Cookies.set('history', JSON.stringify(browse_history), { expires: 1, path: '/app', sameSite: 'Strict', Secure: 'True' });
|
Cookies.set('history', JSON.stringify(browse_history), { expires: 10, path: '/app', samesite: 'strict', secure: 'true' });
|
||||||
}
|
}
|
||||||
createHistroy()
|
createHistroy()
|
||||||
listHistroy()
|
listHistroy()
|
||||||
|
|
||||||
function changeCurrentGroupF(){
|
function changeCurrentGroupF(){
|
||||||
Cookies.remove('group');
|
Cookies.remove('group');
|
||||||
Cookies.set('group', $('#newCurrentGroup').val(), { path: '/app', sameSite: 'Strict', Secure: 'True' });
|
Cookies.set('group', $('#newCurrentGroup').val(), { expires: 365, path: '/app', samesite: 'strict', secure: 'true' });
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
function sort_by_status() {
|
function sort_by_status() {
|
||||||
|
|
Loading…
Reference in New Issue