mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-17 10:34:31 +08:00
DirectAdmin change password plugin
This commit is contained in:
parent
9d26fe049e
commit
6cfd002055
6 changed files with 222 additions and 1 deletions
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
class DirectAdminChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sHost = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $iPort = 2222;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sAllowedEmails = '';
|
||||
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
private $oLogger = null;
|
||||
|
||||
/**
|
||||
* @param string $sHost
|
||||
* @param int $iPort
|
||||
*
|
||||
* @return \DirectAdminChangePasswordDriver
|
||||
*/
|
||||
public function SetConfig($sHost, $iPort)
|
||||
{
|
||||
$this->sHost = $sHost;
|
||||
$this->iPort = $iPort;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAllowedEmails
|
||||
*
|
||||
* @return \DirectAdminChangePasswordDriver
|
||||
*/
|
||||
public function SetAllowedEmails($sAllowedEmails)
|
||||
{
|
||||
$this->sAllowedEmails = $sAllowedEmails;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Log\Logger $oLogger
|
||||
*
|
||||
* @return \DirectAdminChangePasswordDriver
|
||||
*/
|
||||
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->Email() &&
|
||||
\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->sAllowedEmails);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Account $oAccount
|
||||
* @param string $sPrevPassword
|
||||
* @param string $sNewPassword
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('DirectAdmin: Try to change password for '.$oAccount->Email());
|
||||
}
|
||||
|
||||
$bResult = false;
|
||||
if (!empty($this->sHost) && 0 < $this->iPort && $oAccount)
|
||||
{
|
||||
$sEmail = \trim(\strtolower($oAccount->Email()));
|
||||
|
||||
$sHost = \trim($this->sHost);
|
||||
$sHost = \str_replace('{user:host-imap}', $oAccount->Domain()->IncHost(), $sHost);
|
||||
$sHost = \str_replace('{user:host-smtp}', $oAccount->Domain()->OutHost(), $sHost);
|
||||
$sHost = \str_replace('{user:domain}', \MailSo\Base\Utils::GetDomainFromEmail($sEmail), $sHost);
|
||||
$sHost = \rtrim($this->sHost, '/\\');
|
||||
|
||||
if (!\preg_match('/^http[s]?:\/\//i', $sHost))
|
||||
{
|
||||
$sHost = 'http://'.$sHost;
|
||||
}
|
||||
|
||||
$sUrl = $sHost.':'.$this->iPort.'/CMD_CHANGE_EMAIL_PASSWORD';
|
||||
|
||||
$iCode = 0;
|
||||
$oHttp = \MailSo\Base\Http::SingletonInstance();
|
||||
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('DirectAdmin[Api Request]:'.$sUrl);
|
||||
}
|
||||
|
||||
$mResult = $oHttp->SendPostRequest($sUrl,
|
||||
array(
|
||||
'email' => $sEmail,
|
||||
'oldpassword' => $sPrevPassword,
|
||||
'password1' => $sNewPassword,
|
||||
'password2' => $sNewPassword,
|
||||
'api' => '1'
|
||||
), 'MailSo Http User Agent (v1)', $iCode, $this->oLogger);
|
||||
|
||||
if (false !== $mResult && 200 === $iCode)
|
||||
{
|
||||
$aRes = @\parse_str($mResult);
|
||||
if (is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1))
|
||||
{
|
||||
$bResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('DirectAdmin[Error]: Response: '.$mResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
}
|
20
plugins/directadmin-change-password/LICENSE
Normal file
20
plugins/directadmin-change-password/LICENSE
Normal file
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 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/directadmin-change-password/README
Normal file
1
plugins/directadmin-change-password/README
Normal file
|
@ -0,0 +1 @@
|
|||
Plugin that adds functionality to change the email account password (DirectAdmin).
|
1
plugins/directadmin-change-password/VERSION
Normal file
1
plugins/directadmin-change-password/VERSION
Normal file
|
@ -0,0 +1 @@
|
|||
1.0
|
55
plugins/directadmin-change-password/index.php
Normal file
55
plugins/directadmin-change-password/index.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
class DirectadminChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
public function Init()
|
||||
{
|
||||
$this->addHook('main.fabrica', 'MainFabrica');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param mixed $oProvider
|
||||
*/
|
||||
public function MainFabrica($sName, &$oProvider)
|
||||
{
|
||||
switch ($sName)
|
||||
{
|
||||
case 'change-password':
|
||||
|
||||
$sHost = \trim($this->Config()->Get('plugin', 'direct_admin_host', ''));
|
||||
$iPort = (int) $this->Config()->Get('plugin', 'direct_admin_port', 2222);
|
||||
|
||||
if (!empty($sHost) && 0 < $iPort)
|
||||
{
|
||||
include_once __DIR__.'/DirectAdminChangePasswordDriver.php';
|
||||
|
||||
$oProvider = new DirectAdminChangePasswordDriver();
|
||||
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
|
||||
$oProvider->SetConfig($sHost, $iPort);
|
||||
$oProvider->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function configMapping()
|
||||
{
|
||||
return array(
|
||||
\RainLoop\Plugins\Property::NewInstance('direct_admin_host')->SetLabel('DirectAdmin Host')
|
||||
->SetDefaultValue('')
|
||||
->SetDescription('Allowed patterns: {user:host-imap}, {user:host-smpt}, {user:domain}'),
|
||||
\RainLoop\Plugins\Property::NewInstance('direct_admin_port')->SetLabel('DirectAdmin Port')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
|
||||
->SetDefaultValue(2222),
|
||||
\RainLoop\Plugins\Property::NewInstance('allowed_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('*')
|
||||
);
|
||||
}
|
||||
}
|
|
@ -84,7 +84,7 @@
|
|||
White List
|
||||
</div>
|
||||
<div class="alert alert-block span6 alert-null-left-margin" style="width: 562px;">
|
||||
List of users webmail is allowed to access.
|
||||
List of domain users webmail is allowed to access.
|
||||
Use a space as delimiter.
|
||||
</div>
|
||||
<textarea class="input-xxlarge" style="width: 600px" rows="8" data-bind="value: whiteList" tabindex="-1"></textarea>
|
||||
|
|
Loading…
Add table
Reference in a new issue