From 8c047bc0da81c6925db15bef205d20da484b2cb2 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Mon, 25 Sep 2023 12:02:57 -0700 Subject: [PATCH] Fix to allow analysis to run against the installer (#1633) --- .github/workflows/php-ci.yml | 3 +-- phpstan.neon | 4 ++-- src/install/install.php | 39 ++++++++++++++++++------------------ src/load.php | 8 ++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/php-ci.yml b/.github/workflows/php-ci.yml index ce2a4170d..3ef315467 100644 --- a/.github/workflows/php-ci.yml +++ b/.github/workflows/php-ci.yml @@ -45,7 +45,6 @@ jobs: echo > ./src/data/log/license.log echo > ./src/data/log/application.log echo > ./src/data/log/php_error.log - rm -rf ./src/install mkdir /tmp/builds/ && tar -cvf /tmp/builds/build.tar ./ - name: Upload Build Archive for Tests @@ -62,7 +61,7 @@ jobs: matrix: php: [ 8.0 ] - name: PHPStan + name: PHP ${{ matrix.php }} - PHPStan steps: - uses: actions/download-artifact@v3 with: diff --git a/phpstan.neon b/phpstan.neon index 7e166832a..fcbe4ea45 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,10 +5,11 @@ parameters: level: 1 paths: - src + bootstrapFiles: + - src/load.php excludePaths: analyse: - src/vendor - - src/library/Registrar/Adapter/srsx.php - src/library/Box/Request.php - src/library/Box/Response.php - src/library/Model/Admin.php @@ -17,7 +18,6 @@ parameters: - src/library/Model/Product.php - src/library/Server/Manager/Custom.php - src/library/Server/Manager/Whm.php - - src/rector.php ignoreErrors: - '#^Function __trans not found\.$#' - '#^Function __pluralTrans not found\.$#' diff --git a/src/install/install.php b/src/install/install.php index 7d2528bdc..e4641276d 100644 --- a/src/install/install.php +++ b/src/install/install.php @@ -151,25 +151,8 @@ final class Box_Installer $this->generateEmailTemplates(); session_destroy(); // Try to remove install folder - function rmAllDir($dir) - { - if (is_dir($dir)) { - $contents = scandir($dir); - foreach ($contents as $content) { - if ('.' !== $content && '..' !== $content) { - if ('dir' === filetype($dir . DIRECTORY_SEPARATOR . $content)) { - rmAllDir($dir . DIRECTORY_SEPARATOR . $content); - } else { - unlink($dir . DIRECTORY_SEPARATOR . $content); - } - } - } - reset($contents); - rmdir($dir); - } - } try { - rmAllDir('..' . DIRECTORY_SEPARATOR . 'install'); + $this->rmAllDir('..' . DIRECTORY_SEPARATOR . 'install'); } catch (Exception) { // do nothing } @@ -503,6 +486,24 @@ final class Box_Installer return $emailService->templateBatchGenerate(); } + + public function rmAllDir($dir) + { + if (is_dir($dir)) { + $contents = scandir($dir); + foreach ($contents as $content) { + if ('.' !== $content && '..' !== $content) { + if ('dir' === filetype($dir . DIRECTORY_SEPARATOR . $content)) { + $this->rmAllDir($dir . DIRECTORY_SEPARATOR . $content); + } else { + unlink($dir . DIRECTORY_SEPARATOR . $content); + } + } + } + reset($contents); + rmdir($dir); + } + } } $action = $_GET['a'] ?? 'index'; @@ -511,4 +512,4 @@ $installer = new Box_Installer(); // Don't attempt to run the installer if we're not in a web environment. This is to prevent the installer from running when using prepare.php to prepare the environment for testing. if (!Environment::isCLI()) { $installer->run($action); -} \ No newline at end of file +} diff --git a/src/load.php b/src/load.php index 1ce2acb45..ec5db49d9 100644 --- a/src/load.php +++ b/src/load.php @@ -51,7 +51,7 @@ function checkInstaller() $filesystem = new Filesystem(); // Check if /install directory still exists after installation has been completed. - if ($filesystem->exists(PATH_CONFIG) && $filesystem->exists('install/index.php')) { + if ($filesystem->exists(PATH_CONFIG) && $filesystem->exists('install/install.php') && Environment::isProduction()) { throw new Exception('For security reasons, you have to delete the install directory before you can use FOSSBilling.', 2); } } @@ -214,9 +214,6 @@ checkConfig(); // All seems good, so load the config file. $config = require PATH_CONFIG; -// Verify the installer was removed. -checkInstaller(); - // Config loaded - set globals and relevant settings. date_default_timezone_set($config['i18n']['timezone'] ?? 'UTC'); define('BB_DEBUG', $config['debug']); @@ -237,6 +234,9 @@ $loader->addNamespace('Box\\Mod\\', PATH_MODS); $loader->checkClassMap(); $loader->register(); +// Verify the installer was removed. +checkInstaller(); + // Check if SSL required, and enforce if so. checkSSL();