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() ? $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(BB_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 \Whoops\Run(); $prettyPage = new \Whoops\Handler\PrettyPageHandler(); $prettyPage->setPageTitle('An error ocurred'); $prettyPage->addDataTable('FOSSBilling environment', [ 'PHP Version' => phpversion(), 'Error code' => $e->getCode(), ]); $whoops->pushHandler($prettyPage); $whoops->allowQuit(false); $whoops->writeToOutput(false); echo $whoops->handleException($e); } else { $page = " An error ocurred

Error

"; $page = str_replace(PHP_EOL, '', $page); echo $page; if ($e->getCode()) { echo sprintf('

Error code: %s

', $e->getCode()); } echo sprintf('

%s

', $e->getMessage()); echo sprintf('

Look for detailed error explanation

', urlencode($e->getMessage())); echo '

Powered by FOSSBilling

'; } } } set_exception_handler('handler_exception'); set_error_handler('handler_error'); // Check for Composer packages if (!file_exists(BB_PATH_VENDOR)) { throw new Exception("It seems like Composer packages are missing. You have to run \"composer install\" in order to install them. For detailed instruction, you can see Composer's getting started guide.

If you have downloaded FOSSBilling from GitHub releases, this shouldn't happen.", 110); } // Multisite support. Load new configuration depending on the current hostname // If being run from CLI, first parameter must be the hostname $configPath = BB_PATH_ROOT.'/bb-config.php'; if ((isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) || ('cli' == php_sapi_name() && isset($argv[1]))) { if ('cli' == php_sapi_name()) { $host = $argv[1]; } else { $host = $_SERVER['HTTP_HOST']; } $predictConfigPath = BB_PATH_ROOT.'/bb-config-'.$host.'.php'; if (file_exists($predictConfigPath)) { $configPath = $predictConfigPath; } } // Try to check if configuration is available if (!file_exists($configPath) || 0 == filesize($configPath)) { // Try to create an empty configuration file @file_put_contents($configPath, ''); $base_url = 'http'.(isset($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'] || 1 == $_SERVER['HTTPS']) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ? 's' : '').'://'.$_SERVER['HTTP_HOST']; $base_url .= preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])); $url = $base_url.'/install/index.php'; if (file_exists(BB_PATH_ROOT.'/install/index.php')) { header("Location: $url"); } $configFile = pathinfo($configPath, PATHINFO_BASENAME); $msg = sprintf("Your $configFile file seems to be invalid. It's possible that your preexisting configuration file may not contain the required configuration parameters or have become corrupted. FOSSBilling needs to have a valid configuration file present in order to function properly.

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 if (file_exists($configPath) && 0 !== filesize($configPath) && file_exists(BB_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_once $configPath; require BB_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('BB_PATH_CACHE', $config['path_data'].'/cache'); define('BB_PATH_LOG', $config['path_data'].'/log'); define('BB_SSL', ('https' === substr($config['url'], 0, 5))); 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', BB_PATH_LOG.'/php_error.log');