From 98bf6c5ce3d410238e54d7ac8d48db20b2d31a72 Mon Sep 17 00:00:00 2001 From: Scott Wichser Date: Sun, 21 Feb 2016 19:51:17 -0600 Subject: [PATCH 1/3] Add a batch file wrapper so that commands run correctly on Windows. --- app/console.bat | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/console.bat diff --git a/app/console.bat b/app/console.bat new file mode 100644 index 00000000..43b3552f --- /dev/null +++ b/app/console.bat @@ -0,0 +1,3 @@ +@ECHO OFF +SET BIN_TARGET=%~dp0/console +php "%BIN_TARGET%" %* From baf24768bf251ccc95a8a51902e47201703665f4 Mon Sep 17 00:00:00 2001 From: Scott Wichser Date: Sun, 21 Feb 2016 19:54:44 -0600 Subject: [PATCH 2/3] Use the camo image proxy for Markdown images. --- src/Config/Configuration.php | 13 +++++++++++++ src/MarkdownEngine.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Config/Configuration.php b/src/Config/Configuration.php index 1f1e7fcb..05d80df0 100644 --- a/src/Config/Configuration.php +++ b/src/Config/Configuration.php @@ -125,6 +125,19 @@ public function getConfigTreeBuilder() ->integerNode('push_port')->defaultValue(8592)->end() ->end() ->end() + ->arrayNode('camo') + ->addDefaultsIfNotSet() + ->canBeEnabled() + ->info("Settings for the camo image proxy") + ->children() + ->scalarNode('base_url')->isRequired()->attribute('manual', true)->end() + ->scalarNode('key')->isRequired()->attribute('manual', true)->end() + ->arrayNode('whitelisted_domains') + ->prototype('scalar') + ->end() + ->end() + ->end() + ->end() ->end() ->end() diff --git a/src/MarkdownEngine.php b/src/MarkdownEngine.php index 3f5fe267..5a000526 100644 --- a/src/MarkdownEngine.php +++ b/src/MarkdownEngine.php @@ -13,6 +13,19 @@ */ class MarkdownEngine extends \Parsedown { + /** + * Constructor for our extension of Parsedown + */ + function __construct() + { + $this->camo = Array( + 'enabled' => \Service::getParameter('bzion.features.camo.enabled'), + 'key' => \Service::getParameter('bzion.features.camo.key'), + 'base_url' => \Service::getParameter('bzion.features.camo.base_url'), + 'whitelisted_domains' => \Service::getParameter('bzion.features.camo.whitelisted_domains') + ); + } + /** * Whether or not to allow images to be rendered. If set to false, it'll be rendered as a hyperlink * @var bool @@ -30,7 +43,21 @@ class MarkdownEngine extends \Parsedown protected function inlineImage($Excerpt) { if ($this->allowImages) { - return parent::inlineImage($Excerpt); + $Image = parent::inlineImage($Excerpt); + + if ($this->camo['enabled']) { + $parts = parse_url($Image['element']['attributes']['src']); + + if (!isset($parts['host']) || strlen($parts['host']) === 0) { + return null; + } + + if (!in_array($parts['host'], $this->camo['whitelisted_domains'])) { + $Image['element']['attributes']['src'] = $this->camo['base_url'].hash_hmac('sha1', $Image['element']['attributes']['src'], $this->camo['key']).'/'.bin2hex($Image['element']['attributes']['src']); + } + } + + return $Image; } return null; From 2294d30940c3ba6e266130f63f93251a5590b15a Mon Sep 17 00:00:00 2001 From: Scott Wichser Date: Sun, 21 Feb 2016 20:22:10 -0600 Subject: [PATCH 3/3] Make it work without the camo section in the configuration file. --- src/MarkdownEngine.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/MarkdownEngine.php b/src/MarkdownEngine.php index 5a000526..4b8e3fce 100644 --- a/src/MarkdownEngine.php +++ b/src/MarkdownEngine.php @@ -18,12 +18,14 @@ class MarkdownEngine extends \Parsedown */ function __construct() { - $this->camo = Array( - 'enabled' => \Service::getParameter('bzion.features.camo.enabled'), - 'key' => \Service::getParameter('bzion.features.camo.key'), - 'base_url' => \Service::getParameter('bzion.features.camo.base_url'), - 'whitelisted_domains' => \Service::getParameter('bzion.features.camo.whitelisted_domains') - ); + $this->camo = Array(); + $this->camo['enabled'] = \Service::getParameter('bzion.features.camo.enabled'); + + if ($this->camo['enabled']) { + $this->camo['key'] = \Service::getParameter('bzion.features.camo.key'); + $this->camo['base_url'] = \Service::getParameter('bzion.features.camo.base_url'); + $this->camo['whitelisted_domains'] = \Service::getParameter('bzion.features.camo.whitelisted_domains'); + } } /**