mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
cPanel use extension login-cpanel instead of login-remote
This commit is contained in:
parent
e554bcc27e
commit
f2c4b8a1b3
3 changed files with 102 additions and 5 deletions
77
plugins/login-cpanel/index.php
Normal file
77
plugins/login-cpanel/index.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
class LogincPanelPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Login cPanel',
|
||||
AUTHOR = 'SnappyMail',
|
||||
URL = 'https://snappymail.eu/',
|
||||
VERSION = '1.4',
|
||||
RELEASE = '2024-03-27',
|
||||
REQUIRED = '2.36.1',
|
||||
CATEGORY = 'Login',
|
||||
LICENSE = 'MIT',
|
||||
DESCRIPTION = 'Tries to login using the cPanel $_ENV["REMOTE_*"] variables';
|
||||
|
||||
public function Init() : void
|
||||
{
|
||||
$this->addPartHook('cPanelAutoLogin', 'AutoLogin');
|
||||
$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'] = $_ENV['REMOTE_USER'];
|
||||
// $aResult['DevPassword'] = $_ENV['REMOTE_PASSWORD'];
|
||||
}
|
||||
}
|
||||
|
||||
private static bool $login = false;
|
||||
public function AutoLogin() : bool
|
||||
{
|
||||
$oActions = \RainLoop\Api::Actions();
|
||||
|
||||
$oException = null;
|
||||
$oAccount = null;
|
||||
|
||||
$sEmail = $_ENV['REMOTE_USER'] ?? '';
|
||||
$sPassword = $_ENV['REMOTE_PASSWORD'] ?? '';
|
||||
|
||||
if (\strlen($sEmail) && \strlen($sPassword)) {
|
||||
try
|
||||
{
|
||||
static::$login = true;
|
||||
$oAccount = $oActions->LoginProcess($sEmail, $sPassword);
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
$oLogger = $oActions->Logger();
|
||||
$oLogger && $oLogger->WriteException($oException);
|
||||
}
|
||||
}
|
||||
|
||||
\MailSo\Base\Http::Location('./');
|
||||
return true;
|
||||
}
|
||||
|
||||
public function FilterLoginCredentials(&$sEmail, &$sImapUser, &$sPassword, &$sSmtpUser)
|
||||
{
|
||||
// cPanel https://github.com/the-djmaze/snappymail/issues/697
|
||||
// && !empty($_ENV['CPANEL'])
|
||||
if (static::$login/* && $sImapUser == $_ENV['REMOTE_USER']*/) {
|
||||
if (empty($_ENV['REMOTE_TEMP_USER'])) {
|
||||
$iPos = \strpos($sPassword, '[::cpses::]');
|
||||
if ($iPos) {
|
||||
$_ENV['REMOTE_TEMP_USER'] = \substr($sPassword, 0, $iPos);
|
||||
}
|
||||
}
|
||||
if (!empty($_ENV['REMOTE_TEMP_USER'])) {
|
||||
$sImapUser = $_ENV['REMOTE_USER'] . '/' . $_ENV['REMOTE_TEMP_USER'];
|
||||
$sSmtpUser = $_ENV['REMOTE_USER'] . '/' . $_ENV['REMOTE_TEMP_USER'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue