Pavel Loginov 2020-08-09 09:18:30 +02:00
parent 17edd5c92b
commit bc38039f61
4 changed files with 103 additions and 69 deletions

View File

@ -50,6 +50,7 @@ def logging(serv, action, **kwargs):
import sql
import http.cookies
log_path = get_config_var('main', 'log_path')
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
if not os.path.exists(log_path):
os.makedirs(log_path)
@ -59,12 +60,21 @@ def logging(serv, action, **kwargs):
except:
IP = ''
try:
cookie = http.cookies.SimpleCookie(os.environ.get("HTTP_COOKIE"))
user_uuid = cookie.get('uuid')
login = sql.get_user_name_by_uuid(user_uuid.value)
except:
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:
mess = get_data('date_in_log') + action + "\n"
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")
elif kwargs.get('haproxywi') == 1:
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:
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")
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")
try:
log.write(mess)

View File

@ -24,7 +24,6 @@ error_log = ""
error = ""
def send_cookie(login):
session_ttl = int()
session_ttl = sql.get_setting('session_ttl')
session_ttl = int(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)
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["uuid"] = user_uuid
c["uuid"]["path"] = "/"
# c["uuid"]["sameSite"] = "Strict"
c["uuid"]["path"] = "/app"
# c["uuid"]["samesite"] = "Strict"
c["uuid"]["Secure"] = "True"
c["uuid"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
c["group"] = user_groups
c["group"]["path"] = "/"
# c["group"]["sameSite"] = "Strict"
c["group"]["path"] = "/app"
# c["group"]["samesite"] = "Strict"
c["group"]["Secure"] = "True"
c["group"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
print(c)
print(c.output())
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:
pass
print("Content-type: text/html\n")
@ -63,14 +67,14 @@ def ban():
expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=10)
c["ban"] = 1
c["ban"]["path"] = "/"
# c["ban"]["sameSite"] = "Strict"
# c["ban"]["samesite"] = "Strict"
c["ban"]["Secure"] = "True"
c["ban"]["expires"] = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
try:
funct.logging('locahost', login+' failed log in', haproxywi=1, login=1)
except:
funct.logging('locahost', ' Failed log in. Wrong username', haproxywi=1)
print(c)
print(c.output())
print("Content-type: text/html\n")
print('ban')
@ -84,7 +88,6 @@ def check_in_ldap(user, password):
root_user = sql.get_setting('ldap_user')
root_password = sql.get_setting('ldap_password')
ldap_base = sql.get_setting('ldap_base')
domain = sql.get_setting('ldap_domain')
ldap_search_field = sql.get_setting('ldap_search_field')
ldap_user_attribute = sql.get_setting('ldap_user_attribute')
ldap_type = sql.get_setting('ldap_type')
@ -109,7 +112,7 @@ def check_in_ldap(user, password):
sys.exit()
except ldap.SERVER_DOWN:
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()
except ldap.LDAPError as e:
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)
except:
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('<meta http-equiv="refresh" content="0; url=/app/login.py">')
sys.exit()

View File

@ -51,10 +51,9 @@
{% endif %}
{% if config %}
{% if role <= 2 %}
<div id="config">
<h4>Config from {{ serv }}</h4>
</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="{{ cfg }}.old" name="oldconfig">
<div style="margin-left: 23%;width: 60%;">
@ -75,7 +74,6 @@
{% if note %}
<div class="alert alert-info"><b>Note:</b> If you reconfigure Master server, Slave will reconfigured automatically</div>
{% endif %}
</div>
{% endif %}
{% endif %}
{% if aftersave %}

View File

@ -204,8 +204,8 @@ function setRefreshInterval(interval) {
hideAutoRefreshDiv();
} else {
clearInterval(intervalId);
Cookies.set('auto-refresh', interval, { expires: 365 });
Cookies.set('auto-refresh-pause', "0", { expires: 365 });
Cookies.set('auto-refresh', interval, { expires: 365, samesite: 'strict', secure: 'true' });
Cookies.set('auto-refresh-pause', "0", { expires: 365, samesite: 'strict', secure: 'true' });
startSetInterval(interval);
hideAutoRefreshDiv();
autoRefreshStyle(interval);
@ -257,13 +257,13 @@ function pauseAutoRefresh() {
$(function() {
$('.auto-refresh-pause').css('display', 'none');
$('.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(){
var autoRefresh = Cookies.get('auto-refresh');
setRefreshInterval(autoRefresh);
Cookies.set('auto-refresh-pause', "0", { expires: 365 });
Cookies.set('auto-refresh-pause', "0", { expires: 365, samesite: 'strict', secure: 'true' });
}
function hideAutoRefreshDiv() {
@ -378,6 +378,13 @@ function showLog() {
}
function showMap() {
$("#ajax").empty();
try {
myCodeMirror.toTextArea();
} catch (e) {
console.log(e)
}
$("#saveconfig").remove();
$("h4").remove();
$("#ajax-compare").empty();
$("#config").empty();
$(".alert-info").empty();
@ -424,7 +431,13 @@ function showCompare() {
}
function showCompareConfigs() {
$("#ajax").empty();
$("#config").empty();
try {
myCodeMirror.toTextArea();
} catch (e) {
console.log(e)
}
$("#saveconfig").remove();
$("h4").remove();
$(".alert-info").empty();
$.ajax( {
url: "options.py",
@ -452,6 +465,13 @@ function showCompareConfigs() {
function showConfig() {
var service = $('#service').val();
$("#ajax").empty();
try {
myCodeMirror.toTextArea();
} catch (e) {
console.log(e)
}
$("#saveconfig").remove();
$("h4").remove();
$("#ajax-compare").empty();
$("#config").empty();
$(".alert").empty();
@ -613,7 +633,7 @@ $( function() {
$(".footer").css("margin-left", "1%");
$(".show_menu").show();
$("#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() {
$(".top-menu").show( "drop", "fast" );
@ -623,7 +643,7 @@ $( function() {
$(".footer").css("margin-left", "207px");
$(".show_menu").hide();
$("#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');
if (hideMenu == "show") {
@ -789,6 +809,7 @@ $( function() {
success: function( data ) {
if (data.indexOf('ok') != '-1') {
window.location.replace(ref);
console.log(data)
} else if (data.indexOf('disabled') != '-1') {
$('.alert').show();
$('.alert').html(data);
@ -989,7 +1010,7 @@ function createHistroy() {
}
catch {
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() {
@ -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()
listHistroy()
function changeCurrentGroupF(){
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();
}
function sort_by_status() {