From 58d87ef3096f36693c1b287795696e9070882805 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 15 Jul 2023 20:32:14 -0700 Subject: [PATCH] Standalone.civi-setup.php - Fix 'HTTP'/'HTTPS' detection on non-Apache environments --- setup/plugins/init/Standalone.civi-setup.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/setup/plugins/init/Standalone.civi-setup.php b/setup/plugins/init/Standalone.civi-setup.php index ca71d74ea9..7c0820b4c8 100644 --- a/setup/plugins/init/Standalone.civi-setup.php +++ b/setup/plugins/init/Standalone.civi-setup.php @@ -9,6 +9,17 @@ if (!defined('CIVI_SETUP')) { exit("Installation plugins must only be loaded by the installer.\n"); } +function _standalone_setup_scheme(): string { + if ((!empty($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] == 'https') || + (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || + (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443')) { + return 'https'; + } + else { + return 'http'; + } +} + \Civi\Setup::dispatcher() ->addListener('civi.setup.checkAuthorized', function (\Civi\Setup\Event\CheckAuthorizedEvent $e) { $model = $e->getModel(); @@ -82,7 +93,7 @@ if (!defined('CIVI_SETUP')) { // original: $model->cmsBaseUrl = $_SERVER['HTTP_ORIGIN'] ?: $_SERVER['HTTP_REFERER']; if (empty($model->cmsBaseUrl)) { // A buildkit install (which uses cv core:install) sets this correctly. But a standard composer-then-website type install does not. - $model->cmsBaseUrl = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']; + $model->cmsBaseUrl = _standalone_setup_scheme() . '://' . $_SERVER['HTTP_HOST']; } // These paths get set as -- 2.25.1