From 7c575fe0f8676c47f913bfe47166088ad3740a2b Mon Sep 17 00:00:00 2001 From: Pavel Loginov Date: Thu, 4 Feb 2021 01:25:37 +0600 Subject: [PATCH] v4.5.9.0 Changelog: https://haproxy-wi.org/changelog.py#4_5_9 --- app/options.py | 12 ++++- app/sql.py | 20 ++++++-- inc/script.js | 130 +++++++++++++++++++++++++++++++------------------ inc/style.css | 9 +++- inc/users.js | 25 +++++++++- 5 files changed, 141 insertions(+), 55 deletions(-) diff --git a/app/options.py b/app/options.py index 007f5bd0..6cb4173a 100644 --- a/app/options.py +++ b/app/options.py @@ -1497,8 +1497,12 @@ if form.getvalue('get_ldap_email'): ldap_search_field = sql.get_setting('ldap_search_field') ldap_class_search = sql.get_setting('ldap_class_search') ldap_user_attribute = sql.get_setting('ldap_user_attribute') + ldap_type = sql.get_setting('ldap_type') + + ldap_proto = 'ldap' if ldap_type == "0" else 'ldaps' + + l = ldap.initialize('{}://{}:{}/'.format(ldap_proto, server, port)) - l = ldap.initialize(server + ':' + port) try: l.protocol_version = ldap.VERSION3 l.set_option(ldap.OPT_REFERRALS, 0) @@ -1666,6 +1670,7 @@ if form.getvalue('serverdel') is not None: sys.exit() if sql.delete_server(serverdel): sql.delete_waf_server(serverdel) + sql.delete_port_scanner_settings(serverdel) print("Ok") funct.logging(hostname, ' has been deleted server with ', haproxywi=1, login=1) @@ -2294,4 +2299,7 @@ if form.getvalue('show_versions'): env = Environment(loader=FileSystemLoader('templates')) template = env.get_template('ajax/check_version.html') template = template.render(versions=funct.versions()) - print(template) \ No newline at end of file + print(template) + +if form.getvalue('get_group_name_by_id'): + print(sql.get_group_name_by_id(form.getvalue('get_group_name_by_id'))) diff --git a/app/sql.py b/app/sql.py index 671a3e96..35581439 100644 --- a/app/sql.py +++ b/app/sql.py @@ -511,6 +511,21 @@ def select_groups(**kwargs): con.close() +def get_group_name_by_id(group_id): + con, cur = get_cur() + sql = """select name from groups where id = '%s' """ % group_id + + try: + cur.execute(sql) + except sqltool.Error as e: + funct.out_error(e) + else: + for name in cur.fetchone(): + return name + cur.close() + con.close() + + def select_server_by_name(name): con, cur = get_cur() sql = """select ip from servers where hostname='%s' """ % name @@ -570,9 +585,9 @@ def write_user_uuid(login, user_uuid): funct.out_error(e) for id in cur.fetchall(): if mysql_enable == '1': - sql = """ insert into uuid (user_id, uuid, exp) values('%s', '%s', now()+ INTERVAL '%s' day) """ % (id[0], user_uuid, session_ttl) + sql = """ insert into uuid (user_id, uuid, exp) values('%s', '%s', now()+ INTERVAL '%s' day) """ % (id[0], user_uuid, session_ttl) else: - sql = """ insert into uuid (user_id, uuid, exp) values('%s', '%s', datetime('now', '+%s days')) """ % (id[0], user_uuid, session_ttl) + sql = """ insert into uuid (user_id, uuid, exp) values('%s', '%s', datetime('now', '+%s days')) """ % (id[0], user_uuid, session_ttl) try: cur.execute(sql) con.commit() @@ -2378,7 +2393,6 @@ def is_cloud(): else: for cl_uuid in cur.fetchall(): cloud_uuid = cl_uuid[0] - cur.close() con.close() return cloud_uuid diff --git a/inc/script.js b/inc/script.js index 820b4508..a49346de 100644 --- a/inc/script.js +++ b/inc/script.js @@ -803,41 +803,6 @@ $( function() { $("#label_select_all").text("Select all"); } }); - $('#changeCurrentGroup').click(function() { - $.ajax( { - url: "options.py", - data: { - getcurrentusergroup: 1, - token: $('#token').val() - }, - type: "POST", - success: function( data ) { - if (data.indexOf('danger') != '-1') { - $("#ajax").html(data); - } else { - $('.alert-danger').remove(); - $('#current-user-groups-form').html(data); - $( "select" ).selectmenu(); - $( "#current-user-groups-dialog" ).dialog({ - resizable: false, - height: "auto", - width: 290, - modal: true, - title: "Change a new current group", - buttons: { - "Change": function() { - $( this ).dialog( "close" ); - changeCurrentGroupF(); - }, - Cancel: function() { - $( this ).dialog( "close" ); - } - } - }); - } - } - } ); - }); $('#auth').submit(function() { let searchParams = new URLSearchParams(window.location.search) if(searchParams.has('ref')) { @@ -886,19 +851,9 @@ $( function() { } ); var showUpdates = $( "#show-updates" ).dialog({ autoOpen: false, - resizable: false, - height: "auto", width: 600, modal: true, - title: 'There is a new version HAProxy-WI.', - show: { - effect: "fade", - duration: 200 - }, - hide: { - effect: "fade", - duration: 200 - }, + title: 'There is a new version HAProxy-WI', buttons: { Close: function() { $( this ).dialog( "close" ); @@ -908,7 +863,39 @@ $( function() { }); $('#show-updates-button').click(function() { - showUpdates.dialog('open'); + showUpdates.dialog('open'); + }); + var showUserSettings = $( "#show-user-settings" ).dialog({ + autoOpen: false, + width: 600, + modal: true, + title: 'User settings', + buttons: { + Save: function() { + saveUserSettings(); + $( this ).dialog( "close" ); + }, + "Change group": function(){ + showCurrentGroup(this); + $( this ).dialog( "close" ); + }, + Close: function() { + $( this ).dialog( "close" ); + clearTips(); + } + } + }); + + $('#show-user-settings-button').click(function() { + if (sessionStorage.getItem('disabled_alert') == '1') { + $('#disable_alert_for_tab').prop('checked', true); + $( "input[type=checkbox]" ).checkboxradio('refresh'); + } + if (localStorage.getItem('disabled_alert') == '1') { + $('#disable_alert_for_all').prop('checked', true); + $( "input[type=checkbox]" ).checkboxradio('refresh'); + } + showUserSettings.dialog('open'); }); var location = window.location.href; var cur_url = '/app/' + location.split('/').pop(); @@ -1037,6 +1024,52 @@ $( function() { } } }); +function saveUserSettings(){ + if ($('#disable_alert_for_tab').is(':checked')) { + sessionStorage.setItem('disabled_alert', '1'); + } else { + sessionStorage.removeItem('disabled_alert'); + } + if ($('#disable_alert_for_all').is(':checked')) { + localStorage.setItem('disabled_alert', '1'); + } else { + localStorage.removeItem('disabled_alert'); + } +} +function showCurrentGroup(dialog_id) { + $.ajax( { + url: "options.py", + data: { + getcurrentusergroup: 1, + token: $('#token').val() + }, + type: "POST", + success: function( data ) { + if (data.indexOf('danger') != '-1') { + $("#ajax").html(data); + } else { + $('.alert-danger').remove(); + $('#current-user-groups-form').html(data); + $( "select" ).selectmenu(); + $( "#current-user-groups-dialog" ).dialog({ + width: 290, + modal: true, + title: "Change a new current group", + buttons: { + "Change": function() { + $( this ).dialog( "close" ); + changeCurrentGroupF(); + }, + Cancel: function() { + $( this ).dialog( "close" ); + $( dialog_id ).dialog("open" ); + } + } + }); + } + } + } ); +} function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -1227,7 +1260,8 @@ async function waitConsumer() { cur_url = cur_url.split('?'); if (cur_url[0] != 'servers.py#installproxy' && cur_url[0] != 'servers.py#installmon' && cur_url[0] != 'users.py#installmon' && cur_url[0] != 'ha.py' && cur_url[0] != 'users.py#updatehapwi' && - cur_url[0] != 'add.py?service=nginx#ssl' && cur_url[0] != 'add.py#ssl' && cur_url[0] != 'servers.py#geolite2') { + cur_url[0] != 'add.py?service=nginx#ssl' && cur_url[0] != 'add.py#ssl' && cur_url[0] != 'servers.py#geolite2' + && cur_url[0] != 'login.py' && sessionStorage.getItem('disabled_alert') === null && localStorage.getItem('disabled_alert') === null) { NProgress.configure({showSpinner: false}); $.ajax({ url: "options.py", diff --git a/inc/style.css b/inc/style.css index 4db5f0a8..6d54f7d3 100644 --- a/inc/style.css +++ b/inc/style.css @@ -427,6 +427,9 @@ pre { padding: 15px; width: 30%; } +.padding-top20 { + padding-top: 20px; +} .first-collumn { padding-left: 15px; width: 20%; @@ -1123,11 +1126,15 @@ label { .tooltip { font-size: 12px; padding-bottom: 10px; + color: #9d9d9d; } .tooltipTop { margin-bottom: -20px; padding-top: 10px; - color: #9d9d9d; +} +.tooltipTd { + margin-bottom: -10px; + padding: 0; } #stats_filter { margin-left: 5px; diff --git a/inc/users.js b/inc/users.js index e911e9ae..b181f8a4 100644 --- a/inc/users.js +++ b/inc/users.js @@ -1013,12 +1013,14 @@ function addCreds(dialog_id) { if (data.indexOf('error:') != '-1') { toastr.error(data); } else { + var group_name = getGroupNameById($('#new-sshgroup').val()); + console.log(group_name) var getId = new RegExp('ssh-table-[0-9]+'); var id = data.match(getId) + ''; id = id.split('-').pop(); common_ajax_action_after_success(dialog_id, 'ssh-table-'+id, 'ssh_enable_table', data); $('select:regex(id, credentials)').append('').selectmenu("refresh"); - $('select:regex(id, ssh-key-name)').append('').selectmenu("refresh"); + $('select:regex(id, ssh-key-name)').append('').selectmenu("refresh"); $("input[type=submit], button").button(); $("input[type=checkbox]").checkboxradio(); $("select").selectmenu(); @@ -1027,6 +1029,27 @@ function addCreds(dialog_id) { }); } } +function getGroupNameById(group_id) { + var group_name = '' + $.ajax({ + url: "options.py", + async: false, + data: { + get_group_name_by_id: group_id, + token: $('#token').val() + }, + type: "POST", + success: function (data) { + if (data.indexOf('error:') != '-1') { + toastr.error(data); + } else { + console.log(data); + group_name = data; + } + } + }); + return group_name; +} function addTelegram(dialog_id) { var valid = true; toastr.clear();