Fix cPanel automate login issue

This commit is contained in:
the-djmaze 2022-11-24 12:20:57 +01:00
parent cd66ce1d28
commit 29473045f8
2 changed files with 21 additions and 6 deletions

View file

@ -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"

View file

@ -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);
}
}
}
}