mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-22 22:04:43 +08:00
Added hMailServer change password for #551
This commit is contained in:
parent
0910b8f27d
commit
258afdd26e
2 changed files with 104 additions and 0 deletions
85
plugins/change-password-hmailserver/driver.php
Normal file
85
plugins/change-password-hmailserver/driver.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
use MailSo\Net\ConnectSettings;
|
||||
|
||||
class ChangePasswordHMailServerDriver
|
||||
{
|
||||
const
|
||||
NAME = 'hMailServer',
|
||||
DESCRIPTION = 'Change passwords using hMailServer. The PHP extension COM must be installed to use this plugin';
|
||||
|
||||
private
|
||||
$oConfig = null;
|
||||
|
||||
function __construct(\RainLoop\Config\Plugin $oConfig, \MailSo\Log\Logger $oLogger)
|
||||
{
|
||||
$this->oConfig = $oConfig;
|
||||
$this->oLogger = $oLogger;
|
||||
}
|
||||
|
||||
public static function isSupported() : bool
|
||||
{
|
||||
return \class_exists('COM');
|
||||
}
|
||||
|
||||
public static function configMapping() : array
|
||||
{
|
||||
return array(
|
||||
\RainLoop\Plugins\Property::NewInstance('hmailserver_login')->SetLabel('Admin Login')
|
||||
->SetDefaultValue('Administrator'),
|
||||
\RainLoop\Plugins\Property::NewInstance('hmailserver_password')->SetLabel('Admin Password')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
|
||||
->SetDefaultValue(''),
|
||||
\RainLoop\Plugins\Property::NewInstance('hmailserver_emails')->SetLabel('Allowed emails')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||
->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net')
|
||||
->SetDefaultValue('*')
|
||||
);
|
||||
}
|
||||
|
||||
public function ChangePassword(\RainLoop\Model\Account $oAccount, string $sPrevPassword, string $sNewPassword) : bool
|
||||
{
|
||||
if (!\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->oConfig->Get('plugin', 'hmailserver_emails', ''))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Try to change password for '.$oAccount->Email());
|
||||
|
||||
$bResult = false;
|
||||
|
||||
try
|
||||
{
|
||||
$oHmailApp = new \COM('hMailServer.Application');
|
||||
$oHmailApp->Connect();
|
||||
|
||||
if ($oHmailApp->Authenticate(
|
||||
$this->oConfig->Get('plugin', 'hmailserver_login', ''),
|
||||
$this->oConfig->Get('plugin', 'hmailserver_password', '')
|
||||
)) {
|
||||
$sEmail = $oAccount->Email();
|
||||
$sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail);
|
||||
$oHmailDomain = $oHmailApp->Domains->ItemByName($sDomain);
|
||||
if ($oHmailDomain) {
|
||||
$oHmailAccount = $oHmailDomain->Accounts->ItemByAddress($sEmail);
|
||||
if ($oHmailAccount) {
|
||||
$oHmailAccount->Password = $sNewPassword;
|
||||
$oHmailAccount->Save();
|
||||
$bResult = true;
|
||||
} else {
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Unknown account ('.$sEmail.')', \MailSo\Log\Enumerations\Type::ERROR);
|
||||
}
|
||||
} else {
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Unknown domain ('.$sDomain.')', \MailSo\Log\Enumerations\Type::ERROR);
|
||||
}
|
||||
} else {
|
||||
$this->oLogger && $this->oLogger->Write('hMailServer: Auth error', \MailSo\Log\Enumerations\Type::ERROR);
|
||||
}
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
$this->oLogger && $this->oLogger->WriteException($oException);
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
}
|
19
plugins/change-password-hmailserver/index.php
Normal file
19
plugins/change-password-hmailserver/index.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
use \RainLoop\Exceptions\ClientException;
|
||||
|
||||
class ChangePasswordHMailServerPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Change Password hMailServer',
|
||||
VERSION = '2.0',
|
||||
RELEASE = '2022-10-14',
|
||||
REQUIRED = '2.15.3',
|
||||
CATEGORY = 'Security',
|
||||
DESCRIPTION = 'Extension to allow users to change their passwords through hMailServer';
|
||||
|
||||
public function Supported() : string
|
||||
{
|
||||
return 'Use Change Password plugin';
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue