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:
Jaap Marcus 2022-06-02 16:10:26 +02:00
parent e8b73b4943
commit 869abb0469
No known key found for this signature in database
GPG key ID: 1C387772097B418E
2 changed files with 88 additions and 0 deletions

View 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;
}
}
}

View 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';
}
}