mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
HestiaCP Password reset support
Resets password via hostname:8083/reset/mail/ endpoint Should also work on VestaCP < 1.0.0 or after they have patched the bug in 1.0.x
This commit is contained in:
parent
e8b73b4943
commit
869abb0469
2 changed files with 88 additions and 0 deletions
68
plugins/change-password-hestia/driver.php
Normal file
68
plugins/change-password-hestia/driver.php
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ChangePasswordHestiaDriver
|
||||||
|
{
|
||||||
|
const
|
||||||
|
NAME = 'Hestia',
|
||||||
|
DESCRIPTION = 'Change passwords in Hestia.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \RainLoop\Config\Plugin
|
||||||
|
*/
|
||||||
|
private $oConfig = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \MailSo\Log\Logger
|
||||||
|
*/
|
||||||
|
protected $oLogger = null;
|
||||||
|
|
||||||
|
function __construct(\RainLoop\Config\Plugin $oConfig, \MailSo\Log\Logger $oLogger)
|
||||||
|
{
|
||||||
|
$this->oConfig = $oConfig;
|
||||||
|
$this->oLogger = $oLogger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function isSupported() : bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function configMapping() : array
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('hestia_host')->SetLabel('Hestia Host')
|
||||||
|
->SetDefaultValue('')
|
||||||
|
->SetDescription('Ex: localhost or domain.com'),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('hestia_port')->SetLabel('Hestia Port')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::INT)
|
||||||
|
->SetDefaultValue(8083),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('hestia_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('*')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ChangePassword(\RainLoop\Model\Account $oAccount, string $sPrevPassword, string $sNewPassword) : bool
|
||||||
|
{
|
||||||
|
if (!\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->oConfig->Get('plugin', 'hestia_allowed_emails', ''))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sHost = $this->oConfig->Get('plugin', 'hestia_login');
|
||||||
|
$sPort = $this->oConfig->Get('plugin', 'hestia_port');
|
||||||
|
|
||||||
|
$HTTP = \SnappyMail\HTTP\Request::factory();
|
||||||
|
$postvars = array(
|
||||||
|
'email' => $oAccount->Email(),
|
||||||
|
'password' => $sPrevPassword,
|
||||||
|
'new' => $sNewPassword,
|
||||||
|
);
|
||||||
|
$cRequest = $HTTP->doRequest('POST','https://'.$sHost.':'.$sPort.'/reset/mail/',http_build_query($postvars));
|
||||||
|
if($cRequest -> body == '==ok=='){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
plugins/change-password-hestia/index.php
Normal file
20
plugins/change-password-hestia/index.php
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use \RainLoop\Exceptions\ClientException;
|
||||||
|
|
||||||
|
class ChangePasswordHestiaPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
{
|
||||||
|
const
|
||||||
|
NAME = 'Change Password Hestia',
|
||||||
|
AUTHOR = 'Jaap Marcus',
|
||||||
|
VERSION = '1.0',
|
||||||
|
RELEASE = '2022-06-02',
|
||||||
|
REQUIRED = '2.16.3',
|
||||||
|
CATEGORY = 'Security',
|
||||||
|
DESCRIPTION = 'Extension to allow users to change their passwords through HestiaCP';
|
||||||
|
|
||||||
|
public function Supported() : string
|
||||||
|
{
|
||||||
|
return 'Use Change Password plugin';
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue