mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-18 04:40:30 +08:00
Revamp for #351
This commit is contained in:
parent
3522f76d37
commit
1dccfdba3b
4 changed files with 95 additions and 65 deletions
20
plugins/change-password-poppassd/LICENSE
Normal file
20
plugins/change-password-poppassd/LICENSE
Normal file
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 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,14 +1,13 @@
|
|||
<?php
|
||||
|
||||
class ChangePasswordDriverISPConfig
|
||||
class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
|
||||
{
|
||||
const
|
||||
NAME = 'Poppassd',
|
||||
DESCRIPTION = 'Change passwords using Poppassd.';
|
||||
|
||||
private
|
||||
$oConfig = null,
|
||||
$oLogger = null;
|
||||
$oConfig = null;
|
||||
|
||||
function __construct(\RainLoop\Config\Plugin $oConfig, \MailSo\Log\Logger $oLogger)
|
||||
{
|
||||
|
@ -44,17 +43,41 @@ class ChangePasswordDriverISPConfig
|
|||
|
||||
try
|
||||
{
|
||||
$oPoppassdClient = new PoppassdClient();
|
||||
if ($this->oLogger) {
|
||||
$oPoppassdClient->SetLogger($this->oLogger);
|
||||
}
|
||||
$oPoppassdClient->Connect(
|
||||
$this->Connect(
|
||||
$this->oConfig->Get('plugin', 'poppassd_host', ''),
|
||||
(int) $this->oConfig->Get('plugin', 'poppassd_port', 106)
|
||||
);
|
||||
$oPoppassdClient->Login($oAccount->Login(), $sPrevPassword)
|
||||
->NewPass($sNewPassword)
|
||||
->Disconnect()
|
||||
|
||||
if ($this->bIsLoggined) {
|
||||
$this->writeLogException(
|
||||
new \RuntimeException('Already authenticated for this session'),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
$sLogin = \trim($sLogin);
|
||||
|
||||
try
|
||||
{
|
||||
$this->sendRequestWithCheck('user', \trim($sLogin), true);
|
||||
$this->sendRequestWithCheck('pass', $sPassword, true);
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
$this->writeLogException($oException, \MailSo\Log\Enumerations\Type::NOTICE, true);
|
||||
}
|
||||
|
||||
$this->bIsLoggined = true;
|
||||
|
||||
if ($this->bIsLoggined) {
|
||||
$this->sendRequestWithCheck('newpass', $sNewPassword);
|
||||
} else {
|
||||
$this->writeLogException(
|
||||
new \RuntimeException('Required login'),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
|
||||
$this->Disconnect()
|
||||
;
|
||||
|
||||
return true;
|
||||
|
@ -65,10 +88,7 @@ class ChangePasswordDriverISPConfig
|
|||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class PoppassdClient extends \MailSo\Net\NetClient
|
||||
{
|
||||
private
|
||||
$bIsLoggined = false,
|
||||
$iRequestTime = 0;
|
||||
|
@ -83,32 +103,6 @@ class PoppassdClient extends \MailSo\Net\NetClient
|
|||
$this->validateResponse();
|
||||
}
|
||||
|
||||
public function Login(string $sLogin, string $sPassword) : self
|
||||
{
|
||||
if ($this->bIsLoggined) {
|
||||
$this->writeLogException(
|
||||
new \RuntimeException('Already authenticated for this session'),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
$sLogin = \trim($sLogin);
|
||||
$sPassword = $sPassword;
|
||||
|
||||
try
|
||||
{
|
||||
$this->sendRequestWithCheck('user', $sLogin, true);
|
||||
$this->sendRequestWithCheck('pass', $sPassword, true);
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
$this->writeLogException($oException, \MailSo\Log\Enumerations\Type::NOTICE, true);
|
||||
}
|
||||
|
||||
$this->bIsLoggined = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function Logout() : void
|
||||
{
|
||||
if ($this->bIsLoggined) {
|
||||
|
@ -117,19 +111,6 @@ class PoppassdClient extends \MailSo\Net\NetClient
|
|||
$this->bIsLoggined = false;
|
||||
}
|
||||
|
||||
public function NewPass(string $sNewPassword) : self
|
||||
{
|
||||
if ($this->bIsLoggined) {
|
||||
$this->sendRequestWithCheck('newpass', $sNewPassword);
|
||||
} else {
|
||||
$this->writeLogException(
|
||||
new \RuntimeException('Required login'),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function secureRequestParams($sCommand, $sAddToCommand) : ?string
|
||||
{
|
||||
if (\strlen($sAddToCommand)) {
|
||||
|
@ -144,9 +125,10 @@ class PoppassdClient extends \MailSo\Net\NetClient
|
|||
return null;
|
||||
}
|
||||
|
||||
private function sendRequest(string $sCommand, string $sAddToCommand = '') : self
|
||||
private function sendRequestWithCheck(string $sCommand, string $sAddToCommand = '', bool $bAuthRequestValidate = false) : void
|
||||
{
|
||||
if (!\strlen(\trim($sCommand))) {
|
||||
$sCommand = \trim($sCommand);
|
||||
if (!\strlen($sCommand)) {
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException(),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
|
@ -154,7 +136,6 @@ class PoppassdClient extends \MailSo\Net\NetClient
|
|||
|
||||
$this->IsConnected(true);
|
||||
|
||||
$sCommand = \trim($sCommand);
|
||||
$sRealCommand = $sCommand . (\strlen($sAddToCommand) ? ' '.$sAddToCommand : '');
|
||||
|
||||
$sFakeCommand = '';
|
||||
|
@ -166,15 +147,7 @@ class PoppassdClient extends \MailSo\Net\NetClient
|
|||
$this->iRequestTime = \microtime(true);
|
||||
$this->sendRaw($sRealCommand, true, $sFakeCommand);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function sendRequestWithCheck(string $sCommand, string $sAddToCommand = '', bool $bAuthRequestValidate = false) : self
|
||||
{
|
||||
$this->sendRequest($sCommand, $sAddToCommand);
|
||||
$this->validateResponse($bAuthRequestValidate);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function validateResponse(bool $bAuthRequestValidate = false) : self
|
19
plugins/change-password-poppassd/index.php
Normal file
19
plugins/change-password-poppassd/index.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
use \RainLoop\Exceptions\ClientException;
|
||||
|
||||
class ChangePasswordPoppassdPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Change Password Poppassd',
|
||||
VERSION = '2.15.0',
|
||||
RELEASE = '2022-04-28',
|
||||
REQUIRED = '2.15.1',
|
||||
CATEGORY = 'Security',
|
||||
DESCRIPTION = 'Extension to allow users to change their passwords through Poppassd';
|
||||
|
||||
public function Supported() : string
|
||||
{
|
||||
return 'Use Change Password plugin';
|
||||
}
|
||||
}
|
|
@ -52,7 +52,6 @@ class ChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// foreach (\glob(__DIR__ . '/../change-password-*', GLOB_ONLYDIR) as $file) {
|
||||
foreach (\glob(__DIR__ . '/drivers/*.php') as $file) {
|
||||
$name = \basename($file, '.php');
|
||||
$class = 'ChangePasswordDriver' . $name;
|
||||
|
@ -71,6 +70,25 @@ class ChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (\glob(__DIR__ . '/../change-password-*', GLOB_ONLYDIR) as $file) {
|
||||
$name = \str_replace('change-password-', '', \basename($file));
|
||||
$class = "ChangePassword{$name}Driver";
|
||||
$file .= '/driver.php';
|
||||
try
|
||||
{
|
||||
if (\is_readable($file) && ($all || $this->Config()->Get('plugin', "driver_{$name}_enabled", false))) {
|
||||
require_once $file;
|
||||
if ($class::isSupported()) {
|
||||
yield $name => $class;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
\trigger_error("ERROR {$class}: " . $oException->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function Supported() : string
|
||||
|
|
Loading…
Reference in a new issue