From f8c6b14b3d0a554f90ed9a8fdc9c868f8ff86bca Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 19 May 2015 10:33:50 -0300 Subject: [PATCH 1/7] addEntityFilter to banProductReview --- .../Nexcessnet/Turpentine/Model/Observer/Ban.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php index ad6152961..984a26503 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php @@ -271,8 +271,14 @@ public function banCacheType( $eventObject ) { */ public function banProductReview( $eventObject ) { $patterns = array(); + /* @var $review \Mage_Review_Model_Review*/ $review = $eventObject->getObject(); - $products = $review->getProductCollection()->getItems(); + + /* @var $productCollection \Mage_Review_Model_Resource_Review_Product_Collection*/ + $productCollection = $review->getProductCollection(); + + $products = $productCollection->addEntityFilter((int)$review->getEntityPkValue())->getItems(); + $productIds = array_unique( array_map( create_function( '$p', 'return $p->getEntityId();' ), $products ) ); From a202dc8ded039b46f3e1a0bc101cfc864ef84792 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 27 Aug 2015 16:03:17 +0100 Subject: [PATCH 2/7] add check to admin to enable/disable restricting varnish to matching store URL --- .../Model/Varnish/Configurator/Abstract.php | 24 +++++++++++++++++-- .../Nexcessnet/Turpentine/etc/system.xml | 10 ++++++++ .../Nexcessnet/Turpentine/misc/version-3.vcl | 5 +--- .../Nexcessnet/Turpentine/misc/version-4.vcl | 5 +--- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index 96dd7dce5..97ef75885 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -219,7 +219,23 @@ public function getAllowedHostsRegex() { $pattern = '('.implode('|', array_map("preg_quote", $hosts)).')'; return $pattern; } - + + /** + * Get the Host normalization sub routine + * + * @return string + */ + protected function _vcl_sub_allowed_hosts_regex() { + $tpl = <<_formatTemplate( $tpl, array( + 'allowed_hosts_regex' => $this->getAllowedHostsRegex() ) ); + } + /** * Get the base url path regex * @@ -821,7 +837,6 @@ protected function _getTemplateVars() { 'admin_frontname' => $this->_getAdminFrontname(), 'normalize_host_target' => $this->_getNormalizeHostTarget(), 'url_base_regex' => $this->getBaseUrlPathRegex(), - 'allowed_hosts_regex' => $this->getAllowedHostsRegex(), 'url_excludes' => $this->_getUrlExcludes(), 'get_param_excludes' => $this->_getGetParamExcludes(), 'get_param_ignored' => $this->_getIgnoreGetParameters(), @@ -857,6 +872,11 @@ protected function _getTemplateVars() { 'esi_private_ttl' => Mage::helper( 'turpentine/esi' ) ->getDefaultEsiTtl(), ); + + if( (bool)Mage::getStoreConfig( 'turpentine_vcl/urls/bypass_cache_store_url') ) { + $vars['allowed_hosts'] = $this->_vcl_sub_allowed_hosts_regex(); + } + if( Mage::getStoreConfig( 'turpentine_vcl/normalization/encoding' ) ) { $vars['normalize_encoding'] = $this->_vcl_sub_normalize_encoding(); } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index b6fc98715..cc4a7b190 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -503,6 +503,16 @@ 0 0 + + + If enabled any URL in the client that does not start with a store URL will bypass the cache + select + turpentine/config_select_toggle + 11 + 1 + 0 + 0 + diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 0603b6bfe..3b8e3217f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -161,10 +161,7 @@ sub vcl_recv { error 403 "External ESI requests are not allowed"; } } - # if host is not allowed in magento pass to backend - if (req.http.host !~ "{{allowed_hosts_regex}}") { - return (pass); - } + {{allowed_hosts}} # no frontend cookie was sent to us AND this is not an ESI or AJAX call if (req.http.Cookie !~ "frontend=" && !req.http.X-Varnish-Esi-Method) { if (client.ip ~ crawler_acl || diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 89629ada7..ac3690894 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -159,10 +159,7 @@ sub vcl_recv { return (synth(403, "External ESI requests are not allowed")); } } - # if host is not allowed in magento pass to backend - if (req.http.host !~ "{{allowed_hosts_regex}}") { - return (pass); - } + {{allowed_hosts}} # no frontend cookie was sent to us AND this is not an ESI or AJAX call if (req.http.Cookie !~ "frontend=" && !req.http.X-Varnish-Esi-Method) { if (client.ip ~ crawler_acl || From fe1ac74994e7f2b63d44aed00edc477bb7b2e9fb Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Thu, 27 Aug 2015 22:49:44 +0200 Subject: [PATCH 3/7] ESI Decoder: Button to show block content. Added button to the ESI Decoder tool to show the content of the ESI block. Added auto-detect for Magento root. --- contrib/tools/esi-decoder.php | 36 ++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/contrib/tools/esi-decoder.php b/contrib/tools/esi-decoder.php index da6d093cb..7e066ac20 100644 --- a/contrib/tools/esi-decoder.php +++ b/contrib/tools/esi-decoder.php @@ -7,13 +7,21 @@ * * Make sure you place this utility on a protected spot on your web server where only authorized users can use it. * - * If the URLs you see in "varnishlog" or "varnishncsa", read this FAQ item: + * If the URLs you see in "varnishlog" or "varnishncsa" are not working because they are cut off, read this FAQ item: * https://github.com/nexcess/magento-turpentine/wiki/FAQ#im-using-varnishncsa-to-generate-logs-and-the-esi-urls-are-cut-off-how-do-i-get-the-full-url-in-the-logs * */ -// You might need to fix the path to your app/Mage.php on the line below. -require_once dirname(__FILE__).'/../../app/Mage.php'; +$tries = 5; +$dir = dirname(__FILE__); +while( $tries-- && ! file_exists( $dir . '/app/Mage.php' ) ) { + $dir = dirname($dir); // go one dir up +} +if ( file_exists( $dir . '/app/Mage.php' ) ) { + require_once $dir . '/app/Mage.php'; +} else { + die( "Could not find 'app/Mage.php'. Please edit esi-decoder.php and 'require' it manually." ); +} Mage::app(); $data = ( empty($_REQUEST['data']) ) ? '' : $_REQUEST['data']; @@ -69,7 +77,12 @@ } $dataHelper = Mage::helper( 'turpentine/data' ); $esiDataArray = $dataHelper->thaw( $processData ); -?> + $showContentUrl = Mage::getUrl( 'turpentine/esi/getBlock', + array( 'method' => 'esi', + 'ttl' => 0, + 'hmac' => $dataHelper->getHmac( $processData ), + 'data' => $processData ) ); + ?>
=  DATA  =
@@ -78,14 +91,19 @@ $refPreg = preg_quote( $esiHelper->getEsiReferrerParam(), '|' ); if ( preg_match('|'.$refPreg.'/([\w\.\-]+),*|', $data, $matches) ): $processData = $matches[1]; + ?> +
=  REFERRER  =
+
+
urlBase64Decode( $processData ) ); ?>
+
+ -
=  REFERRER  =
-
-
urlBase64Decode( $processData ) ); ?>
+
+
From b6d3972aeb91a20811bbf14cb355aec7d736e8aa Mon Sep 17 00:00:00 2001 From: Barry Carlyon Date: Fri, 28 Aug 2015 09:53:41 +0100 Subject: [PATCH 4/7] This fixes 904 The code here is doing a boolean check but the setting is saved as a string (no, yes or yes_admin) As per #904 this fixes the config geneator --- .../Model/Varnish/Configurator/Abstract.php | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index 96dd7dce5..dc3153262 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -39,10 +39,10 @@ static public function getFromSocket( $socket ) { return null; } switch( $version ) { - case '4.0': - return Mage::getModel( - 'turpentine/varnish_configurator_version4', - array( 'socket' => $socket ) ); + case '4.0': + return Mage::getModel( + 'turpentine/varnish_configurator_version4', + array( 'socket' => $socket ) ); case '3.0': return Mage::getModel( @@ -209,17 +209,17 @@ protected function _getNormalizeHostTarget() { * @return string */ public function getAllowedHostsRegex() { - $hosts = array(); - foreach( Mage::app()->getStores() as $store ) { - $hosts[] = parse_url( $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB , false ), PHP_URL_HOST ); - } - - $hosts = array_values(array_unique( $hosts )); - + $hosts = array(); + foreach( Mage::app()->getStores() as $store ) { + $hosts[] = parse_url( $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB , false ), PHP_URL_HOST ); + } + + $hosts = array_values(array_unique( $hosts )); + $pattern = '('.implode('|', array_map("preg_quote", $hosts)).')'; - return $pattern; + return $pattern; } - + /** * Get the base url path regex * @@ -292,7 +292,7 @@ protected function _getDefaultBackend() { 'first_byte_timeout' => $timeout . 's', 'between_bytes_timeout' => $timeout . 's', ); - if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) ) { + if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) { return $this->_vcl_director( 'default', $default_options ); } else { return $this->_vcl_backend( 'default', @@ -313,7 +313,7 @@ protected function _getAdminBackend() { 'first_byte_timeout' => $timeout . 's', 'between_bytes_timeout' => $timeout . 's', ); - if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) ) { + if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) { return $this->_vcl_director( 'admin', $admin_options ); } else { return $this->_vcl_backend( 'admin', @@ -821,7 +821,7 @@ protected function _getTemplateVars() { 'admin_frontname' => $this->_getAdminFrontname(), 'normalize_host_target' => $this->_getNormalizeHostTarget(), 'url_base_regex' => $this->getBaseUrlPathRegex(), - 'allowed_hosts_regex' => $this->getAllowedHostsRegex(), + 'allowed_hosts_regex' => $this->getAllowedHostsRegex(), 'url_excludes' => $this->_getUrlExcludes(), 'get_param_excludes' => $this->_getGetParamExcludes(), 'get_param_ignored' => $this->_getIgnoreGetParameters(), @@ -872,7 +872,7 @@ protected function _getTemplateVars() { if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_target' ) ) { $vars['normalize_cookie_target'] = $this->_getNormalizeCookieTarget(); } - + $customIncludeFile = $this->_getCustomIncludeFilename(); if( is_readable( $customIncludeFile ) ) { $vars['custom_vcl_include'] = file_get_contents( $customIncludeFile ); From f38cf734f29ee7a81654d2995d11e8aeff2487cb Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Tue, 1 Sep 2015 12:02:26 +0100 Subject: [PATCH 5/7] fix use of getStoreConfig in getDefaultBackend and getAdminBackend --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php index dc3153262..f33e798ff 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -292,7 +292,7 @@ protected function _getDefaultBackend() { 'first_byte_timeout' => $timeout . 's', 'between_bytes_timeout' => $timeout . 's', ); - if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) { + if ( Mage::getStoreConfig( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) { return $this->_vcl_director( 'default', $default_options ); } else { return $this->_vcl_backend( 'default', @@ -313,7 +313,7 @@ protected function _getAdminBackend() { 'first_byte_timeout' => $timeout . 's', 'between_bytes_timeout' => $timeout . 's', ); - if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) { + if ( Mage::getStoreConfig( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) { return $this->_vcl_director( 'admin', $admin_options ); } else { return $this->_vcl_backend( 'admin', From 9333bc2b70da804e4f16698a4536ef7ad2e0a9fa Mon Sep 17 00:00:00 2001 From: Richard Aspden Date: Tue, 1 Sep 2015 12:12:33 +0100 Subject: [PATCH 6/7] Fix for forced autodetection on socket when connecting, use specified version when possible --- .../Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php index 595b15384..94bbc8ab9 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -345,7 +345,9 @@ protected function _connect() { $banner['text'] ); } - $this->_version = $this->_determineVersion($banner['text']); + if ($this->_version == null) { // If autodetecting + $this->_version = $this->_determineVersion($banner['text']); + } return $this->isConnected(); } From 08dbebe7f899d6394d0cdece01c4693447b3db05 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 14 Sep 2015 09:44:27 -0300 Subject: [PATCH 7/7] refs Bump version. --- app/code/community/Nexcessnet/Turpentine/etc/config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 2ca4e4fa4..f49d4c5c1 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -20,7 +20,7 @@ - 0.6.5 + 0.6.6