mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-05 23:47:03 +03:00
Cleanup MailSo\Base\Http
This commit is contained in:
parent
51d9c3adbb
commit
09b3fa3141
5 changed files with 28 additions and 110 deletions
|
|
@ -31,66 +31,6 @@ class Http
|
||||||
return $oInstance;
|
return $oInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function HasQuery(string $sKey) : bool
|
|
||||||
{
|
|
||||||
return isset($_GET[$sKey]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $mDefault = null
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function GetQuery(string $sKey, $mDefault = null)
|
|
||||||
{
|
|
||||||
return isset($_GET[$sKey]) ? $_GET[$sKey] : $mDefault;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function GetQueryAsArray() : ?array
|
|
||||||
{
|
|
||||||
return isset($_GET) && \is_array($_GET) ? $_GET : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function HasPost(string $sKey) : bool
|
|
||||||
{
|
|
||||||
return isset($_POST[$sKey]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $mDefault = null
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function GetPost(string $sKey, $mDefault = null)
|
|
||||||
{
|
|
||||||
return isset($_POST[$sKey]) ? $_POST[$sKey] : $mDefault;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function GetPostAsArray() : ?array
|
|
||||||
{
|
|
||||||
return isset($_POST) && \is_array($_POST) ? $_POST : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function HasRequest(string $sKey) : bool
|
|
||||||
{
|
|
||||||
return isset($_REQUEST[$sKey]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $mDefault = null
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function GetRequest(string $sKey, $mDefault = null)
|
|
||||||
{
|
|
||||||
return isset($_REQUEST[$sKey]) ? $_REQUEST[$sKey] : $mDefault;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function HasServer(string $sKey) : bool
|
|
||||||
{
|
|
||||||
return isset($_SERVER[$sKey]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $mDefault = null
|
* @param mixed $mDefault = null
|
||||||
*
|
*
|
||||||
|
|
@ -101,26 +41,6 @@ class Http
|
||||||
return isset($_SERVER[$sKey]) ? $_SERVER[$sKey] : $mDefault;
|
return isset($_SERVER[$sKey]) ? $_SERVER[$sKey] : $mDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function HasEnv(string $sKey) : bool
|
|
||||||
{
|
|
||||||
return isset($_ENV[$sKey]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $mDefault = null
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function GetEnv(string $sKey, $mDefault = null)
|
|
||||||
{
|
|
||||||
return isset($_ENV[$sKey]) ? $_ENV[$sKey] : $mDefault;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ServerProtocol() : string
|
|
||||||
{
|
|
||||||
return $this->GetServer('SERVER_PROTOCOL', 'HTTP/1.0');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function GetMethod() : string
|
public function GetMethod() : string
|
||||||
{
|
{
|
||||||
return $this->GetServer('REQUEST_METHOD', '');
|
return $this->GetServer('REQUEST_METHOD', '');
|
||||||
|
|
@ -136,11 +56,6 @@ class Http
|
||||||
return ('GET' === $this->GetMethod());
|
return ('GET' === $this->GetMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetQueryString() : string
|
|
||||||
{
|
|
||||||
return $this->GetServer('QUERY_STRING', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function CheckLocalhost(string $sServer) : bool
|
public function CheckLocalhost(string $sServer) : bool
|
||||||
{
|
{
|
||||||
return \in_array(\strtolower(\trim($sServer)), array(
|
return \in_array(\strtolower(\trim($sServer)), array(
|
||||||
|
|
@ -229,7 +144,7 @@ class Http
|
||||||
|
|
||||||
if ($bWithRemoteUserData)
|
if ($bWithRemoteUserData)
|
||||||
{
|
{
|
||||||
$sUser = \trim($this->HasServer('REMOTE_USER') ? $this->GetServer('REMOTE_USER', '') : '');
|
$sUser = \trim($this->GetServer('REMOTE_USER', ''));
|
||||||
$sHost = (0 < \strlen($sUser) ? $sUser.'@' : '').$sHost;
|
$sHost = (0 < \strlen($sUser) ? $sUser.'@' : '').$sHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -529,7 +444,7 @@ class Http
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->StatusHeader(304);
|
static::StatusHeader(304);
|
||||||
$bResult = true;
|
$bResult = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -570,9 +485,8 @@ class Http
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function StatusHeader(int $iStatus, string $sCustomStatusText = '') : void
|
public static function StatusHeader(int $iStatus, string $sCustomStatusText = '') : void
|
||||||
{
|
{
|
||||||
$iStatus = (int) $iStatus;
|
|
||||||
if (99 < $iStatus)
|
if (99 < $iStatus)
|
||||||
{
|
{
|
||||||
$aStatus = array(
|
$aStatus = array(
|
||||||
|
|
@ -588,11 +502,15 @@ class Http
|
||||||
416 => 'Requested range not satisfiable'
|
416 => 'Requested range not satisfiable'
|
||||||
);
|
);
|
||||||
|
|
||||||
$sCustomStatusText = \trim($sCustomStatusText);
|
|
||||||
$sHeaderHead = \ini_get('cgi.rfc2616_headers') && false !== \strpos(\strtolower(\php_sapi_name()), 'cgi') ? 'Status:' : $this->ServerProtocol();
|
|
||||||
$sHeaderText = (0 === \strlen($sCustomStatusText) && isset($aStatus[$iStatus]) ? $aStatus[$iStatus] : $sCustomStatusText);
|
$sHeaderText = (0 === \strlen($sCustomStatusText) && isset($aStatus[$iStatus]) ? $aStatus[$iStatus] : $sCustomStatusText);
|
||||||
|
|
||||||
\header(\trim($sHeaderHead.' '.$iStatus.' '.$sHeaderText), true, $iStatus);
|
\http_response_code($iStatus);
|
||||||
|
if (isset($_SERVER['SERVER_PROTOCOL'])) {
|
||||||
|
\header("{$_SERVER['SERVER_PROTOCOL']} {$iStatus} {$sHeaderText}", true, $iStatus);
|
||||||
|
}
|
||||||
|
if (\ini_get('cgi.rfc2616_headers') && false !== \strpos(\strtolower(\php_sapi_name()), 'cgi')) {
|
||||||
|
\header("Status: {$iStatus} {$sHeaderText}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -602,9 +520,9 @@ class Http
|
||||||
return '' === $sUrl ? '/' : '/'.$sUrl.'/';
|
return '' === $sUrl ? '/' : '/'.$sUrl.'/';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetUrl()
|
public function GetUrl() : string
|
||||||
{
|
{
|
||||||
return $this->GetServer('REQUEST_URI', '');
|
return $_SERVER['REQUEST_URI'] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetFullUrl() : string
|
public function GetFullUrl() : string
|
||||||
|
|
|
||||||
|
|
@ -298,7 +298,7 @@ class Actions
|
||||||
|
|
||||||
public function ParseQueryString(): string
|
public function ParseQueryString(): string
|
||||||
{
|
{
|
||||||
$sQuery = \trim($this->Http()->GetQueryString());
|
$sQuery = \trim($_SERVER['QUERY_STRING'] ?? '');
|
||||||
|
|
||||||
$iPos = \strpos($sQuery, '&');
|
$iPos = \strpos($sQuery, '&');
|
||||||
if (0 < $iPos) {
|
if (0 < $iPos) {
|
||||||
|
|
@ -307,7 +307,7 @@ class Actions
|
||||||
|
|
||||||
$sQuery = \trim(\trim($sQuery), ' /');
|
$sQuery = \trim(\trim($sQuery), ' /');
|
||||||
|
|
||||||
$aSubQuery = $this->Http()->GetQuery('q');
|
$aSubQuery = $_GET['q'] ?? null;
|
||||||
if (\is_array($aSubQuery)) {
|
if (\is_array($aSubQuery)) {
|
||||||
$aSubQuery = \array_map(function ($sS) {
|
$aSubQuery = \array_map(function ($sS) {
|
||||||
return \trim(\trim($sS), ' /');
|
return \trim(\trim($sS), ' /');
|
||||||
|
|
@ -2021,7 +2021,7 @@ class Actions
|
||||||
if (!empty($sKey) && ($bForce || $this->Config()->Get('cache', 'enable', true) && $this->Config()->Get('cache', 'http', true))) {
|
if (!empty($sKey) && ($bForce || $this->Config()->Get('cache', 'enable', true) && $this->Config()->Get('cache', 'http', true))) {
|
||||||
$sIfNoneMatch = $this->Http()->GetHeader('If-None-Match', '');
|
$sIfNoneMatch = $this->Http()->GetHeader('If-None-Match', '');
|
||||||
if ($this->etag($sKey) === $sIfNoneMatch) {
|
if ($this->etag($sKey) === $sIfNoneMatch) {
|
||||||
$this->Http()->StatusHeader(304);
|
\MailSo\Base\Http::StatusHeader(304);
|
||||||
$this->cacheByKey($sKey);
|
$this->cacheByKey($sKey);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -303,7 +303,7 @@ trait Raw
|
||||||
{
|
{
|
||||||
$iFullContentLength = \strlen($sLoadedData);
|
$iFullContentLength = \strlen($sLoadedData);
|
||||||
|
|
||||||
$self->Http()->StatusHeader(206);
|
\MailSo\Base\Http::StatusHeader(206);
|
||||||
|
|
||||||
$iRangeStart = (int) $sRangeStart;
|
$iRangeStart = (int) $sRangeStart;
|
||||||
$iRangeEnd = (int) $sRangeEnd;
|
$iRangeEnd = (int) $sRangeEnd;
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ class Service
|
||||||
|
|
||||||
if ($bAdmin && !$this->oActions->Config()->Get('security', 'allow_admin_panel', true))
|
if ($bAdmin && !$this->oActions->Config()->Get('security', 'allow_admin_panel', true))
|
||||||
{
|
{
|
||||||
$this->oHttp->StatusHeader(403);
|
\MailSo\Base\Http::StatusHeader(403);
|
||||||
echo $this->oServiceActions->ErrorTemplates('Access Denied.',
|
echo $this->oServiceActions->ErrorTemplates('Access Denied.',
|
||||||
'Access to the SnappyMail Admin Panel is not allowed!', true);
|
'Access to the SnappyMail Admin Panel is not allowed!', true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ class ServiceActions
|
||||||
$aResponseItem = null;
|
$aResponseItem = null;
|
||||||
$oException = null;
|
$oException = null;
|
||||||
|
|
||||||
$sAction = $this->oHttp->GetPost('Action');
|
$sAction = $_POST['Action'] ?? null;
|
||||||
if (empty($sAction) && $this->oHttp->IsGet() && !empty($this->aPaths[2]))
|
if (empty($sAction) && $this->oHttp->IsGet() && !empty($this->aPaths[2]))
|
||||||
{
|
{
|
||||||
$sAction = $this->aPaths[2];
|
$sAction = $this->aPaths[2];
|
||||||
|
|
@ -93,7 +93,7 @@ class ServiceActions
|
||||||
{
|
{
|
||||||
if ($this->oHttp->IsPost() &&
|
if ($this->oHttp->IsPost() &&
|
||||||
$this->Config()->Get('security', 'csrf_protection', false) &&
|
$this->Config()->Get('security', 'csrf_protection', false) &&
|
||||||
$this->oHttp->GetPost('XToken', '') !== Utils::GetCsrfToken())
|
($_POST['XToken'] ?? '') !== Utils::GetCsrfToken())
|
||||||
{
|
{
|
||||||
throw new Exceptions\ClientException(Notifications::InvalidToken);
|
throw new Exceptions\ClientException(Notifications::InvalidToken);
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +107,7 @@ class ServiceActions
|
||||||
|
|
||||||
$this->Logger()->Write('Action: '.$sMethodName, \MailSo\Log\Enumerations\Type::NOTE, 'JSON');
|
$this->Logger()->Write('Action: '.$sMethodName, \MailSo\Log\Enumerations\Type::NOTE, 'JSON');
|
||||||
|
|
||||||
$aPost = $this->oHttp->GetPostAsArray();
|
$aPost = $_POST ?? null;
|
||||||
if ($aPost)
|
if ($aPost)
|
||||||
{
|
{
|
||||||
$this->oActions->SetActionParams($aPost, $sMethodName);
|
$this->oActions->SetActionParams($aPost, $sMethodName);
|
||||||
|
|
@ -222,7 +222,7 @@ class ServiceActions
|
||||||
if (\method_exists($this->oActions, 'Append') &&
|
if (\method_exists($this->oActions, 'Append') &&
|
||||||
\is_callable(array($this->oActions, 'Append')))
|
\is_callable(array($this->oActions, 'Append')))
|
||||||
{
|
{
|
||||||
$this->oActions->SetActionParams($this->oHttp->GetPostAsArray(), 'Append');
|
isset($_POST) && $this->oActions->SetActionParams($_POST, 'Append');
|
||||||
$bResponse = \call_user_func(array($this->oActions, 'Append'));
|
$bResponse = \call_user_func(array($this->oActions, 'Append'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -291,7 +291,7 @@ class ServiceActions
|
||||||
if (\method_exists($this->oActions, $sAction) &&
|
if (\method_exists($this->oActions, $sAction) &&
|
||||||
\is_callable(array($this->oActions, $sAction)))
|
\is_callable(array($this->oActions, $sAction)))
|
||||||
{
|
{
|
||||||
$aActionParams = $this->oHttp->GetQueryAsArray();
|
$aActionParams = isset($_GET) && \is_array($_GET) ? $_GET : null;
|
||||||
|
|
||||||
$aActionParams['File'] = $aFile;
|
$aActionParams['File'] = $aFile;
|
||||||
$aActionParams['Error'] = $iError;
|
$aActionParams['Error'] = $iError;
|
||||||
|
|
@ -372,7 +372,7 @@ class ServiceActions
|
||||||
|
|
||||||
if (!$bResult)
|
if (!$bResult)
|
||||||
{
|
{
|
||||||
$this->oHttp->StatusHeader(404);
|
\MailSo\Base\Http::StatusHeader(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -629,7 +629,7 @@ class ServiceActions
|
||||||
{
|
{
|
||||||
$this->oHttp->ServerNoCache();
|
$this->oHttp->ServerNoCache();
|
||||||
|
|
||||||
$sTo = \trim($this->oHttp->GetQuery('to', ''));
|
$sTo = \trim($_GET['to'] ?? '');
|
||||||
if (!empty($sTo) && \preg_match('/^mailto:/i', $sTo))
|
if (!empty($sTo) && \preg_match('/^mailto:/i', $sTo))
|
||||||
{
|
{
|
||||||
$oAccount = $this->oActions->GetAccountFromSignMeToken();
|
$oAccount = $this->oActions->GetAccountFromSignMeToken();
|
||||||
|
|
@ -660,7 +660,7 @@ class ServiceActions
|
||||||
$oAccount = null;
|
$oAccount = null;
|
||||||
$bLogout = true;
|
$bLogout = true;
|
||||||
|
|
||||||
$sSsoHash = $this->oHttp->GetRequest('hash', '');
|
$sSsoHash = $_REQUEST['hash'] ?? '';
|
||||||
if (!empty($sSsoHash))
|
if (!empty($sSsoHash))
|
||||||
{
|
{
|
||||||
$mData = null;
|
$mData = null;
|
||||||
|
|
@ -738,8 +738,8 @@ class ServiceActions
|
||||||
$oAccount = null;
|
$oAccount = null;
|
||||||
$bLogout = true;
|
$bLogout = true;
|
||||||
|
|
||||||
$sEmail = $this->oHttp->GetEnv('REMOTE_USER', '');
|
$sEmail = $_ENV['REMOTE_USER'] ?? '';
|
||||||
$sPassword = $this->oHttp->GetEnv('REMOTE_PASSWORD', '');
|
$sPassword = $_ENV['REMOTE_PASSWORD'] ?? '';
|
||||||
|
|
||||||
if (0 < \strlen($sEmail) && 0 < \strlen(\trim($sPassword)))
|
if (0 < \strlen($sEmail) && 0 < \strlen(\trim($sPassword)))
|
||||||
{
|
{
|
||||||
|
|
@ -772,7 +772,7 @@ class ServiceActions
|
||||||
$oAccount = null;
|
$oAccount = null;
|
||||||
$bLogout = true;
|
$bLogout = true;
|
||||||
|
|
||||||
switch (\strtolower($this->oHttp->GetRequest('Output', 'Redirect')))
|
switch (\strtolower($_REQUEST['Output'] ?? 'Redirect'))
|
||||||
{
|
{
|
||||||
case 'json':
|
case 'json':
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue