LSaddon::ppolicy: improve password expiration extra displayed column

Add LStip to show password last changed date and password max age.
This commit is contained in:
Benjamin Renard 2023-12-05 12:51:54 +01:00
parent 2d08374a53
commit 78af62d428
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
4 changed files with 53 additions and 19 deletions

View file

@ -137,20 +137,22 @@ function get_ppolicy_password_max_age($ppolicy_dn=null) {
* @param string $text The text of the badge * @param string $text The text of the badge
* @param string $bg_color The background color of the badge (optional, default: green) * @param string $bg_color The background color of the badge (optional, default: green)
* @param string $color The text color of the badge (optional, default: white) * @param string $color The text color of the badge (optional, default: white)
* @param string $title The text title of the badge (optional, default: empty string)
* *
* @return string The HTML code of the badge * @return string The HTML code of the badge
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
*/ */
function _ppolicy_badge($text, $bg_color='green', $color='white') { function _ppolicy_badge($text, $bg_color='green', $color='white', $title='') {
// Disable HTML formating on PHP cli // Disable HTML formating on PHP cli
if (php_sapi_name() == 'cli') return $text; if (php_sapi_name() == 'cli') return $text;
return sprintf( return sprintf(
'<span style=" '<span style="
background-color: %s; color: %s; background-color: %s; color: %s;
padding: 0.2em; font-size: 0.8em; border-radius: 0.4em;" padding: 0.2em; font-size: 0.8em; border-radius: 0.4em;"
class="LStips" title="%s"
>%s</span>', >%s</span>',
$bg_color, $color, $text $bg_color, $color, $title, $text
); );
} }
@ -170,7 +172,10 @@ function ppolicy_extraDisplayColumn_password_expiration($entry) {
$change_time = ldapDate2Timestamp($change_time); $change_time = ldapDate2Timestamp($change_time);
$max_age = get_ppolicy_password_max_age($entry->pwdPolicySubentry); $max_age = get_ppolicy_password_max_age($entry->pwdPolicySubentry);
if ($max_age === false) if ($max_age === false)
return _ppolicy_badge(__('Unknown'), 'gray'); return _ppolicy_badge(
__('Unknown'), 'gray', 'white',
sprintf(_('Last password changed: %s, no duration of validity configured.'), date('Y-m-d H:i', $change_time))
);
if (!$max_age) if (!$max_age)
return _('Never'); return _('Never');
$expiration_date = $change_time + $max_age; $expiration_date = $change_time + $max_age;
@ -178,7 +183,9 @@ function ppolicy_extraDisplayColumn_password_expiration($entry) {
if ($expiration_date <= $now) if ($expiration_date <= $now)
return _ppolicy_badge( return _ppolicy_badge(
sprintf(_('Expired (since %s)'), date('Y-m-d H:i', $expiration_date)), sprintf(_('Expired (since %s)'), date('Y-m-d H:i', $expiration_date)),
'black'); 'black', 'white',
sprintf(_('Last password changed: %s, duration of validity: %s days'), date('Y-m-d H:i', $change_time), floor($max_age/86400))
);
$delta = $expiration_date - $now; $delta = $expiration_date - $now;
if ($delta <= LS_PPOLICY_CRITICAL_EXPIRATION_THRESHOLD) if ($delta <= LS_PPOLICY_CRITICAL_EXPIRATION_THRESHOLD)
$badge_color = 'red'; $badge_color = 'red';
@ -188,7 +195,9 @@ function ppolicy_extraDisplayColumn_password_expiration($entry) {
$badge_color = 'green'; $badge_color = 'green';
return _ppolicy_badge( return _ppolicy_badge(
sprintf(_('Expire on %s'), date('Y-m-d H:i', $expiration_date)), sprintf(_('Expire on %s'), date('Y-m-d H:i', $expiration_date)),
$badge_color); $badge_color, 'white',
sprintf(_('Last password changed: %s, duration of validity: %s days'), date('Y-m-d H:i', $change_time), floor($max_age/86400))
);
} }
/** /**

View file

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: LdapSaisie\n" "Project-Id-Version: LdapSaisie\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n" "POT-Creation-Date: \n"
"PO-Revision-Date: 2023-10-13 18:57+0200\n" "PO-Revision-Date: 2023-12-05 12:48+0100\n"
"Last-Translator: Benjamin Renard <brenard@easter-eggs.com>\n" "Last-Translator: Benjamin Renard <brenard@easter-eggs.com>\n"
"Language-Team: LdapSaisie <ldapsaisie-users@lists.labs.libre-entreprise." "Language-Team: LdapSaisie <ldapsaisie-users@lists.labs.libre-entreprise."
"org>\n" "org>\n"
@ -56,26 +56,40 @@ msgstr ""
"Politique de mots de passe : Une erreur est survenue en écrivant une ligne " "Politique de mots de passe : Une erreur est survenue en écrivant une ligne "
"CSV." "CSV."
#: includes/addons/LSaddons.ppolicy.php:169 #: includes/addons/LSaddons.ppolicy.php:171
#: includes/addons/LSaddons.ppolicy.php:175 #: includes/addons/LSaddons.ppolicy.php:180
msgid "Never" msgid "Never"
msgstr "Jamais" msgstr "Jamais"
#: includes/addons/LSaddons.ppolicy.php:173 #: includes/addons/LSaddons.ppolicy.php:176
msgid "Unknown" msgid "Unknown"
msgstr "Inconnu" msgstr "Inconnu"
#: includes/addons/LSaddons.ppolicy.php:180 #: includes/addons/LSaddons.ppolicy.php:177
#, php-format
msgid "Last password changed: %s, no duration of validity configured."
msgstr ""
"Dernière modification du mot de passe : %s, pas de durée de validité "
"configurée."
#: includes/addons/LSaddons.ppolicy.php:185
#, php-format #, php-format
msgid "Expired (since %s)" msgid "Expired (since %s)"
msgstr "Expiré (depuis %s)" msgstr "Expiré (depuis %s)"
#: includes/addons/LSaddons.ppolicy.php:190 #: includes/addons/LSaddons.ppolicy.php:187
#: includes/addons/LSaddons.ppolicy.php:199
#, php-format
msgid "Last password changed: %s, duration of validity: %s days"
msgstr ""
"Dernière modification du mot de passe : %s, durée de validité : %s jours."
#: includes/addons/LSaddons.ppolicy.php:197
#, php-format #, php-format
msgid "Expire on %s" msgid "Expire on %s"
msgstr "Expirera le %s" msgstr "Expirera le %s"
#: includes/addons/LSaddons.ppolicy.php:260 #: includes/addons/LSaddons.ppolicy.php:269
msgid "Not set" msgid "Not set"
msgstr "Non défini" msgstr "Non défini"
@ -557,7 +571,7 @@ msgstr ""
#: includes/addons/LSaddons.ftp.php:48 #: includes/addons/LSaddons.ftp.php:48
msgid "FTP: Unable to delete file %{file} on the remote server." msgid "FTP: Unable to delete file %{file} on the remote server."
msgstr "" msgstr ""
"FTP : Impossible de supprimer le fichier %{dir} sur le serveur distant." "FTP : Impossible de supprimer le fichier %{file} sur le serveur distant."
#: includes/addons/LSaddons.ftp.php:51 #: includes/addons/LSaddons.ftp.php:51
msgid "" msgid ""

View file

@ -22,26 +22,37 @@ msgstr ""
msgid "Password policy: An error occured writing a CSV row." msgid "Password policy: An error occured writing a CSV row."
msgstr "" msgstr ""
#: includes/addons/LSaddons.ppolicy.php:169 #: includes/addons/LSaddons.ppolicy.php:171
#: includes/addons/LSaddons.ppolicy.php:175 #: includes/addons/LSaddons.ppolicy.php:180
msgid "Never" msgid "Never"
msgstr "" msgstr ""
#: includes/addons/LSaddons.ppolicy.php:173 #: includes/addons/LSaddons.ppolicy.php:176
msgid "Unknown" msgid "Unknown"
msgstr "" msgstr ""
#: includes/addons/LSaddons.ppolicy.php:180 #: includes/addons/LSaddons.ppolicy.php:177
#, php-format
msgid "Last password changed: %s, no duration of validity configured."
msgstr ""
#: includes/addons/LSaddons.ppolicy.php:185
#, php-format #, php-format
msgid "Expired (since %s)" msgid "Expired (since %s)"
msgstr "" msgstr ""
#: includes/addons/LSaddons.ppolicy.php:190 #: includes/addons/LSaddons.ppolicy.php:187
#: includes/addons/LSaddons.ppolicy.php:199
#, php-format
msgid "Last password changed: %s, duration of validity: %s days"
msgstr ""
#: includes/addons/LSaddons.ppolicy.php:197
#, php-format #, php-format
msgid "Expire on %s" msgid "Expire on %s"
msgstr "" msgstr ""
#: includes/addons/LSaddons.ppolicy.php:260 #: includes/addons/LSaddons.ppolicy.php:269
msgid "Not set" msgid "Not set"
msgstr "" msgstr ""