mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 15:45:55 +08:00
Vesta Control Panel Support
This commit is contained in:
parent
0ea982671b
commit
b3023a4e4f
20
plugins/vesta-change-password/LICENSE
Normal file
20
plugins/vesta-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/vesta-change-password/README
Normal file
1
plugins/vesta-change-password/README
Normal file
|
@ -0,0 +1 @@
|
|||
Plugin that adds functionality to change the email account password (Vesta Control Panel).
|
1
plugins/vesta-change-password/VERSION
Normal file
1
plugins/vesta-change-password/VERSION
Normal file
|
@ -0,0 +1 @@
|
|||
1.0
|
146
plugins/vesta-change-password/VestaChangePasswordDriver.php
Normal file
146
plugins/vesta-change-password/VestaChangePasswordDriver.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
|
||||
class VestaChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sHost = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $iPort = 8083;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sAllowedEmails = '';
|
||||
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
private $oLogger = null;
|
||||
|
||||
/**
|
||||
* @param string $sHost
|
||||
* @param int $iPort
|
||||
*
|
||||
* @return \VestaChangePasswordDriver
|
||||
*/
|
||||
public function SetConfig($sHost, $iPort)
|
||||
{
|
||||
$this->sHost = $sHost;
|
||||
$this->iPort = $iPort;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sAllowedEmails
|
||||
*
|
||||
* @return \VestaChangePasswordDriver
|
||||
*/
|
||||
public function SetAllowedEmails($sAllowedEmails)
|
||||
{
|
||||
$this->sAllowedEmails = $sAllowedEmails;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Log\Logger $oLogger
|
||||
*
|
||||
* @return \VestaChangePasswordDriver
|
||||
*/
|
||||
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('Vesta: 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, '/\\');
|
||||
$sHost = 'https://'.$sHost;
|
||||
|
||||
$sUrl = $sHost.':'.$this->iPort.'/reset/mail/';
|
||||
|
||||
$iCode = 0;
|
||||
$oHttp = \MailSo\Base\Http::SingletonInstance();
|
||||
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Vesta[Api Request]:'.$sUrl);
|
||||
}
|
||||
|
||||
$mResult = $oHttp->SendPostRequest($sUrl,
|
||||
array(
|
||||
'email' => $sEmail,
|
||||
'password' => $sPrevPassword,
|
||||
'new' => $sNewPassword,
|
||||
), 'MailSo Http User Agent (v1)', $iCode, $this->oLogger);
|
||||
|
||||
if (false !== $mResult && 200 === $iCode)
|
||||
{
|
||||
$aRes = null;
|
||||
@\parse_str($mResult, $aRes);
|
||||
if (is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1))
|
||||
{
|
||||
$bResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Vesta[Error]: Response: '.$mResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->Write('Vesta[Error]: Empty Response: Code:'.$iCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
}
|
55
plugins/vesta-change-password/index.php
Normal file
55
plugins/vesta-change-password/index.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
class VestaChangePasswordPlugin 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', 'vesta_host', ''));
|
||||
$iPort = (int) $this->Config()->Get('plugin', 'vesta_port', 8083);
|
||||
|
||||
if (!empty($sHost) && 0 < $iPort)
|
||||
{
|
||||
include_once __DIR__.'/VestaChangePasswordDriver.php';
|
||||
|
||||
$oProvider = new VestaChangePasswordDriver();
|
||||
$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('vesta_host')->SetLabel('Vesta Host')
|
||||
->SetDefaultValue('')
|
||||
->SetDescription('Allowed patterns: {user:host-imap}, {user:host-smtp}, {user:domain}'),
|
||||
\RainLoop\Plugins\Property::NewInstance('Vesta_port')->SetLabel('Vesta Port')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
|
||||
->SetDefaultValue(8083),
|
||||
\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('*')
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue