getCode() . '] occurred in [' . $e->getFile() . '] at line [' . $e->getLine() . ']: [' . trim(strip_tags($e->getMessage())) . ']'; } else { if (APPLICATION_ENV === 'testing') { echo $e->getMessage() . PHP_EOL; return; } error_log($e->getMessage()); if (defined('BB_MODE_API')) { $code = $e->getCode() ?: 9998; $result = ['result' => null, 'error' => ['message' => $e->getMessage(), 'code' => $code]]; echo json_encode($result); return false; } if (defined('BB_DEBUG') && BB_DEBUG && file_exists(PATH_VENDOR)) { /** * If advanced debugging is enabled, print Whoops instead of our error page. * flip/whoops documentation: https://github.com/filp/whoops/blob/master/docs/API%20Documentation.md. */ $whoops = new Run(); $prettyPage = new PrettyPageHandler(); $prettyPage->setPageTitle('An error ocurred'); $prettyPage->addDataTable('FOSSBilling environment', [ 'PHP Version' => PHP_VERSION, 'Error code' => $e->getCode(), ]); $whoops->pushHandler($prettyPage); $whoops->allowQuit(false); $whoops->writeToOutput(false); echo $whoops->handleException($e); } else { $page = "
%s
', $e->getMessage()); echo sprintf('Powered by FOSSBilling
composer install\" in order to install them. For detailed instruction, you can see Composer's getting started guide.Please use the example config as reference here. You may need to manually restore a old config file or fix your existing one.
"; throw new Exception($msg, 101); } // Try to check if /install directory still exists, even after the installation was completed and display a message if (file_exists($configPath) && 0 !== filesize($configPath) && file_exists(PATH_ROOT . '/install/index.php')) { throw new Exception('For safety reasons, you have to delete the /install directory to start using FOSSBilling.Please delete the /install directory from your web server.', 102);
}
// Detect old for files from an old BoxBilling or FOSSBilling preview installation.
function detectOldFiles(){
$i = 0;
$msg = '';
$foundOld = false;
$oldFolderNames = ['bb-data','bb-library','bb-locale','bb-modules','bb-themes','bb-uploads','bb-cron.php','bb-di.php','bb-load.php','bb-config.php'];
$newFolderNames = ['data','library','locale','modules','themes','uploads','cron.php','di.php','load.php','config.php'];
foreach ($oldFolderNames as $folder){
$toCheck = PATH_ROOT . DIRECTORY_SEPARATOR . $folder;
$newName = $newFolderNames[$i];
if(file_exists($toCheck) or is_dir($toCheck)){
$msg .= "$folder --> $newName
";
$foundOld = true;
}
$i++;
}
if($foundOld){
$finalMsg = "The FOSSBilling file structure has been changed, please migrate any custom files and folders from the old folder to the new folder and then delete the old ones. You will also need to update the paths in your config.php file.
";
$finalMsg .= "Feel free to join our Discord Server for assistance.
";
$finalMsg .= "Files and folders renamed:
";
$finalMsg .= $msg;
throw new Exception($finalMsg);
}
}
detectOldFiles();
// Try to check if /install directory still exists, even after the installation was completed
if (file_exists($configPath) && 0 !== filesize($configPath) && file_exists(PATH_ROOT . '/install/index.php')) {
throw new Exception('For safety reasons, you have to delete the /install directory to start using FOSSBilling.
Please delete the /install directory from your web server.', 102); } $config = require $configPath; require PATH_VENDOR . '/autoload.php'; date_default_timezone_set($config['timezone']); define('BB_DEBUG', $config['debug']); define('BB_URL', $config['url']); define('BB_SEF_URLS', $config['sef_urls']); define('PATH_CACHE', $config['path_data'] . '/cache'); define('PATH_LOG', $config['path_data'] . '/log'); define('BB_SSL', str_starts_with($config['url'], 'https')); if ($config['sef_urls']) { define('BB_URL_API', $config['url'] . 'api/'); } else { define('BB_URL_API', $config['url'] . 'index.php?_url=/api/'); } if ($config['debug']) { error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); } else { error_reporting(E_RECOVERABLE_ERROR); ini_set('display_errors', '0'); ini_set('display_startup_errors', '0'); } ini_set('log_errors', '1'); ini_set('html_errors', false); ini_set('error_log', PATH_LOG . '/php_error.log'); $isApache = (function_exists('apache_get_version')) ? true : false; $serverSoftware = (isset($_SERVER['SERVER_SOFTWARE'])) ? $_SERVER['SERVER_SOFTWARE'] : ''; if ($isApache or (false !== stripos($serverSoftware, 'apache'))) { if (!file_exists(PATH_ROOT . '/.htaccess')) { throw new Exception('Error: You appear to be running an Apache server without a valid .htaccess file. You may need to rename htaccess.txt to .htaccess'); } } // If the configured security mode is strict, redirect to HTTPS if (isset($config['security']['force_https']) && $config['security']['force_https'] && 'cli' !== PHP_SAPI){ $isHTTPS = false; if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { $isHTTPS = true; } if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') { $isHTTPS = true; } if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && strtolower($_SERVER['HTTP_X_FORWARDED_SSL']) == 'on') { $isHTTPS = true; } if(!$isHTTPS){ $url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; header('Location: ' . $url); exit; } }