From 29473045f8bed04e92b8805c30e72805b479e4d1 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 24 Nov 2022 12:20:57 +0100 Subject: [PATCH] Fix cPanel automate login issue --- .../cpanel/webmail/webmail_snappymail.yaml | 2 +- plugins/login-remote/index.php | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/integrations/cpanel/var/cpanel/webmail/webmail_snappymail.yaml b/integrations/cpanel/var/cpanel/webmail/webmail_snappymail.yaml index 30a093c44..682f79565 100644 --- a/integrations/cpanel/var/cpanel/webmail/webmail_snappymail.yaml +++ b/integrations/cpanel/var/cpanel/webmail/webmail_snappymail.yaml @@ -1,3 +1,3 @@ -url: "/3rdparty/snappymail/" +url: "/3rdparty/snappymail/?RemoteAutoLogin" displayname: "SnappyMail" icon: "/3rdparty/snappymail/snappymail/v/2.22.1/static/logo-text.png" diff --git a/plugins/login-remote/index.php b/plugins/login-remote/index.php index 3abbfd004..cc2dfce52 100644 --- a/plugins/login-remote/index.php +++ b/plugins/login-remote/index.php @@ -6,8 +6,8 @@ class LoginRemotePlugin extends \RainLoop\Plugins\AbstractPlugin NAME = 'Login Remote', AUTHOR = 'SnappyMail', URL = 'https://snappymail.eu/', - VERSION = '1.0', - RELEASE = '2022-11-11', + VERSION = '1.1', + RELEASE = '2022-11-24', REQUIRED = '2.21.0', CATEGORY = 'Login', LICENSE = 'MIT', @@ -17,15 +17,18 @@ class LoginRemotePlugin extends \RainLoop\Plugins\AbstractPlugin { $this->addPartHook('RemoteAutoLogin', 'ServiceRemoteAutoLogin'); $this->addHook('filter.app-data', 'FilterAppData'); + $this->addHook('login.credentials', 'FilterLoginCredentials'); } public function FilterAppData($bAdmin, &$aResult) { if (!$bAdmin && \is_array($aResult) && empty($aResult['Auth']) && isset($_ENV['REMOTE_USER'])) { - $aResult['DevEmail'] = $this->Config()->Get('plugin', 'email', $_ENV['REMOTE_USER']); + $aResult['DevEmail'] = $_ENV['REMOTE_USER']; +// $aResult['DevPassword'] = $_ENV['REMOTE_PASSWORD']; } } + private static bool $login = false; public function ServiceRemoteAutoLogin() : bool { $oActions = \RainLoop\Api::Actions(); @@ -36,10 +39,10 @@ class LoginRemotePlugin extends \RainLoop\Plugins\AbstractPlugin $sEmail = $_ENV['REMOTE_USER'] ?? ''; $sPassword = $_ENV['REMOTE_PASSWORD'] ?? ''; - if (\strlen($sEmail) && \strlen($sPassword)) - { + if (\strlen($sEmail) && \strlen($sPassword)) { try { + static::$login = true; $oAccount = $oActions->LoginProcess($sEmail, $sPassword); if ($oAccount instanceof \RainLoop\Model\MainAccount) { $oActions->SetAuthToken($oAccount); @@ -56,4 +59,16 @@ class LoginRemotePlugin extends \RainLoop\Plugins\AbstractPlugin return true; } + public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword) + { + // cPanel https://github.com/the-djmaze/snappymail/issues/697 + if (static::$login/* && $sLogin == $_SERVER['REMOTE_USER']*/) { + $iPos = \strpos($sPassword, '[::cpses::]'); + if ($iPos) { + $sKey = \substr($sPassword, 0, $iPos); + $sLogin = $_SERVER['REMOTE_USER'] . '/' . \substr($sPassword, 0, $iPos); + } + } + } + }