From f2c4b8a1b373d516c93a98af5cb1ac3dd49593f7 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 17 Apr 2024 01:10:03 +0200 Subject: [PATCH] cPanel use extension login-cpanel instead of login-remote --- plugins/login-cpanel/LICENSE | 20 +++++++++ plugins/login-cpanel/index.php | 77 ++++++++++++++++++++++++++++++++++ snappymail/v/0.0.0/cpanel.php | 10 ++--- 3 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 plugins/login-cpanel/LICENSE create mode 100644 plugins/login-cpanel/index.php diff --git a/plugins/login-cpanel/LICENSE b/plugins/login-cpanel/LICENSE new file mode 100644 index 000000000..f709b02e2 --- /dev/null +++ b/plugins/login-cpanel/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2016 RainLoop Team + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/plugins/login-cpanel/index.php b/plugins/login-cpanel/index.php new file mode 100644 index 000000000..9bc5ebf7a --- /dev/null +++ b/plugins/login-cpanel/index.php @@ -0,0 +1,77 @@ +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']; + } + } + } + +} diff --git a/snappymail/v/0.0.0/cpanel.php b/snappymail/v/0.0.0/cpanel.php index 4f0168d20..4159a4a2d 100644 --- a/snappymail/v/0.0.0/cpanel.php +++ b/snappymail/v/0.0.0/cpanel.php @@ -1,7 +1,7 @@ Set('logs', 'path', $_ENV['HOME'] . '/logs/snappymail'); $oConfig->Set('cache', 'path', $_ENV['TMPDIR'] . '/snappymail'); - \SnappyMail\Repository::installPackage('plugin', 'login-remote'); - \SnappyMail\Repository::enablePackage('login-remote'); + \SnappyMail\Repository::installPackage('plugin', 'login-cpanel'); + \SnappyMail\Repository::enablePackage('login-cpanel'); $sFile = APP_PRIVATE_DATA.'domains/cpanel.json'; if (!file_exists($sFile)) { @@ -22,9 +22,9 @@ if (defined('APP_PLUGINS_PATH') && !empty($_ENV['CPANEL']) && !is_dir(APP_PLUGIN file_put_contents($sFile, json_encode($config, JSON_PRETTY_PRINT)); } -// \RainLoop\Api::Actions()->Plugins()->loadPlugin('login-remote'); +// \RainLoop\Api::Actions()->Plugins()->loadPlugin('login-cpanel'); if (!isset($_GET['installed'])) { - \header('Location: ?RemoteAutoLogin&installed'); + \header('Location: ?cPanelAutoLogin&installed'); exit; }