This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 99c05c9
Showing
9 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor | ||
phpstan.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Thumbnail Processor Addon for Shopware 6 to use secure ImgProxy | ||
|
||
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) | ||
|
||
This plugins allows you to use your self-hosted secured ImgProxy. You will need Plugin `Thumbnail Processor`. | ||
|
||
## Install | ||
|
||
Download the plugin from the release page and enable it in shopware. | ||
|
||
## Usage | ||
Adjust the config. [See docs of ImgProxy.](https://docs.imgproxy.net/#/configuration?id=url-signature) | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
echo "Fix php files" | ||
php ../../../dev-ops/analyze/vendor/bin/php-cs-fixer fix --config=../../../vendor/shopware/platform/.php_cs.dist -vv . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
php "`dirname \"$0\"`"/phpstan-config-generator.php | ||
composer dump-autoload | ||
php ../../../dev-ops/analyze/vendor/bin/phpstan analyze --configuration phpstan.neon --autoload-file=../../../vendor/autoload.php src | ||
php ../../../dev-ops/analyze/vendor/bin/psalm --config=psalm.xml --show-info=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "frosh/platform-thumbnail-processor-secure-imgproxy", | ||
"keywords": [ | ||
"shopware", | ||
"backend", | ||
"admin", | ||
"media", | ||
"media manager", | ||
"cdn", | ||
"storage", | ||
"thumbnail" | ||
], | ||
"description": "This plugins allows you to use secured imgproxy in thumbnail processor", | ||
"version": "v1.0.0", | ||
"type": "shopware-platform-plugin", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "FriendsOfShopware", | ||
"homepage": "https://friendsofshopware.de" | ||
} | ||
], | ||
"require": { | ||
"shopware/core": "*", | ||
"frosh/platform-thumbnail-processor": "*" | ||
}, | ||
"extra": { | ||
"shopware-plugin-class": "Frosh\\ThumbnailProcessorImgProxy\\FroshPlatformThumbnailProcessorImgProxy", | ||
"label": { | ||
"de-DE": "ThumbnailProcessorImgProxy Addon", | ||
"en-GB": "ThumbnailProcessorImgProxy Addon" | ||
}, | ||
"description": { | ||
"de-DE": "Deutsche Beschreibung des Plugins", | ||
"en-GB": "English description of the plugin" | ||
} | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Frosh\\ThumbnailProcessorImgProxy\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Frosh\ThumbnailProcessorImgProxy; | ||
|
||
use Shopware\Core\Framework\Plugin; | ||
|
||
class FroshPlatformThumbnailProcessorImgProxy extends Plugin | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/master/src/Core/System/SystemConfig/Schema/config.xsd"> | ||
|
||
<card> | ||
<title>Configuration</title> | ||
|
||
<input-field> | ||
<name>Domain</name> | ||
<label>Domain</label> | ||
<placeholder>https://imgproxy.example.com/</placeholder> | ||
</input-field> | ||
|
||
<input-field> | ||
<name>imgproxykey</name> | ||
<label>KEY</label> | ||
</input-field> | ||
|
||
<input-field> | ||
<name>imgproxysalt</name> | ||
<label>SALT</label> | ||
</input-field> | ||
|
||
<input-field> | ||
<name>resizingType</name> | ||
<label>resizing_type</label> | ||
<defaultValue>fit</defaultValue> | ||
<placeholder>fit</placeholder> | ||
</input-field> | ||
|
||
<input-field> | ||
<name>gravity</name> | ||
<label>gravity</label> | ||
<defaultValue>sm</defaultValue> | ||
<placeholder>sm</placeholder> | ||
</input-field> | ||
|
||
<input-field type="bool"> | ||
<name>enlarge</name> | ||
<label>enlarge</label> | ||
<defaultValue>0</defaultValue> | ||
<placeholder>0</placeholder> | ||
</input-field> | ||
|
||
<input-field type="int"> | ||
<name>signatureSize</name> | ||
<label>signature size</label> | ||
<defaultValue>32</defaultValue> | ||
<placeholder>32</placeholder> | ||
</input-field> | ||
|
||
</card> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="Frosh\ThumbnailProcessorImgProxy\Service\ThumbnailUrlTemplate" decorates="Frosh\ThumbnailProcessor\Service\ThumbnailUrlTemplateInterface"> | ||
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/> | ||
<argument type="service" id="Frosh\ThumbnailProcessorImgProxy\Service\ThumbnailUrlTemplate.inner"/> | ||
</service> | ||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Frosh\ThumbnailProcessorImgProxy\Service; | ||
|
||
use Frosh\ThumbnailProcessor\Service\ThumbnailUrlTemplateInterface; | ||
use Shopware\Core\System\SystemConfig\SystemConfigService; | ||
|
||
class ThumbnailUrlTemplate implements ThumbnailUrlTemplateInterface | ||
{ | ||
/** @var string */ | ||
private $domain; | ||
|
||
/** @var string */ | ||
private $key; | ||
|
||
/** @var string */ | ||
private $salt; | ||
|
||
/** @var string */ | ||
private $resizingType; | ||
|
||
/** @var string */ | ||
private $gravity; | ||
|
||
/** @var int */ | ||
private $enlarge; | ||
|
||
/** @var int */ | ||
private $signatureSize; | ||
|
||
/** | ||
* @var ThumbnailUrlTemplateInterface | ||
*/ | ||
private $parent; | ||
|
||
public function __construct(SystemConfigService $systemConfigService, ThumbnailUrlTemplateInterface $parent) | ||
{ | ||
$this->domain = $systemConfigService->get('FroshPlatformThumbnailProcessorImgProxy.config.Domain'); | ||
$this->key = $systemConfigService->get('FroshPlatformThumbnailProcessorImgProxy.config.imgproxykey'); | ||
$this->salt = $systemConfigService->get('FroshPlatformThumbnailProcessorImgProxy.config.imgproxysalt'); | ||
$this->resizingType = $systemConfigService->get('FroshPlatformThumbnailProcessorImgProxy.config.resizingType') ?: 'fit'; | ||
$this->gravity = $systemConfigService->get('FroshPlatformThumbnailProcessorImgProxy.config.gravity') ?: 'sm'; | ||
$this->enlarge = $systemConfigService->get('FroshPlatformThumbnailProcessorImgProxy.config.enlarge') ?: 0; | ||
$this->signatureSize = $systemConfigService->get('FroshPlatformThumbnailProcessorImgProxy.config.signatureSize') ?: 32; | ||
$this->parent = $parent; | ||
} | ||
|
||
/** | ||
* @param string $mediaUrl | ||
* @param string $mediaPath | ||
* @param string $width | ||
* @param string $height | ||
*/ | ||
public function getUrl($mediaUrl, $mediaPath, $width, $height): string | ||
{ | ||
$keyBin = pack('H*', $this->key); | ||
$saltBin = pack('H*', $this->salt); | ||
|
||
if (empty($keyBin) || empty($saltBin)) { | ||
return $this->parent->getUrl($mediaUrl, $mediaPath, $width, $height); | ||
} | ||
|
||
$extension = pathinfo($mediaPath, PATHINFO_EXTENSION); | ||
$encodedUrl = rtrim(strtr(base64_encode($mediaUrl . '/' . $mediaPath), '+/', '-_'), '='); | ||
|
||
$path = "/{$this->resizingType}/{$width}/{$height}/{$this->gravity}/{$this->enlarge}/{$encodedUrl}.{$extension}"; | ||
$signature = hash_hmac('sha256', $saltBin . $path, $keyBin, true); | ||
|
||
if ($this->signatureSize !== 32) { | ||
$signature = pack('A' . $this->signatureSize, $signature); | ||
} | ||
|
||
$signature = rtrim(strtr(base64_encode($signature), '+/', '-_'), '='); | ||
|
||
return $this->domain . '/' . $signature . $path; | ||
} | ||
} |