From ea0b7068b7b94ce48597b2de01c14b859ea4f08b Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Fri, 9 Feb 2024 22:00:00 -0800 Subject: [PATCH] Minor bugfixes / deprecation cleanups (#2128) * Minor bugfixes / deprecation cleanups * Making the tests happy --- src/library/Box/Url.php | 3 +++ src/library/FOSSBilling/SentryHelper.php | 2 +- src/library/Server/Account.php | 2 +- src/load.php | 15 ++++++++------- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/library/Box/Url.php b/src/library/Box/Url.php index 6b04a9b3b..f09763884 100644 --- a/src/library/Box/Url.php +++ b/src/library/Box/Url.php @@ -1,4 +1,5 @@ baseUri . $uri; if (!empty($params)) { @@ -51,6 +53,7 @@ class Box_Url implements FOSSBilling\InjectionAwareInterface public function adminLink($uri, $params = []) { + $uri ??= ''; $uri = trim($uri, '/'); $uri = ADMIN_PREFIX . '/' . $uri; diff --git a/src/library/FOSSBilling/SentryHelper.php b/src/library/FOSSBilling/SentryHelper.php index a5d8c6b76..6218a98ea 100644 --- a/src/library/FOSSBilling/SentryHelper.php +++ b/src/library/FOSSBilling/SentryHelper.php @@ -170,7 +170,7 @@ class SentryHelper /** * Tries to guess what type of webserver is being used and tags the Sentry event with it. */ - private static function estimateWebServer(): string + public static function estimateWebServer(): string { $serverSoftware = $_SERVER['SERVER_SOFTWARE'] ?? ''; if (function_exists('apache_get_version') || (stripos(strtolower($serverSoftware), 'apache') !== false)) { diff --git a/src/library/Server/Account.php b/src/library/Server/Account.php index 5499ec35f..440e519ee 100644 --- a/src/library/Server/Account.php +++ b/src/library/Server/Account.php @@ -29,7 +29,7 @@ class Server_Account * * @return string returns the username as a string */ - public function getUsername(): string + public function getUsername(): ?string { return $this->username; } diff --git a/src/load.php b/src/load.php index d0b00e4b8..e532d79e3 100644 --- a/src/load.php +++ b/src/load.php @@ -11,6 +11,7 @@ use FOSSBilling\Config; use FOSSBilling\Environment; +use FOSSBilling\SentryHelper; use Symfony\Component\Filesystem\Filesystem; use Whoops\Handler\PrettyPageHandler; use Whoops\Run; @@ -116,7 +117,8 @@ function checkSSL() $config = include PATH_CONFIG; if (isset($config['security']['force_https']) && $config['security']['force_https'] && !Environment::isCLI()) { if (!FOSSBilling\Tools::isHTTPS()) { - $url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $hostname = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST'] ?? ''; + $url = 'https://' . $hostname . $_SERVER['REQUEST_URI']; header('Location: ' . $url); exit; } @@ -131,9 +133,8 @@ function checkWebServer() $filesystem = new Filesystem(); // Check for missing required .htaccess on Apache and Apache-compatible web servers. - $isApache = function_exists('apache_get_version') ? true : false; - $serverSoftware = $_SERVER['SERVER_SOFTWARE'] ?? ''; - if ($isApache or (stripos($serverSoftware, 'apache') !== false) or stripos($serverSoftware, 'litespeed') !== false) { + $webSever = SentryHelper::estimateWebServer(); + if ($webSever === 'Apache' || $webSever === 'Litespeed') { if (!$filesystem->exists('.htaccess')) { throw new Exception('Missing .htaccess file', 5); } @@ -232,9 +233,6 @@ checkRequirements(); // Requirements met - load required packages/files. require PATH_VENDOR . DIRECTORY_SEPARATOR . 'autoload.php'; -// Check web server and web server settings. -checkWebServer(); - // Check for legacy BoxBilling/FOSSBilling files. checkLegacyFiles(); @@ -269,6 +267,9 @@ checkInstaller(); // Check if SSL required, and enforce if so. checkSSL(); +// Check web server and web server settings. +checkWebServer(); + // Set error and exception handlers, and default logging settings. ini_set('log_errors', '1'); ini_set('html_errors', false);