Move plugins to webmail repository.

This commit is contained in:
RainLoop Team 2013-11-20 16:26:00 +04:00
parent 17958b15cb
commit cf0968b5a8
32 changed files with 4348 additions and 0 deletions

View file

@ -0,0 +1,159 @@
<?php
class CpanelChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var string
*/
private $sHost = '';
/**
* @var int
*/
private $iPost = 2087;
/**
* @var string
*/
private $sUser = '';
/**
* @var string
*/
private $sPassword = '';
/**
* @var array
*/
private $aDomains = array();
/**
* @var \MailSo\Log\Logger
*/
private $oLogger = null;
/**
* @param string $sHost
* @param int $iPost
* @param bool $sSsl
* @param string $sUser
* @param string $sPassword
*
* @return \CpanleChangePasswordDriver
*/
public function SetConfig($sHost, $iPost, $sSsl, $sUser, $sPassword)
{
$this->sHost = $sHost;
$this->iPost = $iPost;
$this->sSsl = $sSsl;
$this->sUser = $sUser;
$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 $oAccount
* @param string $sPrevPassword
* @param string $sNewPassword
*
* @return bool
*/
public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword)
{
if ($this->oLogger)
{
$this->oLogger->Write('Try to change password for '.$oAccount->Email());
}
include_once __DIR__.'/xmlapi.php';
$bResult = false;
if (!empty($this->sHost) && 0 < $this->iPost &&
0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) &&
$oAccount && \class_exists('xmlapi'))
{
try
{
$oXmlApi = new \xmlapi($this->sHost);
$oXmlApi->set_port($this->iPost);
$oXmlApi->set_protocol($this->sSsl ? 'https' : 'http');
$oXmlApi->set_debug(false);
$oXmlApi->set_output('json');
$oXmlApi->set_http_client('curl');
$oXmlApi->password_auth($this->sUser, $this->sPassword);
$sEmail = $oAccount->Email();
$aArgs = array(
'email' => \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail),
'domain' => \MailSo\Base\Utils::GetDomainFromEmail($sEmail),
'password' => $sNewPassword
);
$sResult = $oXmlApi->api2_query($this->sUser, 'Email', 'passwdpop', $aArgs);
if ($sResult)
{
$aResult = @\json_decode($sResult, true);
$bResult = isset($aResult['cpanelresult']['data'][0]['result']) &&
!!$aResult['cpanelresult']['data'][0]['result'];
}
if (!$bResult && $this->oLogger)
{
$this->oLogger->Write('CPANEL: '.$sResult, \MailSo\Log\Enumerations\Type::ERROR);
}
}
catch (\Exception $oException)
{
if ($this->oLogger)
{
$this->oLogger->WriteException($oException);
}
}
}
return $bResult;
}
}

View 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.

View file

@ -0,0 +1 @@
1.1

View file

@ -0,0 +1,73 @@
<?php
class CpanelChangePasswordPlugin 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', 'host', ''));
$iPost = (int) $this->Config()->Get('plugin', 'port', 2087);
$sUser = (string) $this->Config()->Get('plugin', 'user', '');
$sPassword = (string) $this->Config()->Get('plugin', 'password', '');
$sSsl = (bool) $this->Config()->Get('plugin', 'ssl', false);
if (!empty($sHost) && 0 < $iPost && 0 < \strlen($sUser) && 0 < \strlen($sPassword))
{
include_once __DIR__.'/CpanelChangePasswordDriver.php';
$oProvider = new CpanelChangePasswordDriver();
$oProvider->SetLogger($this->Manager()->Actions()->Logger());
$oProvider->SetConfig($sHost, $iPost, $sSsl, $sUser, $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('host')->SetLabel('cPanel Host')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('cPanel Port')
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
->SetDefaultValue(2087),
\RainLoop\Plugins\Property::NewInstance('ssl')->SetLabel('Use SSL')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDefaultValue(false),
\RainLoop\Plugins\Property::NewInstance('user')->SetLabel('cPanel User')
->SetDefaultValue(''),
\RainLoop\Plugins\Property::NewInstance('password')->SetLabel('cPanel 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')
);
}
}

File diff suppressed because it is too large Load diff