Resolve #910 MailSo\Base\Http::GetHost(): Return value must be of type string

This commit is contained in:
the-djmaze 2023-02-04 21:20:03 +01:00
parent fc5b26dfc2
commit be0348b324
4 changed files with 12 additions and 17 deletions

View file

@ -109,23 +109,18 @@ class Http
));
}
public function GetHost(bool $bWithRemoteUserData = false, bool $bWithoutWWW = true, bool $bWithoutPort = false) : string
public function GetHost(bool $bWithoutWWW = true, bool $bWithoutPort = false) : string
{
$sHost = static::GetServer('HTTP_HOST', '');
if (!\strlen($sHost)) {
$sName = static::GetServer('SERVER_NAME');
$sName = static::GetServer('SERVER_NAME', '');
$iPort = (int) static::GetServer('SERVER_PORT', 80);
$sHost = (\in_array($iPort, array(80, 433))) ? $sName : $sName.':'.$iPort;
}
if ($bWithoutWWW) {
$sHost = 'www.' === \substr(\strtolower($sHost), 0, 4) ? \substr($sHost, 4) : $sHost;
}
if ($bWithRemoteUserData) {
$sUser = \trim(static::GetServer('REMOTE_USER', ''));
$sHost = (\strlen($sUser) ? $sUser.'@' : '').$sHost;
if ($bWithoutWWW && 'www.' === \substr(\strtolower($sHost), 0, 4)) {
$sHost = \substr($sHost, 4);
}
return $bWithoutPort ? \preg_replace('/:\d+$/', '', $sHost) : $sHost;
@ -249,6 +244,6 @@ class Http
public function GetFullUrl() : string
{
return $this->GetScheme().'://'.$this->GetHost(true, false).$this->GetPath();
return $this->GetScheme().'://'.$this->GetHost(false).$this->GetPath();
}
}

View file

@ -147,7 +147,7 @@ class Actions
. '][' . \MailSo\Base\Http::GetServer('SERVER_SOFTWARE', '~')
. '][' . (\MailSo\Base\Utils::FunctionCallable('php_sapi_name') ? \php_sapi_name() : '~')
. '][Streams:' . \implode(',', \stream_get_transports())
. '][' . $oHttp->GetMethod() . ' ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false, false) . \MailSo\Base\Http::GetServer('REQUEST_URI', '') . ']'
. '][' . $oHttp->GetMethod() . ' ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false) . \MailSo\Base\Http::GetServer('REQUEST_URI', '') . ']'
);
}
@ -293,13 +293,13 @@ class Actions
if (false !== \strpos($sLine, '{request:domain}')) {
$sLine = \str_replace('{request:domain}',
Utils::UrlEncode($this->Http()->GetHost(false, true, true), $bUrlEncode), $sLine);
Utils::UrlEncode($this->Http()->GetHost(true, true), $bUrlEncode), $sLine);
}
if (false !== \strpos($sLine, '{request:domain-clear}')) {
$sLine = \str_replace('{request:domain-clear}',
Utils::UrlEncode(
\MailSo\Base\Utils::GetClearDomainName($this->Http()->GetHost(false, true, true)), $bUrlEncode), $sLine);
Utils::UrlEncode(\MailSo\Base\Utils::GetClearDomainName($this->Http()->GetHost(true, true)), $bUrlEncode),
$sLine);
}
$aClear['/\{request:([^}]*)\}/i'] = 'request';
@ -907,7 +907,7 @@ class Actions
protected function getAdditionalLogParamsByUserLogin(string $sLogin, bool $bAdmin = false): array
{
$sHost = $bAdmin ? $this->Http()->GetHost(false, true, true) : \MailSo\Base\Utils::GetDomainFromEmail($sLogin);
$sHost = $bAdmin ? $this->Http()->GetHost(true, true) : \MailSo\Base\Utils::GetDomainFromEmail($sLogin);
return array(
'{imap:login}' => $sLogin,
'{imap:host}' => $sHost,

View file

@ -37,7 +37,7 @@ trait UserAuth
$bAdded = false;
if ($this->Config()->Get('login', 'determine_user_domain', false)) {
$sUserHost = \trim($this->Http()->GetHost(false, true, true));
$sUserHost = \trim($this->Http()->GetHost(true, true));
$this->Logger()->Write('Determined user domain: ' . $sUserHost, \LOG_INFO, 'LOGIN');
$aDomainParts = \explode('.', $sUserHost);

View file

@ -39,7 +39,7 @@ abstract class Service
$oHttp = \MailSo\Base\Http::SingletonInstance();
if ($oConfig->Get('security', 'force_https', false) && !$oHttp->IsSecure()) {
\header('Location: https://'.$oHttp->GetHost(false, false).$oHttp->GetUrl());
\header('Location: https://'.$oHttp->GetHost(false).$oHttp->GetUrl());
exit;
}