Files
postfixadmin/model/CliResetmfa.php
T
Rodrigo Cortés Cano 1eaaecfcbc 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
2026-11-18 13:22:21 +00:00

42 lines
1.3 KiB
PHP

<?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.');
}
}