getMessage() . PHP_EOL; return ; } error_log($e->getMessage()); if(defined('BB_MODE_API')) { $code = $e->getCode() ? $e->getCode() : 9998; $result = array('result'=>NULL, 'error'=>array('message'=>$e->getMessage(), 'code'=>$code)); print json_encode($result); return false; } $page = " An error ocurred

Error

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

Error code: %s

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

%s

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

Look for detailed error explanation

', urlencode($e->getMessage())); if(defined('BB_DEBUG') && BB_DEBUG) { print sprintf('%s', 'Set BB_DEBUG to FALSE, to hide the message below'); print sprintf('

Class: "%s"

', get_class($e)); print sprintf('

File: "%s"

', $e->getFile()); print sprintf('

Line: "%s"

', $e->getLine()); print sprintf('Trace:
%s
', $e->getTraceAsString()); } print("

Powered by BoxBilling

"); } set_exception_handler("handler_exception"); set_error_handler('handler_error'); // Check for Composer packages $vendorPath = BB_PATH_ROOT.'/bb-vendor'; if(!file_exists($vendorPath)) { 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 BoxBilling from GitHub releases, this shouldn't happen.", 103); } // 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']) || (php_sapi_name() == 'cli' && isset($argv[1]) ) ) { if(php_sapi_name() == 'cli') { $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']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ? 's' : '')."://".$_SERVER['HTTP_HOST']; $base_url .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])); $url = $base_url . '/install/index.php'; $configFile = pathinfo($configPath, PATHINFO_BASENAME); $msg = sprintf("The $configFile path seems to be invalid. You may have not generated the configuration file yet, or the configuration file may not contain the required configuration parameters. BoxBilling needs to have a valid configuration file present in order to function properly.

Need some help with the installation? We got it. You can create the configuration file using the interactive installer, or manually create the configuration file.

If it's your first time setting up BoxBilling, you can continue with the web-based interactive BoxBilling installation.", $url); 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 BoxBilling.

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', (substr($config['url'], 0, 5) === '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', BB_PATH_LOG . '/php_error.log');