Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

@@ -10,13 +10,14 @@
*/
/* Init */
define('REPORT_EXCEPTIONS', TRUE);
require_once str_replace( 'applications/core/interface/imageproxy/imageproxy.php', '', str_replace( '\\', '/', __FILE__ ) ) . 'init.php';
$url = \IPS\Request::i()->img;
/* Check for a valid key */
if ( !\IPS\Login::compareHashes( hash_hmac( "sha256", $url, \IPS\Settings::i()->site_secret_key ), (string) \IPS\Request::i()->key ) )
{
\IPS\Output::i()->sendOutput( NULL, 500 );
\IPS\Output::i()->sendOutput( NULL, 403 );
}
@@ -32,30 +33,36 @@ try
throw new \UnderflowException;
}
if ( $cacheEntry )
if ( $cacheEntry['location'] )
{
/* Set the cache expiration time */
$cacheExpires = new \DateTime; // Use of \DateTime is intentional, do not replace with \IPS\DateTime
$cacheExpires->setTimestamp( (int) $cacheEntry['cache_time'] );
$cacheExpires->add( new \DateInterval( sprintf( 'P%dD', \IPS\Settings::i()->image_proxy_cache_period ) ) );
$cacheExpires->add( new \DateInterval( ( \IPS\Settings::i()->image_proxy_cache_period ) ? sprintf( 'P%dD', \IPS\Settings::i()->image_proxy_cache_period ) : 'P1Y' ) );
$file = \IPS\File::get( 'core_Imageproxycache', $cacheEntry['location'] );
}
else
{
\IPS\Output::i()->sendOutput( NULL, 500 );
\IPS\Output::i()->sendOutput( NULL, 404 );
}
}
/* Not in cache - fetch and store */
catch ( \UnderflowException $e )
{
/* If the image proxy is disabled and the image isn't already stored, 301. This prevents images being stored when image proxy is disabled */
if( !\IPS\Settings::i()->remote_image_proxy )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::external( mb_substr( $url, 0, 2 ) === '//' ? "http:{$url}" : $url ) );
}
/* Set the cache expiration time */
$cacheExpires = new \DateTime; // Use of \DateTime is intentional, do not replace with \IPS\DateTime
$cacheExpires->add( new \DateInterval( sprintf( 'P%dD', \IPS\Settings::i()->image_proxy_cache_period ) ) );
$cacheExpires->add( new \DateInterval( ( \IPS\Settings::i()->image_proxy_cache_period ) ? sprintf( 'P%dD', \IPS\Settings::i()->image_proxy_cache_period ) : 'P1Y' ) );
/* First, let's store a placeholder row that we will later update - this prevents being able to DOS the server if the image is crazy */
\IPS\Db::i()->insert( 'core_image_proxy', array(
\IPS\Db::i()->replace( 'core_image_proxy', array(
'md5_url' => md5( $url ),
'location' => NULL,
'cache_time' => time(),
@@ -67,11 +74,10 @@ catch ( \UnderflowException $e )
/* Check it's a valid image */
$image = \IPS\Image::create( (string) $output );
$imageExtension = $image->type;
unset( $image );
}
catch ( \Exception $e )
{
\IPS\Output::i()->sendOutput( NULL, 500 );
\IPS\Output::i()->sendOutput( NULL, 502 );
}
/* Work out an appropriate filename */
@@ -86,16 +92,35 @@ catch ( \UnderflowException $e )
}
else
{
$filename = md5( uniqid() ) . '.' . $imageExtension;
$filename = md5( mt_rand() ) . '.' . $imageExtension;
}
/* Cache */
$file = \IPS\File::create( 'core_Imageproxycache', $filename, (string) $output, 'imageproxy' );
try
{
$thumbDims = \IPS\Settings::i()->attachment_image_size ? explode( 'x', \IPS\Settings::i()->attachment_image_size ) : array( 1000, 750 );
$image->resizeToMax( $thumbDims[0], $thumbDims[1] );
$imageData = (string) $image;
unset( $image, $output );
$file = \IPS\File::create( 'core_Imageproxycache', $filename, $imageData, 'imageproxy' );
$location = (string) $file;
}
catch( \DomainException $e )
{
\IPS\Log::log( $e, 'imageproxy' );
$location = NULL;
}
\IPS\Db::i()->replace( 'core_image_proxy', array(
'md5_url' => md5( $url ),
'location' => (string) $file,
'location' => $location,
'cache_time' => time(),
) );
if( $location === NULL )
{
\IPS\Output::i()->sendOutput( NULL, 404 );
}
}
try
@@ -106,7 +131,7 @@ try
'expires' => $cacheExpires->format( 'D, d M Y H:i:s \G\M\T' )
) );
}
catch ( \RuntimeException $e )
catch ( \RuntimeException $e )
{
\IPS\Log::debug( "Failed fetching proxy image", 'imageProxy' );
}