From 869abb04693d5243d347c6550ea76d7e74ac6b44 Mon Sep 17 00:00:00 2001 From: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com> Date: Thu, 2 Jun 2022 16:10:26 +0200 Subject: [PATCH] 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 --- plugins/change-password-hestia/driver.php | 68 +++++++++++++++++++++++ plugins/change-password-hestia/index.php | 20 +++++++ 2 files changed, 88 insertions(+) create mode 100644 plugins/change-password-hestia/driver.php create mode 100644 plugins/change-password-hestia/index.php diff --git a/plugins/change-password-hestia/driver.php b/plugins/change-password-hestia/driver.php new file mode 100644 index 000000000..aa6a82494 --- /dev/null +++ b/plugins/change-password-hestia/driver.php @@ -0,0 +1,68 @@ +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; + } + } +} diff --git a/plugins/change-password-hestia/index.php b/plugins/change-password-hestia/index.php new file mode 100644 index 000000000..b88cff25f --- /dev/null +++ b/plugins/change-password-hestia/index.php @@ -0,0 +1,20 @@ +