Add POPPASSD change password plugin

This commit is contained in:
RainLoop Team 2013-12-29 18:48:35 +04:00
parent a8a21f42f7
commit 9ec92e9946
6 changed files with 198 additions and 0 deletions

View file

@ -67,6 +67,11 @@
<param name="plugin-name" value="ispmanager-change-password"/>
</antcall>
</target>
<target name="poppassd-change-password">
<antcall target="_build_plugin_">
<param name="plugin-name" value="poppassd-change-password"/>
</antcall>
</target>
<target name="black-list">
<antcall target="_build_plugin_">
<param name="plugin-name" value="black-list"/>

View file

@ -0,0 +1,119 @@
<?php
class ChangePasswordPoppassdDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface
{
/**
* @var string
*/
private $sHost = '127.0.0.1';
/**
* @var int
*/
private $iPort = 106;
/**
* @var string
*/
private $sAllowedEmails = '';
/**
* @var \MailSo\Log\Logger
*/
private $oLogger = null;
/**
* @param string $sHost
*
* @return \ChangePasswordPoppassdDriver
*/
public function SetHost($sHost)
{
$this->sHost = $sHost;
return $this;
}
/**
* @param string $iHost
*
* @return \ChangePasswordPoppassdDriver
*/
public function SetPort($iHost)
{
$this->iHost = $iHost;
return $this;
}
/**
* @param string $aDomains
*
* @return \ChangePasswordPoppassdDriver
*/
public function SetAllowedEmails($sAllowedEmails)
{
$this->sAllowedEmails = $sAllowedEmails;
return $this;
}
/**
* @param \MailSo\Log\Logger $oLogger
*
* @return \ChangePasswordPoppassdDriver
*/
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)
{
$bResult = false;
try
{
$oPoppassdClient = \MailSo\Poppassd\PoppassdClient::NewInstance();
if ($this->oLogger instanceof \MailSo\Log\Logger)
{
$oPoppassdClient->SetLogger($this->oLogger);
}
$oPoppassdClient
->Connect($this->sHost, $this->iPort)
->Login($oAccount->Login(), $oAccount->Password())
->NewPass($sNewPassword)
->LogoutAndDisconnect()
;
$bResult = true;
}
catch (\Exception $oException)
{
$bResult = false;
}
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 @@
Plugin that adds functionality to change the email account password (POPPASSD).

View file

@ -0,0 +1 @@
1.0

View file

@ -0,0 +1,52 @@
<?php
class PoppassdChangePasswordPlugin 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':
include_once __DIR__.'/ChangePasswordPoppassdDriver.php';
$oProvider = new ChangePasswordPoppassdDriver();
$oProvider
->SetHost($this->Config()->Get('plugin', 'host', ''))
->SetPort($this->Config()->Get('plugin', 'port', ''))
->SetAllowedEmails(\strtolower(\trim($this->Config()->Get('plugin', 'allowed_emails', ''))))
->SetLogger($this->Manager()->Actions()->Logger())
;
break;
}
}
/**
* @return array
*/
public function configMapping()
{
return array(
\RainLoop\Plugins\Property::NewInstance('host')->SetLabel('POPPASSD Host')
->SetDefaultValue('127.0.0.1'),
\RainLoop\Plugins\Property::NewInstance('port')->SetLabel('POPPASSD Port')
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
->SetDefaultValue(106),
\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('*')
);
}
}