mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
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 <address> and postfixadmin-cli mailbox resetmfa <address> ) thanks @TrapoSAMA
This commit is contained in:
1 parent
f3ffeae493
commit
1eaaecfcbc
53 files changed
+343
-4
No files matched your search
+2
-2
@@ -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).
|
||||
|
||||
@@ -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.
|
||||
Vendored
+9
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,6 +14,8 @@ $PALANG['search_mailboxes_aliases'] = 'Search mailboxes and aliases...';
|
||||
//
|
||||
|
||||
|
||||
$PALANG['mfa'] = 'MFA';
|
||||
|
||||
$PALANG['YES'] = 'YES';
|
||||
$PALANG['NO'] = 'NO';
|
||||
$PALANG['edit'] = 'edit';
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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', '' , ''),
|
||||
|
||||
@@ -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 <address> Reset MFA for an existing account.\n");
|
||||
}
|
||||
|
||||
foreach ($commands as $cmd) {
|
||||
$this->out("{$cmd}\n\n");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/** Reset MFA for an existing administrator or mailbox from the local CLI. */
|
||||
class CliResetmfa extends Shell
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
if (!in_array($this->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 <admin|mailbox> resetmfa <address>');
|
||||
$this->out('Remove the MFA secret from an existing account, even when web reset is disabled.');
|
||||
}
|
||||
}
|
||||
@@ -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' , ''),
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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:");
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<th class="text-center text-nowrap">{$PALANG.password}</th>
|
||||
{/if}
|
||||
<th>{$PALANG.active}</th>
|
||||
{if $show_mailbox_mfa|default:false}<th>{$PALANG.mfa}</th>{/if}
|
||||
{if $CONF.smtp_active_flag===YES}
|
||||
<th>{$PALANG.smtp_active}</th>{/if}
|
||||
{assign var="colspan" value="`$colspan-6`"}
|
||||
@@ -123,6 +124,7 @@
|
||||
{else}
|
||||
<span class="bi bi-square" aria-hidden="true"></span>
|
||||
{/if}</a></td>
|
||||
{if $show_mailbox_mfa|default:false}<td>{if $item.mfa}{$PALANG.YES}{else}{$PALANG.NO}{/if}</td>{/if}
|
||||
{if $CONF.smtp_active_flag===YES}
|
||||
<td><a class="btn btn-sm btn-{if ($item.smtp_active==0)}info{else}warning{/if} list-action-icon" title="{$PALANG.smtp_active}: {if $item.smtp_active==1}{$PALANG.YES}{else}{$PALANG.NO}{/if}" aria-label="{$PALANG.smtp_active}: {if $item.smtp_active==1}{$PALANG.YES}{else}{$PALANG.NO}{/if}"
|
||||
href="{#url_editactive#}mailbox&id={$item.username|escape:"url"}&active={if ($item.smtp_active==0)}1{else}0{/if}&field=smtp_active&token={CSRF_Token type="url"}"
|
||||
|
||||
+4
-1
@@ -129,11 +129,14 @@
|
||||
<a href="list-virtual.php?domain={$item.target_domain|escape:"quotes"}">{$item.target_domain}</a>
|
||||
{* do we need escape:url or escpae:quotes here? see #705 *}
|
||||
{elseif $table == 'domain' && $key == 'domain'}
|
||||
{$linktext} {if $item.full_mailbox_count > 0}<span class="text-danger">({$item.full_mailbox_count})</span>{/if}
|
||||
{$linktext} {if isset($item.mfa) && $item.mfa}<span class="badge text-bg-success">{$PALANG.mfa}</span>{/if}
|
||||
{if $item.full_mailbox_count > 0}<span class="text-danger">({$item.full_mailbox_count})</span>{/if}
|
||||
{if $dns_check_mode > 0 && isset($item.dns_active) && $item.dns_active == 0}<span class="bi bi-exclamation-triangle text-danger" role="img" aria-label="Inactive DNS" title="Inactive DNS"></span>{/if}
|
||||
{* {elseif $table == 'domain' && $key == 'domain'}
|
||||
<a href="list.php?table=domain&domain={$item.domain|escape:"url"}">{$item.domain}</a>
|
||||
*}
|
||||
{elseif $key == 'mfa'}
|
||||
{if $item.mfa}{$PALANG.YES}{else}{$PALANG.NO}{/if}
|
||||
{elseif $key == 'active'}
|
||||
{if $item._can_edit}
|
||||
<a class="btn btn-sm btn-{if ($item.active==0)}info{else}warning{/if} list-action-icon" title="{$field.label}: {$item._active}" aria-label="{$field.label}: {$item._active}"
|
||||
|
||||
@@ -88,6 +88,15 @@ class MailboxnameHttpTest extends TestCase
|
||||
'table' => 'mailboxname', 'edit' => self::USERNAME, 'CSRF_Token' => $token[1],
|
||||
'reset_totp' => '1', 'value' => ['name' => 'Changed <script data-name-fixture>', 'active' => 0],
|
||||
]);
|
||||
self::assertSame(403, $status);
|
||||
self::assertSame('<b>Original</b>', db_query_one('SELECT name FROM ' . table_by_key('mailbox') . ' WHERE username = ?', [self::USERNAME])['name']);
|
||||
[$status, $html] = $this->request('/edit.php?table=mailboxname&edit=' . urlencode(self::USERNAME));
|
||||
self::assertSame(200, $status, $html);
|
||||
self::assertSame(1, preg_match('/name=[\'"]CSRF_Token[\'"] value=[\'"]([^\'"]+)/', $html, $token));
|
||||
[$status] = $this->request('/edit.php', [
|
||||
'table' => 'mailboxname', 'edit' => self::USERNAME, 'CSRF_Token' => $token[1],
|
||||
'value' => ['name' => 'Changed <script data-name-fixture>', 'active' => 0],
|
||||
]);
|
||||
self::assertSame(302, $status);
|
||||
$mailbox = db_query_one('SELECT name, active FROM ' . table_by_key('mailbox') . ' WHERE username = ?', [self::USERNAME]);
|
||||
self::assertSame('Changed <script data-name-fixture>', $mailbox['name']);
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
class MfaStatusTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private array $savedConfig;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->savedConfig = Config::getInstance()->getAll();
|
||||
Config::write('totp', 'YES');
|
||||
foreach (['mfa-visible.example', 'mfa-hidden.example', 'mfa-empty.example'] as $domain) {
|
||||
db_insert('domain', ['domain' => $domain, 'description' => '', 'transport' => 'virtual']);
|
||||
}
|
||||
db_insert('domain_admins', ['username' => 'mfa-owner', 'domain' => 'mfa-visible.example', 'active' => true], ['created'], true);
|
||||
db_insert('domain_admins', ['username' => 'mfa-owner', 'domain' => 'mfa-empty.example', 'active' => true], ['created'], true);
|
||||
foreach (['yes' => 'test-secret', 'empty' => '', 'none' => null] as $name => $secret) {
|
||||
db_insert('admin', ['username' => $name . '@mfa-visible.example', 'password' => 'unused', 'totp_secret' => $secret, 'active' => false]);
|
||||
db_insert('mailbox', ['username' => $name . '@mfa-visible.example', 'local_part' => $name,
|
||||
'domain' => 'mfa-visible.example', 'password' => 'unused', 'name' => '', 'maildir' => '',
|
||||
'totp_secret' => $secret, 'active' => false]);
|
||||
}
|
||||
db_insert('mailbox', ['username' => 'yes@mfa-hidden.example', 'local_part' => 'yes',
|
||||
'domain' => 'mfa-hidden.example', 'password' => 'unused', 'name' => '', 'maildir' => '', 'totp_secret' => 'hidden-secret']);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
foreach (['mfa-visible.example', 'mfa-hidden.example', 'mfa-empty.example'] as $domain) {
|
||||
db_delete('mailbox', 'domain', $domain);
|
||||
db_delete('domain_admins', 'domain', $domain);
|
||||
db_delete('domain', 'domain', $domain);
|
||||
}
|
||||
foreach (['yes', 'empty', 'none'] as $name) {
|
||||
db_delete('admin', 'username', $name . '@mfa-visible.example');
|
||||
}
|
||||
foreach ($this->savedConfig as $key => $value) {
|
||||
Config::write($key, $value);
|
||||
}
|
||||
unset($_SESSION['sessid']);
|
||||
}
|
||||
|
||||
public function testAdministratorStatusIncludesInactiveAccountsWithoutExposingSecrets(): void
|
||||
{
|
||||
$handler = new AdminHandler();
|
||||
self::assertTrue($handler->getList(''));
|
||||
$rows = array_column($handler->result(), null, 'username');
|
||||
self::assertSame(1, (int)$rows['yes@mfa-visible.example']['mfa']);
|
||||
self::assertSame(0, (int)$rows['empty@mfa-visible.example']['mfa']);
|
||||
self::assertSame(0, (int)$rows['none@mfa-visible.example']['mfa']);
|
||||
self::assertArrayNotHasKey('totp_secret', $rows['yes@mfa-visible.example']);
|
||||
$keys = array_keys($handler->getStruct());
|
||||
self::assertSame(array_search('active', $keys) + 1, array_search('mfa', $keys));
|
||||
}
|
||||
|
||||
public function testDomainIndicatorRespectsAdministratorScope(): void
|
||||
{
|
||||
$_SESSION['sessid']['roles'] = ['admin'];
|
||||
$handler = new DomainHandler(0, 'mfa-owner');
|
||||
self::assertTrue($handler->getList(''));
|
||||
$rows = array_column($handler->result(), null, 'domain');
|
||||
self::assertSame(1, (int)$rows['mfa-visible.example']['mfa']);
|
||||
self::assertSame(0, (int)$rows['mfa-empty.example']['mfa']);
|
||||
self::assertArrayNotHasKey('mfa-hidden.example', $rows);
|
||||
}
|
||||
|
||||
public function testResetActionRetainsExistingBehavior(): void
|
||||
{
|
||||
foreach ([AdminHandler::class, MailboxHandler::class] as $class) {
|
||||
self::assertArrayHasKey('totp_action', (new $class())->getStruct());
|
||||
db_update($class === AdminHandler::class ? 'admin' : 'mailbox', 'username', 'yes@mfa-visible.example', ['active' => true]);
|
||||
$handler = new $class();
|
||||
self::assertTrue($handler->init('yes@mfa-visible.example'));
|
||||
self::assertStringContainsString('name="reset_totp"', $handler->result()['totp_action']);
|
||||
self::assertArrayNotHasKey('totp_action', (new $class(1))->getStruct());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCliResetWorksWithTotpDisabled(): void
|
||||
{
|
||||
Config::write('totp', 'NO');
|
||||
foreach ([AdminHandler::class => 'admin', MailboxHandler::class => 'mailbox'] as $class => $table) {
|
||||
$dispatch = (object)['params' => [], 'args' => ['YES@mfa-visible.example'], 'shell' => $table, 'shellCommand' => 'resetmfa'];
|
||||
$shell = new class ($dispatch) extends CliResetmfa {
|
||||
public function out($string, $newline = true)
|
||||
{
|
||||
}
|
||||
public function err($string)
|
||||
{
|
||||
}
|
||||
};
|
||||
$shell->handler_to_use = $class;
|
||||
self::assertSame(0, $shell->execute());
|
||||
self::assertNull(db_query_one('SELECT totp_secret FROM ' . table_by_key($table) . ' WHERE username = :username', ['username' => 'yes@mfa-visible.example'])['totp_secret']);
|
||||
self::assertSame(0, $shell->execute());
|
||||
$dispatch->args = ['missing@mfa-visible.example'];
|
||||
self::assertSame(1, $shell->execute());
|
||||
$dispatch->args = [];
|
||||
self::assertSame(1, $shell->execute());
|
||||
$dispatch->args = ['none@mfa-visible.example', 'yes@mfa-visible.example'];
|
||||
self::assertSame(1, $shell->execute());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class TotpManagementHttpTest extends TestCase
|
||||
self::assertTrue(mkdir($this->directory));
|
||||
$config = Config::getInstance()->getAll();
|
||||
$config['totp'] = 'YES';
|
||||
$config['page_size'] = 2;
|
||||
$config['default_language'] = 'en';
|
||||
$config['language_hook'] = '';
|
||||
$config['mailbox_post_TOTP_change_secret_script'] = '';
|
||||
@@ -69,6 +70,9 @@ class TotpManagementHttpTest extends TestCase
|
||||
foreach (['admin', 'mailbox'] as $table) {
|
||||
db_execute('DELETE FROM ' . table_by_key($table) . ' WHERE username = :username', ['username' => self::USERNAME]);
|
||||
}
|
||||
db_delete('domain_admins', 'domain', self::DOMAIN);
|
||||
db_delete('mailbox', 'username', 'plain@' . self::DOMAIN);
|
||||
db_delete('mailbox', 'username', 'zz@' . self::DOMAIN);
|
||||
db_execute('DELETE FROM ' . table_by_key('domain') . ' WHERE domain = :domain', ['domain' => self::DOMAIN]);
|
||||
if (isset($this->directory) && is_dir($this->directory)) {
|
||||
foreach (new DirectoryIterator($this->directory) as $file) {
|
||||
@@ -132,6 +136,74 @@ class TotpManagementHttpTest extends TestCase
|
||||
self::assertSame($newSecret, $this->storedSecret($table));
|
||||
}
|
||||
|
||||
#[DataProvider('accountTypes')]
|
||||
public function testAdministrativeWebResetRetainsPermissionsAndCsrf(string $table, string $role): void
|
||||
{
|
||||
db_update($table, 'username', self::USERNAME, ['totp_secret' => self::SECRET]);
|
||||
db_insert('domain_admins', ['username' => self::USERNAME, 'domain' => self::DOMAIN, 'active' => true], ['created'], true);
|
||||
$token = $this->startSession('global-admin');
|
||||
$path = '/edit.php?table=' . $table . '&edit=' . urlencode(self::USERNAME);
|
||||
[$status, $body] = $this->request($path);
|
||||
self::assertSame(200, $status, $body);
|
||||
self::assertStringContainsString('name="reset_totp"', $body);
|
||||
[$status] = $this->request($path, ['CSRF_Token' => 'invalid', 'reset_totp' => '1']);
|
||||
self::assertSame(419, $status);
|
||||
self::assertSame(self::SECRET, $this->storedSecret($table));
|
||||
|
||||
$token = $this->startSession('admin');
|
||||
[$status] = $this->request($path, ['CSRF_Token' => $token, 'reset_totp' => '1']);
|
||||
if ($table === 'admin') {
|
||||
self::assertSame(302, $status);
|
||||
self::assertSame(self::SECRET, $this->storedSecret($table));
|
||||
$token = $this->startSession('global-admin');
|
||||
[$status] = $this->request($path, ['CSRF_Token' => $token, 'reset_totp' => '1']);
|
||||
}
|
||||
self::assertSame(302, $status);
|
||||
self::assertNull($this->storedSecret($table));
|
||||
}
|
||||
|
||||
public function testDomainAdminCannotResetAnUnmanagedMailbox(): void
|
||||
{
|
||||
db_update('mailbox', 'username', self::USERNAME, ['totp_secret' => self::SECRET]);
|
||||
$token = $this->startSession('admin');
|
||||
[$status] = $this->request('/edit.php?table=mailbox&edit=' . urlencode(self::USERNAME), ['CSRF_Token' => $token, 'reset_totp' => '1']);
|
||||
self::assertSame(302, $status);
|
||||
self::assertSame(self::SECRET, $this->storedSecret('mailbox'));
|
||||
}
|
||||
|
||||
public function testMailboxMfaVisibilityUsesTheCompleteAuthorizedSearchResult(): void
|
||||
{
|
||||
db_insert('domain_admins', ['username' => self::USERNAME, 'domain' => self::DOMAIN, 'active' => true], ['created'], true);
|
||||
foreach (['plain' => null, 'zz' => self::SECRET] as $name => $secret) {
|
||||
db_insert('mailbox', ['username' => $name . '@' . self::DOMAIN, 'password' => 'unused',
|
||||
'name' => $name, 'maildir' => '', 'local_part' => $name, 'domain' => self::DOMAIN,
|
||||
'active' => true, 'totp_secret' => $secret], ['created', 'modified'], true);
|
||||
}
|
||||
$this->startSession('admin');
|
||||
$path = '/list-virtual.php?domain=' . self::DOMAIN;
|
||||
[$status, $body] = $this->request($path . '&limit=0');
|
||||
self::assertSame(200, $status, $body);
|
||||
self::assertStringContainsString('<th>MFA</th>', $body);
|
||||
self::assertStringNotContainsString('<td>Yes</td>', $body);
|
||||
self::assertStringNotContainsString(self::SECRET, $body);
|
||||
[$status, $body] = $this->request($path . '&limit=2');
|
||||
self::assertSame(200, $status, $body);
|
||||
self::assertStringContainsString('<td>YES</td>', $body);
|
||||
[$status, $body] = $this->request($path . '&limit=0&search%5B_%5D=plain');
|
||||
self::assertSame(200, $status, $body);
|
||||
self::assertStringNotContainsString('<th>MFA</th>', $body);
|
||||
[$status, $body] = $this->request('/list.php?table=domain');
|
||||
self::assertSame(200, $status, $body);
|
||||
self::assertStringContainsString('badge text-bg-success">MFA</span>', $body);
|
||||
db_update('mailbox', 'username', 'zz@' . self::DOMAIN, ['totp_secret' => null]);
|
||||
[$status, $body] = $this->request($path . '&limit=0');
|
||||
self::assertSame(200, $status, $body);
|
||||
self::assertStringNotContainsString('<th>MFA</th>', $body);
|
||||
[$status, $body] = $this->request('/list.php?table=domain');
|
||||
self::assertSame(200, $status, $body);
|
||||
self::assertStringNotContainsString('badge text-bg-success">MFA</span>', $body);
|
||||
}
|
||||
|
||||
private function currentCode(string $secret): string
|
||||
{
|
||||
if (time() % 30 === 29) {
|
||||
|
||||
Vendored
+7
-1
@@ -11,12 +11,18 @@ $CONF = array_replace($CONF, json_decode(file_get_contents(getenv('PFA_TOTP_TEST
|
||||
require dirname(__DIR__, 2) . '/public/common.php';
|
||||
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
if ($path === '/__session') {
|
||||
init_session('test@totp-http.example.com', ($_GET['role'] ?? '') === 'admin', true);
|
||||
init_session('test@totp-http.example.com', in_array($_GET['role'] ?? '', ['admin', 'global-admin'], true), true);
|
||||
if (($_GET['role'] ?? '') === 'global-admin') {
|
||||
$_SESSION['sessid']['roles'][] = 'global-admin';
|
||||
}
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['token' => CsrfToken::generate()]);
|
||||
} elseif ($path === '/users/totp.php') {
|
||||
chdir(dirname(__DIR__, 2) . '/public/users');
|
||||
require 'totp.php';
|
||||
} elseif (in_array($path, ['/edit.php', '/list.php', '/list-virtual.php'], true)) {
|
||||
chdir(dirname(__DIR__, 2) . '/public');
|
||||
require basename($path);
|
||||
} else {
|
||||
http_response_code(404);
|
||||
}
|
||||
Reference in new issue
Block a user