Skip to content

Commit

Permalink
Fix installing helpdesk without HTTPS via install.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Nov 4, 2023
1 parent f21054f commit 4a24df3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
9 changes: 2 additions & 7 deletions app/Http/Middleware/HttpsRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ public function handle($request, Closure $next)
{
if (\Helper::isHttps()) {
//$request->setTrustedProxies( [ $request->getClientIp() ], array_keys($this->headers));

if (//!$request->secure()
!in_array(strtolower($_SERVER['X_FORWARDED_PROTO'] ?? ''), array('https', 'on', 'ssl', '1'), true)
&& strtolower($_SERVER['HTTPS'] ?? '') != 'on'
&& ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') != 'https'
&& ($_SERVER['HTTP_CF_VISITOR'] ?? '') != '{"scheme":"https"}'
) {
//!$request->secure()
if (!\Helper::isCurrentUrlHttps()) {
return redirect()->secure($request->getRequestUri());
}
}
Expand Down
28 changes: 27 additions & 1 deletion app/Misc/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,33 @@ public static function getProtocol($url = '')

public static function isHttps($url = '')
{
return self::getProtocol($url) == 'https';
if (\Helper::isInstaller()) {
// In the Installer we determine HTTPS from URL.
return self::isCurrentUrlHttps();
} else {
return self::getProtocol($url) == 'https';
}
}

public static function isInstaller()
{
$request_uri = $_SERVER['REQUEST_URI'] ?? '';
$request_uri = preg_replace("#\?.*#", '', $request_uri);

return strstr($request_uri, '/install/') || preg_match("#/install$#", $request_uri);
}

public static function isCurrentUrlHttps()
{
if (in_array(strtolower($_SERVER['X_FORWARDED_PROTO'] ?? ''), array('https', 'on', 'ssl', '1'), true)
|| strtolower($_SERVER['HTTPS'] ?? '') == 'on'
|| ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') == 'https'
|| ($_SERVER['HTTP_CF_VISITOR'] ?? '') == '{"scheme":"https"}'
) {
return true;
} else {
return false;
}
}

public static function fixProtocol($url)
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function register()
{
// Forse HTTPS if using CloudFlare "Flexible SSL"
// https://support.cloudflare.com/hc/en-us/articles/200170416-What-do-the-SSL-options-mean-
if (\Helper::getProtocol() == 'https') {
if (\Helper::isHttps()) {
// $_SERVER['HTTPS'] = 'on';
// $_SERVER['SERVER_PORT'] = '443';
$this->app['url']->forceScheme('https');
Expand Down

0 comments on commit 4a24df3

Please sign in to comment.