Better cPanel integration #697

This commit is contained in:
the-djmaze 2022-11-24 14:30:09 +01:00
parent 3948b11998
commit b44da10e27
3 changed files with 40 additions and 12 deletions

View file

@ -29,15 +29,6 @@
*/
//define('APP_DATA_FOLDER_PATH', dirname(__DIR__) . '/snappymail-data/');
//define('APP_DATA_FOLDER_PATH', '/var/external-snappymail-data-folder/');
if (isset($_ENV['CPANEL']) && isset($_ENV['TMPDIR'])) {
define('APP_DATA_FOLDER_PATH', $_ENV['TMPDIR'] . '/snappymail/');
/*
$_ENV['USER'] => <username>
$_ENV['HOME'] => /home/<username>
$_ENV['TMPDIR'] => /home/<username>/tmp
$_ENV['REAL_DBOWNER'] => <username>
*/
}
/**
* Additional configuration file name

View file

@ -0,0 +1,27 @@
<?php
// cPanel https://github.com/the-djmaze/snappymail/issues/697
if (defined('APP_PLUGINS_PATH') && !empty($_ENV['CPANEL']) && !is_dir(APP_PLUGINS_PATH.'login-remote')) {
$asApi = $_ENV['SNAPPYMAIL_INCLUDE_AS_API'];
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
\SnappyMail\Repository::installPackage('plugin', 'login-remote');
$aList = \SnappyMail\Repository::getEnabledPackagesNames();
$aList[] = 'login-remote';
$oConfig = \RainLoop\Api::Config();
$oConfig->Set('plugins', 'enable', true);
$oConfig->Set('plugins', 'enabled_list', \implode(',', \array_unique($aList)));
$oConfig->Set('login', 'default_domain', 'cpanel');
$oConfig->Save();
$sFile = APP_PRIVATE_DATA.'domains/cpanel.json';
if (!file_exists($sFile)) {
$config = json_decode(file_get_contents(__DIR__ . '/app/domains/default.json'), true);
$config['IMAP']['shortLogin'] = true;
$config['SMTP']['shortLogin'] = true;
file_put_contents($sFile, json_encode($config, JSON_PRETTY_PRINT));
}
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = $asApi;
}

View file

@ -71,16 +71,21 @@ define('APP_PRIVATE_DATA_NAME', $sPrivateDataFolderInternalName ?: '_default_');
unset($sPrivateDataFolderInternalName);
if (!defined('APP_DATA_FOLDER_PATH')) {
$sCustomDataPath = function_exists('__get_custom_data_full_path') ? rtrim(trim(__get_custom_data_full_path()), '\\/') : $sCustomDataPath;
// cPanel https://github.com/the-djmaze/snappymail/issues/697
if (!empty($_ENV['CPANEL']) && isset($_ENV['TMPDIR'])) {
$sCustomDataPath = $_ENV['TMPDIR'] . '/snappymail';
} else {
$sCustomDataPath = function_exists('__get_custom_data_full_path') ? rtrim(trim(__get_custom_data_full_path()), '\\/') : $sCustomDataPath;
}
define('APP_DATA_FOLDER_PATH', strlen($sCustomDataPath) ? $sCustomDataPath.'/' : APP_INDEX_ROOT_PATH.'data/');
unset($sCustomDataPath);
}
unset($sCustomDataPath);
if (!defined('APP_CONFIGURATION_NAME')) {
define('APP_CONFIGURATION_NAME', function_exists('__get_additional_configuration_name')
? trim(__get_additional_configuration_name()) : $sCustomConfiguration);
unset($sCustomConfiguration);
}
unset($sCustomConfiguration);
$sData = is_file(APP_DATA_FOLDER_PATH.'DATA.php') ? file_get_contents(APP_DATA_FOLDER_PATH.'DATA.php') : '';
define('APP_PRIVATE_DATA', APP_DATA_FOLDER_PATH.'_data_'.($sData ? md5($sData) : '').'/'.APP_PRIVATE_DATA_NAME.'/');
@ -158,6 +163,11 @@ if (!ini_get('zlib.output_compression') && !ini_get('brotli.output_compression')
}
}
// cPanel https://github.com/the-djmaze/snappymail/issues/697
if (!empty($_ENV['CPANEL']) && !is_dir(APP_PLUGINS_PATH.'login-remote')) {
require __DIR__ . '/cpanel.php';
}
if (class_exists('RainLoop\\Api')) {
RainLoop\Api::Handle();
// NextCloud/OwnCloud?