From 86d62342082887495683cfb143ff8679536f512b Mon Sep 17 00:00:00 2001
From: tautvydaskarvelis Powered by FOSSBilling
Please use the example config as reference here. You may need to manually restore a old config file or fix your existing one.
"); + $msg = "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); } @@ -273,7 +277,7 @@ if (file_exists($configPath) && 0 !== filesize($configPath) && file_exists(BB_PA 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; +$config = require $configPath; require BB_PATH_VENDOR.'/autoload.php'; date_default_timezone_set($config['timezone']); @@ -283,7 +287,7 @@ 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))); +define('BB_SSL', (str_starts_with($config['url'], 'https'))); if ($config['sef_urls']) { define('BB_URL_API', $config['url'].'api/'); diff --git a/src/bb-update.php b/src/bb-update.php index 4a5d28650..d94b15a7d 100644 --- a/src/bb-update.php +++ b/src/bb-update.php @@ -18,7 +18,7 @@ */ class BBPatch_25 extends BBPatchAbstract { - public function patch() + public function patch(): void { // Change table data storage engine $query = 'ALTER TABLE `activity_admin_history` ENGINE = INNODB; @@ -96,7 +96,7 @@ class BBPatch_25 extends BBPatchAbstract */ class BBPatch_24 extends BBPatchAbstract { - public function patch() + public function patch(): void { // Initializing meta description support for announcements $q = 'ALTER TABLE `post` ADD `description` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL AFTER `title`'; @@ -114,7 +114,7 @@ class BBPatch_24 extends BBPatchAbstract class BBPatch_23 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE mod_email_queue CHANGE `from` sender varchar(255) ;'; $this->execSql($q); @@ -129,7 +129,7 @@ class BBPatch_23 extends BBPatchAbstract class BBPatch_22 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `client_balance` CHANGE `rel_id` `rel_id` VARCHAR(20) NULL DEFAULT NULL;'; $this->execSql($q); @@ -141,7 +141,7 @@ class BBPatch_22 extends BBPatchAbstract */ class BBPatch_21 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'CREATE TABLE IF NOT EXISTS `mod_email_queue` ( `id` int(11) NOT NULL AUTO_INCREMENT, @@ -168,7 +168,7 @@ class BBPatch_21 extends BBPatchAbstract */ class BBPatch_20 extends BBPatchAbstract { - public function patch() + public function patch(): void { $tables = [ 'activity_admin_history' => ['created_at', 'updated_at'], @@ -246,7 +246,7 @@ class BBPatch_20 extends BBPatchAbstract */ class BBPatch_19 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `client` MODIFY `birthday` date;'; $this->execSql($q); @@ -258,7 +258,7 @@ class BBPatch_19 extends BBPatchAbstract */ class BBPatch_18 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `promo` ADD `client_groups` TEXT NULL AFTER `products`;'; $this->execSql($q); @@ -270,7 +270,7 @@ class BBPatch_18 extends BBPatchAbstract */ class BBPatch_17 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = "CREATE TABLE IF NOT EXISTS `session` ( `id` varchar(32) NOT NULL DEFAULT '', @@ -287,7 +287,7 @@ class BBPatch_17 extends BBPatchAbstract */ class BBPatch_16 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'CREATE TABLE IF NOT EXISTS `form` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, @@ -339,7 +339,7 @@ class BBPatch_16 extends BBPatchAbstract */ class BBPatch_15 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'CREATE TABLE IF NOT EXISTS `client_order_meta` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, @@ -385,7 +385,7 @@ class BBPatch_15 extends BBPatchAbstract */ class BBPatch_14 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `service_license` ADD `checked_at` VARCHAR( 35 ) DEFAULT NULL AFTER `plugin`;'; $this->execSql($q); @@ -397,7 +397,7 @@ class BBPatch_14 extends BBPatchAbstract */ class BBPatch_13 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `forum` ADD `category` VARCHAR( 255 ) NOT NULL AFTER `id`;'; $this->execSql($q); @@ -415,7 +415,7 @@ class BBPatch_13 extends BBPatchAbstract */ class BBPatch_12 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `admin` ADD `permissions` TEXT NULL DEFAULT NULL AFTER `api_token`;'; $this->execSql($q); @@ -427,7 +427,7 @@ class BBPatch_12 extends BBPatchAbstract */ class BBPatch_11 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `client_order` ADD `referred_by` VARCHAR( 255 ) NULL AFTER `config`;'; $this->execSql($q); @@ -475,7 +475,7 @@ class BBPatch_11 extends BBPatchAbstract */ class BBPatch_10 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `client` ADD `auth_type` VARCHAR( 255 ) NULL AFTER `role`;'; $this->execSql($q); @@ -489,7 +489,7 @@ class BBPatch_10 extends BBPatchAbstract */ class BBPatch_9 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = "UPDATE currency SET format = REPLACE(format, '%price%' , '{{price}}' ) WHERE 1;"; $this->execSql($q); @@ -501,7 +501,7 @@ class BBPatch_9 extends BBPatchAbstract */ class BBPatch_8 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `client` ADD `salt` VARCHAR(255) NULL AFTER `pass`;'; $this->execSql($q); @@ -516,7 +516,7 @@ class BBPatch_8 extends BBPatchAbstract */ class BBPatch_7 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `email_template` ADD `description` TEXT NULL AFTER `content`;'; $this->execSql($q); @@ -556,7 +556,7 @@ class BBPatch_7 extends BBPatchAbstract */ class BBPatch_6 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `transaction` CHANGE `amount` `amount` VARCHAR( 255 ) NULL DEFAULT NULL;'; $this->execSql($q); @@ -594,7 +594,7 @@ class BBPatch_6 extends BBPatchAbstract */ class BBPatch_5 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `extension_meta` ADD `client_id` INT NULL DEFAULT NULL AFTER `id`;'; $this->execSql($q); @@ -663,7 +663,7 @@ class BBPatch_5 extends BBPatchAbstract class BBPatch_4 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = "INSERT INTO `email_template` (`action_code`, `category`, `enabled`, `subject`, `content`) VALUES ('support_ticket_admin_close', 'support', 1, 'Support Ticket Closed', '
Ticket ID: #{{ticket.id}}
closed
{{company.signature}}
');"; $this->execSql($q); @@ -720,7 +720,7 @@ class BBPatch_4 extends BBPatchAbstract class BBPatch_3 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = "INSERT INTO `extension` (`type`, `name`, `status`, `version`) VALUES ('mod', 'branding', 'installed', '1.0.0');"; @@ -743,7 +743,7 @@ class BBPatch_3 extends BBPatchAbstract class BBPatch_2 extends BBPatchAbstract { - public function patch() + public function patch(): void { $q = 'ALTER TABLE `client_order` CHANGE `group_id` `group_id` VARCHAR( 255 ) NULL DEFAULT NULL;'; $this->execSql($q); @@ -776,7 +776,7 @@ class BBPatch_2 extends BBPatchAbstract class BBPatch_1 extends BBPatchAbstract { - public function patch() + public function patch(): void { $query = " INSERT INTO `email_template` (`action_code`, `category`, `enabled`, `subject`, `content`) VALUES @@ -791,9 +791,9 @@ class BBPatch_1 extends BBPatchAbstract abstract class BBPatchAbstract { - protected $pdo = null; - private $version = 0; - private $k = 'last_patch'; + protected mixed $pdo; + private int $version; + private string $k = 'last_patch'; public function __construct($di) { @@ -805,12 +805,12 @@ abstract class BBPatchAbstract abstract public function patch(); - public function donePatching() + public function donePatching(): void { $this->setParamValue($this->k, $this->version); } - protected function execSql($sql) + protected function execSql($sql): void { $stmt = $this->pdo->prepare($sql); try { @@ -820,17 +820,17 @@ abstract class BBPatchAbstract } } - public function getVersion() + public function getVersion(): int { return $this->version; } - public function isPatched() + public function isPatched(): bool { return $this->getParamValue($this->k, 0) >= $this->version; } - private function setParamValue($param, $value) + private function setParamValue($param, $value): void { if (is_null($this->getParamValue($param))) { $query = 'INSERT INTO setting (param, value, public, updated_at, created_at) VALUES (:param, :value, 1, :u, :c)'; @@ -862,13 +862,13 @@ abstract class BBPatchAbstract $patches = []; foreach (get_declared_classes() as $class) { - if (false !== strpos($class, 'BBPatch_')) { + if (str_contains($class, 'BBPatch_')) { $patches[] = $class; } } -require_once dirname(__FILE__) . '/bb-load.php'; -$di = include dirname(__FILE__) . '/bb-di.php'; +require_once __DIR__ . '/bb-load.php'; +$di = include __DIR__ . '/bb-di.php'; error_log('Executing FOSSBilling update script'); natsort($patches); @@ -888,4 +888,4 @@ foreach ($patches as $class) { } error_log('FOSSBilling update completed'); -echo 'Update completed. You are using FOSSBilling ' . Box_Version::VERSION . PHP_EOL; \ No newline at end of file +echo 'Update completed. You are using FOSSBilling ' . Box_Version::VERSION . PHP_EOL; diff --git a/src/index.php b/src/index.php index 7cb14f85c..0da24f8f5 100644 --- a/src/index.php +++ b/src/index.php @@ -12,18 +12,17 @@ * with this source code in the file LICENSE */ -require_once dirname(__FILE__).'/bb-load.php'; -$di = include dirname(__FILE__).'/bb-di.php'; +require_once __DIR__ .'/bb-load.php'; +$di = include __DIR__ .'/bb-di.php'; $url = $di['request']->getQuery('_url'); $admin_prefix = $di['config']['admin_area_prefix']; if (0 === strncasecmp($url, $admin_prefix, strlen($admin_prefix))) { $url = str_replace($admin_prefix, '', preg_replace('/\?.+/', '', $url)); $app = new Box_AppAdmin(); - $app->setUrl($url); } else { $app = new Box_AppClient(); - $app->setUrl($url); } +$app->setUrl($url); $di['translate'](); $app->setDi($di); echo $app->run(); diff --git a/src/install/install.php b/src/install/install.php index da23ea3ee..8313df145 100644 --- a/src/install/install.php +++ b/src/install/install.php @@ -13,16 +13,19 @@ * with this source code in the file LICENSE */ +use Box\Mod\Email\Service; +use Twig\Loader\FilesystemLoader; + /** * @return bool * * @see http://stackoverflow.com/a/2886224/2728507 */ -function isSSL() +function isSSL(): bool { return (!empty($_SERVER['HTTPS']) && 'off' !== $_SERVER['HTTPS']) - || 443 == $_SERVER['SERVER_PORT']; + || 443 === $_SERVER['SERVER_PORT']; } date_default_timezone_set('UTC'); @@ -31,7 +34,7 @@ error_reporting(E_ALL); ini_set('display_errors', 0); ini_set('display_startup_errors', 1); ini_set('log_errors', '1'); -ini_set('error_log', dirname(__FILE__) . '/logs/php_error.log'); +ini_set('error_log', __DIR__ . '/logs/php_error.log'); $protocol = isSSL() ? 'https' : 'http'; $url = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; @@ -39,30 +42,30 @@ $current_url = pathinfo($url, PATHINFO_DIRNAME); $root_url = str_replace('/install', '', $current_url) . '/'; define('BB_URL', $root_url); -define('BB_URL_INSTALL', BB_URL . 'install/'); -define('BB_URL_ADMIN', BB_URL . 'index.php?_url=/bb-admin'); +const BB_URL_INSTALL = BB_URL . 'install/'; +const BB_URL_ADMIN = BB_URL . 'index.php?_url=/bb-admin'; -define('BB_PATH_ROOT', realpath(dirname(__FILE__) . '/..')); -define('BB_PATH_LIBRARY', BB_PATH_ROOT . '/bb-library'); -define('BB_PATH_VENDOR', BB_PATH_ROOT . '/vendor'); -define('BB_PATH_INSTALL_THEMES', BB_PATH_ROOT . '/install'); -define('BB_PATH_THEMES', BB_PATH_ROOT . '/bb-themes'); -define('BB_PATH_LICENSE', BB_PATH_ROOT . '/LICENSE'); -define('BB_PATH_SQL', BB_PATH_ROOT . '/install/sql/structure.sql'); -define('BB_PATH_SQL_DATA', BB_PATH_ROOT . '/install/sql/content.sql'); -define('BB_PATH_INSTALL', BB_PATH_ROOT . '/install'); -define('BB_PATH_CONFIG', BB_PATH_ROOT . '/bb-config.php'); -define('BB_PATH_CRON', BB_PATH_ROOT . '/bb-cron.php'); -define('BB_PATH_LANGS', BB_PATH_ROOT . '/bb-locale'); +define('BB_PATH_ROOT', dirname(__DIR__)); +const BB_PATH_LIBRARY = BB_PATH_ROOT . '/bb-library'; +const BB_PATH_VENDOR = BB_PATH_ROOT . '/vendor'; +const BB_PATH_INSTALL_THEMES = BB_PATH_ROOT . '/install'; +const BB_PATH_THEMES = BB_PATH_ROOT . '/bb-themes'; +const BB_PATH_LICENSE = BB_PATH_ROOT . '/LICENSE'; +const BB_PATH_SQL = BB_PATH_ROOT . '/install/sql/structure.sql'; +const BB_PATH_SQL_DATA = BB_PATH_ROOT . '/install/sql/content.sql'; +const BB_PATH_INSTALL = BB_PATH_ROOT . '/install'; +const BB_PATH_CONFIG = BB_PATH_ROOT . '/bb-config.php'; +const BB_PATH_CRON = BB_PATH_ROOT . '/bb-cron.php'; +const BB_PATH_LANGS = BB_PATH_ROOT . '/bb-locale'; /* Config paths & templates */ -define('BB_PATH_HTACCESS', BB_PATH_ROOT . '/.htaccess'); -define('BB_PATH_HTACCESS_TEMPLATE', BB_PATH_ROOT . '/htaccess.txt'); +const BB_PATH_HTACCESS = BB_PATH_ROOT . '/.htaccess'; +const BB_PATH_HTACCESS_TEMPLATE = BB_PATH_ROOT . '/htaccess.txt'; -define('BB_HURAGA_CONFIG', BB_PATH_THEMES . '/huraga/config/settings_data.json'); -define('BB_HURAGA_CONFIG_TEMPLATE', BB_PATH_THEMES . '/huraga/config/settings_data.json.txt'); +const BB_HURAGA_CONFIG = BB_PATH_THEMES . '/huraga/config/settings_data.json'; +const BB_HURAGA_CONFIG_TEMPLATE = BB_PATH_THEMES . '/huraga/config/settings_data.json.txt'; // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, [ @@ -74,7 +77,7 @@ require BB_PATH_VENDOR . '/autoload.php'; final class Box_Installer { - private $session; + private Session $session; public function __construct() { @@ -82,7 +85,7 @@ final class Box_Installer $this->session = new Session(); } - public function run($action) + public function run($action): void { switch ($action) { case 'check-db': @@ -115,26 +118,26 @@ final class Box_Installer $name = $_POST['db_name']; if (!$this->canConnectToDatabase($host.';'.$port, $name, $user, $pass)) { throw new Exception('Could not connect to the database, or the database does not exist'); - } else { - $this->session->set('db_host', $host); - $this->session->set('db_port', $port); - $this->session->set('db_name', $name); - $this->session->set('db_user', $user); - $this->session->set('db_pass', $pass); } + $this->session->set('db_host', $host); + $this->session->set('db_port', $port); + $this->session->set('db_name', $name); + $this->session->set('db_user', $user); + $this->session->set('db_pass', $pass); + // Configuring administrator's account $admin_email = $_POST['admin_email']; $admin_pass = $_POST['admin_pass']; $admin_name = $_POST['admin_name']; if (!$this->isValidAdmin($admin_email, $admin_pass, $admin_name)) { throw new Exception('Administrator\'s account is not valid'); - } else { - $this->session->set('admin_email', $admin_email); - $this->session->set('admin_pass', $admin_pass); - $this->session->set('admin_name', $admin_name); } + $this->session->set('admin_email', $admin_email); + $this->session->set('admin_pass', $admin_pass); + $this->session->set('admin_name', $admin_name); + $this->session->set('license', 'FOSSBilling CE'); $this->makeInstall($this->session); $this->generateEmailTemplates(); @@ -145,8 +148,8 @@ final class Box_Installer if (is_dir($dir)) { $contents = scandir($dir); foreach ($contents as $content) { - if ('.' != $content && '..' != $content) { - if ('dir' == filetype($dir . '/' . $content)) { + if ('.' !== $content && '..' !== $content) { + if ('dir' === filetype($dir . '/' . $content)) { rmAllDir($dir . '/' . $content); } else { unlink($dir . '/' . $content); @@ -159,7 +162,7 @@ final class Box_Installer } try { rmAllDir('../install'); - } catch (Exception $e) { + } catch (Exception) { // do nothing } echo 'ok'; @@ -215,7 +218,7 @@ final class Box_Installer } } - private function render($name, $vars = []) + private function render($name, $vars = []): string { $options = [ 'paths' => [BB_PATH_INSTALL_THEMES], @@ -226,7 +229,7 @@ final class Box_Installer 'auto_reload' => true, 'cache' => false, ]; - $loader = new \Twig\Loader\FilesystemLoader($options['paths']); + $loader = new FilesystemLoader($options['paths']); $twig = new Twig\Environment($loader, $options); // $twig->addExtension(new Twig_Extension_Optimizer()); $twig->addGlobal('request', $_REQUEST); @@ -235,7 +238,7 @@ final class Box_Installer return $twig->render($name, $vars); } - private function getLicense() + private function getLicense(): bool|string { $path = BB_PATH_LICENSE; if (!file_exists($path)) { @@ -245,15 +248,15 @@ final class Box_Installer return file_get_contents($path); } - private function getPdo($host, $db, $user, $pass) + private function getPdo($host, $db, $user, $pass): PDO { - $pdo = new \PDO('mysql:host=' . $host, + $pdo = new PDO('mysql:host=' . $host, $user, $pass, [ - \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, - \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, - \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC, + PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, ] ); @@ -277,11 +280,11 @@ final class Box_Installer return $pdo; } - private function canConnectToDatabase($host, $db, $user, $pass) + private function canConnectToDatabase($host, $db, $user, $pass): bool { try { $this->getPdo($host, $db, $user, $pass); - } catch (\Exception $e) { + } catch (Exception $e) { error_log($e->getMessage()); return false; @@ -290,7 +293,7 @@ final class Box_Installer return true; } - private function isValidAdmin($email, $pass, $name) + private function isValidAdmin($email, $pass, $name): bool { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return false; @@ -307,7 +310,7 @@ final class Box_Installer return true; } - private function makeInstall($ns) + private function makeInstall($ns): bool { $this->_isValidInstallData($ns); $this->_createConfigurationFile($ns); @@ -325,16 +328,15 @@ final class Box_Installer $sql = preg_split('/\;[\r]*\n/ism', $sql); $sql = array_map('trim', $sql); - $err = ''; foreach ($sql as $query) { if (!trim($query)) { continue; } - $res = $pdo->query($query); + $pdo->query($query); } - $passwordObject = new \Box_Password(); + $passwordObject = new Box_Password(); $stmt = $pdo->prepare("INSERT INTO admin (role, name, email, pass, protected, created_at, updated_at) VALUES('admin', :admin_name, :admin_email, :admin_pass, 1, NOW(), NOW());"); $stmt->execute([ 'admin_name' => $ns->get('admin_name'), @@ -363,7 +365,7 @@ final class Box_Installer return true; } - private function _sendMail($ns) + private function _sendMail($ns): void { $admin_name = $ns->get('admin_name'); $admin_email = $ns->get('admin_email'); @@ -384,7 +386,7 @@ final class Box_Installer @mail($admin_email, $subject, $content); } - private function _createConfigurationFile($data) + private function _createConfigurationFile($data): void { $output = $this->_getConfigOutput($data); if (!@file_put_contents(BB_PATH_CONFIG, $output)) { @@ -392,7 +394,7 @@ final class Box_Installer } } - private function _getConfigOutput($ns) + private function _getConfigOutput($ns): string { // TODO: Why not just take the defaults from the bb.config.example.php file and modify accordingly? Also this method doesn't preserve the comments in the example config. $data = [ @@ -453,7 +455,7 @@ final class Box_Installer return $output; } - private function _isValidInstallData($ns) + private function _isValidInstallData($ns): void { if (!$this->canConnectToDatabase($ns->get('db_host'), $ns->get('db_name'), $ns->get('db_user'), $ns->get('db_pass'))) { throw new Exception('Can not connect to database'); @@ -464,12 +466,12 @@ final class Box_Installer } } - private function generateEmailTemplates() + private function generateEmailTemplates(): bool { define('BB_PATH_MODS', BB_PATH_ROOT . '/bb-modules'); - $emailService = new \Box\Mod\Email\Service(); - $di = $di = include BB_PATH_ROOT . '/bb-di.php'; + $emailService = new Service(); + $di = include BB_PATH_ROOT . '/bb-di.php'; $di['translate'](); $emailService->setDi($di);