mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Changes for #326
This commit is contained in:
parent
3d0421762a
commit
f39b1bb14d
4 changed files with 17 additions and 26 deletions
|
|
@ -236,7 +236,7 @@ export const
|
||||||
setAttribute('data-x-src-cid', value.slice(4));
|
setAttribute('data-x-src-cid', value.slice(4));
|
||||||
result.foundCIDs.push(value.slice(4));
|
result.foundCIDs.push(value.slice(4));
|
||||||
}
|
}
|
||||||
else if (/^https?:\/\//i.test(value) || '//' === value.slice(0, 2))
|
else if (/^(https?:)?\/\//i.test(value))
|
||||||
{
|
{
|
||||||
setAttribute('data-x-src', useProxy ? proxy(value) : value);
|
setAttribute('data-x-src', useProxy ? proxy(value) : value);
|
||||||
result.hasExternals = true;
|
result.hasExternals = true;
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,7 @@ export const
|
||||||
serverRequestRaw('Download', download, customSpecSuffix),
|
serverRequestRaw('Download', download, customSpecSuffix),
|
||||||
|
|
||||||
proxy = url =>
|
proxy = url =>
|
||||||
SERVER_PREFIX + '/ProxyExternal/' + btoa(url).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
|
SERVER_PREFIX + '/ProxyExternal/' + btoa(url.replace(/ /g, '%20')).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
|
||||||
/*
|
|
||||||
return './?/ProxyExternal/'.Utils::EncodeKeyValuesQ(array(
|
|
||||||
'Rnd' => \md5(\microtime(true)),
|
|
||||||
'Token' => Utils::GetConnectionToken(),
|
|
||||||
'Url' => $sUrl
|
|
||||||
)).'/';
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} type
|
* @param {string} type
|
||||||
|
|
|
||||||
|
|
@ -344,28 +344,19 @@ class ServiceActions
|
||||||
public function ServiceProxyExternal() : string
|
public function ServiceProxyExternal() : string
|
||||||
{
|
{
|
||||||
$sData = empty($this->aPaths[1]) ? '' : $this->aPaths[1];
|
$sData = empty($this->aPaths[1]) ? '' : $this->aPaths[1];
|
||||||
if (!empty($sData) && $this->Config()->Get('labs', 'use_local_proxy_for_external_images', false))
|
if ($sData && $this->Config()->Get('labs', 'use_local_proxy_for_external_images', false)) {
|
||||||
{
|
|
||||||
$this->oActions->verifyCacheByKey($sData);
|
$this->oActions->verifyCacheByKey($sData);
|
||||||
$aData = Utils::DecodeKeyValuesQ($sData);
|
$sUrl = \MailSo\Base\Utils::UrlSafeBase64Decode($sData);
|
||||||
if (!\is_array($aData) && $this->oActions->GetAccount()) {
|
if (!empty($sUrl)) {
|
||||||
$aData = [
|
\header('X-Content-Location: '.$sUrl);
|
||||||
// 'Rnd' => md5(\microtime(true)),
|
|
||||||
'Token' => Utils::GetConnectionToken(),
|
|
||||||
'Url' => \MailSo\Base\Utils::UrlSafeBase64Decode($sData)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
if (\is_array($aData) && !empty($aData['Token']) && !empty($aData['Url']) && $aData['Token'] === Utils::GetConnectionToken())
|
|
||||||
{
|
|
||||||
\header('X-Content-Location: '.$aData['Url']);
|
|
||||||
$tmp = \tmpfile();
|
$tmp = \tmpfile();
|
||||||
$HTTP = \SnappyMail\HTTP\Request::factory();
|
$HTTP = \SnappyMail\HTTP\Request::factory();
|
||||||
$HTTP->max_redirects = 2;
|
$HTTP->max_redirects = 2;
|
||||||
$HTTP->streamBodyTo($tmp);
|
$HTTP->streamBodyTo($tmp);
|
||||||
$oResponse = $HTTP->doRequest('GET', $aData['Url']);
|
$oResponse = $HTTP->doRequest('GET', $sUrl);
|
||||||
if ($oResponse && 200 === $oResponse->status
|
if ($oResponse && 200 === $oResponse->status
|
||||||
&& \str_starts_with($oResponse->getHeader('content-type'), 'image/')
|
&& \str_starts_with($oResponse->getHeader('content-type'), 'image/')
|
||||||
) {
|
) try {
|
||||||
$this->oActions->cacheByKey($sData);
|
$this->oActions->cacheByKey($sData);
|
||||||
\header('Content-Type: ' . $oResponse->getHeader('content-type'));
|
\header('Content-Type: ' . $oResponse->getHeader('content-type'));
|
||||||
\header('Cache-Control: public');
|
\header('Cache-Control: public');
|
||||||
|
|
@ -374,6 +365,10 @@ class ServiceActions
|
||||||
\rewind($tmp);
|
\rewind($tmp);
|
||||||
\fpassthru($tmp);
|
\fpassthru($tmp);
|
||||||
exit;
|
exit;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$msg = \get_class($HTTP) . ': ' . $e->getMessage();
|
||||||
|
\SnappyMail\Log::error('Proxy', $msg);
|
||||||
|
// \error_log(\get_class($HTTP) . ': ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,9 @@ class Response
|
||||||
{
|
{
|
||||||
if ($location = $this->getHeader('location')) {
|
if ($location = $this->getHeader('location')) {
|
||||||
$uri = \is_array($location) ? $location[0] : $location;
|
$uri = \is_array($location) ? $location[0] : $location;
|
||||||
if (!\preg_match('#^[a-z][a-z0-9\\+\\.\\-]+://[^/]+#i', $uri)) {
|
if (!\preg_match('#^([a-z][a-z0-9\\+\\.\\-]+:)?//[^/]+#i', $uri)) {
|
||||||
// no host
|
// no host
|
||||||
\preg_match('#^([a-z][a-z0-9\\+\\.\\-]+://[^/]+)(/[^\\?\\#]*)#i', $this->final_uri, $match);
|
\preg_match('#^((?:[a-z][a-z0-9\\+\\.\\-]+:)?//[^/]+)(/[^\\?\\#]*)#i', $this->final_uri, $match);
|
||||||
if ('/' === $uri[0]) {
|
if ('/' === $uri[0]) {
|
||||||
// absolute path
|
// absolute path
|
||||||
$uri = $match[1] . $uri;
|
$uri = $match[1] . $uri;
|
||||||
|
|
@ -88,6 +88,9 @@ class Response
|
||||||
$uri = $match[1] . \substr($match[2], 0, $rpos+1) . $uri;
|
$uri = $match[1] . \substr($match[2], 0, $rpos+1) . $uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ('//' === \substr($uri, 0, 2)) {
|
||||||
|
$uri = \explode(':', $this->request_uri)[0] . ':' . $uri;
|
||||||
|
}
|
||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue