From 9946bb34272826982c3f0c9264291384e2f8a812 Mon Sep 17 00:00:00 2001 From: jkellerer Date: Sat, 30 Oct 2021 16:51:26 +0200 Subject: [PATCH] [Web] Display app password name in last login (#4304) --- data/web/inc/functions.inc.php | 2 +- data/web/js/site/user.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/data/web/inc/functions.inc.php b/data/web/inc/functions.inc.php index 209baa3a..7ac0af58 100644 --- a/data/web/inc/functions.inc.php +++ b/data/web/inc/functions.inc.php @@ -258,7 +258,7 @@ function last_login($action, $username, $sasl_limit_days = 7) { switch ($action) { case 'get': if (filter_var($username, FILTER_VALIDATE_EMAIL) && hasMailboxObjectAccess($_SESSION['mailcow_cc_username'], $_SESSION['mailcow_cc_role'], $username)) { - $stmt = $pdo->prepare('SELECT `real_rip`, MAX(`datetime`) as `datetime`, `service`, `app_password` FROM `sasl_log` + $stmt = $pdo->prepare('SELECT `real_rip`, MAX(`datetime`) as `datetime`, `service`, `app_password`, MAX(`app_passwd`.`name`) as `app_password_name` FROM `sasl_log` LEFT OUTER JOIN `app_passwd` on `sasl_log`.`app_password` = `app_passwd`.`id` WHERE `username` = :username AND HOUR(TIMEDIFF(NOW(), `datetime`)) < :sasl_limit_days diff --git a/data/web/js/site/user.js b/data/web/js/site/user.js index f37ae747..fb6de191 100644 --- a/data/web/js/site/user.js +++ b/data/web/js/site/user.js @@ -101,10 +101,11 @@ jQuery(function($){ $.each(data.sasl, function (i, item) { var datetime = new Date(item.datetime.replace(/-/g, "/")); var local_datetime = datetime.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"}); - item.app_password ? app_password = ' App' : app_password = "", item.location ? ip_location = ' ' : ip_location = ""; - service = '
' + item.service.toUpperCase() + '
'; - item.real_rip.startsWith("Web") ? real_rip = item.real_rip : real_rip = '' + item.real_rip + ""; - ip_data = real_rip + ip_location + app_password; + var service = '
' + item.service.toUpperCase() + '
'; + var app_password = item.app_password ? ' ' + escapeHtml(item.app_password_name || "App") + '' : ''; + var real_rip = item.real_rip.startsWith("Web") ? item.real_rip : '' + item.real_rip + ""; + var ip_location = item.location ? ' ' : ''; + var ip_data = real_rip + ip_location + app_password; $(".last-login").append('
  • ' + local_datetime + " " + service + " " + lang.from + " " + ip_data + "
  • "); }) $('.last-login').append('');