Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit f2c4b8a

Browse files
author
the-djmaze
committed
cPanel use extension login-cpanel instead of login-remote
1 parent e554bcc commit f2c4b8a

File tree

3 files changed

+102
-5
lines changed

3 files changed

+102
-5
lines changed

plugins/login-cpanel/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 RainLoop Team
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

plugins/login-cpanel/index.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
class LogincPanelPlugin extends \RainLoop\Plugins\AbstractPlugin
4+
{
5+
const
6+
NAME = 'Login cPanel',
7+
AUTHOR = 'SnappyMail',
8+
URL = 'https://snappymail.eu/',
9+
VERSION = '1.4',
10+
RELEASE = '2024-03-27',
11+
REQUIRED = '2.36.1',
12+
CATEGORY = 'Login',
13+
LICENSE = 'MIT',
14+
DESCRIPTION = 'Tries to login using the cPanel $_ENV["REMOTE_*"] variables';
15+
16+
public function Init() : void
17+
{
18+
$this->addPartHook('cPanelAutoLogin', 'AutoLogin');
19+
$this->addHook('filter.app-data', 'FilterAppData');
20+
$this->addHook('login.credentials', 'FilterLoginCredentials');
21+
}
22+
23+
public function FilterAppData($bAdmin, &$aResult)
24+
{
25+
if (!$bAdmin && \is_array($aResult) && empty($aResult['Auth']) && isset($_ENV['REMOTE_USER'])) {
26+
$aResult['DevEmail'] = $_ENV['REMOTE_USER'];
27+
// $aResult['DevPassword'] = $_ENV['REMOTE_PASSWORD'];
28+
}
29+
}
30+
31+
private static bool $login = false;
32+
public function AutoLogin() : bool
33+
{
34+
$oActions = \RainLoop\Api::Actions();
35+
36+
$oException = null;
37+
$oAccount = null;
38+
39+
$sEmail = $_ENV['REMOTE_USER'] ?? '';
40+
$sPassword = $_ENV['REMOTE_PASSWORD'] ?? '';
41+
42+
if (\strlen($sEmail) && \strlen($sPassword)) {
43+
try
44+
{
45+
static::$login = true;
46+
$oAccount = $oActions->LoginProcess($sEmail, $sPassword);
47+
}
48+
catch (\Throwable $oException)
49+
{
50+
$oLogger = $oActions->Logger();
51+
$oLogger && $oLogger->WriteException($oException);
52+
}
53+
}
54+
55+
\MailSo\Base\Http::Location('./');
56+
return true;
57+
}
58+
59+
public function FilterLoginCredentials(&$sEmail, &$sImapUser, &$sPassword, &$sSmtpUser)
60+
{
61+
// cPanel https://github.com/the-djmaze/snappymail/issues/697
62+
// && !empty($_ENV['CPANEL'])
63+
if (static::$login/* && $sImapUser == $_ENV['REMOTE_USER']*/) {
64+
if (empty($_ENV['REMOTE_TEMP_USER'])) {
65+
$iPos = \strpos($sPassword, '[::cpses::]');
66+
if ($iPos) {
67+
$_ENV['REMOTE_TEMP_USER'] = \substr($sPassword, 0, $iPos);
68+
}
69+
}
70+
if (!empty($_ENV['REMOTE_TEMP_USER'])) {
71+
$sImapUser = $_ENV['REMOTE_USER'] . '/' . $_ENV['REMOTE_TEMP_USER'];
72+
$sSmtpUser = $_ENV['REMOTE_USER'] . '/' . $_ENV['REMOTE_TEMP_USER'];
73+
}
74+
}
75+
}
76+
77+
}

snappymail/v/0.0.0/cpanel.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
// cPanel https://github.com/the-djmaze/snappymail/issues/697
4-
if (defined('APP_PLUGINS_PATH') && !empty($_ENV['CPANEL']) && !is_dir(APP_PLUGINS_PATH.'login-remote')) {
4+
if (defined('APP_PLUGINS_PATH') && !empty($_ENV['CPANEL']) && !is_dir(APP_PLUGINS_PATH.'login-cpanel')) {
55
$asApi = !empty($_ENV['SNAPPYMAIL_INCLUDE_AS_API']);
66
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
77

@@ -11,8 +11,8 @@
1111
$oConfig->Set('logs', 'path', $_ENV['HOME'] . '/logs/snappymail');
1212
$oConfig->Set('cache', 'path', $_ENV['TMPDIR'] . '/snappymail');
1313

14-
\SnappyMail\Repository::installPackage('plugin', 'login-remote');
15-
\SnappyMail\Repository::enablePackage('login-remote');
14+
\SnappyMail\Repository::installPackage('plugin', 'login-cpanel');
15+
\SnappyMail\Repository::enablePackage('login-cpanel');
1616

1717
$sFile = APP_PRIVATE_DATA.'domains/cpanel.json';
1818
if (!file_exists($sFile)) {
@@ -22,9 +22,9 @@
2222
file_put_contents($sFile, json_encode($config, JSON_PRETTY_PRINT));
2323
}
2424

25-
// \RainLoop\Api::Actions()->Plugins()->loadPlugin('login-remote');
25+
// \RainLoop\Api::Actions()->Plugins()->loadPlugin('login-cpanel');
2626
if (!isset($_GET['installed'])) {
27-
\header('Location: ?RemoteAutoLogin&installed');
27+
\header('Location: ?cPanelAutoLogin&installed');
2828
exit;
2929
}
3030

0 commit comments

Comments
 (0)