From b44da10e27d9b6e7e1cd03fd9f7566421bf6cc96 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 24 Nov 2022 14:30:09 +0100 Subject: [PATCH] Better cPanel integration #697 --- _include.php | 9 --------- snappymail/v/0.0.0/cpanel.php | 27 +++++++++++++++++++++++++++ snappymail/v/0.0.0/include.php | 16 +++++++++++++--- 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 snappymail/v/0.0.0/cpanel.php diff --git a/_include.php b/_include.php index be4231442..9f16ed888 100644 --- a/_include.php +++ b/_include.php @@ -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'] => - $_ENV['HOME'] => /home/ - $_ENV['TMPDIR'] => /home//tmp - $_ENV['REAL_DBOWNER'] => -*/ -} /** * Additional configuration file name diff --git a/snappymail/v/0.0.0/cpanel.php b/snappymail/v/0.0.0/cpanel.php new file mode 100644 index 000000000..bcdd7bb0c --- /dev/null +++ b/snappymail/v/0.0.0/cpanel.php @@ -0,0 +1,27 @@ +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; +} diff --git a/snappymail/v/0.0.0/include.php b/snappymail/v/0.0.0/include.php index 3823e7d54..d655c23e7 100644 --- a/snappymail/v/0.0.0/include.php +++ b/snappymail/v/0.0.0/include.php @@ -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?