From 1eaaecfcbc58113152b4fac418e06875cecff35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Cort=C3=A9s=20Cano?= <38475681+TrapoSAMA@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:22:21 -0300 Subject: [PATCH] Show configured MFA status and add CLI reset commands (#1196) The administrator list shows a translated Yes/No MFA column immediately after Active. Domains display an MFA badge only when at least one mailbox has a configured secret. Add resetmfa task for the postfixadmin-cli command. ( postfixadmin-cli admin resetmfa
and postfixadmin-cli mailbox resetmfa
) thanks @TrapoSAMA --- CHANGELOG.TXT | 4 +- DOCUMENTS/MFA.md | 28 ++++++++ debian/manpage/postfixadmin-cli.1 | 9 +++ languages/bg.lang | 1 + languages/ca.lang | 1 + languages/cn.lang | 1 + languages/cs.lang | 1 + languages/da.lang | 1 + languages/de.lang | 1 + languages/en.lang | 2 + languages/es.lang | 2 + languages/et.lang | 1 + languages/eu.lang | 1 + languages/fi.lang | 1 + languages/fo.lang | 1 + languages/fr.lang | 1 + languages/gl.lang | 1 + languages/hr.lang | 1 + languages/hu.lang | 1 + languages/is.lang | 1 + languages/it.lang | 1 + languages/ja.lang | 1 + languages/ko.lang | 1 + languages/lt.lang | 1 + languages/mk.lang | 1 + languages/nb.lang | 1 + languages/nl.lang | 1 + languages/nn.lang | 1 + languages/pl.lang | 1 + languages/pt-br.lang | 1 + languages/pt-pt.lang | 1 + languages/ro.lang | 1 + languages/ru.lang | 1 + languages/sk.lang | 1 + languages/sl.lang | 1 + languages/sv.lang | 1 + languages/tr.lang | 1 + languages/tw.lang | 1 + languages/ua.lang | 1 + model/AdminHandler.php | 4 ++ model/CliHelp.php | 4 ++ model/CliResetmfa.php | 41 +++++++++++ model/DomainHandler.php | 3 + model/MailboxHandler.php | 2 + public/edit.php | 5 ++ public/list-virtual.php | 9 +++ scripts/postfixadmin-cli.php | 1 + templates/list-virtual_mailbox.tpl | 2 + templates/list.tpl | 5 +- tests/MailboxnameHttpTest.php | 9 +++ tests/MfaStatusTest.php | 103 ++++++++++++++++++++++++++++ tests/TotpManagementHttpTest.php | 72 +++++++++++++++++++ tests/fixtures/totp-http-router.php | 8 ++- 53 files changed, 343 insertions(+), 4 deletions(-) create mode 100644 DOCUMENTS/MFA.md create mode 100644 model/CliResetmfa.php create mode 100644 tests/MfaStatusTest.php diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 96927819..b1c735f1 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -8,6 +8,8 @@ Changes in 'master' (not in a release yet) (20XX/XX/XX) -------------------------- + + - Show configured MFA in administrator, domain and mailbox lists; add the admin/mailbox resetmfa CLI task. - Restore mailbox-user TOTP exception links and use the shared navigation header without overlapping logos. - Enforce managed-domain authorization for administrator TOTP self-exceptions, including partial edits. - Follow up security search filtering, password-recovery messages and password confirmation for TOTP exception forms. @@ -15,8 +17,6 @@ Changes in 'master' (not in a release yet) (20XX/XX/XX) - Open expanded navigation dropdowns on mouse hover while retaining click, touch and keyboard controls. - Add Cancel to shared create/edit forms and mail composers, returning to the configured list or dashboard. - Use the concise Spanish "MX de respaldo" label for Backup MX in domain lists and forms. - - - CVE-2026-121551: Escape stored application-password and TOTP-exception list values. (see #1172, thanks @TrapoSAMA) - Require explicit TemplateEscape modes instead of boolean template escaping arguments. (see #1172, thanks @TrapoSAMA) - Treat recipient_delimiter as a set of alternative characters, matching Postfix behavior (see #1143, thanks @MatzeKitt). diff --git a/DOCUMENTS/MFA.md b/DOCUMENTS/MFA.md new file mode 100644 index 00000000..35e8cb2a --- /dev/null +++ b/DOCUMENTS/MFA.md @@ -0,0 +1,28 @@ +# MFA status and administrative reset + +The administrator list shows whether each account has an MFA secret configured. +The domain list marks a domain with an MFA badge when at least one of its +mailboxes has a configured secret. The mailbox list shows a translated Yes/No +MFA column only when its complete authorized search result contains such a +mailbox. Pagination does not change the column's visibility. Inactive accounts +retain their configured-MFA status. No secrets are included in these indicators. + +Administrative MFA reset through the web interface retains its existing +permissions: global administrators can reset administrator accounts; domain +administrators can reset mailboxes within their managed domains. TOTP must be +enabled for the web reset action to be available. Account holders can still +manage their own MFA. + +With local access to the installation, reset an existing account using: + +```sh +scripts/postfixadmin-cli admin resetmfa admin@example.com +scripts/postfixadmin-cli mailbox resetmfa user@example.com +``` + +The CLI reset remains available when TOTP is disabled. It removes +the stored TOTP secret, including for inactive accounts. The account holder can +configure MFA again. As with the existing administrative web reset, this does +not revoke application passwords or exceptions and does not invoke the mailbox +TOTP-change hook. Reset commands must be run by someone authorized to administer +the installation and with access to its configuration and database. diff --git a/debian/manpage/postfixadmin-cli.1 b/debian/manpage/postfixadmin-cli.1 index 79d3ff16..9ac8cd12 100644 --- a/debian/manpage/postfixadmin-cli.1 +++ b/debian/manpage/postfixadmin-cli.1 @@ -33,6 +33,9 @@ Delete an item. Print database scheme (useful for developers only). .IP \fBhelp\fP Print help output. +.IP \fBresetmfa\fP +Remove the MFA secret from an existing account (admin and mailbox modules only). +Works independently of the web-interface reset setting. .SH OPTIONS Different combinations of \fBMODULES\fP and \fBTASKS\fP have different sets of available options to use. Please see the help messages and @@ -53,6 +56,12 @@ To view the information of a domain: .P .B postfixadmin-cli \fIdomain view\fP \fRexample.com\fP .P +To reset MFA for an administrator or mailbox: +.P +.B postfixadmin-cli \fIadmin resetmfa\fP \fRadmin@example.com\fP +.P +.B postfixadmin-cli \fImailbox resetmfa\fP \fRuser@example.com\fP +.P .SH REPORTING BUGS Please report bugs to the Debian BTS, i.e. using \fBreportbug\fP(1). .SH SEE ALSO diff --git a/languages/bg.lang b/languages/bg.lang index ad02d0ae..9bdf40f2 100644 --- a/languages/bg.lang +++ b/languages/bg.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Bulgarian diff --git a/languages/ca.lang b/languages/ca.lang index 46982eb2..453e6b5e 100644 --- a/languages/ca.lang +++ b/languages/ca.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Catalan diff --git a/languages/cn.lang b/languages/cn.lang index 52928d18..e8b3a1c7 100644 --- a/languages/cn.lang +++ b/languages/cn.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Simplified Chinese diff --git a/languages/cs.lang b/languages/cs.lang index 2c897f11..9e20e5dd 100644 --- a/languages/cs.lang +++ b/languages/cs.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Czech Language Translation of PostfixAdmin diff --git a/languages/da.lang b/languages/da.lang index 227f7b83..fc0a0754 100644 --- a/languages/da.lang +++ b/languages/da.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Danish diff --git a/languages/de.lang b/languages/de.lang index 670eae76..68c61074 100644 --- a/languages/de.lang +++ b/languages/de.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file German diff --git a/languages/en.lang b/languages/en.lang index c581004b..855e33dc 100644 --- a/languages/en.lang +++ b/languages/en.lang @@ -14,6 +14,8 @@ $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; // +$PALANG['mfa'] = 'MFA'; + $PALANG['YES'] = 'YES'; $PALANG['NO'] = 'NO'; $PALANG['edit'] = 'edit'; diff --git a/languages/es.lang b/languages/es.lang index 5790fe77..5e678acd 100644 --- a/languages/es.lang +++ b/languages/es.lang @@ -14,6 +14,8 @@ $PALANG['search_mailboxes_aliases'] = 'Buscar buzones y alias...'; // // by Iñaki Rodríguez (irodriguez@ackstorm.es / irodriguez@virtualminds.es) +$PALANG['mfa'] = 'MFA'; + $PALANG['YES'] = 'SI'; $PALANG['NO'] = 'NO'; $PALANG['edit'] = 'editar'; diff --git a/languages/et.lang b/languages/et.lang index e3476cc8..99e3187b 100644 --- a/languages/et.lang +++ b/languages/et.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Estonian diff --git a/languages/eu.lang b/languages/eu.lang index dbd7ca33..74ce5fd3 100644 --- a/languages/eu.lang +++ b/languages/eu.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Euskara diff --git a/languages/fi.lang b/languages/fi.lang index d3c09b1a..dcc925f3 100644 --- a/languages/fi.lang +++ b/languages/fi.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Finnish diff --git a/languages/fo.lang b/languages/fo.lang index 1f45a1cc..fe5d30fb 100644 --- a/languages/fo.lang +++ b/languages/fo.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Faroese diff --git a/languages/fr.lang b/languages/fr.lang index 30034700..ab7b960e 100644 --- a/languages/fr.lang +++ b/languages/fr.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'DNS actif'; $PALANG['dns_inactive'] = 'DNS inactif'; $PALANG['search_mailboxes_aliases'] = 'Rechercher les boîtes aux lettres et alias...'; +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file French diff --git a/languages/gl.lang b/languages/gl.lang index cccaa5b4..8e15a675 100644 --- a/languages/gl.lang +++ b/languages/gl.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Spanish diff --git a/languages/hr.lang b/languages/hr.lang index c49774c6..eb328143 100644 --- a/languages/hr.lang +++ b/languages/hr.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Croatian diff --git a/languages/hu.lang b/languages/hu.lang index 79361d6e..781a651c 100644 --- a/languages/hu.lang +++ b/languages/hu.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Hungarian diff --git a/languages/is.lang b/languages/is.lang index 39db2355..64650a48 100644 --- a/languages/is.lang +++ b/languages/is.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Icelandic diff --git a/languages/it.lang b/languages/it.lang index c6dec79a..63ed1df6 100644 --- a/languages/it.lang +++ b/languages/it.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Italian diff --git a/languages/ja.lang b/languages/ja.lang index d23d7724..1511401d 100644 --- a/languages/ja.lang +++ b/languages/ja.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id: en.lang 275 2007-12-28 21:42:09Z christian_boltz $ // // Language file Japanese diff --git a/languages/ko.lang b/languages/ko.lang index f7f25d52..6441baeb 100644 --- a/languages/ko.lang +++ b/languages/ko.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Korean diff --git a/languages/lt.lang b/languages/lt.lang index 8c7f798d..3bfce690 100644 --- a/languages/lt.lang +++ b/languages/lt.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Lithuanian diff --git a/languages/mk.lang b/languages/mk.lang index bd855256..523d8c88 100644 --- a/languages/mk.lang +++ b/languages/mk.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Macedonian diff --git a/languages/nb.lang b/languages/nb.lang index 404e051c..d9c7a0bd 100644 --- a/languages/nb.lang +++ b/languages/nb.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Norwegian (bokmål) diff --git a/languages/nl.lang b/languages/nl.lang index 083bf1cb..4c6d4f4a 100644 --- a/languages/nl.lang +++ b/languages/nl.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Dutch diff --git a/languages/nn.lang b/languages/nn.lang index ebb31a86..f7ff170d 100644 --- a/languages/nn.lang +++ b/languages/nn.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Norwegian - Bokmål diff --git a/languages/pl.lang b/languages/pl.lang index c33b81af..8bc91cd4 100644 --- a/languages/pl.lang +++ b/languages/pl.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Polish diff --git a/languages/pt-br.lang b/languages/pt-br.lang index 2e956de2..4d6d96e3 100644 --- a/languages/pt-br.lang +++ b/languages/pt-br.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX // // Language file Portuguese - Brazil diff --git a/languages/pt-pt.lang b/languages/pt-pt.lang index d2192da8..9bb492f1 100644 --- a/languages/pt-pt.lang +++ b/languages/pt-pt.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX // // Language file Português - Portugal diff --git a/languages/ro.lang b/languages/ro.lang index d6f08e23..4b704b14 100644 --- a/languages/ro.lang +++ b/languages/ro.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX // // Language file Romanian // by Dan < dmarican at gmail dot com> diff --git a/languages/ru.lang b/languages/ru.lang index 346ad476..1fac70d0 100644 --- a/languages/ru.lang +++ b/languages/ru.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Russian diff --git a/languages/sk.lang b/languages/sk.lang index f56da701..2af8abaf 100644 --- a/languages/sk.lang +++ b/languages/sk.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Slovak diff --git a/languages/sl.lang b/languages/sl.lang index d9c09c1e..c1ad8fa9 100644 --- a/languages/sl.lang +++ b/languages/sl.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Slovenian diff --git a/languages/sv.lang b/languages/sv.lang index bd104744..2b7a2066 100644 --- a/languages/sv.lang +++ b/languages/sv.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Swedish diff --git a/languages/tr.lang b/languages/tr.lang index 2785815b..0dea2a49 100644 --- a/languages/tr.lang +++ b/languages/tr.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Türkçe diff --git a/languages/tw.lang b/languages/tw.lang index 71e6dfc3..57805e24 100644 --- a/languages/tw.lang +++ b/languages/tw.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Traditional Chinese diff --git a/languages/ua.lang b/languages/ua.lang index f3feffad..f405dc4e 100644 --- a/languages/ua.lang +++ b/languages/ua.lang @@ -7,6 +7,7 @@ $PALANG['dns_active'] = 'Active DNS'; # XXX $PALANG['dns_inactive'] = 'Inactive DNS'; # XXX $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...'; # XXX +$PALANG['mfa'] = 'MFA'; # XXX # $Id$ // // Language file Ukrainian diff --git a/model/AdminHandler.php b/model/AdminHandler.php index b61c28cc..ae5e6c65 100644 --- a/model/AdminHandler.php +++ b/model/AdminHandler.php @@ -4,6 +4,8 @@ class AdminHandler extends PFAHandler { + public array $taskNames = ['Help', 'Add', 'Update', 'Delete', 'View', 'Scheme', 'Resetmfa']; + protected string $db_table = 'admin'; protected string $id_field = 'username'; @@ -84,6 +86,8 @@ class AdminHandler extends PFAHandler ' ) AS __domain on username = __domain_username'), 'active' => self::pacol(1, 1, 1, 'bool', 'active' , '' , 1), + 'mfa' => self::pacol(0, 0, 1, 'vnum', 'mfa', '', 0, [], 0, 1, + "CASE WHEN totp_secret IS NOT NULL AND totp_secret <> '' THEN 1 ELSE 0 END AS mfa"), 'phone' => self::pacol(1, $reset_by_sms, 0, 'text', 'pCreate_mailbox_phone', 'pCreate_mailbox_phone_desc', ''), 'email_other' => self::pacol(1, $passwordReset, 0, 'mail', 'pCreate_mailbox_email', 'pCreate_mailbox_email_desc', ''), 'token' => self::pacol(1, 0, 0, 'text', '' , ''), diff --git a/model/CliHelp.php b/model/CliHelp.php index c8194db4..794bbd5d 100644 --- a/model/CliHelp.php +++ b/model/CliHelp.php @@ -61,6 +61,10 @@ class CliHelp extends Shell "\t\tA address of recipient.\n", ); + if (in_array($this->handler_to_use, [AdminHandler::class, MailboxHandler::class], true)) { + $this->out(" resetmfa
Reset MFA for an existing account.\n"); + } + foreach ($commands as $cmd) { $this->out("{$cmd}\n\n"); } diff --git a/model/CliResetmfa.php b/model/CliResetmfa.php new file mode 100644 index 00000000..1c3f9b6d --- /dev/null +++ b/model/CliResetmfa.php @@ -0,0 +1,41 @@ +handler_to_use, [AdminHandler::class, MailboxHandler::class], true) + || count($this->args) !== 1 + || array_diff(array_keys($this->params), ['webroot']) + ) { + $this->help(); + return 1; + } + + $handler = new $this->handler_to_use(); + if (!$handler->init($this->args[0])) { + $this->err($handler->errormsg); + return 1; + } + + $username = $handler->result()[$handler->getId_field()]; + $table = $this->handler_to_use === AdminHandler::class ? 'admin' : 'mailbox'; + try { + $totp = new TotpPf($table, new Login($table)); + $totp->removeTotpFromUser($username); + } catch (Exception $e) { + $this->err(Config::lang_f('pTOTP_reset_failed', $username)); + return 1; + } + + $this->out(Config::lang_f('pTOTP_reset_success', $username)); + return 0; + } + + public function help() + { + $this->out('Usage: postfixadmin-cli resetmfa
'); + $this->out('Remove the MFA secret from an existing account, even when web reset is disabled.'); + } +} diff --git a/model/DomainHandler.php b/model/DomainHandler.php index 8fae23c2..e8c4ec0e 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -113,6 +113,9 @@ class DomainHandler extends PFAHandler # editing? form list 'domain' => self::pacol($this->new, 1, 1, 'text', 'domain' , '' ,'', array(), 0, 0, "", "", 'list-virtual.php?domain=%s'), 'full_mailbox_count' => self::pacol(0, 0, 1, 'vnum', '' , '' , '', array(), 0, 0, 'coalesce(__full_mailbox_count,0) as full_mailbox_count'), + 'mfa' => self::pacol(0, 0, 1, 'vnum', '', '', 0, [], 0, 1, + 'CASE WHEN EXISTS (SELECT 1 FROM ' . table_by_key('mailbox') . ' AS mfa_mailbox' + . ' WHERE mfa_mailbox.domain = ' . table_by_key('domain') . ".domain AND mfa_mailbox.totp_secret IS NOT NULL AND mfa_mailbox.totp_secret <> '') THEN 1 ELSE 0 END AS mfa"), 'dns_active' => self::pacol(0, 0, 1, 'bool', '' , ''), 'dns_checked' => self::pacol(0, 0, 1, 'ts', '' , '', null), 'description' => self::pacol($super, $super, $super, 'text', 'description' , ''), diff --git a/model/MailboxHandler.php b/model/MailboxHandler.php index f2ae83df..ed595dc0 100644 --- a/model/MailboxHandler.php +++ b/model/MailboxHandler.php @@ -7,6 +7,8 @@ */ class MailboxHandler extends PFAHandler { + public array $taskNames = ['Help', 'Add', 'Update', 'Delete', 'View', 'Scheme', 'Resetmfa']; + protected string $db_table = 'mailbox'; protected string $id_field = 'username'; protected ?string $domain_field = 'domain'; diff --git a/public/edit.php b/public/edit.php index 277fb086..058dfaf3 100644 --- a/public/edit.php +++ b/public/edit.php @@ -111,6 +111,11 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { # Reset TOTP secret (mailbox/admin edit by Admin) if (safepost('reset_totp') === '1') { + if (!$is_admin) { + http_response_code(403); + exit(Config::lang('invalid_parameter')); + } + if (Config::bool('totp') && !$new && ($table === 'mailbox' || $table === 'admin')) { if (!$handler->init($edit)) { diff --git a/public/list-virtual.php b/public/list-virtual.php index c663a542..5739f654 100644 --- a/public/list-virtual.php +++ b/public/list-virtual.php @@ -259,6 +259,13 @@ if (Config::bool('used_quotas') && (!Config::bool('new_quota_table'))) { $sql_where .= " AND ( $table_quota.path='quota/storage' OR $table_quota.path IS NULL ) "; } +// Check the complete authorized result set, before pagination. +$show_mailbox_mfa = false; +if (db_query_one("SELECT 1 $sql_from $sql_join $sql_where AND $table_mailbox.totp_secret IS NOT NULL AND $table_mailbox.totp_secret <> '' LIMIT 1", $sql_params)) { + $show_mailbox_mfa = true; +} +$smarty->assign('show_mailbox_mfa', $show_mailbox_mfa); + $mailbox_pagebrowser_query = "$sql_from\n$sql_join\n$sql_where\n$sql_order"; $query = "$sql_select\n$mailbox_pagebrowser_query\n$sql_limit"; @@ -269,6 +276,8 @@ $tMailbox = array(); foreach ($result as $row) { + $row['mfa'] = isset($row['totp_secret']) && $row['totp_secret'] !== ''; + unset($row['totp_secret']); if ($password_expiration) { $password_expiration_timestamp = strtotime((string)$row['password_expiration']); $row['password_expiration_never'] = mailbox_password_expiration_is_never( diff --git a/scripts/postfixadmin-cli.php b/scripts/postfixadmin-cli.php index 3c26a830..a41efb05 100644 --- a/scripts/postfixadmin-cli.php +++ b/scripts/postfixadmin-cli.php @@ -386,6 +386,7 @@ class PostfixAdmin $this->stdout(" delete Delete an item"); $this->stdout(" scheme Print database scheme (useful for developers only)"); $this->stdout(" help Print help output"); + $this->stdout(" resetmfa Reset MFA (admin and mailbox modules only)"); $this->stdout(""); $this->stdout(""); $this->stdout("For module-specific help, see:"); diff --git a/templates/list-virtual_mailbox.tpl b/templates/list-virtual_mailbox.tpl index b97a2e1f..37a8e06c 100644 --- a/templates/list-virtual_mailbox.tpl +++ b/templates/list-virtual_mailbox.tpl @@ -33,6 +33,7 @@ {$PALANG.password} {/if} {$PALANG.active} + {if $show_mailbox_mfa|default:false}{$PALANG.mfa}{/if} {if $CONF.smtp_active_flag===YES} {$PALANG.smtp_active}{/if} {assign var="colspan" value="`$colspan-6`"} @@ -123,6 +124,7 @@ {else} {/if} + {if $show_mailbox_mfa|default:false}{if $item.mfa}{$PALANG.YES}{else}{$PALANG.NO}{/if}{/if} {if $CONF.smtp_active_flag===YES} {$item.target_domain} {* do we need escape:url or escpae:quotes here? see #705 *} {elseif $table == 'domain' && $key == 'domain'} - {$linktext} {if $item.full_mailbox_count > 0}({$item.full_mailbox_count}){/if} + {$linktext} {if isset($item.mfa) && $item.mfa}{$PALANG.mfa}{/if} + {if $item.full_mailbox_count > 0}({$item.full_mailbox_count}){/if} {if $dns_check_mode > 0 && isset($item.dns_active) && $item.dns_active == 0}{/if} {* {elseif $table == 'domain' && $key == 'domain'} {$item.domain} *} + {elseif $key == 'mfa'} + {if $item.mfa}{$PALANG.YES}{else}{$PALANG.NO}{/if} {elseif $key == 'active'} {if $item._can_edit} 'mailboxname', 'edit' => self::USERNAME, 'CSRF_Token' => $token[1], 'reset_totp' => '1', 'value' => ['name' => 'Changed