Fix password expiration handling and visibility on 4.x (#1110)

- port the password-expiration correction to `postfixadmin_4.0`
- make password expiration optional and disabled by default
- make 0 consistently mean that domain passwords do not expire
- validate whole-day policies from 0 through 36500
- align password-change paths and preserve the existing Login fallback
- show mailbox expiration states in lists and CSV output
- add the new labels to every 4.x language file
- document how to enable the feature in `config.local.php`

thanks @TrapoSAMA
This commit is contained in:
Rodrigo Cortés Cano authored and GitHub committed 2026-08-11 09:28:19 +01:00
1 parent 4ed71f0218
commit 6e93d57766
46 files changed
+416 -20

No files matched your search

+15 -2
View File
@@ -16,16 +16,29 @@ Password Expiration is merged with PostfixAdmin - so no additional database chan
## Database Fields
* mailbox.password_expiry - timestamp, when the mailbox password expires.
* domain.password_expiry - default duration for when a password will expire
* domain.password_expiry - default duration in days for when a password will
expire. 0 means that passwords in the domain do not expire. Valid policy
values are whole numbers from 0 through 36500.
Changes in MySQL/MariaDB mailbox table (as defined in `$CONF['database_tables']` from config.inc.php):
## Changes in Postfix Admin :
To enable password expiration, add the following to your config.inc.php file:
Password expiration is disabled by default. To enable it, add the following to
your `config.local.php` file:
`$CONF['password_expiration'] = 'YES';`
The domain policy is a fixed duration, not a countdown. It is applied when a
password is changed; changing the domain policy does not rewrite expiration
dates already stored for existing mailboxes. The mailbox list shows the stored
date for each account, or "Does not expire" when the domain policy is 0.
PostfixAdmin records and displays password expiration, but does not reject an
expired password when a mailbox user signs in to PostfixAdmin to change it.
Enforcement for IMAP, POP3, SMTP, or webmail login belongs in the corresponding
authentication query, as illustrated below.
## RoundCube Password Plugin
If you are using Roundcube's password plugin, you should also adapt the `$config['password_query']` value.
+1 -1
View File
@@ -783,7 +783,7 @@ $CONF['xmlrpc_enabled'] = false;
//Account expiration info
//If enabled, mailbox passwords have a password_expiry field set, which is updated each time the password is changed, based on the parent domain's password_expiry (days) value.
//More details in Password_Expiration.md
$CONF['password_expiration'] = 'YES';
$CONF['password_expiration'] = 'NO';
// If defined, use this rather than trying to construct it from $_SERVER parameters.
// used in (at least) password-recover.php.
+71 -1
View File
@@ -330,6 +330,68 @@ function get_password_expiration_value(string $domain)
return 0;
}
const PASSWORD_EXPIRATION_MAX_DAYS = 36500;
const PASSWORD_EXPIRATION_NEVER = '9999-12-31 23:59:59';
/**
* Check whether a stored mailbox expiry represents a non-expiring password.
*
* A zero or invalid domain policy disables expiration. The sentinel also
* remains authoritative when a later domain policy change is non-retroactive.
*/
function mailbox_password_expiration_is_never($mailbox_expiry, $domain_policy): bool
{
$policy = (string)$domain_policy;
if (!preg_match('/^[1-9][0-9]*$/D', $policy) || (int)$policy > PASSWORD_EXPIRATION_MAX_DAYS) {
return true;
}
$expiry = strtotime((string)$mailbox_expiry);
$never = strtotime(PASSWORD_EXPIRATION_NEVER);
return $expiry !== false && $never !== false && $expiry >= $never;
}
/**
* Return the mailbox expiry timestamp for a password changed now.
*
* A domain value of 0 means that passwords do not expire. The database still
* requires a timestamp, so use the latest portable DATETIME value as a
* sentinel. The same applies when password expiration is disabled globally.
*/
function get_mailbox_password_expiry(string $domain, ?int $now = null): string
{
if (!Config::bool('password_expiration')) {
return PASSWORD_EXPIRATION_NEVER;
}
$value = get_password_expiration_value($domain);
$value_string = (string)$value;
if (!preg_match('/^(0|[1-9][0-9]*)$/D', $value_string)) {
error_log("Invalid password_expiry value for domain $domain; treating it as no expiration");
return PASSWORD_EXPIRATION_NEVER;
}
$days = (int)$value_string;
if ($days === 0) {
return PASSWORD_EXPIRATION_NEVER;
}
if ($days > PASSWORD_EXPIRATION_MAX_DAYS) {
error_log("password_expiry value for domain $domain exceeds the supported maximum; treating it as no expiration");
return PASSWORD_EXPIRATION_NEVER;
}
$base = $now ?? time();
$expiry = strtotime("+$days days", $base);
if ($expiry === false) {
throw new RuntimeException("Unable to calculate password expiry for domain $domain");
}
return date('Y-m-d H:i', $expiry);
}
/**
* check_email
* Checks if an email is valid - if it is, return true, else false.
@@ -2183,7 +2245,15 @@ function gen_show_status($show_alias)
$now = "datetime('now')";
}
$stat_result = db_query_one("SELECT * FROM " . table_by_key('mailbox') . " WHERE username = ? AND password_expiry <= $now AND active = ?", array($show_alias, db_get_boolean(true)));
$mailbox_table = table_by_key('mailbox');
$domain_table = table_by_key('domain');
$stat_result = db_query_one(
"SELECT $mailbox_table.username FROM $mailbox_table " .
"INNER JOIN $domain_table ON $domain_table.domain = $mailbox_table.domain " .
"WHERE $mailbox_table.username = ? AND $mailbox_table.password_expiry <= $now " .
"AND $domain_table.password_expiry > 0 AND $mailbox_table.active = ?",
array($show_alias, db_get_boolean(true))
);
if (!empty($stat_result)) {
$stat_string .= "<span style='background-color:" . $CONF['show_expired_color'] . "'>" . $CONF['show_status_text'] . "</span>&nbsp;";
+2
View File
@@ -42,6 +42,8 @@ $PALANG['pFooter_logged_as'] = 'Потребител %s'; # XXX # XXX Text chang
$PALANG['pLogin_welcome'] = 'Администраторът може да се логне оттук, за администриране на домейн.';
$PALANG['pLogin_username'] = "&nbsp;Логин (е-мейл)";
$PALANG['password'] = 'Парола';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Изход'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Login d\'administrador per l\'administració de dominis.';
$PALANG['pLogin_username'] = 'Usuari (e-mail)'; # XXX compare with pUsersLogin_username - should be "Login (email)"
$PALANG['password'] = 'Contrasenya';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Usuari'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = '邮件管理员请从这里登录以管理你的域名.';
$PALANG['pLogin_username'] = '帐号 (邮件地址)'; # XXX compare with pUsersLogin_username - should be "Login (email)"
$PALANG['password'] = '密码';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = '登录';
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -49,6 +49,8 @@ $PALANG['pFooter_logged_as'] = 'Přihlášen jako %s';
$PALANG['pLogin_welcome'] = 'Zde se přihlašují emailoví administrátoři pro administraci svých domén.';
$PALANG['pLogin_username'] = 'Uživatelské jméno (email)';
$PALANG['password'] = 'Heslo';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Jazyk';
$PALANG['pLogin_button'] = 'Přihlásit';
$PALANG['pLogin_failed'] = 'Neplatné uživatelské jméno (email) nebo heslo.';
+2
View File
@@ -45,6 +45,8 @@ $PALANG['pFooter_logged_as'] = 'Indlogget som %s'; # XXX Text change: 'logged in
$PALANG['pLogin_welcome'] = 'Postadministrator: Log ind for at administrere dine domæner.';
$PALANG['pLogin_username'] = 'Brugernavn (email)';
$PALANG['password'] = 'Adgangskode';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Log ind'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'Dit brugernavn eller adgangskode var ikke korrekt.';
+2
View File
@@ -43,6 +43,8 @@ $PALANG['pFooter_logged_as'] = 'Angemeldet als %s';
$PALANG['pLogin_welcome'] = 'Mail-Administratoren loggen sich bitte hier ein.';
$PALANG['pLogin_username'] = 'Login (eMail)';
$PALANG['password'] = 'Passwort';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Sprache';
$PALANG['pLogin_button'] = 'Login';
$PALANG['pLogin_failed'] = 'Ihre Mailadresse oder das Passwort sind nicht korrekt.';
+2
View File
@@ -45,6 +45,8 @@ $PALANG['pFooter_logged_as'] = 'Logged in as %s';
$PALANG['pLogin_welcome'] = 'Mail admins login here to administer your domain.';
$PALANG['pLogin_username'] = 'Login (email)';
$PALANG['password'] = 'Password';
$PALANG['password_expiration_on'] = 'Expires on';
$PALANG['password_expiration_never'] = 'Does not expire';
$PALANG['pLogin_language'] = 'Language';
$PALANG['pLogin_button'] = 'Login';
$PALANG['pLogin_failed'] = 'Your email address or password is not correct.';
+2
View File
@@ -42,6 +42,8 @@ $PALANG['pFooter_logged_as'] = 'Autenticado como %s'; # XXX Text change: 'logge
$PALANG['pLogin_welcome'] = 'Login de administrador para administración de dominios.';
$PALANG['pLogin_username'] = 'Usuario (e-mail)'; # XXX compare with pUsersLogin_username - should be "Login (email)"
$PALANG['password'] = 'Contraseña';
$PALANG['password_expiration_on'] = 'Expira el';
$PALANG['password_expiration_never'] = 'No expira';
$PALANG['pLogin_language'] = 'Lenguaje'; # XXX
$PALANG['pLogin_button'] = 'Usuario'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'La cuenta de email o la contraseña no son correctas.';
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'E-posti haldaja, logi siit domeeni administreerimiseks sisse.';
$PALANG['pLogin_username'] = 'Kasutajanimi (e-posti aadress)';
$PALANG['password'] = 'Parool';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Logi sisse';
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Kudeatzailearen logina domeinuak kudeatzeko.';
$PALANG['pLogin_username'] = 'Erabiltzailea (e-mail)'; # XXX compare with pUsersLogin_username - should be "Login (email)"
$PALANG['password'] = 'Pasahitza';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Erabiltzailea'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -42,6 +42,8 @@ $PALANG['pFooter_logged_as'] = 'Kirjautunut sisään tunnuksella %s'; # XXX Text
$PALANG['pLogin_welcome'] = 'Kirjautuminen';
$PALANG['pLogin_username'] = 'Tunnus';
$PALANG['password'] = 'Salasana';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Kirjaudu';
$PALANG['pLogin_failed'] = 'Sähköpostiosoite tai salasana väärin!';
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Umsitarar kunnu logga inn her fyri at umsita tykkara navnaøki.';
$PALANG['pLogin_username'] = 'Login (e-post)';
$PALANG['password'] = 'Loyniorð';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Logga inn';
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -45,6 +45,8 @@ $PALANG['pFooter_logged_as'] = 'Connecté en tant que %s';
$PALANG['pLogin_welcome'] = 'Entrez votre adresse email pour administrer votre domaine.';
$PALANG['pLogin_username'] = 'Adresse email';
$PALANG['password'] = 'Mot de passe';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Langue';
$PALANG['pLogin_button'] = 'Entrer';
$PALANG['pLogin_failed'] = 'Votre courriel ou mot de passe est incorrect.';
+2
View File
@@ -40,6 +40,8 @@ $PALANG['pFooter_logged_as'] = 'Autenticado como %s'; # XXX Text change: 'logge
$PALANG['pLogin_welcome'] = 'Login de administrador para administración de dominios.';
$PALANG['pLogin_username'] = 'Usuario (e-mail)'; # XXX compare with pUsersLogin_username - should be "Login (email)"
$PALANG['password'] = 'Contrasinal';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Linguaxe'; # XXX
$PALANG['pLogin_button'] = 'Usuario'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'A conta de email ou o contrasinal non son correctas.';
+2
View File
@@ -40,6 +40,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Administratori prijavite se ovdje.';
$PALANG['pLogin_username'] = 'Korisničko ime (adresa e-pošte)'; # XXX check translation - should be "Login (email)"
$PALANG['password'] = 'Lozinka';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Prijavi'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -42,6 +42,8 @@ $PALANG['pFooter_logged_as'] = '%s-ként bejelentkezve'; # XXX Text change: 'log
$PALANG['pLogin_welcome'] = 'Mail adminisztrátorok itt jelentkezzenek be, hogy adminisztrálják a domainjüket.';
$PALANG['pLogin_username'] = 'Bejelentkezés (email)'; # XXX compare with pUsersLogin_username - should be "Login (email)"
$PALANG['password'] = 'Jelszó';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Bejelentkezés'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Póst kerfisstjóri tengist hér til að viðhalda póstkerfi lénsins þins.';
$PALANG['pLogin_username'] = 'Auðkenni(email)'; # XXX check translation - should be "Login (email)"
$PALANG['password'] = 'Lykilorð';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Tengjast'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -43,6 +43,8 @@ $PALANG['pFooter_logged_as'] = 'Collegato come %s';
$PALANG['pLogin_welcome'] = 'Gli amministratori di posta devono effettuare il login qui per amministrare il proprio dominio.';
$PALANG['pLogin_username'] = 'Nome utente (email)';
$PALANG['password'] = 'Password';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Lingua';
$PALANG['pLogin_button'] = 'Entra';
$PALANG['pLogin_failed'] = 'Il tuo indirizzo email o password non sono corretti.';
+2
View File
@@ -43,6 +43,8 @@ $PALANG['pFooter_logged_as'] = 'ログイン名 %s';
$PALANG['pLogin_welcome'] = 'こちらからドメインの管理ができます。';
$PALANG['pLogin_username'] = 'ログイン (メールアドレス)';
$PALANG['password'] = 'パスワード';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = '言語';
$PALANG['pLogin_button'] = 'ログイン';
$PALANG['pLogin_failed'] = 'ユーザ名かパスワードが違います。';
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Prisijungęs kaip %s';
$PALANG['pLogin_welcome'] = 'Pašto srities administratorius.';
$PALANG['pLogin_username'] = 'Vartotojas (el.paštas)';
$PALANG['password'] = 'Slaptažodis';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Kalba';
$PALANG['pLogin_button'] = 'Prisijungti';
$PALANG['pLogin_failed'] = 'Neteisingas el. pašto adresas arba slaptažodis.';
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Логин за администрирање на домени (Само за администратори!)';
$PALANG['pLogin_username'] = 'Корисничко име (email)';
$PALANG['password'] = 'Лозинка';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Пријава';
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -43,6 +43,8 @@ $PALANG['pFooter_logged_as'] = 'Logget inn som %s'; # XXX Text change: 'logged i
$PALANG['pLogin_welcome'] = 'E-postadministratorer kan logge inn her for å administrere sine domener';
$PALANG['pLogin_username'] = 'Brukernavn (e-postadresse)';
$PALANG['password'] = 'Passord';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Logg inn';
$PALANG['pLogin_failed'] = 'E-postadressen eller passordet er ikke korrekt.';
+2
View File
@@ -43,6 +43,8 @@ $PALANG['pFooter_logged_as'] = 'aangemeld als %s';
$PALANG['pLogin_welcome'] = 'Mail beheerders log hier in om uw domeinen te beheren.';
$PALANG['pLogin_username'] = 'Login (e-mail)';
$PALANG['password'] = 'Wachtwoord';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Taal';
$PALANG['pLogin_button'] = 'Login';
$PALANG['pLogin_failed'] = 'Uw login gegevens zijn onjuist.';
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Postadministrator; Logg inn her for å administrere ditt domene';
$PALANG['pLogin_username'] = 'Brukernavn (e-postadressen)';
$PALANG['password'] = 'Passord';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Logg inn';
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -44,6 +44,8 @@ $PALANG['pFooter_logged_as'] = 'Zalogowano jako %s';
$PALANG['pLogin_welcome'] = 'Sekcja przeznaczona dla administratorów domen.';
$PALANG['pLogin_username'] = 'Użytkownik (email)'; # XXX check translation - should be "Login (email)"
$PALANG['password'] = 'Hasło';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Zaloguj';
$PALANG['pLogin_failed'] = 'Twój adres Email lub hasło jest niepoprawne.';
+2
View File
@@ -43,6 +43,8 @@ $PALANG['pFooter_logged_as'] = 'Autenticado como %s'; # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Administradores devem se autenticar aqui para gerenciar seus domínios.';
$PALANG['pLogin_username'] = 'Usuário (email)';
$PALANG['password'] = 'Senha';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Entrar';
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -43,6 +43,8 @@ $PALANG['pFooter_logged_as'] = 'Autenticado como %s'; # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Administradores devem de se autenticar aqui para gerir os domínios.';
$PALANG['pLogin_username'] = 'Utilizador (email)';
$PALANG['password'] = 'Password';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Linguagem'; # XXX
$PALANG['pLogin_button'] = 'Entrar';
$PALANG['pLogin_failed'] = 'O endereço de email ou password não estão correctos.'; # XXX
+2
View File
@@ -42,6 +42,8 @@ $PALANG['pFooter_logged_as'] = 'Logat ca %s';
$PALANG['pLogin_welcome'] = 'Conectare pentru administratorii de domeniu';
$PALANG['pLogin_username'] = 'Login (email)';
$PALANG['password'] = 'Parola';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Limba';
$PALANG['pLogin_button'] = 'Login';
$PALANG['pLogin_failed'] = 'Adresa de email sau parola nu sunt corecte';
+2
View File
@@ -45,6 +45,8 @@ $PALANG['pFooter_logged_as'] = 'Логин: %s';
$PALANG['pLogin_welcome'] = 'Вход для администраторов почтовых доменов.';
$PALANG['pLogin_username'] = 'Имя (email)';
$PALANG['password'] = 'Пароль';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Язык';
$PALANG['pLogin_button'] = 'Войти';
$PALANG['pLogin_failed'] = 'Ваш адрес email или пароль неверен.';
+2
View File
@@ -42,6 +42,8 @@ $PALANG['pFooter_logged_as'] = 'Prihlásený ako %s';
$PALANG['pLogin_welcome'] = 'Prihlásenie administrátorov pre správu domén';
$PALANG['pLogin_username'] = 'Užívateľské meno (email)';
$PALANG['password'] = 'Heslo';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Jazyk';
$PALANG['pLogin_button'] = 'Prihlásiť';
$PALANG['pLogin_failed'] = 'Váš email alebo heslo nie je správne.';
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = 'Administratorji se prijavite tukaj.';
$PALANG['pLogin_username'] = 'Uporabniško ime (e-poštni naslov)'; # XXX check translation - should be "Login (email)"
$PALANG['password'] = 'Geslo';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = 'Prijavi'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'Your email address or password are not correct.'; # XXX
+2
View File
@@ -44,6 +44,8 @@ $PALANG['pFooter_logged_as'] = 'Inloggad som %s'; # XXX Text change: 'logged in
$PALANG['pLogin_welcome'] = 'E-postadministratörer loggar in här för att hantera domäner.';
$PALANG['pLogin_username'] = 'Login (e-post)'; # XXX compare with pUsersLogin_username - should be "Login (email)"
$PALANG['password'] = 'Lösenord';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Språk';
$PALANG['pLogin_button'] = 'Login';
$PALANG['pLogin_failed'] = 'E-postadressen eller lösenordet är felaktigt.';
+2
View File
@@ -41,6 +41,8 @@ $PALANG['pFooter_logged_as'] = 'Giriş yapılan kullanıcı: %s';
$PALANG['pLogin_welcome'] = 'E-Posta Yöneticileri, buradan domainlerinizi yönetmek için giriş yapabilirsiniz.';
$PALANG['pLogin_username'] = 'Kullanıcı adı (e-posta)'; # # XXX check translation - should be "Login (email)"
$PALANG['password'] = 'Şifre'; # XXX compare with pUsersLogin_password - should be "Password"
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Dil';
$PALANG['pLogin_button'] = 'Giriş'; # XXX compare with pUsersLogin_button - should be "Login"
$PALANG['pLogin_failed'] = 'E-posta adresiniz veya şifreniz yanlış.';
+2
View File
@@ -42,6 +42,8 @@ $PALANG['pFooter_logged_as'] = 'Logged as %s'; # XXX # XXX Text change: 'logged
$PALANG['pLogin_welcome'] = '郵件管理員請從這裡登錄以管理你的網域.';
$PALANG['pLogin_username'] = '帳號(電郵)';
$PALANG['password'] = '密碼';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Language'; # XXX
$PALANG['pLogin_button'] = '登錄';
$PALANG['pLogin_failed'] = '你的帳號或密碼不正確。';
+2
View File
@@ -43,6 +43,8 @@ $PALANG['pFooter_logged_as'] = 'Логін: %s';
$PALANG['pLogin_welcome'] = 'Вхід для адміністраторів поштових доменів';
$PALANG['pLogin_username'] = 'Логін (Email)';
$PALANG['password'] = 'Пароль';
$PALANG['password_expiration_on'] = 'Expires on'; # XXX
$PALANG['password_expiration_never'] = 'Does not expire'; # XXX
$PALANG['pLogin_language'] = 'Мова - Language';
$PALANG['pLogin_button'] = 'УВІЙТИ';
$PALANG['pLogin_failed'] = 'Ваша електронна адреса або пароль неправильні.';
+20
View File
@@ -11,6 +11,26 @@ class DomainHandler extends PFAHandler
protected $id_field = 'domain';
protected $domain_field = 'domain';
protected function _validate_password_expiry($field, $val)
{
$value = (string)$val;
$valid = preg_match('/^(0|[1-9][0-9]*)$/D', $value) === 1
&& (int)$value <= PASSWORD_EXPIRATION_MAX_DAYS;
if (!$valid) {
$this->errormsg[$field] = Config::lang_f('invalid_value_given', $field);
}
return $valid;
}
protected function setmore(array $values)
{
if (array_key_exists('password_expiry', $this->values)) {
$this->values['password_expiry'] = (int)$this->values['password_expiry'];
}
}
protected function validate_new_id()
{
$domain_check = check_domain($this->id);
+4 -6
View File
@@ -136,12 +136,10 @@ class Login
'password' => pacrypt($new_password, '', $username),
);
if (Config::bool('password_expiration')) {
$domain = $this->getUserDomain($username);
if (!is_null($domain)) {
$password_expiration_value = (int)get_password_expiration_value($domain);
$set['password_expiry'] = date('Y-m-d H:i', strtotime("+$password_expiration_value day"));
}
$user_domain = $this->getUserDomain($username);
if (!is_null($user_domain)) {
$domain = $user_domain;
$set['password_expiry'] = get_mailbox_password_expiry($user_domain);
}
$result = db_update($this->table, 'username', $username, $set);
+21 -9
View File
@@ -62,7 +62,7 @@ class MailboxHandler extends PFAHandler
'token_validity' => self::pacol(1, 0, 0, 'ts', '', '', date("Y-m-d H:i:s", time())),
'created' => self::pacol(0, 0, 1, 'ts', 'created', ''),
'modified' => self::pacol(0, 0, 1, 'ts', 'last_modified', ''),
'password_expiry' => self::pacol(0, 0, 1, 'ts', 'password_expiration', ''),
'password_expiry' => self::pacol(0, 0, (int)Config::bool('password_expiration'), 'ts', 'password_expiration', ''),
# TODO: add virtual 'notified' column and allow to display who received a vacation response?
);
@@ -225,6 +225,9 @@ class MailboxHandler extends PFAHandler
protected function read_from_db_postprocess($db_result)
{
$password_expiration_policies = array();
$password_expiration_never_label = Config::lang('password_expiration_never');
foreach ($db_result as $key => $row) {
if (isset($row['quota']) && is_numeric($row['quota']) && $row['quota'] > -1) { # quota could be disabled in $struct
$db_result[$key]['quotabytes'] = $row['quota'];
@@ -233,6 +236,21 @@ class MailboxHandler extends PFAHandler
$db_result[$key]['quotabytes'] = -1;
$db_result[$key]['quota'] = -1;
}
if (Config::bool('password_expiration') && isset($row['password_expiry'], $row['domain'])) {
$domain = (string)$row['domain'];
if (!array_key_exists($domain, $password_expiration_policies)) {
$password_expiration_policies[$domain] = get_password_expiration_value($domain);
}
$raw_expiry = $row['_password_expiry'] ?? $row['password_expiry'];
if (mailbox_password_expiration_is_never(
$raw_expiry,
$password_expiration_policies[$domain]
)) {
$db_result[$key]['password_expiry'] = $password_expiration_never_label;
}
}
}
return $db_result;
}
@@ -284,14 +302,8 @@ class MailboxHandler extends PFAHandler
}
if (!empty($this->values['password'])) {
// provide some default value to keep MySQL etc happy.
$this->values['password_expiry'] = date('Y-m-d H:i', strtotime("+365 days"));
if (Config::bool('password_expiration')) {
$domain_dirty = $this->domain_from_id();
$domain = trim($domain_dirty, "`'"); // naive assumption it is ' escaping.
$password_expiration_value = (int)get_password_expiration_value($domain);
$this->values['password_expiry'] = date('Y-m-d H:i', strtotime("+$password_expiration_value day"));
}
$domain = $this->domain_from_id();
$this->values['password_expiry'] = get_mailbox_password_expiry($domain);
}
return true;
+29 -1
View File
@@ -152,6 +152,7 @@ if (Config::bool('alias_domain')) {
#
$table_alias = table_by_key('alias');
$table_domain = table_by_key('domain');
$table_mailbox = table_by_key('mailbox');
if (count($search) == 0 || !isset($search['_'])) {
@@ -212,7 +213,8 @@ if ($display_mailbox_aliases) {
}
if ($password_expiration) {
$sql_select .= ", $table_mailbox.password_expiry as password_expiration ";
$sql_select .= ", $table_mailbox.password_expiry as password_expiration, $table_domain.password_expiry as domain_password_expiration ";
$sql_join .= " LEFT JOIN $table_domain ON $table_mailbox.domain=$table_domain.domain ";
}
if (Config::bool('vacation_control_admin')) {
@@ -247,6 +249,21 @@ $delimiter = preg_quote($CONF['recipient_delimiter'], "/");
$goto_single_rec_del = "";
foreach ($result as $row) {
if ($password_expiration) {
$password_expiration_timestamp = strtotime((string)$row['password_expiration']);
$row['password_expiration_never'] = mailbox_password_expiration_is_never(
$row['password_expiration'],
$row['domain_password_expiration']
);
$row['password_expiration_expired'] = !$row['password_expiration_never']
&& $password_expiration_timestamp !== false
&& $password_expiration_timestamp <= time();
if ($password_expiration_timestamp !== false) {
$row['password_expiration'] = date('Y-m-d H:i', $password_expiration_timestamp);
}
}
if ($display_mailbox_aliases) {
$goto_split = explode(",", $row['goto']);
$row['goto_mailbox'] = 0;
@@ -511,6 +528,17 @@ $smarty->assign('tAlias', $tAlias);
$smarty->assign('alias_data', $alias_data);
$smarty->assign('tMailbox', $tMailbox);
$smarty->assign('password_expiration', $password_expiration);
$password_expiration_on_label = Config::lang('password_expiration_on');
if ($password_expiration_on_label === '') {
$password_expiration_on_label = Config::lang('password_expiration');
}
$password_expiration_never_label = Config::lang('password_expiration_never');
if ($password_expiration_never_label === '') {
$password_expiration_never_label = Config::lang('pOverview_unlimited');
}
$smarty->assign('password_expiration_on_label', $password_expiration_on_label);
$smarty->assign('password_expiration_never_label', $password_expiration_never_label);
$smarty->assign('gen_show_status_mailbox', $gen_show_status_mailbox, false);
$smarty->assign('boolconf_used_quotas', Config::bool('used_quotas'));
$smarty->assign('divide_quota', $divide_quota);
+12
View File
@@ -14,6 +14,7 @@
<th>{$PALANG.name}</th>
{if $CONF.quota===YES}<th>{$PALANG.pOverview_mailbox_quota}</th>{/if}
<th>{$PALANG.last_modified}</th>
{if $password_expiration}<th class="text-center">{$PALANG.password}</th>{/if}
<th>{$PALANG.active}</th>
{if $CONF.smtp_active_flag===YES}<th>{$PALANG.smtp_active}</th>{/if}
{assign var="colspan" value="`$colspan-6`"}
@@ -76,6 +77,17 @@
</td>
{/if}
<td>{$item.modified}</td>
{if $password_expiration}
<td class="text-center">
{if $item.password_expiration_never}
<span class="glyphicon glyphicon-lock text-muted" role="img" title="{$password_expiration_never_label}" aria-label="{$password_expiration_never_label}"></span>
{elseif $item.password_expiration_expired}
<span class="glyphicon glyphicon-lock text-danger" role="img" title="{$PALANG.pStatus_expired}{$item.password_expiration}" aria-label="{$PALANG.pStatus_expired}{$item.password_expiration}"></span>
{else}
<span class="glyphicon glyphicon-lock text-success" role="img" title="{$password_expiration_on_label} {$item.password_expiration}" aria-label="{$password_expiration_on_label} {$item.password_expiration}"></span>
{/if}
</td>
{/if}
<td><a class="btn btn-{if ($item.active==0)}info{else}warning{/if} list-action-icon" title="{$PALANG.active}: {if $item.active==1}{$PALANG.YES}{else}{$PALANG.NO}{/if}" aria-label="{$PALANG.active}: {if $item.active==1}{$PALANG.YES}{else}{$PALANG.NO}{/if}" href="{#url_editactive#}mailbox&amp;id={$item.username|escape:"url"}&amp;active={if ($item.active==0)}1{else}0{/if}&amp;token={$smarty.session.PFA_token|escape:"url"}"
>{if $item.active==1}<span class="glyphicon glyphicon-check" aria-hidden="true"></span>{else}<span class="glyphicon glyphicon-unchecked" aria-hidden="true"></span>{/if}</a></td>
{if $CONF.smtp_active_flag===YES}
+57
View File
@@ -2,6 +2,63 @@
class DomainHandlerTest extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider passwordExpiryValuesProvider
*/
public function testPasswordExpiryValidation($value, $expected): void
{
$_SESSION = [
'sessid' => [
'roles' => ['global-admin']
]
];
$domain = 'password-expiry-' . uniqid() . '.example';
db_insert(
'domain',
['domain' => $domain, 'description' => 'test', 'transport' => '', 'password_expiry' => 365]
);
db_insert(
'domain_admins',
['username' => 'admin', 'domain' => $domain, 'active' => 1],
['created'],
true
);
try {
$handler = new DomainHandler(0, 'admin', true);
$this->assertTrue($handler->init($domain));
$this->assertSame($expected, $handler->set(['password_expiry' => $value]));
if ($expected) {
$this->assertTrue($handler->save());
$stored = db_query_one(
'SELECT password_expiry FROM domain WHERE domain = :domain',
['domain' => $domain]
);
$this->assertSame((int)$value, (int)$stored['password_expiry']);
}
} finally {
db_delete('domain_admins', 'domain', $domain);
db_delete('domain', 'domain', $domain);
}
}
public function passwordExpiryValuesProvider(): array
{
return [
'no expiration' => [0, true],
'positive integer' => [365, true],
'maximum' => [PASSWORD_EXPIRATION_MAX_DAYS, true],
'negative sentinel' => [-1, false],
'negative value' => [-2, false],
'decimal' => ['1.5', false],
'scientific notation' => ['1e2', false],
'above maximum' => [PASSWORD_EXPIRATION_MAX_DAYS + 1, false],
'text' => ['invalid', false],
];
}
public function testBasic()
{
$x = new DomainHandler();
+25
View File
@@ -2,10 +2,13 @@
class LoginTest extends \PHPUnit\Framework\TestCase
{
private $passwordExpirationConfig;
public function setUp(): void
{
global $CONF;
$this->passwordExpirationConfig = (string)Config::read('password_expiration');
$this->cleanUp();
$CONF['pacrypt'] = 'md5'; // crap
@@ -30,6 +33,7 @@ class LoginTest extends \PHPUnit\Framework\TestCase
public function tearDown(): void
{
Config::write('password_expiration', $this->passwordExpirationConfig);
$this->cleanUp();
parent::tearDown(); // TODO: Change the autogenerated stub
}
@@ -66,6 +70,27 @@ class LoginTest extends \PHPUnit\Framework\TestCase
// Can login with the new one...
$this->assertTrue($login->login('test@example.com', 'foobar2'));
$mailbox = db_query_one(
'SELECT password_expiry FROM mailbox WHERE username = :username',
['username' => 'test@example.com']
);
$this->assertSame(strtotime(PASSWORD_EXPIRATION_NEVER), strtotime($mailbox['password_expiry']));
Config::write('password_expiration', 'YES');
db_execute(
'UPDATE domain SET password_expiry = :days WHERE domain = :domain',
['days' => 30, 'domain' => 'example.com']
);
$this->assertTrue($login->changePassword('test@example.com', 'foobar3', 'foobar2'));
$mailbox = db_query_one(
'SELECT password_expiry FROM mailbox WHERE username = :username',
['username' => 'test@example.com']
);
$expiry = strtotime($mailbox['password_expiry']);
$this->assertGreaterThanOrEqual(strtotime('+29 days'), $expiry);
$this->assertLessThanOrEqual(strtotime('+31 days'), $expiry);
}
+91
View File
@@ -0,0 +1,91 @@
<?php
class PasswordExpirationMailboxHandler extends MailboxHandler
{
public function postprocess(array $rows): array
{
return $this->read_from_db_postprocess($rows);
}
}
class PasswordExpirationTest extends \PHPUnit\Framework\TestCase
{
private $domain;
private $passwordExpirationConfig;
protected function setUp(): void
{
$this->passwordExpirationConfig = (string)Config::read('password_expiration');
$this->domain = 'password-expiry-helper-' . uniqid() . '.example';
db_insert(
'domain',
['domain' => $this->domain, 'description' => 'test', 'transport' => '', 'password_expiry' => 0]
);
Config::write('password_expiration', $this->passwordExpirationConfig);
}
protected function tearDown(): void
{
Config::write('password_expiration', 'YES');
db_delete('domain', 'domain', $this->domain);
}
public function testZeroMeansNoExpiration(): void
{
$this->assertSame(PASSWORD_EXPIRATION_NEVER, get_mailbox_password_expiry($this->domain, 0));
}
public function testPositiveValueProducesExpectedDate(): void
{
db_update('domain', 'domain', $this->domain, ['password_expiry' => 30], []);
$base = strtotime('2026-01-01 00:00');
$this->assertSame(
date('Y-m-d H:i', strtotime('+30 days', $base)),
get_mailbox_password_expiry($this->domain, $base)
);
}
public function testInvalidStoredValuesFailSafe(): void
{
db_update('domain', 'domain', $this->domain, ['password_expiry' => -1], []);
$this->assertSame(PASSWORD_EXPIRATION_NEVER, get_mailbox_password_expiry($this->domain, 0));
db_update(
'domain',
'domain',
$this->domain,
['password_expiry' => PASSWORD_EXPIRATION_MAX_DAYS + 1],
[]
);
$this->assertSame(PASSWORD_EXPIRATION_NEVER, get_mailbox_password_expiry($this->domain, 0));
}
public function testDisabledFeatureMeansPasswordDoesNotExpire(): void
{
Config::write('password_expiration', 'NO');
$this->assertSame(PASSWORD_EXPIRATION_NEVER, get_mailbox_password_expiry($this->domain, 0));
}
public function testNoExpirationDisplayUsesPolicyAndStoredSentinel(): void
{
$this->assertTrue(mailbox_password_expiration_is_never('2026-12-31 00:00:00', 0));
$this->assertTrue(mailbox_password_expiration_is_never(PASSWORD_EXPIRATION_NEVER, 30));
$this->assertTrue(mailbox_password_expiration_is_never('2026-12-31 00:00:00', -1));
$this->assertFalse(mailbox_password_expiration_is_never('2026-12-31 00:00:00', 30));
}
public function testMailboxHandlerFormatsNoExpirationValue(): void
{
$handler = new PasswordExpirationMailboxHandler();
$rows = $handler->postprocess([
[
'username' => 'user@' . $this->domain,
'domain' => $this->domain,
'password_expiry' => '2026-12-31 00:00:00',
],
]);
$this->assertSame(Config::lang('password_expiration_never'), $rows[0]['password_expiry']);
}
}