mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-27 18:18:28 +08:00
added hmailserver-change-password Plugin
This commit is contained in:
parent
53029a4e7d
commit
35240ecff0
5 changed files with 243 additions and 0 deletions
|
@ -72,6 +72,11 @@
|
||||||
<param name="plugin-name" value="poppassd-change-password"/>
|
<param name="plugin-name" value="poppassd-change-password"/>
|
||||||
</antcall>
|
</antcall>
|
||||||
</target>
|
</target>
|
||||||
|
<target name="hmailserver-change-password">
|
||||||
|
<antcall target="_build_plugin_">
|
||||||
|
<param name="plugin-name" value="hmailserver-change-password"/>
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
<target name="snowfall-on-login-screen">
|
<target name="snowfall-on-login-screen">
|
||||||
<antcall target="_build_plugin_">
|
<antcall target="_build_plugin_">
|
||||||
<param name="plugin-name" value="snowfall-on-login-screen"/>
|
<param name="plugin-name" value="snowfall-on-login-screen"/>
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class HmailserverChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $sLogin = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $sPassword = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $aDomains = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \MailSo\Log\Logger
|
||||||
|
*/
|
||||||
|
private $oLogger = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sLogin
|
||||||
|
* @param string $sPassword
|
||||||
|
*
|
||||||
|
* @return \CpanleChangePasswordDriver
|
||||||
|
*/
|
||||||
|
public function SetConfig($sLogin, $sPassword)
|
||||||
|
{
|
||||||
|
$this->sLogin = $sLogin;
|
||||||
|
$this->sPassword = $sPassword;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $aDomains
|
||||||
|
*
|
||||||
|
* @return \CpanleChangePasswordDriver
|
||||||
|
*/
|
||||||
|
public function SetAllowedDomains($aDomains)
|
||||||
|
{
|
||||||
|
if (\is_array($aDomains) && 0 < \count($aDomains))
|
||||||
|
{
|
||||||
|
$this->aDomains = $aDomains;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \MailSo\Log\Logger $oLogger
|
||||||
|
*
|
||||||
|
* @return \CpanleChangePasswordDriver
|
||||||
|
*/
|
||||||
|
public function SetLogger($oLogger)
|
||||||
|
{
|
||||||
|
if ($oLogger instanceof \MailSo\Log\Logger)
|
||||||
|
{
|
||||||
|
$this->oLogger = $oLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function PasswordChangePossibility($oAccount)
|
||||||
|
{
|
||||||
|
return $oAccount && $oAccount->Domain() &&
|
||||||
|
\in_array(\strtolower($oAccount->Domain()->Name()), $this->aDomains);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oHmailAccount
|
||||||
|
* @param string $sPrevPassword
|
||||||
|
* @param string $sNewPassword
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function ChangePassword(\RainLoop\Account $oHmailAccount, $sPrevPassword, $sNewPassword)
|
||||||
|
{
|
||||||
|
if ($this->oLogger)
|
||||||
|
{
|
||||||
|
$this->oLogger->Write('Try to change password for '.$oHmailAccount->Email());
|
||||||
|
}
|
||||||
|
|
||||||
|
$bResult = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$oHmailApp = new COM("hMailServer.Application");
|
||||||
|
$oHmailApp->Connect();
|
||||||
|
|
||||||
|
if ($this->oBaseApp->Authenticate($this->sLogin, $this->sPassword))
|
||||||
|
{
|
||||||
|
$sEmail = $oHmailAccount->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->Write('HMAILSERVER: Unknown account ('.$sEmail.')', \MailSo\Log\Enumerations\Type::ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->oLogger->Write('HMAILSERVER: Unknown domain ('.$sDomain.')', \MailSo\Log\Enumerations\Type::ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->oLogger->Write('HMAILSERVER: Auth error', \MailSo\Log\Enumerations\Type::ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\Exception $oException)
|
||||||
|
{
|
||||||
|
if ($this->oLogger)
|
||||||
|
{
|
||||||
|
$this->oLogger->WriteException($oException);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bResult;
|
||||||
|
}
|
||||||
|
}
|
20
plugins/hmailserver-change-password/LICENSE
Normal file
20
plugins/hmailserver-change-password/LICENSE
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 RainLoop Team
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
plugins/hmailserver-change-password/VERSION
Normal file
1
plugins/hmailserver-change-password/VERSION
Normal file
|
@ -0,0 +1 @@
|
||||||
|
1.0
|
75
plugins/hmailserver-change-password/index.php
Normal file
75
plugins/hmailserver-change-password/index.php
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class HmailserverChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
{
|
||||||
|
public function Init()
|
||||||
|
{
|
||||||
|
$this->addHook('main.fabrica', 'MainFabrica');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function Supported()
|
||||||
|
{
|
||||||
|
if (!class_exists('COM'))
|
||||||
|
{
|
||||||
|
return 'The PHP exention COM must be installed to use this plugin';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sName
|
||||||
|
* @param mixed $oProvider
|
||||||
|
*/
|
||||||
|
public function MainFabrica($sName, &$oProvider)
|
||||||
|
{
|
||||||
|
switch ($sName)
|
||||||
|
{
|
||||||
|
case 'change-password':
|
||||||
|
|
||||||
|
$sLogin = (string) $this->Config()->Get('plugin', 'login', '');
|
||||||
|
$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
|
||||||
|
|
||||||
|
if (0 < \strlen($sLogin) && 0 < \strlen($sPassword))
|
||||||
|
{
|
||||||
|
include_once __DIR__.'/HmailserverChangePasswordDriver.php';
|
||||||
|
|
||||||
|
$oProvider = new HmailserverChangePasswordDriver();
|
||||||
|
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
|
||||||
|
$oProvider->SetConfig($sLogin, $sPassword);
|
||||||
|
|
||||||
|
$sDomains = \strtolower(\trim(\preg_replace('/[\s;,]+/', ' ',
|
||||||
|
$this->Config()->Get('plugin', 'domains', ''))));
|
||||||
|
|
||||||
|
if (0 < \strlen($sDomains))
|
||||||
|
{
|
||||||
|
$aDomains = \explode(' ', $sDomains);
|
||||||
|
$oProvider->SetAllowedDomains($aDomains);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function configMapping()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('login')->SetLabel('HmailServer Admin Login')
|
||||||
|
->SetDefaultValue('Administrator'),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('HmailServer Admin Password')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD)
|
||||||
|
->SetDefaultValue(''),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('domains')->SetLabel('Allowed Domains')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||||
|
->SetDescription('Allowed domains, space as delimiter')
|
||||||
|
->SetDefaultValue('domain1.com domain2.com')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue