From a6b73670022883ff3b72a62891bfd9f34df225db Mon Sep 17 00:00:00 2001 From: "Fedor A. Fetisov" Date: Fri, 13 Oct 2017 19:41:00 +0300 Subject: [PATCH] Make possible to force secure URLs for iframe styles (Fixes #206) --- src/mibew/configs/routing.yml | 9 +++++++++ .../Mibew/Button/Generator/AbstractGenerator.php | 5 +++-- .../Mibew/Controller/Chat/StyleController.php | 13 +++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mibew/configs/routing.yml b/src/mibew/configs/routing.yml index 7f67e159..bcb01c0a 100644 --- a/src/mibew/configs/routing.yml +++ b/src/mibew/configs/routing.yml @@ -80,6 +80,15 @@ chat_user_popup_style: requirements: style: "[0-9A-Za-z_]*" +chat_user_popup_style_force_secure: + path: /chat/style/popup/{style}/force_secure + defaults: + _controller: Mibew\Controller\Chat\StyleController::loadPopupStyleAction + style: "" + force_secure: on + requirements: + style: "[0-9A-Za-z_]*" + chat_user_start: path: /chat defaults: diff --git a/src/mibew/libs/classes/Mibew/Button/Generator/AbstractGenerator.php b/src/mibew/libs/classes/Mibew/Button/Generator/AbstractGenerator.php index a803792d..fb9e64a4 100644 --- a/src/mibew/libs/classes/Mibew/Button/Generator/AbstractGenerator.php +++ b/src/mibew/libs/classes/Mibew/Button/Generator/AbstractGenerator.php @@ -187,7 +187,7 @@ abstract class AbstractGenerator implements GeneratorInterface $style_name = $this->getOption('chat_style'); if (!$style_name) { return $defaults + array( - 'styleLoader' => $this->generateUrl('chat_user_popup_style'), + 'styleLoader' => $this->generateUrl($this->getOption('force_secure') ? 'chat_user_popup_style_force_secure' : 'chat_user_popup_style') // An ugly way to solve the architecture issue ); } @@ -201,7 +201,7 @@ abstract class AbstractGenerator implements GeneratorInterface $defaults ) + array( 'styleLoader' => $this->generateUrl( - 'chat_user_popup_style', + $this->getOption('force_secure') ? 'chat_user_popup_style_force_secure' : 'chat_user_popup_style', // An ugly way to solve the architecture issue array('style' => $style_name) ), ); @@ -219,6 +219,7 @@ abstract class AbstractGenerator implements GeneratorInterface 'url' => $this->getChatUrl(), 'preferIFrame' => $this->getOption('prefer_iframe'), 'modSecurity' => $this->getOption('mod_security'), + 'forceSecure' => $this->getOption('force_secure'), ) + $this->getPopupStyle(); } diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/StyleController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/StyleController.php index 0e903250..ecf9839a 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/StyleController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/StyleController.php @@ -48,10 +48,15 @@ class StyleController extends AbstractController $response = new JsonResponse(); if ($configs['chat']['iframe']['css']) { $generator = $this->getAssetManager()->getUrlGenerator(); - $css = $generator->generate( - $style->getFilesPath() . '/' . $configs['chat']['iframe']['css'], - UrlGeneratorInterface::ABSOLUTE_URL - ); + $css = $request->attributes->get('force_secure') ? + $generator->generateSecure( + $style->getFilesPath() . '/' . $configs['chat']['iframe']['css'], + UrlGeneratorInterface::ABSOLUTE_URL + ) : + $generator->generate( + $style->getFilesPath() . '/' . $configs['chat']['iframe']['css'], + UrlGeneratorInterface::ABSOLUTE_URL + ); $response->setData($css); $response->setCallback('Mibew.Utils.loadStyleSheet'); }