diff --git a/build/plugin.xml b/build/plugin.xml index 6688aa966..259cc027d 100644 --- a/build/plugin.xml +++ b/build/plugin.xml @@ -67,6 +67,11 @@ + + + + + diff --git a/plugins/poppassd-change-password/ChangePasswordPoppassdDriver.php b/plugins/poppassd-change-password/ChangePasswordPoppassdDriver.php new file mode 100644 index 000000000..75e53443f --- /dev/null +++ b/plugins/poppassd-change-password/ChangePasswordPoppassdDriver.php @@ -0,0 +1,119 @@ +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; + } +} \ No newline at end of file diff --git a/plugins/poppassd-change-password/LICENSE b/plugins/poppassd-change-password/LICENSE new file mode 100644 index 000000000..271342337 --- /dev/null +++ b/plugins/poppassd-change-password/LICENSE @@ -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. diff --git a/plugins/poppassd-change-password/README b/plugins/poppassd-change-password/README new file mode 100644 index 000000000..6be76f713 --- /dev/null +++ b/plugins/poppassd-change-password/README @@ -0,0 +1 @@ +Plugin that adds functionality to change the email account password (POPPASSD). \ No newline at end of file diff --git a/plugins/poppassd-change-password/VERSION b/plugins/poppassd-change-password/VERSION new file mode 100644 index 000000000..9f8e9b69a --- /dev/null +++ b/plugins/poppassd-change-password/VERSION @@ -0,0 +1 @@ +1.0 \ No newline at end of file diff --git a/plugins/poppassd-change-password/index.php b/plugins/poppassd-change-password/index.php new file mode 100644 index 000000000..b5f2e3d9b --- /dev/null +++ b/plugins/poppassd-change-password/index.php @@ -0,0 +1,52 @@ +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('*') + ); + } +}