From bbd215687b4da5e968bccf9faccc06c6a7903624 Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 17 Jun 2013 16:28:53 -0400 Subject: [PATCH 001/311] cleanup bypass handling code --- .../Nexcessnet/Turpentine/Helper/Varnish.php | 7 +++-- .../turpentine/varnish_management.phtml | 28 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php index f87aa4729..8f12728de 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php @@ -162,10 +162,11 @@ public function shouldFixProductListToolbar() { * @return boolean */ public function isBypassEnabled() { - $cookieName = Mage::helper( 'turpentine' )->getBypassCookieName(); - $cookieValue = (bool)Mage::getModel( 'core/cookie' )->get($cookieName); + $bypassEnabled = (bool)Mage::getModel( 'core/cookie' )->get( + Mage::helper( 'turpentine/data' )->getBypassCookieName() ) === + $this->getSecretHandshake(); - return $cookieValue; + return $bypassEnabled; } /** diff --git a/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml b/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml index fcb057f48..f4a8a0f05 100644 --- a/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml +++ b/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml @@ -78,39 +78,37 @@ ->__('Download the generated VCL file.')?> - isBypassEnabled() === false): ?> - + + isBypassEnabled() ): ?> __('Create a cookie to bypass Varnish only for your session.')?> + ->__('Remove the bypass cookie and use again Varnish.')?> - - - + __('Remove the bypass cookie and use again Varnish.')?> + ->__('Create a cookie to bypass Varnish only for your session.')?> - - + + getChildHtml(); ?> From 4702a65bf0bda4e73f57c86c4fc12c809c155de3 Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 1 Jul 2013 14:40:23 -0400 Subject: [PATCH 002/311] inline subroutine for character savings --- .../community/Nexcessnet/Turpentine/misc/version-2.vcl | 8 ++------ .../community/Nexcessnet/Turpentine/misc/version-3.vcl | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index d9545af7d..f814c735a 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -50,11 +50,6 @@ sub remove_cache_headers { remove beresp.http.Age; } -sub remove_double_slashes { - # remove double slashes from the URL, for higher cache hit rate - set req.url = regsub(req.url, "(.*)//+(.*)", "\1/\2"); -} - sub generate_session { # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID # from SID URL param @@ -127,7 +122,8 @@ sub vcl_recv { return (pipe); } - call remove_double_slashes; + # remove double slashes from the URL, for higher cache hit rate + set req.url = regsuball(req.url, "(.*)//+(.*)", "\1/\2"); {{normalize_encoding}} {{normalize_user_agent}} diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 64d28ec3d..e0201db71 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -55,11 +55,6 @@ sub remove_cache_headers { unset beresp.http.Age; } -sub remove_double_slashes { - # remove double slashes from the URL, for higher cache hit rate - set req.url = regsub(req.url, "(.*)//+(.*)", "\1/\2"); -} - sub generate_session { # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID # from SID URL param @@ -129,7 +124,8 @@ sub vcl_recv { return (pipe); } - call remove_double_slashes; + # remove double slashes from the URL, for higher cache hit rate + set req.url = regsuball(req.url, "(.*)//+(.*)", "\1/\2"); {{normalize_encoding}} {{normalize_user_agent}} From dae648b466290ba30f181faa984cc30a2eac75ce Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 1 Jul 2013 14:47:48 -0400 Subject: [PATCH 003/311] make bypass cookie not restricted to https --- .../controllers/Varnish/ManagementController.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php index c25e85d2d..7a4f759f0 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php @@ -213,8 +213,14 @@ public function switchNavigationAction() { switch( $type ) { case 'default': - $cookieModel->set( $cookieName, - Mage::helper( 'turpentine/varnish' )->getSecretHandshake() ); + $cookieModel->set( + $cookieName, + Mage::helper( 'turpentine/varnish' )->getSecretHandshake(), + null, // period + null, // path + null, // domain + false, // secure + false ); // httponly $adminSession->addSuccess( Mage::helper( 'turpentine/data' ) ->__( 'The Varnish bypass cookie has been successfully added.' ) ); break; From 98c8624930008485ee00129992471d26abaed656 Mon Sep 17 00:00:00 2001 From: aheadley Date: Tue, 2 Jul 2013 11:29:43 -0400 Subject: [PATCH 004/311] set httponly flag on bypass cookie --- .../Turpentine/controllers/Varnish/ManagementController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php index 7a4f759f0..69fceade6 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php @@ -220,7 +220,7 @@ public function switchNavigationAction() { null, // path null, // domain false, // secure - false ); // httponly + true ); // httponly $adminSession->addSuccess( Mage::helper( 'turpentine/data' ) ->__( 'The Varnish bypass cookie has been successfully added.' ) ); break; From 6fa55c66c83abf4cc5e7ac61b0ec47d0f8cb5f87 Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 15 Jul 2013 14:04:21 -0400 Subject: [PATCH 005/311] allow using PROC env var to set number of processes for warm-cache.sh script --- util/warm-cache.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/util/warm-cache.sh b/util/warm-cache.sh index fa185c597..4952fe76c 100755 --- a/util/warm-cache.sh +++ b/util/warm-cache.sh @@ -19,6 +19,7 @@ SITEMAP_URL="$1" TMP_URL_FILE="/tmp/urls_$(cat /proc/sys/kernel/random/uuid).txt" +PROCS="${PROCS-$(grep processor /proc/cpuinfo | wc -l)}" echo '' | xpath -e '*' &>/dev/null @@ -41,8 +42,6 @@ EOF exit 1 fi -PROCS=$(grep processor /proc/cpuinfo | wc -l) - echo "Getting URLs from sitemap..." curl -ks "$SITEMAP_URL" | \ From efa9b7186c1d40984084d58bcd0fa978a55de073 Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 15 Jul 2013 14:11:29 -0400 Subject: [PATCH 006/311] reorder browser user agent check to correctly identify chrome on os x --- .../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 0172cb34a..332eb883d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -549,10 +549,10 @@ protected function _vcl_sub_normalize_user_agent() { set req.http.X-Normalized-User-Agent = "msie"; } else if (req.http.User-Agent ~ "Firefox") { set req.http.X-Normalized-User-Agent = "firefox"; - } else if (req.http.User-Agent ~ "Safari") { - set req.http.X-Normalized-User-Agent = "safari"; } else if (req.http.User-Agent ~ "Chrome") { set req.http.X-Normalized-User-Agent = "chrome"; + } else if (req.http.User-Agent ~ "Safari") { + set req.http.X-Normalized-User-Agent = "safari"; } else if (req.http.User-Agent ~ "Opera") { set req.http.X-Normalized-User-Agent = "opera"; } else { From 0b07963a0bdfc162ca6dafa22ec313bd9e9b95ab Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Fri, 2 Aug 2013 19:03:02 +0200 Subject: [PATCH 007/311] Added filters to prevent flush/ban matching all URLs like (?:myproduct|) and (?:) --- .../Nexcessnet/Turpentine/Helper/Ban.php | 11 +++++++++-- .../Turpentine/Model/Observer/Ban.php | 17 +++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Ban.php b/app/code/community/Nexcessnet/Turpentine/Helper/Ban.php index 9083afe6b..a468ebc44 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Ban.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Ban.php @@ -30,9 +30,16 @@ class Nexcessnet_Turpentine_Helper_Ban extends Mage_Core_Helper_Abstract { public function getProductBanRegex( $product ) { $urlPatterns = array(); foreach( $this->getParentProducts( $product ) as $parentProduct ) { - $urlPatterns[] = $parentProduct->getUrlKey(); + if ( $parentProduct->getUrlKey() ) { + $urlPatterns[] = $parentProduct->getUrlKey(); + } + } + if ( $product->getUrlKey() ) { + $urlPatterns[] = $product->getUrlKey(); + } + if ( empty($urlPatterns) ) { + $urlPatterns[] = "##_NEVER_MATCH_##"; } - $urlPatterns[] = $product->getUrlKey(); $pattern = sprintf( '(?:%s)', implode( '|', $urlPatterns ) ); return $pattern; } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php index 992be99d1..ad6152961 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php @@ -280,12 +280,17 @@ public function banProductReview( $eventObject ) { implode( '|', array_unique( $productIds ) ) ); $patterns[] = sprintf( '/review/product/view/id/%d/', $review->getEntityId() ); - $patterns[] = sprintf( '(?:%s)', implode( '|', - array_unique( array_map( - create_function( '$p', - 'return $p->getUrlModel()->formatUrlKey( $p->getName() );' ), - $products ) ) - ) ); + $productPatterns = array(); + foreach ( $products as $p ) { + $urlKey = $p->getUrlModel()->formatUrlKey( $p->getName() ); + if ( $urlKey ) { + $productPatterns[] = $urlKey; + } + } + if ( !empty($productPatterns) ) { + $productPatterns = array_unique( $productPatterns ); + $patterns[] = sprintf( '(?:%s)', implode( '|', $productPatterns ) ); + } $urlPattern = implode( '|', $patterns ); $result = $this->_getVarnishAdmin()->flushUrl( $urlPattern ); From a1cf0e32874f24aa282b1bb59692bce7f4e2508d Mon Sep 17 00:00:00 2001 From: nickbock Date: Wed, 21 Aug 2013 13:45:35 +0200 Subject: [PATCH 008/311] Fix: IE caching Ajax Requests version-3.vcl (works) --- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index e0201db71..fa4c92552 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -347,6 +347,9 @@ sub vcl_deliver { set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly"; unset resp.http.X-Varnish-Cookie-Expires; } + if (req.http.X-Varnish-Esi-Method == "ajax" && req.http.X-Varnish-Esi-Access == "private") { + set resp.http.Cache-Control = "no-cache"; + } if ({{debug_headers}} || client.ip ~ debug_acl) { # debugging is on, give some extra info set resp.http.X-Varnish-Hits = obj.hits; From 4412dd604d3f8fbe0b4d13b54343985b80705b28 Mon Sep 17 00:00:00 2001 From: nickbock Date: Wed, 21 Aug 2013 13:46:05 +0200 Subject: [PATCH 009/311] Fix: IE caching Ajax Requests version-2.vcl (not tested) --- app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index f814c735a..82a0bbd52 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -347,6 +347,9 @@ sub vcl_deliver { set resp.http.Set-Cookie = resp.http.Set-Cookie "; HttpOnly"; remove resp.http.X-Varnish-Cookie-Expires; } + if (req.http.X-Varnish-Esi-Method == "ajax" && req.http.X-Varnish-Esi-Access == "private") { + set resp.http.Cache-Control = "no-cache"; + } set resp.http.X-Opt-Debug-Headers = "{{debug_headers}}"; if (resp.http.X-Opt-Debug-Headers == "true" || client.ip ~ debug_acl ) { # debugging is on, give some extra info From bb3b3cb8193145583878a58c038fe6fbbc14e3dc Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 21 Aug 2013 14:14:28 -0400 Subject: [PATCH 010/311] fix compatiblity with kount extension --- app/code/community/Nexcessnet/Turpentine/misc/uuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/uuid.c b/app/code/community/Nexcessnet/Turpentine/misc/uuid.c index 2a6abfc2c..081879bb8 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/uuid.c +++ b/app/code/community/Nexcessnet/Turpentine/misc/uuid.c @@ -12,13 +12,13 @@ void generate_uuid(char* buf) { long c = lrand48(); long d = lrand48(); pthread_mutex_unlock(&lrand_mutex); - sprintf(buf, "frontend=%08lx-%04lx-%04lx-%04lx-%04lx%08lx", + sprintf(buf, "frontend=%08lx-%04lx-%04lx-%04lx-%04lx%04lx", a, b & 0xffff, (b & ((long)0x0fff0000) >> 16) | 0x4000, (c & 0x0fff) | 0x8000, (c & (long)0xffff0000) >> 16, - d + d & 0xffff ); return; } From c8f416cea2060818de0a7278fc290121e84b607a Mon Sep 17 00:00:00 2001 From: aheadley Date: Thu, 3 Oct 2013 17:48:50 -0400 Subject: [PATCH 011/311] fix missing xml declaration in package manifest --- build/build_package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build_package.py b/build/build_package.py index ec817d88d..806d89eb7 100755 --- a/build/build_package.py +++ b/build/build_package.py @@ -125,7 +125,7 @@ def build_tarball(self, pkg_xml, tarball_name=None, keep_pkg_xml=False): cdir = os.getcwd() os.chdir(self._base_dir) with open(manifest_filename, 'w') as xml_file: - ElementTree.ElementTree(pkg_xml).write(xml_file, 'utf-8') + ElementTree.ElementTree(pkg_xml).write(xml_file, 'utf-8', True) self._logger.debug('Wrote package XML') with tarfile.open(tarball_name, 'w:gz') as tarball: for filename in self._file_list: From aea98342fdd3eb290965cd2f4862ef2bc6a14af4 Mon Sep 17 00:00:00 2001 From: Mark Sanborn Date: Thu, 10 Oct 2013 14:34:51 -0700 Subject: [PATCH 012/311] Fixed extremely long initial page load before caching takes place --- .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index da43d543c..5e01bf89e 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -330,6 +330,9 @@ protected function _getBlockLayoutHandles( $block ) { foreach( $layout->getUpdate()->getHandles() as $handle ) { // check if this handle has any block or reference tags that // refer to this block or a child block + if ($handle == '') { + continue; + } if( $layoutXml->xpath( sprintf( '//%s//*[@name=\'%s\']', $handle, $blockName ) ) ) { $activeHandles[] = $handle; From a4a03cb0d2462624880d37bbe5d05781aae94d04 Mon Sep 17 00:00:00 2001 From: Steve Rice Date: Tue, 17 Sep 2013 17:02:33 -0700 Subject: [PATCH 013/311] Provide PrototypeJS and jQuery versions of AJAX updater, fixes #320 --- .../default/template/turpentine/ajax.phtml | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/app/design/frontend/base/default/template/turpentine/ajax.phtml b/app/design/frontend/base/default/template/turpentine/ajax.phtml index 9a10dabbc..7248695dc 100644 --- a/app/design/frontend/base/default/template/turpentine/ajax.phtml +++ b/app/design/frontend/base/default/template/turpentine/ajax.phtml @@ -36,31 +36,46 @@ if( $debugEnabled ) { * @link http://prototypejs.org/doc/latest/ajax/Ajax/Request/index.html * @link http://prototypejs.org/doc/latest/dom/Element/replace/index.html * @link http://madrobby.github.com/scriptaculous/effect-appear/ + * + * @link http://api.jquery.com/jQuery.ajax/ + * @link http://api.jquery.com/fadeIn/ */ -echo sprintf( ' -', - $blockTag, - $blockTag, - $this->getEsiUrl(), - ( $debugEnabled ? 'onComplete' : 'onSuccess' ), - $blockTag -); +HTML; if( $debugEnabled ) { echo sprintf( '', $this->getNameInLayout() ) . PHP_EOL; } From 39af5e07406e680a577cae3096de552b4bab5c58 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 23 Oct 2013 13:56:21 -0400 Subject: [PATCH 014/311] clean up handle blank name check --- .../Nexcessnet/Turpentine/Model/Observer/Esi.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 5e01bf89e..d5cef30c9 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -329,12 +329,11 @@ protected function _getBlockLayoutHandles( $block ) { foreach( $childBlocks as $blockName ) { foreach( $layout->getUpdate()->getHandles() as $handle ) { // check if this handle has any block or reference tags that - // refer to this block or a child block - if ($handle == '') { - continue; - } - if( $layoutXml->xpath( sprintf( - '//%s//*[@name=\'%s\']', $handle, $blockName ) ) ) { + // refer to this block or a child block, unless the handle name + // is blank + if( $handle !== '' && + $layoutXml->xpath( sprintf( + '//%s//*[@name=\'%s\']', $handle, $blockName ) ) ) { $activeHandles[] = $handle; } } From 0916e851e560a91ef839977ef1506c2e76568710 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 23 Oct 2013 14:08:53 -0400 Subject: [PATCH 015/311] use PR#334 to catch bad URIs for dummy requests --- .../Nexcessnet/Turpentine/Model/Dummy/Request.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php b/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php index 6452ef8a2..39840a271 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php @@ -40,7 +40,18 @@ class Nexcessnet_Turpentine_Model_Dummy_Request extends public function __construct( $uri=null ) { $this->_initFakeSuperGlobals(); $this->_fixupFakeSuperGlobals( $uri ); - parent::__construct( $uri ); + try { + parent::__construct( $uri ); + } catch( Exception $e ) { + Mage::helper( 'turpentine/debug' ) + ->logError( 'Bad URI given to dummy request: ' . $uri ); + Mage::helper( 'turpentine/debug' ) + ->logBackTrace(); + Mage::logException( $e ); + if( Mage::helper( 'turpentine/esi' )->getEsiDebugEnabled() ) { + throw $e; + } + } } /** @@ -542,7 +553,7 @@ protected function _fixupFakeSuperGlobals( $uri ) { /** * Check this request against the cms, standard, and default routers to fill * the module/controller/action/route fields. - * + * * TODO: This whole thing is a gigantic hack. Would be nice to have a * better solution. * From f3b2618bd9322a827623e792ff3584ac804ac2ca Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 23 Oct 2013 15:40:43 -0400 Subject: [PATCH 016/311] slightly shorten vcl templates --- .../Nexcessnet/Turpentine/misc/version-2.vcl | 14 +++++--------- .../Nexcessnet/Turpentine/misc/version-3.vcl | 15 +++++---------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 82a0bbd52..bc40a70d9 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -41,14 +41,6 @@ C{ {{debug_acl}} ## Custom Subroutines -sub remove_cache_headers { - # remove cache headers so we can set our own - remove beresp.http.Cache-Control; - remove beresp.http.Expires; - remove beresp.http.Pragma; - remove beresp.http.Cache; - remove beresp.http.Age; -} sub generate_session { # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID @@ -285,7 +277,11 @@ sub vcl_fetch { remove beresp.http.Set-Cookie; } # we'll set our own cache headers if we need them - call remove_cache_headers; + remove beresp.http.Cache-Control; + remove beresp.http.Expires; + remove beresp.http.Pragma; + remove beresp.http.Cache; + remove beresp.http.Age; if (beresp.http.X-Turpentine-Esi == "1") { esi; diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index fa4c92552..61cb9b66f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -46,15 +46,6 @@ import std; ## Custom Subroutines -sub remove_cache_headers { - # remove cache headers so we can set our own - unset beresp.http.Cache-Control; - unset beresp.http.Expires; - unset beresp.http.Pragma; - unset beresp.http.Cache; - unset beresp.http.Age; -} - sub generate_session { # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID # from SID URL param @@ -286,7 +277,11 @@ sub vcl_fetch { unset beresp.http.Set-Cookie; } # we'll set our own cache headers if we need them - call remove_cache_headers; + unset beresp.http.Cache-Control; + unset beresp.http.Expires; + unset beresp.http.Pragma; + unset beresp.http.Cache; + unset beresp.http.Age; if (beresp.http.X-Turpentine-Esi == "1") { set beresp.do_esi = true; From 900574f39f542cd887ce2c36c6f914089b3db0a4 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 23 Oct 2013 16:00:28 -0400 Subject: [PATCH 017/311] update changelog --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4527170d0..6c4e5d9bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -316,3 +316,21 @@ This is the first release of Turpentine marked "stable" in Magento Connect the cache (including ESI) for a single *admin* session (thanks to @alexandre-jardin) * Varnish will now strip the Google-related parameters from the request to increase cache hit-rate + +### RELEASE-0.5.5 + + * Made VCL templates slightly shorter to help with running into the inline + VCL character limit + * The `warm-cache.sh` script now respects the `PROC` environment variable for + the number of processes to use while warming the cache + * [#253] Fixed VCL to correctly identify Chrome on OS X + * [#281] Fixed unintentional flushing of full cache in some cases (thanks + @jeroenvermeulen) + * [#301] Fixed IE caching AJAX ESI includes (thanks @nickbock) + * [#320] AJAX ESI should be compatible with themes that use jQuery instead of + Prototype (thanks @steverice) + * [#334] Bad URIs that cause the dummy request creation to throw an exception + will now log the bad URI and hide the exception when debugging is disabled + (thanks @ajardin) + * [#337] Improve layout handle searching for ESI blocks in some cases (thanks + @sanbornm) From 0537d78b19b7e9d2646854f01a6e1637ed0dc349 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 23 Oct 2013 17:04:43 -0400 Subject: [PATCH 018/311] add php 5.5 for travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index fa9aea83e..8db1f9347 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 5.2 - 5.3 - 5.4 + - 5.5 install: - sudo apt-get install -qq python-markdown libxml-xpath-perl From e2f019cb2217e54d4171c878d101eb5d90597b59 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 23 Oct 2013 17:34:49 -0400 Subject: [PATCH 019/311] add C syntax checking --- build/build_package.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build/build_package.py b/build/build_package.py index 806d89eb7..b37f0e1a2 100755 --- a/build/build_package.py +++ b/build/build_package.py @@ -46,6 +46,7 @@ class Magento_Packager(object): BIN_PHP = os.environ.get('TURPENTINE_BIN_PHP', 'php') BIN_XMLLINT = os.environ.get('TURPENTINE_BIN_XMLLINT', 'xmllint') BIN_BASH = os.environ.get('TURPENTINE_BIN_BASH', 'bash') + BIN_GCC = os.environ.get('TURPENTINE_BIN_GCC', 'gcc') TARGET_DIRS = { 'magelocal': 'app/code/local', @@ -77,6 +78,7 @@ def do_syntax_check(self): '.xml': self._xml_syntax_check, '.sh': self._bash_syntax_check, '.bash': self._bash_syntax_check, + '.c': self._gcc_syntax_check, } def unsupported_syntax_check(filename): self._logger.debug('Skipping syntax check for unsupported file: %s', @@ -323,6 +325,10 @@ def _bash_syntax_check(self, filename): self._logger.debug('Checking Bash syntax for file: %s', filename) return self._run_quiet(self.BIN_BASH, '-n', filename) + def _gcc_syntax_check(self, filename): + self._logger.debug('Checking C syntax for file: %s', filename) + return self._run_quiet(self.BIN_GCC, '-fsyntax-only', filename) + def _run_quiet(self, *pargs): with open('/dev/null', 'w') as dev_null: return not bool(subprocess.call(pargs, stdin=None, stdout=dev_null, From 7afb98308021ce1d6f027841dcab99cc0cdd87b7 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 23 Oct 2013 17:37:42 -0400 Subject: [PATCH 020/311] add build-essential to travis packages --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8db1f9347..d861b4d87 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ php: - 5.5 install: - - sudo apt-get install -qq python-markdown libxml-xpath-perl + - sudo apt-get install -qq python-markdown libxml-xpath-perl build-essential script: - make all From c2a7fbfe2fd0fff7f6de895ebf9ca8c5fb347043 Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 4 Nov 2013 16:55:29 -0500 Subject: [PATCH 021/311] Revert "fix compatiblity with kount extension" This reverts commit bb3b3cb8193145583878a58c038fe6fbbc14e3dc. This fix didn't work completely, trying something else. --- app/code/community/Nexcessnet/Turpentine/misc/uuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/uuid.c b/app/code/community/Nexcessnet/Turpentine/misc/uuid.c index 081879bb8..2a6abfc2c 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/uuid.c +++ b/app/code/community/Nexcessnet/Turpentine/misc/uuid.c @@ -12,13 +12,13 @@ void generate_uuid(char* buf) { long c = lrand48(); long d = lrand48(); pthread_mutex_unlock(&lrand_mutex); - sprintf(buf, "frontend=%08lx-%04lx-%04lx-%04lx-%04lx%04lx", + sprintf(buf, "frontend=%08lx-%04lx-%04lx-%04lx-%04lx%08lx", a, b & 0xffff, (b & ((long)0x0fff0000) >> 16) | 0x4000, (c & 0x0fff) | 0x8000, (c & (long)0xffff0000) >> 16, - d & 0xffff + d ); return; } From 0e34e6513722cc57e9410a5f4992d4a2e4c46701 Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 4 Nov 2013 16:58:47 -0500 Subject: [PATCH 022/311] change generated SID for kount compat --- app/code/community/Nexcessnet/Turpentine/misc/uuid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/uuid.c b/app/code/community/Nexcessnet/Turpentine/misc/uuid.c index 2a6abfc2c..d1e44b613 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/uuid.c +++ b/app/code/community/Nexcessnet/Turpentine/misc/uuid.c @@ -12,7 +12,8 @@ void generate_uuid(char* buf) { long c = lrand48(); long d = lrand48(); pthread_mutex_unlock(&lrand_mutex); - sprintf(buf, "frontend=%08lx-%04lx-%04lx-%04lx-%04lx%08lx", + // SID must match this regex for Kount compat /^\w{1,36}$/ + sprintf(buf, "frontend=%08lx%04lx%04lx%04lx%04lx%08lx", a, b & 0xffff, (b & ((long)0x0fff0000) >> 16) | 0x4000, From 56789d0a61b6a238994e7eed446297b6bdbf9d5e Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 4 Nov 2013 17:01:40 -0500 Subject: [PATCH 023/311] fix typo in uuid comment --- app/code/community/Nexcessnet/Turpentine/misc/uuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/uuid.c b/app/code/community/Nexcessnet/Turpentine/misc/uuid.c index d1e44b613..a9faee747 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/uuid.c +++ b/app/code/community/Nexcessnet/Turpentine/misc/uuid.c @@ -12,7 +12,7 @@ void generate_uuid(char* buf) { long c = lrand48(); long d = lrand48(); pthread_mutex_unlock(&lrand_mutex); - // SID must match this regex for Kount compat /^\w{1,36}$/ + // SID must match this regex for Kount compat /^\w{1,32}$/ sprintf(buf, "frontend=%08lx%04lx%04lx%04lx%04lx%08lx", a, b & 0xffff, From 350b12463d62a55f2f2f91bcb150af828c8190fa Mon Sep 17 00:00:00 2001 From: Konrad Skrzynski Date: Tue, 5 Nov 2013 13:46:22 +0000 Subject: [PATCH 024/311] When ESI blocks are generated the scope of layout is limited only to ESI block definition. For example if layout XML looks like: the "child_block" won't be rendered. The fix will search for references to blocks defined withing ESI block across entire layout definition. modified: app/code/community/Nexcessnet/Turpentine/Helper/Data.php modified: app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php --- app/code/community/Nexcessnet/Turpentine/Helper/Data.php | 8 ++++++++ .../Nexcessnet/Turpentine/controllers/EsiController.php | 1 + 2 files changed, 9 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index 4d2dbfb6f..a28d12719 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -292,6 +292,14 @@ protected function _getChildBlockNames( $blockNode ) { foreach( $blockNode->xpath( './block | ./reference' ) as $childBlockNode ) { $blockNames = array_merge( $blockNames, $this->_getChildBlockNames( $childBlockNode ) ); + if ( $this->getLayout() instanceof Varien_Simplexml_Config ) { + foreach ( $this->getLayout()->getNode()->xpath( sprintf( + '//reference[@name=\'%s\']', (string)$childBlockNode['name'] ) ) as $childBlockLayoutNode ) { + $blockNames = array_merge( $blockNames, + $this->_getChildBlockNames( $childBlockLayoutNode ) ); + + } + } } } else { $blockNames = array(); diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index f492debbd..079fe6cd1 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -156,6 +156,7 @@ protected function _getEsiBlock( $esiData ) { $esiData->getNameInLayout() ) ) ); if( $blockNode instanceof Varien_Simplexml_Element ) { $nodesToGenerate = Mage::helper( 'turpentine/data' ) + ->setLayout( $layout ) ->getChildBlockNames( $blockNode ); Mage::getModel( 'turpentine/shim_mage_core_layout' ) ->shim_generateFullBlock( $blockNode ); From ef0ff37517e12749937ca4d4507bc7ba7b394752 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 6 Nov 2013 13:52:35 -0500 Subject: [PATCH 025/311] fix some minor code style issues --- app/code/community/Nexcessnet/Turpentine/Helper/Data.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index a28d12719..b680efba1 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -292,9 +292,10 @@ protected function _getChildBlockNames( $blockNode ) { foreach( $blockNode->xpath( './block | ./reference' ) as $childBlockNode ) { $blockNames = array_merge( $blockNames, $this->_getChildBlockNames( $childBlockNode ) ); - if ( $this->getLayout() instanceof Varien_Simplexml_Config ) { - foreach ( $this->getLayout()->getNode()->xpath( sprintf( - '//reference[@name=\'%s\']', (string)$childBlockNode['name'] ) ) as $childBlockLayoutNode ) { + if( $this->getLayout() instanceof Varien_Simplexml_Config ) { + foreach( $this->getLayout()->getNode()->xpath( sprintf( + '//reference[@name=\'%s\']', (string)$childBlockNode['name'] ) ) + as $childBlockLayoutNode ) { $blockNames = array_merge( $blockNames, $this->_getChildBlockNames( $childBlockLayoutNode ) ); From 220e549f7946e436cb8305c14a722c0d0bd9f2a3 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 6 Nov 2013 15:51:55 -0500 Subject: [PATCH 026/311] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c4e5d9bb..96cd85fa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -334,3 +334,4 @@ This is the first release of Turpentine marked "stable" in Magento Connect (thanks @ajardin) * [#337] Improve layout handle searching for ESI blocks in some cases (thanks @sanbornm) + * [#356] Fix ESI blocks not rendering child blocks (thanks @magedev) From 8775c5e7a1c20cc456d8f42e535850f6047b0714 Mon Sep 17 00:00:00 2001 From: Jan-Simon Winkelmann Date: Mon, 11 Nov 2013 09:19:08 +0100 Subject: [PATCH 027/311] Fix ESI detection for message block --- .../community/Nexcessnet/Turpentine/Block/Core/Messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php index a4e9c4494..20cf13d4e 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php @@ -353,7 +353,7 @@ protected function _fixMessages() { * @return boolean */ protected function _isEsiRequest() { - return is_subclass_of( Mage::app()->getRequest(), + return is_a( Mage::app()->getRequest(), 'Nexcessnet_Turpentine_Model_Dummy_Request' ); } } From c88816b3ad7cfa937127564847bb4f04f09f5348 Mon Sep 17 00:00:00 2001 From: aheadley Date: Tue, 19 Nov 2013 14:27:21 -0500 Subject: [PATCH 028/311] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96cd85fa9..215949661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -335,3 +335,5 @@ This is the first release of Turpentine marked "stable" in Magento Connect * [#337] Improve layout handle searching for ESI blocks in some cases (thanks @sanbornm) * [#356] Fix ESI blocks not rendering child blocks (thanks @magedev) + * Changed Varnish-generated session ID format for compatibility with the + SFC_Kount extension From 4470ad994e242c8dd4c70409a325e1d4a61a5005 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 20 Nov 2013 13:17:08 -0500 Subject: [PATCH 029/311] more gracefully handle advanced registry loading failures --- .../Turpentine/controllers/EsiController.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 079fe6cd1..44e8e3fab 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -137,8 +137,16 @@ protected function _getEsiBlock( $esiData ) { Mage::register( $key, $value, true ); } foreach( $esiData->getComplexRegistry() as $key => $data ) { - $value = Mage::getModel( $data['model'] )->load( $data['id'] ); - Mage::register( $key, $value, true ); + $value = Mage::getModel( $data['model'] ); + if( !is_object( $value ) ) { + Mage::helper( 'turpentine/debug' )->logWarn( + 'Failed to register key/model: %s as %s(%s)', + $key, $data['model'], $data['id'] ); + continue; + } else { + $value->load( $data['id'] ); + Mage::register( $key, $value, true ); + } } $layout = Mage::getSingleton( 'core/layout' ); Mage::getSingleton( 'core/design_package' ) From 172508b8236ddd138def506464eb693a667fcdcd Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 20 Nov 2013 13:18:36 -0500 Subject: [PATCH 030/311] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 215949661..43ac615b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -337,3 +337,5 @@ This is the first release of Turpentine marked "stable" in Magento Connect * [#356] Fix ESI blocks not rendering child blocks (thanks @magedev) * Changed Varnish-generated session ID format for compatibility with the SFC_Kount extension + * Failures during advanced registry loading in ESI requests should be handled + more gracefully From a93b8120211131f87ca985328773611f692f9ef0 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 20 Nov 2013 13:36:32 -0500 Subject: [PATCH 031/311] add initial release guide docs --- RELEASE_GUIDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 RELEASE_GUIDE.md diff --git a/RELEASE_GUIDE.md b/RELEASE_GUIDE.md new file mode 100644 index 000000000..5078d7eb8 --- /dev/null +++ b/RELEASE_GUIDE.md @@ -0,0 +1,5 @@ +# Release Guide + + - Bump version in `app/code/community/Nexcessnet/Turpentine/etc/config.xml` > + `config/modules/Nexcessnet_Turpentine/version` + - From 727ac56614392933c95ffda9cb48646122348f9f Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 20 Nov 2013 13:52:19 -0500 Subject: [PATCH 032/311] fill out release guide --- RELEASE_GUIDE.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/RELEASE_GUIDE.md b/RELEASE_GUIDE.md index 5078d7eb8..3dafa1ee3 100644 --- a/RELEASE_GUIDE.md +++ b/RELEASE_GUIDE.md @@ -1,5 +1,18 @@ # Release Guide - - Bump version in `app/code/community/Nexcessnet/Turpentine/etc/config.xml` > - `config/modules/Nexcessnet_Turpentine/version` - - + 1. Switch to *devel* branch + 2. Bump version in `app/code/community/Nexcessnet/Turpentine/etc/config.xml` + under `config/modules/Nexcessnet_Turpentine/version` + 3. Commit + 4. Merge *devel* into *master* + 5. Tag *master* branch with `release-` + 6. Push *master* and *devel* branches to GitHub + 7. Run make: `make all` + * The `all` is important, running bare `make` does not build the package + 8. Upload new package (from `build/`) to Magento Connect, use only the notes + from the latest section of the release notes from + `build/magento-connect-changelog-.html` in the release notes box + 9. Update the description box with contents of + `build/magento-connect-desc-.html` + 10. ??? + 11. Profit From 95bf21d410e48b9315afff44449c6475f94d64bc Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 20 Nov 2013 13:52:46 -0500 Subject: [PATCH 033/311] bump version to 0.5.5 --- 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 88b1920dd..1ddbe14f5 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -20,7 +20,7 @@ - 0.5.4 + 0.5.5 From 1444b07a37251154d3bad9dee3fae96ff1a8cea3 Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 25 Nov 2013 13:13:04 -0500 Subject: [PATCH 034/311] filter out deactivated categories in the crawler --- app/code/community/Nexcessnet/Turpentine/Helper/Cron.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php index a06cde033..881fd9a90 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php @@ -162,7 +162,9 @@ public function getAllUrls() { $baseUrl = $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_LINK ); $urls[] = $baseUrl; foreach( Mage::getModel( 'catalog/category' ) - ->getCollection( $storeId ) as $cat ) { + ->getCollection( $storeId ) + ->addIsActiveFilter() + as $cat ) { $urls[] = $cat->getUrl(); foreach( $cat->getProductCollection( $storeId ) ->addUrlRewrite( $cat->getId() ) From 95204db6bf73b2b6464f917e1c3b513f1025c6cc Mon Sep 17 00:00:00 2001 From: Gabriel Somoza Date: Wed, 27 Nov 2013 20:26:12 +0100 Subject: [PATCH 035/311] Workaround to bust event area cache after first event is fired. For EE >= 1.11 and CE > 1.6.0 --- .../Turpentine/Model/Shim/Mage/Core/App.php | 3 +++ .../Turpentine/Model/Shim/Mage/Core/Config.php | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php index d4627c45a..1a1293631 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php @@ -63,6 +63,9 @@ public function shim_addEventObserver( $area, $eventName, $obsName, $this->_shim_getConfig()->extend( $eventConfig, true ); // this wouldn't work if PHP had a sane object model $this->_shim_getApp()->_events[$area][$eventName] = null; + /* clear the event area cache because by the time this gets executed all events have already been + cached in Magento EE 1.11 */ + $this->_shim_getConfig()->unsetEventAreaCache($area); return $this; } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php index 77ac04716..6c7394076 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php @@ -37,4 +37,17 @@ public function shim_setClassNameCache( $groupType, $group, $class, $className ) $config->_classNameCache[$groupType][$group][$class] = $className; return $prevValue; } + + /** + * Clears event area cache so that Turpentine can dynamically add new event + * observers even after the first event was fired. + * + * @param $area string The config area to clear (e.g. 'global') + */ + public function unsetEventAreaCache($area) { + if(version_compare(Mage::getVersion(),'1.11.0', '>=') // enterprise + || version_compare(Mage::getVersion(), '1.6.0', '>=')) // community + unset($this->_eventAreas[$area]); + } + } From 03069c4d98dc15efc15d0ceb379554d9783c2646 Mon Sep 17 00:00:00 2001 From: Jon Wenmoth Date: Thu, 28 Nov 2013 11:01:13 +0000 Subject: [PATCH 036/311] Adding base64 encoded referrer URL to Esi request URLs for cache blocks with the scope of 'page'. This fixes a problem where the current URL was using the last page URL rather than the current URL. --- app/code/community/Nexcessnet/Turpentine/Helper/Esi.php | 9 +++++++++ .../Nexcessnet/Turpentine/Model/Observer/Esi.php | 8 ++++++++ .../Nexcessnet/Turpentine/controllers/EsiController.php | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index 98f8d005c..52c6acfe8 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -118,6 +118,15 @@ public function getEsiMethodParam() { public function getEsiHmacParam() { return self::ESI_HMAC_PARAM; } + + /** + * Get referrer param + * + * @return string + */ + public function getEsiReferrerParam() { + return Mage_Core_Controller_Varien_Action::PARAM_NAME_BASE64_URL; + } /** * Get whether ESI debugging is enabled or not diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index d5cef30c9..0a1c663f5 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -180,6 +180,8 @@ public function injectEsi( $eventObject ) { $dataParam = $esiHelper->getEsiDataParam(); $methodParam = $esiHelper->getEsiMethodParam(); $hmacParam = $esiHelper->getEsiHmacParam(); + $scopeParam = $esiHelper->getEsiScopeParam(); + $referrerParam = $esiHelper->getEsiReferrerParam(); $esiOptions = $this->_getDefaultEsiOptions( $esiOptions ); @@ -211,6 +213,12 @@ public function injectEsi( $eventObject ) { $urlOptions['_secure'] = Mage::app()->getStore() ->isCurrentlySecure(); } + if( $esiOptions[$scopeParam] == 'page' ) { + $urlOptions[$referrerParam] = Mage::helper('core')->urlEncode( + Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current')) + ); + } + $esiUrl = Mage::getUrl( 'turpentine/esi/getBlock', $urlOptions ); $blockObject->setEsiUrl( $esiUrl ); // avoid caching the ESI template output to prevent the double-esi- diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 44e8e3fab..bb521a29f 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -69,7 +69,7 @@ public function getBlockAction() { Mage::app()->setCurrentStore( Mage::app()->getStore( $esiData->getStoreId() ) ); $appShim = Mage::getModel( 'turpentine/shim_mage_core_app' ); - if( $referer = Mage::helper( 'core/http' )->getHttpReferer() ) { + if( $referer = $this->_getRefererUrl() ) { $dummyRequest = Mage::helper( 'turpentine/esi' ) ->getDummyRequest( $referer ); } else { From e5b6a4e1a4f84ab5c4389bb508b6dbd679854e9b Mon Sep 17 00:00:00 2001 From: Jon Wenmoth Date: Thu, 28 Nov 2013 11:21:58 +0000 Subject: [PATCH 037/311] Missed adding value for _current in getUrl call. --- app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 0a1c663f5..284db32bb 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -215,7 +215,7 @@ public function injectEsi( $eventObject ) { } if( $esiOptions[$scopeParam] == 'page' ) { $urlOptions[$referrerParam] = Mage::helper('core')->urlEncode( - Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current')) + Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true)) ); } From cd4122177ed559331db0732f87bdd731cc6604ee Mon Sep 17 00:00:00 2001 From: Gabriel Somoza Date: Thu, 5 Dec 2013 16:51:12 +0100 Subject: [PATCH 038/311] Use $this->_shim_getConfigShim() instead of $this->_shim_getConfig() to avoid fatal error. --- .../Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php index 1a1293631..c5898af95 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php @@ -65,7 +65,7 @@ public function shim_addEventObserver( $area, $eventName, $obsName, $this->_shim_getApp()->_events[$area][$eventName] = null; /* clear the event area cache because by the time this gets executed all events have already been cached in Magento EE 1.11 */ - $this->_shim_getConfig()->unsetEventAreaCache($area); + $this->_shim_getConfigShim()->unsetEventAreaCache($area); return $this; } From dde9f9b5a5984affce1d885f74c4da0ffc8263c3 Mon Sep 17 00:00:00 2001 From: Alexandre Jardin Date: Wed, 4 Dec 2013 17:33:12 +0100 Subject: [PATCH 039/311] Add composer.json --- composer.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 composer.json diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..845fed850 --- /dev/null +++ b/composer.json @@ -0,0 +1,16 @@ +{ + "name": "nexcess/magento-turpentine", + "type": "magento-module", + "license": "GPLv2+", + "description": "A Varnish extension for Magento.", + "homepage": "http://www.magentocommerce.com/magento-connect/2984.html", + "authors": [ + { + "name": "Alex Headley", + "email": "aheadley@waysaboutstuff.com" + } + ], + "require": { + "magento-hackathon/magento-composer-installer": "*" + } +} From 3405908ecece13c4b9960ab9bdffff4def1da28d Mon Sep 17 00:00:00 2001 From: Alexandre Jardin Date: Tue, 17 Dec 2013 15:18:13 +0100 Subject: [PATCH 040/311] Fix verification of the bypass cookie value --- .../community/Nexcessnet/Turpentine/Helper/Varnish.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php index 8f12728de..39ca2447b 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php @@ -162,9 +162,10 @@ public function shouldFixProductListToolbar() { * @return boolean */ public function isBypassEnabled() { - $bypassEnabled = (bool)Mage::getModel( 'core/cookie' )->get( - Mage::helper( 'turpentine/data' )->getBypassCookieName() ) === - $this->getSecretHandshake(); + $cookieName = Mage::helper( 'turpentine/data' )->getBypassCookieName(); + $cookieValue = Mage::getModel( 'core/cookie' )->get( $cookieName ); + + $bypassEnabled = (bool)$cookieValue === (bool)$this->getSecretHandshake(); return $bypassEnabled; } From d51f0f8dd519b6bb24eeada5ab1519a6b3e3b11c Mon Sep 17 00:00:00 2001 From: "Damian A. Pastorini" Date: Wed, 8 Jan 2014 10:50:46 -0300 Subject: [PATCH 041/311] Added .idea folder to gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 00531dd9d..997f34855 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/*.tgz build/*.html app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl +.idea From 9b08a15c1418de494c9f39858de51525f42594c7 Mon Sep 17 00:00:00 2001 From: "Damian A. Pastorini" Date: Wed, 8 Jan 2014 11:38:27 -0300 Subject: [PATCH 042/311] Turpentine - Cache management extended --- .../Turpentine/Block/Adminhtml/Cache/Grid.php | 31 ++++++++++++++ .../controllers/CacheController.php | 40 +++++++++++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 5 +++ .../default/default/layout/turpentine.xml | 3 ++ .../default/default/turpentine/cache-fix.js | 18 +++++++++ 5 files changed, 97 insertions(+) create mode 100644 app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php create mode 100644 app/code/community/Nexcessnet/Turpentine/controllers/CacheController.php create mode 100644 skin/adminhtml/default/default/turpentine/cache-fix.js diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php b/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php new file mode 100644 index 000000000..5da139385 --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php @@ -0,0 +1,31 @@ +_invalidatedTypes[$row->getId()])) { + $cell = ''.$this->__('Invalidated').''; + } else { + if ($row->getStatus()) { + $cell = ''.$value.''; + } else { + $cell = ''.$value.''; + } + } + return $cell; + } + +} diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/CacheController.php b/app/code/community/Nexcessnet/Turpentine/controllers/CacheController.php new file mode 100644 index 000000000..4f3015738 --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/controllers/CacheController.php @@ -0,0 +1,40 @@ +getRequest()->getParam('types'); + $allTypes = Mage::app()->useCache(); + + $updatedTypes = 0; + foreach ($types as $code) { + if (empty($allTypes[$code])) { + $allTypes[$code] = 1; + $updatedTypes++; + } + } + if ($updatedTypes > 0) { + // disable FPC when Varnish cache is enabled: + if($allTypes['turpentine_pages']==1 || $allTypes['turpentine_esi_blocks']==1) + { + $allTypes['full_page'] = 0; + } + // disable FPC when Varnish cache is enabled. + Mage::app()->saveUseCache($allTypes); + $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("%s cache type(s) enabled.", $updatedTypes)); + } + $this->_redirect('*/*'); + } + +} diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 1ddbe14f5..71771ae85 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -115,6 +115,11 @@ --> + + + Nexcessnet_Turpentine_Block_Adminhtml_Cache_Grid + + diff --git a/app/design/adminhtml/default/default/layout/turpentine.xml b/app/design/adminhtml/default/default/layout/turpentine.xml index c960780b7..f0e96d49f 100644 --- a/app/design/adminhtml/default/default/layout/turpentine.xml +++ b/app/design/adminhtml/default/default/layout/turpentine.xml @@ -19,6 +19,9 @@ --> + + skin_jsturpentine/cache-fix.js + Date: Wed, 8 Jan 2014 12:07:24 -0300 Subject: [PATCH 043/311] Fix for Adminhtml override. --- .../Turpentine/controllers/{ => Adminhtml}/CacheController.php | 2 +- app/code/community/Nexcessnet/Turpentine/etc/config.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) rename app/code/community/Nexcessnet/Turpentine/controllers/{ => Adminhtml}/CacheController.php (92%) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/CacheController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php similarity index 92% rename from app/code/community/Nexcessnet/Turpentine/controllers/CacheController.php rename to app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php index 4f3015738..00a46b621 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/CacheController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php @@ -6,7 +6,7 @@ require_once 'Mage/Adminhtml/controllers/CacheController.php'; -class Nexcessnet_Turpentine_CacheController extends Mage_Adminhtml_CacheController +class Nexcessnet_Turpentine_Adminhtml_CacheController extends Mage_Adminhtml_CacheController { /** diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 71771ae85..157624b24 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -370,6 +370,7 @@ Nexcessnet_Turpentine + Nexcessnet_Turpentine_Adminhtml From e96e8ac620f5a84d16a62d8e42159e9fc1e19789 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Thu, 13 Feb 2014 22:15:10 +0100 Subject: [PATCH 044/311] Implemented lurker-friendly-bans. This will prevent the ban list from growing big and slowing down Varnish. https://www.varnish-cache.org/docs/3.0/tutorial/purging.html#bans --- .../community/Nexcessnet/Turpentine/Model/Varnish/Admin.php | 4 +++- .../Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php | 2 ++ app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl | 6 ++++++ app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 6 ++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 37fa56307..b8a6f0318 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -43,7 +43,9 @@ public function flushUrl( $subPattern ) { foreach( Mage::helper( 'turpentine/varnish' )->getSockets() as $socket ) { $socketName = $socket->getConnectionString(); try { - $socket->ban_url( $subPattern ); + // We don't use "ban_url" here, because we want to do lurker friendly bans. + // Lurker friendly bans get cleaned up, so they don't slow down Varnish. + $socket->ban( 'obj.http.X-Varnish-URL', '~', $subPattern ); } catch( Mage_Core_Exception $e ) { $result[$socketName] = $e->getMessage(); continue; 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 b012f2cc1..db7580084 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -57,6 +57,8 @@ * @method array vcl_show() * @method array param_show() * @method array param_set() + * Warning: ban_url does a non-lurker-friendly ban. This means it is not cleaned + * up from the ban list. A long ban list will slow down Varnish. * @method array ban_url() * @method array ban() * @method array ban_list() diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index bc40a70d9..6e3b4e848 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -258,6 +258,10 @@ sub vcl_fetch { # set the grace period set req.grace = {{grace_period}}s; + # Store the URL in the response object, we need this to do lurker friendly bans later + set beresp.http.X-Varnish-Host = req.http.host; + set beresp.http.X-Varnish-URL = req.url; + # if it's part of magento... if (req.url ~ "{{url_base_regex}}") { # we handle the Vary stuff ourselves for now, we'll want to actually @@ -365,6 +369,8 @@ sub vcl_deliver { remove resp.http.X-Turpentine-Flush-Events; remove resp.http.X-Turpentine-Block; remove resp.http.X-Varnish-Session; + remove resp.http.X-Varnish-Host; + remove resp.http.X-Varnish-URL; # this header indicates the session that originally generated a cached # page. it *must* not be sent to a client in production with lax # session validation or that session can be hijacked diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 61cb9b66f..8669db22d 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -256,6 +256,10 @@ sub vcl_fetch { # set the grace period set req.grace = {{grace_period}}s; + # Store the URL in the response object, to be able to do lurker friendly bans later + set beresp.http.X-Varnish-Host = req.http.host; + set beresp.http.X-Varnish-URL = req.url; + # if it's part of magento... if (req.url ~ "{{url_base_regex}}") { # we handle the Vary stuff ourselves for now, we'll want to actually @@ -363,6 +367,8 @@ sub vcl_deliver { unset resp.http.X-Turpentine-Flush-Events; unset resp.http.X-Turpentine-Block; unset resp.http.X-Varnish-Session; + unset resp.http.X-Varnish-Host; + unset resp.http.X-Varnish-URL; # this header indicates the session that originally generated a cached # page. it *must* not be sent to a client in production with lax # session validation or that session can be hijacked From d4fdbd84ee0396d4c257f9574792c6a85160f081 Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 17 Feb 2014 13:40:05 -0500 Subject: [PATCH 045/311] update email addr in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 845fed850..d58ba8bfa 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "authors": [ { "name": "Alex Headley", - "email": "aheadley@waysaboutstuff.com" + "email": "aheadley@nexcess.net" } ], "require": { From 8410776d15b805b19d96160fa1a23ef0cad61050 Mon Sep 17 00:00:00 2001 From: aheadley Date: Tue, 18 Feb 2014 12:50:05 -0500 Subject: [PATCH 046/311] cleanup bypass cookie verification code --- app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php index 39ca2447b..9e648ba33 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php @@ -165,9 +165,7 @@ public function isBypassEnabled() { $cookieName = Mage::helper( 'turpentine/data' )->getBypassCookieName(); $cookieValue = Mage::getModel( 'core/cookie' )->get( $cookieName ); - $bypassEnabled = (bool)$cookieValue === (bool)$this->getSecretHandshake(); - - return $bypassEnabled; + return $cookieValue === $this->getSecretHandshake(); } /** From 82b2b55fcba4c00536c01c8323aabd445f673982 Mon Sep 17 00:00:00 2001 From: aheadley Date: Tue, 18 Feb 2014 13:00:01 -0500 Subject: [PATCH 047/311] update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43ac615b7..ee55ddc45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -339,3 +339,11 @@ This is the first release of Turpentine marked "stable" in Magento Connect SFC_Kount extension * Failures during advanced registry loading in ESI requests should be handled more gracefully + +### RELEASE-0.6.0 + + * [#362] Fixed ESI detection for message block (thanks @eth8505) + * [#380] Fixed ESI cache flushes not firing in some cases (thanks @gabrielsomoza) + * [#391] Added Magento Composer Installer support (thanks @ajardin) + * [#405] Fixed disabling Varnish bypass (thanks @ajardin) + * [#438] Implemented ban lurker-friendly bans (thanks @jeroenvermeulen) From 286c2991d5d79ca3e43ea21ede2d1640f17bd2aa Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Wed, 19 Feb 2014 00:08:56 +0100 Subject: [PATCH 048/311] Fix for caching static URL - v2 Bugfix for: The "check if the request is for part of magento" regex does not match for URLs starting with `/js/`, `/skin/` and `/media/` when a shop has enabled *Add Store Code to Urls* for all stores. This causes caching not to work for these URLs when a cookie is set. This fix is the improved version of https://github.com/nexcess/magento-turpentine/pull/399 after the discussion there with @aheadley --- .../Model/Varnish/Configurator/Abstract.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 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 332eb883d..1fb1d1e7a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -211,19 +211,21 @@ public function getBaseUrlPathRegex() { } /** - * Get the path part of each store's base URL + * Get the path part of each store's base URL and static file URLs * * @return array */ protected function _getBaseUrlPaths() { $paths = array(); - foreach( Mage::app()->getStores() as $storeId => $store ) { - $paths[] = parse_url( $store->getBaseUrl( - Mage_Core_Model_Store::URL_TYPE_LINK, false ), - PHP_URL_PATH ); - $paths[] = parse_url( $store->getBaseUrl( - Mage_Core_Model_Store::URL_TYPE_LINK, true ), - PHP_URL_PATH ); + foreach( Mage::app()->getStores() as $store ) { + $linkTypes = array( Mage_Core_Model_Store::URL_TYPE_LINK, + Mage_Core_Model_Store::URL_TYPE_JS, + Mage_Core_Model_Store::URL_TYPE_SKIN, + Mage_Core_Model_Store::URL_TYPE_MEDIA ); + foreach ( $linkTypes as $linkType ) { + $paths[] = parse_url( $store->getBaseUrl( $linkType , false ), PHP_URL_PATH ); + $paths[] = parse_url( $store->getBaseUrl( $linkType , true ), PHP_URL_PATH ); + } } $paths = array_unique( $paths ); usort( $paths, create_function( '$a, $b', From 7087513d5908a0b0518ce032cb65f670e5b74b20 Mon Sep 17 00:00:00 2001 From: aheadley Date: Tue, 18 Feb 2014 18:29:07 -0500 Subject: [PATCH 049/311] code style fixes for #443 --- .../Model/Varnish/Configurator/Abstract.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 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 1fb1d1e7a..29eef12f6 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -217,14 +217,16 @@ public function getBaseUrlPathRegex() { */ protected function _getBaseUrlPaths() { $paths = array(); + $linkTypes = array( Mage_Core_Model_Store::URL_TYPE_LINK, + Mage_Core_Model_Store::URL_TYPE_JS, + Mage_Core_Model_Store::URL_TYPE_SKIN, + Mage_Core_Model_Store::URL_TYPE_MEDIA ); foreach( Mage::app()->getStores() as $store ) { - $linkTypes = array( Mage_Core_Model_Store::URL_TYPE_LINK, - Mage_Core_Model_Store::URL_TYPE_JS, - Mage_Core_Model_Store::URL_TYPE_SKIN, - Mage_Core_Model_Store::URL_TYPE_MEDIA ); - foreach ( $linkTypes as $linkType ) { - $paths[] = parse_url( $store->getBaseUrl( $linkType , false ), PHP_URL_PATH ); - $paths[] = parse_url( $store->getBaseUrl( $linkType , true ), PHP_URL_PATH ); + foreach( $linkTypes as $linkType ) { + $paths[] = parse_url( $store->getBaseUrl( $linkType , false ), + PHP_URL_PATH ); + $paths[] = parse_url( $store->getBaseUrl( $linkType , true ), + PHP_URL_PATH ); } } $paths = array_unique( $paths ); From d39969b98098983f34a4c264f58e2e7141fd7404 Mon Sep 17 00:00:00 2001 From: evensisftw Date: Wed, 19 Feb 2014 10:29:31 +0000 Subject: [PATCH 050/311] Update Cron.php Resolves incompatibility with mageworx_xsitemap module. --- app/code/community/Nexcessnet/Turpentine/Helper/Cron.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php index a06cde033..b05561bd9 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php @@ -171,7 +171,9 @@ public function getAllUrls() { $urls[] = $prod->getProductUrl(); } } - foreach( Mage::getResourceModel( 'sitemap/cms_page' ) + $sitemap = (Mage::getConfig()->getNode('modules/Mageworx_XSitemap') !== FALSE) ? + 'xsitemap/cms_page' : 'cms_page'; + foreach( Mage::getResourceModel( $sitemap ) ->getCollection( $storeId ) as $item ) { $urls[] = $baseUrl . $item->getUrl(); } From dce42ef0b38e40cd560972b80bebaa213a824aba Mon Sep 17 00:00:00 2001 From: evensisftw Date: Wed, 19 Feb 2014 11:27:21 +0000 Subject: [PATCH 051/311] Resolve incompatibility with mageworx_xsitemap Resolve incompatibility with mageworx_xsitemap. --- app/code/community/Nexcessnet/Turpentine/Helper/Cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php index b05561bd9..d52bddc51 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php @@ -172,7 +172,7 @@ public function getAllUrls() { } } $sitemap = (Mage::getConfig()->getNode('modules/Mageworx_XSitemap') !== FALSE) ? - 'xsitemap/cms_page' : 'cms_page'; + 'xsitemap/cms_page' : 'sitemap/cms_page'; foreach( Mage::getResourceModel( $sitemap ) ->getCollection( $storeId ) as $item ) { $urls[] = $baseUrl . $item->getUrl(); From d747e9ce32d45c43bb13bb411ddffdabb937185c Mon Sep 17 00:00:00 2001 From: Adam Hall Date: Wed, 19 Feb 2014 12:28:52 +0000 Subject: [PATCH 052/311] fix typo Fixed typo in module name check. --- app/code/community/Nexcessnet/Turpentine/Helper/Cron.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php index d52bddc51..17c7aac91 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php @@ -171,7 +171,7 @@ public function getAllUrls() { $urls[] = $prod->getProductUrl(); } } - $sitemap = (Mage::getConfig()->getNode('modules/Mageworx_XSitemap') !== FALSE) ? + $sitemap = (Mage::getConfig()->getNode('modules/MageWorx_XSitemap') !== FALSE) ? 'xsitemap/cms_page' : 'sitemap/cms_page'; foreach( Mage::getResourceModel( $sitemap ) ->getCollection( $storeId ) as $item ) { From 406e229a9fbabfcf3f300f93ce77815b05e06d8f Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 19 Feb 2014 17:19:22 -0500 Subject: [PATCH 053/311] htmlspecialchars_decode on referer url in esi url --- .../Nexcessnet/Turpentine/controllers/EsiController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index bb521a29f..591a63c42 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -70,6 +70,7 @@ public function getBlockAction() { Mage::app()->getStore( $esiData->getStoreId() ) ); $appShim = Mage::getModel( 'turpentine/shim_mage_core_app' ); if( $referer = $this->_getRefererUrl() ) { + $referer = htmlspecialchars_decode( $referer ); $dummyRequest = Mage::helper( 'turpentine/esi' ) ->getDummyRequest( $referer ); } else { From d6bf4d7a7c998bea794f9480bed13fbfdbaac00c Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 19 Feb 2014 18:03:35 -0500 Subject: [PATCH 054/311] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee55ddc45..4b9bb56af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -347,3 +347,5 @@ This is the first release of Turpentine marked "stable" in Magento Connect * [#391] Added Magento Composer Installer support (thanks @ajardin) * [#405] Fixed disabling Varnish bypass (thanks @ajardin) * [#438] Implemented ban lurker-friendly bans (thanks @jeroenvermeulen) + * [#443] Fixed caching of static assets when the *Add Store Code to Urls* option + is enabled (thanks @jeroenvermeulen) From c1b991722e61d92e62ca48824660dfa519150df9 Mon Sep 17 00:00:00 2001 From: aheadley Date: Fri, 21 Feb 2014 15:17:29 -0500 Subject: [PATCH 055/311] implement fix based on @EvrijnSD workaround --- .../Nexcessnet/Turpentine/Helper/Varnish.php | 7 +++ .../Turpentine/Model/Observer/Varnish.php | 59 +++++++++++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 20 +++++++ 3 files changed, 86 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php index 9e648ba33..17ad679bc 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php @@ -176,4 +176,11 @@ public function isBypassEnabled() { public function shouldDisplayNotice() { return $this->getVarnishEnabled() && $this->isBypassEnabled(); } + + public function getFormKeyFixupActionsList() { + $data = Mage::getStoreConfig( + 'turpentine_varnish/miscellaneous/formkey_fixup_actions' ); + $actions = array_filter( explode( PHP_EOL, trim( $data ) ) ); + return $actions; + } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index d2b2d8a9b..5121a44e5 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -92,4 +92,63 @@ public function adminSystemConfigChangedSection( $eventObject ) { } } } + + /** + * Replace the form_key URL (and form) param value with the session's correct + * value + * + * @param mixed $eventObject + * @return null + */ + public function updateFormKeyParam( $eventObject ) { + $helper = Mage::helper( 'turpentine/varnish' ); + if( $helper->shouldResponseUseVarnish() && $this->_csrfFixupNeeded() ) { + $validActions = $helper->getFormKeyFixupActionsList(); + $action = $eventObject->getEvent()->getControllerAction() + ->getFullActionName(); + if( in_array( $action, $validActions ) ) { + $formKey = Mage::getSingleton( 'core/session' )->getFormKey(); + $request = Mage::app()->getRequest(); + Mage::helper( 'turpentine/debug' )->logDebug( + 'Action [%s] valid for CSRF fixup, setting form_key to: %s', + $action, $formKey ); + if( $request->getParam( Mage_Core_Model_Url::FORM_KEY, null ) !== null ) { + $request->setParam( Mage_Core_Model_Url::FORM_KEY, $formKey ); + } + } + } + } + + /** + * Check if this is a version of Magento that needs the form_key fix. + * Relevant versions are: + * + * CE 1.8+ + * EE 1.13+ + * + * @return bool + */ + protected function _csrfFixupNeeded() { + $result = false; + $isEnterprise = false; // ce + if( method_exists( 'Mage', 'getEdition' ) ) { + if( Mage::getEdition() === Mage::EDITION_ENTERPRISE ) { + $isEnterprise = true; + } + } else { + if( Mage::getConfig()->getModuleConfig( 'Enterprise_Enterprise' ) ) { + $isEnterprise = true; + } + } + if( $isEnterprise ) { + if( version_compare( Mage::getVersion(), '1.13', '>=' ) ) { + $result = true; + } + } else { + if( version_compare( Mage::getVersion(), '1.8', '>=' ) ) { + $result = true; + } + } + return $result; + } } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 1ddbe14f5..14786488f 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -40,6 +40,18 @@ {{root_dir}}/var/default.vcl {{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl + + + @@ -178,6 +190,14 @@ + + + + turpentine/observer_varnish + updateFormKeyParam + + + From 51c810421e0ba401e57e749a61e938702788df33 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 26 Feb 2014 17:41:42 -0500 Subject: [PATCH 056/311] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b9bb56af..f794307d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -349,3 +349,4 @@ This is the first release of Turpentine marked "stable" in Magento Connect * [#438] Implemented ban lurker-friendly bans (thanks @jeroenvermeulen) * [#443] Fixed caching of static assets when the *Add Store Code to Urls* option is enabled (thanks @jeroenvermeulen) + * [#345] Fixed compatibility with Magento CE 1.8 and EE 1.13 From 9b1d9f4f66c5eeb17c17a73c27a0c51f3adf859a Mon Sep 17 00:00:00 2001 From: aheadley Date: Thu, 27 Feb 2014 17:33:40 -0500 Subject: [PATCH 057/311] first stab at real fix for form_key --- .../Nexcessnet/Turpentine/Helper/Esi.php | 40 ++++++++++- .../Nexcessnet/Turpentine/Helper/Varnish.php | 33 +++++++++ .../Turpentine/Model/Observer/Esi.php | 37 +++++++++- .../Turpentine/Model/Observer/Varnish.php | 35 +--------- .../Turpentine/controllers/EsiController.php | 11 +++ .../Nexcessnet/Turpentine/etc/config.xml | 11 ++- app/code/local/Mage/Core/Model/Session.php | 68 +++++++++++++++++++ modman | 1 + 8 files changed, 198 insertions(+), 38 deletions(-) create mode 100644 app/code/local/Mage/Core/Model/Session.php diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index 52c6acfe8..2ea1ec786 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -118,8 +118,8 @@ public function getEsiMethodParam() { public function getEsiHmacParam() { return self::ESI_HMAC_PARAM; } - - /** + + /** * Get referrer param * * @return string @@ -318,6 +318,42 @@ public function getFileLayoutUpdatesXmlCacheKey() { ) ); } + /** + * Generate an ESI tag to be replaced by the content from the given URL + * + * Generated tag looks like: + * + * + * @param string $url url to pull content from + * @return string + */ + public function buildEsiIncludeFragment( $url ) { + return sprintf( '', $url ); + } + + /** + * Generate an ESI tag with content that is removed when ESI processed, and + * visible when not + * + * Generated tag looks like: + * $content + * + * @param string $content content to be removed + * @return string + */ + public function buildEsiRemoveFragment( $content ) { + return sprintf( '%s', $content ); + } + + /** + * Get URL for grabbing form key via ESI + * + * @return string + */ + public function getFormKeyEsiUrl() { + return Mage::getUrl( 'turpentine/esi/getFormKey' ); + } + /** * Load the ESI cache clear events from the layout * diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php index 17ad679bc..7ef95c207 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php @@ -183,4 +183,37 @@ public function getFormKeyFixupActionsList() { $actions = array_filter( explode( PHP_EOL, trim( $data ) ) ); return $actions; } + + /** + * Check if this is a version of Magento that needs the form_key fix. + * Relevant versions are: + * + * CE 1.8+ + * EE 1.13+ + * + * @return bool + */ + public function csrfFixupNeeded() { + $result = false; + $isEnterprise = false; // ce + if( method_exists( 'Mage', 'getEdition' ) ) { + if( Mage::getEdition() === Mage::EDITION_ENTERPRISE ) { + $isEnterprise = true; + } + } else { + if( Mage::getConfig()->getModuleConfig( 'Enterprise_Enterprise' ) ) { + $isEnterprise = true; + } + } + if( $isEnterprise ) { + if( version_compare( Mage::getVersion(), '1.13', '>=' ) ) { + $result = true; + } + } else { + if( version_compare( Mage::getVersion(), '1.8', '>=' ) ) { + $result = true; + } + } + return $result; + } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 284db32bb..77e269142 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -141,6 +141,41 @@ public function addMessagesBlockRewrite( $eventObject ) { } } + /** + * Check the magento version and runtime env and set the replace_form_key + * flag if needed + * + * @param Varien_Object $eventObject + * @return null + */ + public function setReplaceFormKeyFlag( $eventObject ) { + $esiHelper = Mage::helper( 'turpentine/esi' ); + $varnishHelper = Mage::helper( 'turpentine/varnish' ); + + if( $esiHelper->shouldResponseUseEsi() && $varnishHelper->csrfFixupNeeded() ) { + Mage::register( 'replace_form_key', true ); + } + } + + /** + * Replace the form key placeholder with the ESI include fragment + * + * @param Varien_Object $eventObject + * @return null + */ + public function replaceFormKeyPlaceholder( $eventObject ) { + if( Mage::registry( 'replace_form_key' ) ) { + $esiHelper = Mage::helper( 'turpentine/esi' ); + $response = $eventObject->getResponse(); + $responseBody = $response->getBody(); + $responseBody = str_replace( '{{replace_form_key}}', + $esiHelper->getEsiIncludeFragment( + $esiHelper->getFormKeyEsiUrl() ), + $responseBody ); + $response->setBody( $responseBody ); + } + } + /** * Encode block data in URL then replace with ESI template * @@ -218,7 +253,7 @@ public function injectEsi( $eventObject ) { Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true)) ); } - + $esiUrl = Mage::getUrl( 'turpentine/esi/getBlock', $urlOptions ); $blockObject->setEsiUrl( $esiUrl ); // avoid caching the ESI template output to prevent the double-esi- diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index 5121a44e5..4abc15649 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -102,7 +102,7 @@ public function adminSystemConfigChangedSection( $eventObject ) { */ public function updateFormKeyParam( $eventObject ) { $helper = Mage::helper( 'turpentine/varnish' ); - if( $helper->shouldResponseUseVarnish() && $this->_csrfFixupNeeded() ) { + if( $helper->shouldResponseUseVarnish() && $helper->csrfFixupNeeded() ) { $validActions = $helper->getFormKeyFixupActionsList(); $action = $eventObject->getEvent()->getControllerAction() ->getFullActionName(); @@ -118,37 +118,4 @@ public function updateFormKeyParam( $eventObject ) { } } } - - /** - * Check if this is a version of Magento that needs the form_key fix. - * Relevant versions are: - * - * CE 1.8+ - * EE 1.13+ - * - * @return bool - */ - protected function _csrfFixupNeeded() { - $result = false; - $isEnterprise = false; // ce - if( method_exists( 'Mage', 'getEdition' ) ) { - if( Mage::getEdition() === Mage::EDITION_ENTERPRISE ) { - $isEnterprise = true; - } - } else { - if( Mage::getConfig()->getModuleConfig( 'Enterprise_Enterprise' ) ) { - $isEnterprise = true; - } - } - if( $isEnterprise ) { - if( version_compare( Mage::getVersion(), '1.13', '>=' ) ) { - $result = true; - } - } else { - if( version_compare( Mage::getVersion(), '1.8', '>=' ) ) { - $result = true; - } - } - return $result; - } } diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 591a63c42..2a71b9f3f 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -30,6 +30,17 @@ public function indexAction() { $this->getResponse()->setRedirect( Mage::getBaseUrl() ); } + public function getFormKeyAction() { + $resp = $this->getResponse(); + $resp->setBody( + Mage::getSingleton( 'core/session' )->real_getFormKey() ); + $resp->setHeader( 'X-Turpentine-Flush-Events', + implode( ',', Mage::helper( 'turpentine/esi' ) + ->getDefaultCacheClearEvents() ) ); + $resp->setHeader( 'X-Turpentine-Block', 'form_key' ); + Mage::register( 'turpentine_nocache_flag', false, true ); + } + /** * Spit out the rendered block from the URL-encoded data * diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 14786488f..434b266bc 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -190,6 +190,7 @@ catalog_product_compare_add]]> + @@ -215,6 +216,10 @@ catalog_product_compare_add]]> turpentine/observer_esi setFlagHeaders + + turpentine/observer_esi + replaceFormKeyPlaceholder + @@ -257,6 +262,10 @@ catalog_product_compare_add]]> turpentine/observer_varnish addProductListToolbarRewrite + + turpentine/observer_esi + setReplaceFormKeyFlag + diff --git a/app/code/local/Mage/Core/Model/Session.php b/app/code/local/Mage/Core/Model/Session.php new file mode 100644 index 000000000..0a5d549a0 --- /dev/null +++ b/app/code/local/Mage/Core/Model/Session.php @@ -0,0 +1,68 @@ +init('core', $name); + } + + /** + * Retrieve Session Form Key + * + * @return string A 16 bit unique key for forms + */ + public function getFormKey() + { + if (Mage::registry('replace_form_key')) { + // flag request for ESI processing + Mage::register('turpentine_esi_flag', true, true); + return '{{form_key_esi_placeholder}}'; + } else { + return $this->real_getFormKey(); + } + } + + public function real_getFormKey() + { + if (!$this->getData('_form_key')) { + $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); + } + return $this->getData('_form_key'); + } +} diff --git a/modman b/modman index e548d16f4..9dabbbac6 100644 --- a/modman +++ b/modman @@ -2,6 +2,7 @@ app/etc/modules/Nexcessnet_Turpentine.xml app/etc/modules/Nexcessnet_Turpentine.xml app/code/community/Nexcessnet/Turpentine/ app/code/community/Nexcessnet/Turpentine/ +app/code/local/Mage/Core/Model/Session.php app/code/local/Mage/Core/Model/Session.php app/design/adminhtml/default/default/layout/turpentine.xml app/design/adminhtml/default/default/layout/turpentine.xml app/design/adminhtml/default/default/template/turpentine/ app/design/adminhtml/default/default/template/turpentine/ app/design/frontend/base/default/layout/turpentine_esi.xml app/design/frontend/base/default/layout/turpentine_esi.xml From 2d9a452a17b0b7f9680c11ec1a5ac5a06dd62432 Mon Sep 17 00:00:00 2001 From: aheadley Date: Thu, 27 Feb 2014 18:25:17 -0500 Subject: [PATCH 058/311] better decision making for esi form key vs real form key --- .../Nexcessnet/Turpentine/Model/Observer/Esi.php | 10 ++++++---- .../Turpentine/controllers/EsiController.php | 8 ++++++++ .../community/Nexcessnet/Turpentine/misc/version-2.vcl | 3 +++ .../community/Nexcessnet/Turpentine/misc/version-3.vcl | 3 +++ app/code/local/Mage/Core/Model/Session.php | 3 ++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 77e269142..d92b2eb94 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -151,8 +151,10 @@ public function addMessagesBlockRewrite( $eventObject ) { public function setReplaceFormKeyFlag( $eventObject ) { $esiHelper = Mage::helper( 'turpentine/esi' ); $varnishHelper = Mage::helper( 'turpentine/varnish' ); - - if( $esiHelper->shouldResponseUseEsi() && $varnishHelper->csrfFixupNeeded() ) { + $request = Mage::app()->getRequest(); + if( $esiHelper->shouldResponseUseEsi() && + $varnishHelper->csrfFixupNeeded() && + !$request->isPost() ) { Mage::register( 'replace_form_key', true ); } } @@ -168,8 +170,8 @@ public function replaceFormKeyPlaceholder( $eventObject ) { $esiHelper = Mage::helper( 'turpentine/esi' ); $response = $eventObject->getResponse(); $responseBody = $response->getBody(); - $responseBody = str_replace( '{{replace_form_key}}', - $esiHelper->getEsiIncludeFragment( + $responseBody = str_replace( '{{form_key_esi_placeholder}}', + $esiHelper->buildEsiIncludeFragment( $esiHelper->getFormKeyEsiUrl() ), $responseBody ); $response->setBody( $responseBody ); diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 2a71b9f3f..1b6f453b3 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -30,6 +30,11 @@ public function indexAction() { $this->getResponse()->setRedirect( Mage::getBaseUrl() ); } + /** + * Spit out the form key for this session + * + * @return null + */ public function getFormKeyAction() { $resp = $this->getResponse(); $resp->setBody( @@ -39,6 +44,9 @@ public function getFormKeyAction() { ->getDefaultCacheClearEvents() ) ); $resp->setHeader( 'X-Turpentine-Block', 'form_key' ); Mage::register( 'turpentine_nocache_flag', false, true ); + + Mage::helper( 'turpentine/debug' )->logDebug( 'Generated form_key: %s', + $resp->getBody() ); } /** diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 6e3b4e848..e7cfaa5ff 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -155,6 +155,9 @@ sub vcl_recv { # varnish 2.1 is buggy with compressed esi content remove req.http.Accept-Encoding; + } else if (req.url ~ "/turpentine/esi/getFormKey/") { + set req.http.X-Varnish-Esi-Method = "esi"; + set req.http.X-Varnish-Esi-Access = "private"; } # no frontend cookie was sent to us if (req.http.Cookie !~ "frontend=") { diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 8669db22d..3ef9c6186 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -152,6 +152,9 @@ sub vcl_recv { !({{debug_headers}} || client.ip ~ debug_acl)) { error 403 "External ESI requests are not allowed"; } + } elseif (req.url ~ "/turpentine/esi/getFormKey/") { + set req.http.X-Varnish-Esi-Method = "esi"; + set req.http.X-Varnish-Esi-Access = "private"; } # no frontend cookie was sent to us if (req.http.Cookie !~ "frontend=") { diff --git a/app/code/local/Mage/Core/Model/Session.php b/app/code/local/Mage/Core/Model/Session.php index 0a5d549a0..4c701738f 100644 --- a/app/code/local/Mage/Core/Model/Session.php +++ b/app/code/local/Mage/Core/Model/Session.php @@ -49,7 +49,8 @@ public function __construct($data=array()) */ public function getFormKey() { - if (Mage::registry('replace_form_key')) { + if (Mage::registry('replace_form_key') && + !Mage::app()->getRequest()->getParam('form_key', false)) { // flag request for ESI processing Mage::register('turpentine_esi_flag', true, true); return '{{form_key_esi_placeholder}}'; From a02fbd8693a5c8250f53e1c8390774e2b6f28676 Mon Sep 17 00:00:00 2001 From: aheadley Date: Fri, 28 Feb 2014 14:11:14 -0500 Subject: [PATCH 059/311] remove previous 1.8 fix --- .../Turpentine/Model/Observer/Varnish.php | 26 ------------------- .../Nexcessnet/Turpentine/etc/config.xml | 23 +--------------- 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index 4abc15649..d2b2d8a9b 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -92,30 +92,4 @@ public function adminSystemConfigChangedSection( $eventObject ) { } } } - - /** - * Replace the form_key URL (and form) param value with the session's correct - * value - * - * @param mixed $eventObject - * @return null - */ - public function updateFormKeyParam( $eventObject ) { - $helper = Mage::helper( 'turpentine/varnish' ); - if( $helper->shouldResponseUseVarnish() && $helper->csrfFixupNeeded() ) { - $validActions = $helper->getFormKeyFixupActionsList(); - $action = $eventObject->getEvent()->getControllerAction() - ->getFullActionName(); - if( in_array( $action, $validActions ) ) { - $formKey = Mage::getSingleton( 'core/session' )->getFormKey(); - $request = Mage::app()->getRequest(); - Mage::helper( 'turpentine/debug' )->logDebug( - 'Action [%s] valid for CSRF fixup, setting form_key to: %s', - $action, $formKey ); - if( $request->getParam( Mage_Core_Model_Url::FORM_KEY, null ) !== null ) { - $request->setParam( Mage_Core_Model_Url::FORM_KEY, $formKey ); - } - } - } - } } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 434b266bc..a36dfdc17 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -40,18 +40,6 @@ {{root_dir}}/var/default.vcl {{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl - - - @@ -190,16 +178,7 @@ catalog_product_compare_add]]> - + From 14284434529f2ee0d507e6900cc6dfca5ebd3883 Mon Sep 17 00:00:00 2001 From: aheadley Date: Fri, 28 Feb 2014 14:11:43 -0500 Subject: [PATCH 060/311] small improvement for vcl handling of form key action --- app/code/community/Nexcessnet/Turpentine/Helper/Esi.php | 8 +++++++- .../Nexcessnet/Turpentine/controllers/EsiController.php | 1 + .../community/Nexcessnet/Turpentine/misc/version-2.vcl | 5 +---- .../community/Nexcessnet/Turpentine/misc/version-3.vcl | 5 +---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index 2ea1ec786..7f2c3a73d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -351,7 +351,13 @@ public function buildEsiRemoveFragment( $content ) { * @return string */ public function getFormKeyEsiUrl() { - return Mage::getUrl( 'turpentine/esi/getFormKey' ); + $urlOptions = array( + $this->getEsiTtlParam() => $this->getDefaultEsiTtl(), + $this->getEsiMethodParam() => 'esi', + $this->getEsiScopeParam() => 'global', + $this->getEsiCacheTypeParam() => 'private', + ); + return Mage::getUrl( 'turpentine/esi/getFormKey', $urlOptions ); } /** diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 1b6f453b3..c409e5d65 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -39,6 +39,7 @@ public function getFormKeyAction() { $resp = $this->getResponse(); $resp->setBody( Mage::getSingleton( 'core/session' )->real_getFormKey() ); + $resp->setHeader( 'X-Turpentine-Cache', '1' ); $resp->setHeader( 'X-Turpentine-Flush-Events', implode( ',', Mage::helper( 'turpentine/esi' ) ->getDefaultCacheClearEvents() ) ); diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index e7cfaa5ff..8a557e12b 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -139,7 +139,7 @@ sub vcl_recv { req.http.Cookie, ".*\bstore=([^;]*).*", "\1"); } # looks like an ESI request, add some extra vars for further processing - if (req.url ~ "/turpentine/esi/getBlock/") { + if (req.url ~ "/turpentine/esi/get(?:Block|FormKey)/") { set req.http.X-Varnish-Esi-Method = regsub( req.url, ".*/{{esi_method_param}}/(\w+)/.*", "\1"); set req.http.X-Varnish-Esi-Access = regsub( @@ -155,9 +155,6 @@ sub vcl_recv { # varnish 2.1 is buggy with compressed esi content remove req.http.Accept-Encoding; - } else if (req.url ~ "/turpentine/esi/getFormKey/") { - set req.http.X-Varnish-Esi-Method = "esi"; - set req.http.X-Varnish-Esi-Access = "private"; } # no frontend cookie was sent to us if (req.http.Cookie !~ "frontend=") { diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 3ef9c6186..278a6d79f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -140,7 +140,7 @@ sub vcl_recv { req.http.Cookie, ".*\bstore=([^;]*).*", "\1"); } # looks like an ESI request, add some extra vars for further processing - if (req.url ~ "/turpentine/esi/getBlock/") { + if (req.url ~ "/turpentine/esi/get(?:Block|FormKey)/") { set req.http.X-Varnish-Esi-Method = regsub( req.url, ".*/{{esi_method_param}}/(\w+)/.*", "\1"); set req.http.X-Varnish-Esi-Access = regsub( @@ -152,9 +152,6 @@ sub vcl_recv { !({{debug_headers}} || client.ip ~ debug_acl)) { error 403 "External ESI requests are not allowed"; } - } elseif (req.url ~ "/turpentine/esi/getFormKey/") { - set req.http.X-Varnish-Esi-Method = "esi"; - set req.http.X-Varnish-Esi-Access = "private"; } # no frontend cookie was sent to us if (req.http.Cookie !~ "frontend=") { From 0b654031c6a76c5bbb4c5c3d59ae67488429191c Mon Sep 17 00:00:00 2001 From: aheadley Date: Fri, 28 Feb 2014 18:19:30 -0500 Subject: [PATCH 061/311] add visibility to the esi_syntax param issue for upgrades --- CHANGELOG.md | 3 ++ .../Turpentine/Model/Varnish/Admin.php | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f794307d6..2b41a9fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -342,6 +342,9 @@ This is the first release of Turpentine marked "stable" in Magento Connect ### RELEASE-0.6.0 +This release *requires* a small addition to Varnish's configuration when used with +Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess/magento-turpentine/wiki/FAQ#wiki-i-upgraded-to-turpentine-06-and-are-the-add-to-cart-buttons-look-broken) + * [#362] Fixed ESI detection for message block (thanks @eth8505) * [#380] Fixed ESI cache flushes not firing in some cases (thanks @gabrielsomoza) * [#391] Added Magento Composer Installer support (thanks @ajardin) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index b8a6f0318..833dba850 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -21,6 +21,9 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin { + const MASK_ESI_SYNTAX = 0x2; + const URL_ESI_SYNTAX_FIX = 'https://github.com/nexcess/magento-turpentine/wiki/FAQ#wiki-i-upgraded-to-turpentine-06-and-are-the-add-to-cart-buttons-look-broken'; + /** * Flush all Magento URLs in Varnish cache * @@ -106,6 +109,7 @@ public function applyConfig() { $vclName = Mage::helper( 'turpentine/data' ) ->secureHash( microtime() ); try { + $this->_testEsiSyntaxParam( $socket ); $socket->vcl_inline( $vclName, $vcl ); sleep( 1 ); //this is probably not really needed $socket->vcl_use( $vclName ); @@ -129,4 +133,35 @@ public function getConfigurator() { $cfgr = Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract::getFromSocket( $sockets[0] ); return $cfgr; } + + protected function _testEsiSyntaxParam( $socket ) { + $session = Mage::getSingleton( 'adminhtml/session' ); + $helper = Mage::helper( 'turpentine/varnish' ); + $result = false; + + if( $helper->csrfFixupNeeded() ) { + $value = $socket->param_show( 'esi_syntax' ); + if( preg_match( '~(\d)\s+\[bitmap\]~', $value['text'], $match ) ) { + $value = hexdec( $match[1] ); + if( $value & self::MASK_ESI_SYNTAX ) { //bitwise intentional + // setting is correct, all is fine + $result = true; + } else { + $session->addWarning( 'Varnish esi_syntax param is ' . + 'not set correctly, please see these instructions ' . + 'to fix this warning.' ); + } + } else { + // error + Mage::helper( 'turpentine/debug' )->logWarning( + 'Failed to parse param.show output to check esi_syntax value' ); + $result = true; + } + } else { + $result = true; + } + + return $result; + } } From 42ad50eb088c353a56c83ef96bce9173948f496f Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 3 Mar 2014 13:54:42 -0500 Subject: [PATCH 062/311] add local session model override to package manifest --- build/mage-package.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/mage-package.xml b/build/mage-package.xml index d53c04465..5c2286c26 100644 --- a/build/mage-package.xml +++ b/build/mage-package.xml @@ -60,6 +60,7 @@ magecommunity + magelocal magedesign magedesign magedesign @@ -68,6 +69,7 @@ Nexcessnet/Turpentine + Mage/Core/Model/Session.php adminhtml/default/default/layout/turpentine.xml adminhtml/default/default/template/turpentine frontend/base/default/layout/turpentine_esi.xml @@ -77,6 +79,7 @@ dir file + file dir file dir @@ -85,6 +88,7 @@ ~.*~ + ~.*~ ~.*~ @@ -97,6 +101,7 @@ + From 65678044352a4b5de14c6d14835a325dee1c721e Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 3 Mar 2014 13:57:11 -0500 Subject: [PATCH 063/311] bump version to 0.6.0 --- 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 a36dfdc17..c7e97727e 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -20,7 +20,7 @@ - 0.5.5 + 0.6.0 From 93b609f422afe20d74df4458a7e6dac3f2576739 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 5 Mar 2014 15:11:03 -0500 Subject: [PATCH 064/311] add technical notes writeup --- TECHINCAL_NOTES.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 TECHINCAL_NOTES.md diff --git a/TECHINCAL_NOTES.md b/TECHINCAL_NOTES.md new file mode 100644 index 000000000..86cf5b0f1 --- /dev/null +++ b/TECHINCAL_NOTES.md @@ -0,0 +1,65 @@ +# Turpentine Technical Notes + +This document is intended to serve as a guide to some of Turpentine's more complicated mechanics and as a small historical guide to Turpentine's development. + +## In the beginning... + +When Turpentine was started, there were a few pre-existing extensions intended to make Magento work with Varnish, notably Phoenix Media's "Pagecache powered by Varnish" and Madalin Oprea's "Magneto-Varnish" but we (Nexcess.net) didn't find them suitable for our needs for various reasons, so it was decided that we would make our own. + +As context for further discussion, let me explain why an extension is even needed for Magento to work with Varnish. Varnish works as a proxy cache, requests are sent from the client to Varnish, which examines the request to see if Varnish can serve the response from its cache, and if not (or the response is not already in Varnish's cache) the request is forwarded on to the backend (Magento running on your webserver of choice). Magento sends the response back to Varnish, Varnish caches it (or not) and then forwards the response back to the client. The problem with Varnish in conjunction with Magento is that cookies are one of the things that makes Varnish consider a request to be un-cacheable (by default), and Magento sends a session cookie with every dynamic response (when the request goes to a PHP script rather than a static asset like an image). Most of Magento does not function, or does not function correctly unless the session cookie uniquely identifies a visitor, thus additional work is needed to get the two working together. + +The most obvious and fastest to implement solution is to just let the first request from a client pass through Varnish to the backend and send the response back unmodified which lets the client get the session cookie, then strip the cookie from further requests from the client and caching those responses. This is how Turpentine originally worked, along with many of the other Varnish extensions available for Magento. However this method quickly runs into several problems: + + * You can't serve cached responses once a client takes an action that modifies their session, such as adding something to the cart. So you set another cookie that says "bypass the Varnish cache" when the session is modified. This means the typical experience for a client is a slow first page load, subsequent pages are much faster (since they are cached), then page loads are slow again once they login or add something to the cart. + * You have to keep a list of what "actions" cause the client to modify their session so the "bypass the Varnish cache" cookie can be set when needed. There are some tricks you can use to guess when this is, but they are not very reliable. + * Varnish can end up serving cached content from another session if the cache is cleared and a client that already has a session cookie visits the site. + +Given these problems, it's clear that a better solution is needed, which is where ESI (Edge Side Includes) come in. + +## ESI or: How I learned to stop worrying and love the Cache + +ESI was originally created so that CDN providers (like Akamai) could serve their customer's content from cache but still pull in dynamic content as needed. Fortunately, many proxy cache servers saw the benefit in this and also implemented it which is how it came to be in Varnish. ESI essentially lets part(s) of a page be marked that they should be pulled from a separate URL. What this means for Magento is that pages can be cached as a whole, then the dynamic parts replaced with the content specific for the client's session. This ends up being such an improvement over the previous method that it's like going from a rusty tricycle to a [SR-71 Blackbird](http://en.wikipedia.org/wiki/Lockheed_SR-71_Blackbird). + +However, actually implementing ESI in Magento is horrendously complicated as Magento doesn't seem to have been designed with rendering just a single block, rather than an entire page, which is needed to serve the actual ESI requests from Varnish. Luckily, Hugues Alary did most of the hard work and made it available in his [Magento-Varnish](https://github.com/huguesalary/Magento-Varnish) extension. The core of how both Magento-Varnish and Turpentine work is: + + 1. The extension has a [layout file](/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/layout/turpentine_esi.xml) that tells the extension which blocks should be included via ESI. + 2. The extension waits for the [`core_block_abstract_to_html_before`](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/etc/config.xml#L183) event to trigger during a request, then [examines the block](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L191) the event was fired for and checks whether the block should be included via ESI based on the layout file. + 3. If the block should be ESI included, the block's normal template is replaced by a [special template](/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/template/turpentine/esi.phtml) with the ESI include tag that signals Varnish to instead pull the block's content from a separate request. A flag is also added to the request to signal to Varnish that the request should have ESI processing run on it. + 4. The response finishes and is sent to Varnish, Varnish sees the ESI flag and sends a request to get the ESI content, which is then [rendered](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php#L58) and sent back to Varnish to be included in the original response. + +Turpentine and Magento-Varnish differ mostly significantly on the final step. To render the ESI included block separately from the original request quite a bit of data is needed from the original request. Things like the block's name, what design/theme was active, and (most importantly) the registry keys that the block needs. Magento-Varnish's approach is that all that data should be saved in the cache, then looked up from the cache when the ESI request came back based on the cache key in the ESI request URL. Unfortunately, this can cause problems if Magento's cache and Varnish's cache are not in sync. For example, if the Magento cache is flushed but the Varnish cache is not, it can lead to Varnish requesting ESI blocks that Magento doesn't have the data to render. With Turpentine, I wanted to avoid this so instead all of the data is [encrypted](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L241) then just included in the ESI URL itself, neatly avoiding the cache syncing issue. There was [some concern](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L266) that the ESI URLs would be too long and cause problems, as the HTTP standard doesn't define a maximum length. Fortunately it seems most webservers and clients use at least a 2048 char limit and in practice there have been no reports of this being an issue. + +## I got 99 problems... + +As mentioned, Magento isn't really designed to easily facilitate the rendering of a single block, or really work with the proxy cache/ESI model which means a number of work arounds are required to make it work. + +### Generating Session Cookies without PHP + +Even with the addition of ESI, a client still needs a way to get their session cookie, or else every client would be sharing the same session (which leads to obvious problems). The first request from a client with no session cookie could be passed back to Magento in order to have Magento generate the session token, but we want the highest cache hit rate and least backend traffic possible. Fortunately, Magento isn't very strict about session tokens. As long as they are unique, Magento doesn't seem to care what they look like. So rather than passing back to Magento to get the session token, why not make Varnish simply generate the session token and add it to the request if the client doesn't send one? + +It sounds simple enough, but Varnish doesn't actually have any easy way to generate unique session tokens. At first, this seemed like a wash but then I remembered that you can actually write straight C code in the VCL for more advanced functionality, such as generating the session token! So that's what Turpentine does: a small C function is included in the VCL to [generate uuids](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/uuid.c), then that function is used to [make a session cookie](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl#L58) if no session cookie was sent in the request, and the cookie is [passed back to the client](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl#L340) in the response so it is sent with future requests. + +### Serializing Registry Data + +To include the registry data required for ESI block rendering in the ESI URL, Turpentine simply takes a list of the needed registry keys (provided in the layout file) for the block and serializes it using PHP's native [`serialize`](http://us3.php.net/serialize) function which turns stores the data in a string which we can then include in the URL as a simple GET parameter. However, a registry key can be associated with any data type, including whole objects. While `serialize` will typically work on objects there are some edge cases (such as XML documents) that cannot be serialized. In order to accomodate these documents, Turpentine considers some objects to be "[complex registry data](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L441)" and handles those separately from the standard PHP types like string, int, simple classes, etc. Complex registry data is considered to be Magento "models" that correspond to database records and have `getId` methods (typically things like products, categories, etc). Then Turpentine can simply serialize the model's class and ID, then load the model with the ID instead of serializing the entire object. This neatly sidesteps the whole issue of finding a way to serialize objects that are unserializable. + +### Runtime Events Registration and Class Rewrites + +The flash messages block in Magento is another source of problems. Flash messages are the small blocks near the top of pages that show a little message, generally for only a single page load, typically after an "action" like adding something to the cart triggers the "$product was added to your cart" flash message. The main issue with flash messages is that they don't use a template, so they can be handled like regular blocks (by switching templates) and thus require a block rewrite. However, there are cases where the flash messages are handled separately via another extension which loads them via AJAX or some other mechanism that Turpentine's special handling via ESI/AJAX would interfere with, so Turpentine's handling needs to be toggle-able. To ensure that the messages block's behavior is correct when Turpentine's handling is switched off, Turpentine needs to only add the block rewrite at runtime, after checking whether it should be added or not via the config options. Magento has no support for this though, so a workaround is required to add support for it. + +To accomplish this, Turpentine includes an [app "shim" class](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php) that provides access to Magento's *protected* members, which works thanks to PHP's object model. In PHP, if class `Child` inherits from class `Parent`, then `Child` objects can access their *protected* methods and members that come from class `Parent`, and more importantly the `Child` object can access the *protected* methods and members that come from class `Parent` on **any** object from `Parent` class or that inherits from `Parent`. This means the Turpentine's app shim can access `Mage_Core_Model_App`'s *protected* members to add block rewrites and register for events without including them in the extension's XML files. + +### CSRF Form Key Handling + +In recent versions of Magento (CE 1.8+ and EE 1.13+), CSRF protection was added to several additional forms, where previously it had only really been used on login form (in the frontend). This has caused problems for quite a few full page cache implementations in addition to Turpentine because it makes the form submission URLs unique to a session which is then cached and, for users that don't have that session/form key, those forms are then broken (i.e. the "Add to Cart" button clicked with the wrong form key simply redirects the client to the homepage rather than actually adding the product to the cart). + +This change effectively broke Turpentine for those Magento versions, and finding a solution was not trivial. The [first attempt](/nexcess/magento-turpentine/commit/c1b991722e61d92e62ca48824660dfa519150df9) at a fix was to just keep a list of actions that use the form key, and to replace it with the session's correct form key before the action runs. While it worked, it more or less removed the CSRF protection and felt very "hacky", so after some thought a better solution came to mind. Why not have Varnish use ESI to replace the form key inside the links and forms that use it? This keeps the CSRF protection and would have a negligible performance impact as the form key only needs to be requested once and then can be pulled from cache for future requests from that client and session (since the form key is constant for the life of the session). The actual implementation of this presented two hurdles though: + + 1. Because the form key is located inside HTML attributes (`href="http://example.com/example/action/form_key//"` for example), by default Varnish doesn't see the ESI include tag which completely breaks the buttons and forms that use the form key. + 2. How does Magento know when to generate the actual form key, and not the ESI tag that is replaced by the form key. For example, the form key ESI is needed when generating the "Add to Cart" button, but the actual form key is needed both for both the ESI request to pull in the form key, and when that button is clicked so that it can be compared to the form key that was submitted. + +The first is solved by a Varnish config change. Adding `-p esi_syntax=0x2` to Varnish's startup command tells it to look for any ESI tags, even if they're not in properly structured HTML syntax (like the example). The second was more tricky, at first it seemed a static list of actions that use the form key would be needed (like the original fix) that could be used to tell the mage/core session class when to generate the form key, and when to generate the form key ESI tag. However, the solution was staring me in the face: the request itself tells you when you need the actual form key, as it's only needed when the request includes the form key in the GET params or POST data to do the comparison between the actual form key, and the form key sent with the request. Thus we can just [check](/nexcess/magento-turpentine/blob/master/app/code/local/Mage/Core/Model/Session.php#L53) if the form key was sent in the request and either generate the real form key, or the ESI tag. + +## Closing Time + +As you can see, there are a number of interesting "tricks" required to really integrate Varnish and Magento well, and this only covers the most interesting ones. Things like purging stale ESI blocks or cache warming have been left out, though they are arguably just as important as what was covered for a well functioning Varnish extension. Hopefully in the future Magento will make Varnish integration easier, or even better, add native Varnish support. From 194420f987774e87a2e904301b74b9df7cabce3f Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 5 Mar 2014 15:16:45 -0500 Subject: [PATCH 065/311] fix links in tech notes --- TECHINCAL_NOTES.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/TECHINCAL_NOTES.md b/TECHINCAL_NOTES.md index 86cf5b0f1..5cabedf9c 100644 --- a/TECHINCAL_NOTES.md +++ b/TECHINCAL_NOTES.md @@ -22,12 +22,12 @@ ESI was originally created so that CDN providers (like Akamai) could serve their However, actually implementing ESI in Magento is horrendously complicated as Magento doesn't seem to have been designed with rendering just a single block, rather than an entire page, which is needed to serve the actual ESI requests from Varnish. Luckily, Hugues Alary did most of the hard work and made it available in his [Magento-Varnish](https://github.com/huguesalary/Magento-Varnish) extension. The core of how both Magento-Varnish and Turpentine work is: - 1. The extension has a [layout file](/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/layout/turpentine_esi.xml) that tells the extension which blocks should be included via ESI. - 2. The extension waits for the [`core_block_abstract_to_html_before`](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/etc/config.xml#L183) event to trigger during a request, then [examines the block](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L191) the event was fired for and checks whether the block should be included via ESI based on the layout file. - 3. If the block should be ESI included, the block's normal template is replaced by a [special template](/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/template/turpentine/esi.phtml) with the ESI include tag that signals Varnish to instead pull the block's content from a separate request. A flag is also added to the request to signal to Varnish that the request should have ESI processing run on it. - 4. The response finishes and is sent to Varnish, Varnish sees the ESI flag and sends a request to get the ESI content, which is then [rendered](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php#L58) and sent back to Varnish to be included in the original response. + 1. The extension has a [layout file](https://github.com/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/layout/turpentine_esi.xml) that tells the extension which blocks should be included via ESI. + 2. The extension waits for the [`core_block_abstract_to_html_before`](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/etc/config.xml#L183) event to trigger during a request, then [examines the block](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L191) the event was fired for and checks whether the block should be included via ESI based on the layout file. + 3. If the block should be ESI included, the block's normal template is replaced by a [special template](https://github.com/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/template/turpentine/esi.phtml) with the ESI include tag that signals Varnish to instead pull the block's content from a separate request. A flag is also added to the request to signal to Varnish that the request should have ESI processing run on it. + 4. The response finishes and is sent to Varnish, Varnish sees the ESI flag and sends a request to get the ESI content, which is then [rendered](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php#L58) and sent back to Varnish to be included in the original response. -Turpentine and Magento-Varnish differ mostly significantly on the final step. To render the ESI included block separately from the original request quite a bit of data is needed from the original request. Things like the block's name, what design/theme was active, and (most importantly) the registry keys that the block needs. Magento-Varnish's approach is that all that data should be saved in the cache, then looked up from the cache when the ESI request came back based on the cache key in the ESI request URL. Unfortunately, this can cause problems if Magento's cache and Varnish's cache are not in sync. For example, if the Magento cache is flushed but the Varnish cache is not, it can lead to Varnish requesting ESI blocks that Magento doesn't have the data to render. With Turpentine, I wanted to avoid this so instead all of the data is [encrypted](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L241) then just included in the ESI URL itself, neatly avoiding the cache syncing issue. There was [some concern](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L266) that the ESI URLs would be too long and cause problems, as the HTTP standard doesn't define a maximum length. Fortunately it seems most webservers and clients use at least a 2048 char limit and in practice there have been no reports of this being an issue. +Turpentine and Magento-Varnish differ mostly significantly on the final step. To render the ESI included block separately from the original request quite a bit of data is needed from the original request. Things like the block's name, what design/theme was active, and (most importantly) the registry keys that the block needs. Magento-Varnish's approach is that all that data should be saved in the cache, then looked up from the cache when the ESI request came back based on the cache key in the ESI request URL. Unfortunately, this can cause problems if Magento's cache and Varnish's cache are not in sync. For example, if the Magento cache is flushed but the Varnish cache is not, it can lead to Varnish requesting ESI blocks that Magento doesn't have the data to render. With Turpentine, I wanted to avoid this so instead all of the data is [encrypted](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L241) then just included in the ESI URL itself, neatly avoiding the cache syncing issue. There was [some concern](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L266) that the ESI URLs would be too long and cause problems, as the HTTP standard doesn't define a maximum length. Fortunately it seems most webservers and clients use at least a 2048 char limit and in practice there have been no reports of this being an issue. ## I got 99 problems... @@ -37,28 +37,28 @@ As mentioned, Magento isn't really designed to easily facilitate the rendering o Even with the addition of ESI, a client still needs a way to get their session cookie, or else every client would be sharing the same session (which leads to obvious problems). The first request from a client with no session cookie could be passed back to Magento in order to have Magento generate the session token, but we want the highest cache hit rate and least backend traffic possible. Fortunately, Magento isn't very strict about session tokens. As long as they are unique, Magento doesn't seem to care what they look like. So rather than passing back to Magento to get the session token, why not make Varnish simply generate the session token and add it to the request if the client doesn't send one? -It sounds simple enough, but Varnish doesn't actually have any easy way to generate unique session tokens. At first, this seemed like a wash but then I remembered that you can actually write straight C code in the VCL for more advanced functionality, such as generating the session token! So that's what Turpentine does: a small C function is included in the VCL to [generate uuids](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/uuid.c), then that function is used to [make a session cookie](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl#L58) if no session cookie was sent in the request, and the cookie is [passed back to the client](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl#L340) in the response so it is sent with future requests. +It sounds simple enough, but Varnish doesn't actually have any easy way to generate unique session tokens. At first, this seemed like a wash but then I remembered that you can actually write straight C code in the VCL for more advanced functionality, such as generating the session token! So that's what Turpentine does: a small C function is included in the VCL to [generate uuids](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/uuid.c), then that function is used to [make a session cookie](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl#L58) if no session cookie was sent in the request, and the cookie is [passed back to the client](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl#L340) in the response so it is sent with future requests. ### Serializing Registry Data -To include the registry data required for ESI block rendering in the ESI URL, Turpentine simply takes a list of the needed registry keys (provided in the layout file) for the block and serializes it using PHP's native [`serialize`](http://us3.php.net/serialize) function which turns stores the data in a string which we can then include in the URL as a simple GET parameter. However, a registry key can be associated with any data type, including whole objects. While `serialize` will typically work on objects there are some edge cases (such as XML documents) that cannot be serialized. In order to accomodate these documents, Turpentine considers some objects to be "[complex registry data](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L441)" and handles those separately from the standard PHP types like string, int, simple classes, etc. Complex registry data is considered to be Magento "models" that correspond to database records and have `getId` methods (typically things like products, categories, etc). Then Turpentine can simply serialize the model's class and ID, then load the model with the ID instead of serializing the entire object. This neatly sidesteps the whole issue of finding a way to serialize objects that are unserializable. +To include the registry data required for ESI block rendering in the ESI URL, Turpentine simply takes a list of the needed registry keys (provided in the layout file) for the block and serializes it using PHP's native [`serialize`](http://us3.php.net/serialize) function which turns stores the data in a string which we can then include in the URL as a simple GET parameter. However, a registry key can be associated with any data type, including whole objects. While `serialize` will typically work on objects there are some edge cases (such as XML documents) that cannot be serialized. In order to accomodate these documents, Turpentine considers some objects to be "[complex registry data](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L441)" and handles those separately from the standard PHP types like string, int, simple classes, etc. Complex registry data is considered to be Magento "models" that correspond to database records and have `getId` methods (typically things like products, categories, etc). Then Turpentine can simply serialize the model's class and ID, then load the model with the ID instead of serializing the entire object. This neatly sidesteps the whole issue of finding a way to serialize objects that are unserializable. ### Runtime Events Registration and Class Rewrites The flash messages block in Magento is another source of problems. Flash messages are the small blocks near the top of pages that show a little message, generally for only a single page load, typically after an "action" like adding something to the cart triggers the "$product was added to your cart" flash message. The main issue with flash messages is that they don't use a template, so they can be handled like regular blocks (by switching templates) and thus require a block rewrite. However, there are cases where the flash messages are handled separately via another extension which loads them via AJAX or some other mechanism that Turpentine's special handling via ESI/AJAX would interfere with, so Turpentine's handling needs to be toggle-able. To ensure that the messages block's behavior is correct when Turpentine's handling is switched off, Turpentine needs to only add the block rewrite at runtime, after checking whether it should be added or not via the config options. Magento has no support for this though, so a workaround is required to add support for it. -To accomplish this, Turpentine includes an [app "shim" class](/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php) that provides access to Magento's *protected* members, which works thanks to PHP's object model. In PHP, if class `Child` inherits from class `Parent`, then `Child` objects can access their *protected* methods and members that come from class `Parent`, and more importantly the `Child` object can access the *protected* methods and members that come from class `Parent` on **any** object from `Parent` class or that inherits from `Parent`. This means the Turpentine's app shim can access `Mage_Core_Model_App`'s *protected* members to add block rewrites and register for events without including them in the extension's XML files. +To accomplish this, Turpentine includes an [app "shim" class](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php) that provides access to Magento's *protected* members, which works thanks to PHP's object model. In PHP, if class `Child` inherits from class `Parent`, then `Child` objects can access their *protected* methods and members that come from class `Parent`, and more importantly the `Child` object can access the *protected* methods and members that come from class `Parent` on **any** object from `Parent` class or that inherits from `Parent`. This means the Turpentine's app shim can access `Mage_Core_Model_App`'s *protected* members to add block rewrites and register for events without including them in the extension's XML files. ### CSRF Form Key Handling In recent versions of Magento (CE 1.8+ and EE 1.13+), CSRF protection was added to several additional forms, where previously it had only really been used on login form (in the frontend). This has caused problems for quite a few full page cache implementations in addition to Turpentine because it makes the form submission URLs unique to a session which is then cached and, for users that don't have that session/form key, those forms are then broken (i.e. the "Add to Cart" button clicked with the wrong form key simply redirects the client to the homepage rather than actually adding the product to the cart). -This change effectively broke Turpentine for those Magento versions, and finding a solution was not trivial. The [first attempt](/nexcess/magento-turpentine/commit/c1b991722e61d92e62ca48824660dfa519150df9) at a fix was to just keep a list of actions that use the form key, and to replace it with the session's correct form key before the action runs. While it worked, it more or less removed the CSRF protection and felt very "hacky", so after some thought a better solution came to mind. Why not have Varnish use ESI to replace the form key inside the links and forms that use it? This keeps the CSRF protection and would have a negligible performance impact as the form key only needs to be requested once and then can be pulled from cache for future requests from that client and session (since the form key is constant for the life of the session). The actual implementation of this presented two hurdles though: +This change effectively broke Turpentine for those Magento versions, and finding a solution was not trivial. The [first attempt](https://github.com/nexcess/magento-turpentine/commit/c1b991722e61d92e62ca48824660dfa519150df9) at a fix was to just keep a list of actions that use the form key, and to replace it with the session's correct form key before the action runs. While it worked, it more or less removed the CSRF protection and felt very "hacky", so after some thought a better solution came to mind. Why not have Varnish use ESI to replace the form key inside the links and forms that use it? This keeps the CSRF protection and would have a negligible performance impact as the form key only needs to be requested once and then can be pulled from cache for future requests from that client and session (since the form key is constant for the life of the session). The actual implementation of this presented two hurdles though: 1. Because the form key is located inside HTML attributes (`href="http://example.com/example/action/form_key//"` for example), by default Varnish doesn't see the ESI include tag which completely breaks the buttons and forms that use the form key. 2. How does Magento know when to generate the actual form key, and not the ESI tag that is replaced by the form key. For example, the form key ESI is needed when generating the "Add to Cart" button, but the actual form key is needed both for both the ESI request to pull in the form key, and when that button is clicked so that it can be compared to the form key that was submitted. -The first is solved by a Varnish config change. Adding `-p esi_syntax=0x2` to Varnish's startup command tells it to look for any ESI tags, even if they're not in properly structured HTML syntax (like the example). The second was more tricky, at first it seemed a static list of actions that use the form key would be needed (like the original fix) that could be used to tell the mage/core session class when to generate the form key, and when to generate the form key ESI tag. However, the solution was staring me in the face: the request itself tells you when you need the actual form key, as it's only needed when the request includes the form key in the GET params or POST data to do the comparison between the actual form key, and the form key sent with the request. Thus we can just [check](/nexcess/magento-turpentine/blob/master/app/code/local/Mage/Core/Model/Session.php#L53) if the form key was sent in the request and either generate the real form key, or the ESI tag. +The first is solved by a Varnish config change. Adding `-p esi_syntax=0x2` to Varnish's startup command tells it to look for any ESI tags, even if they're not in properly structured HTML syntax (like the example). The second was more tricky, at first it seemed a static list of actions that use the form key would be needed (like the original fix) that could be used to tell the mage/core session class when to generate the form key, and when to generate the form key ESI tag. However, the solution was staring me in the face: the request itself tells you when you need the actual form key, as it's only needed when the request includes the form key in the GET params or POST data to do the comparison between the actual form key, and the form key sent with the request. Thus we can just [check](https://github.com/nexcess/magento-turpentine/blob/master/app/code/local/Mage/Core/Model/Session.php#L53) if the form key was sent in the request and either generate the real form key, or the ESI tag. ## Closing Time From d3b512519210c68979c473a3367cfae9015cbe01 Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 5 Mar 2014 15:23:57 -0500 Subject: [PATCH 066/311] fix some more links and typos --- TECHINCAL_NOTES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TECHINCAL_NOTES.md b/TECHINCAL_NOTES.md index 5cabedf9c..e6f10bd06 100644 --- a/TECHINCAL_NOTES.md +++ b/TECHINCAL_NOTES.md @@ -4,7 +4,7 @@ This document is intended to serve as a guide to some of Turpentine's more compl ## In the beginning... -When Turpentine was started, there were a few pre-existing extensions intended to make Magento work with Varnish, notably Phoenix Media's "Pagecache powered by Varnish" and Madalin Oprea's "Magneto-Varnish" but we (Nexcess.net) didn't find them suitable for our needs for various reasons, so it was decided that we would make our own. +When Turpentine was started, there were a few pre-existing extensions intended to make Magento work with Varnish, notably Phoenix Media's [Pagecache powered by Varnish](http://www.magentocommerce.com/magento-connect/pagecache-powered-by-varnish.html) and Madalin Oprea's [Magneto-Varnish](https://github.com/madalinoprea/magneto-varnish) but we ([Nexcess.net](http://www.nexcess.net/)) didn't find them suitable for our needs for various reasons, so it was decided that we would make our own. As context for further discussion, let me explain why an extension is even needed for Magento to work with Varnish. Varnish works as a proxy cache, requests are sent from the client to Varnish, which examines the request to see if Varnish can serve the response from its cache, and if not (or the response is not already in Varnish's cache) the request is forwarded on to the backend (Magento running on your webserver of choice). Magento sends the response back to Varnish, Varnish caches it (or not) and then forwards the response back to the client. The problem with Varnish in conjunction with Magento is that cookies are one of the things that makes Varnish consider a request to be un-cacheable (by default), and Magento sends a session cookie with every dynamic response (when the request goes to a PHP script rather than a static asset like an image). Most of Magento does not function, or does not function correctly unless the session cookie uniquely identifies a visitor, thus additional work is needed to get the two working together. @@ -27,7 +27,7 @@ However, actually implementing ESI in Magento is horrendously complicated as Mag 3. If the block should be ESI included, the block's normal template is replaced by a [special template](https://github.com/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/template/turpentine/esi.phtml) with the ESI include tag that signals Varnish to instead pull the block's content from a separate request. A flag is also added to the request to signal to Varnish that the request should have ESI processing run on it. 4. The response finishes and is sent to Varnish, Varnish sees the ESI flag and sends a request to get the ESI content, which is then [rendered](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php#L58) and sent back to Varnish to be included in the original response. -Turpentine and Magento-Varnish differ mostly significantly on the final step. To render the ESI included block separately from the original request quite a bit of data is needed from the original request. Things like the block's name, what design/theme was active, and (most importantly) the registry keys that the block needs. Magento-Varnish's approach is that all that data should be saved in the cache, then looked up from the cache when the ESI request came back based on the cache key in the ESI request URL. Unfortunately, this can cause problems if Magento's cache and Varnish's cache are not in sync. For example, if the Magento cache is flushed but the Varnish cache is not, it can lead to Varnish requesting ESI blocks that Magento doesn't have the data to render. With Turpentine, I wanted to avoid this so instead all of the data is [encrypted](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L241) then just included in the ESI URL itself, neatly avoiding the cache syncing issue. There was [some concern](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L266) that the ESI URLs would be too long and cause problems, as the HTTP standard doesn't define a maximum length. Fortunately it seems most webservers and clients use at least a 2048 char limit and in practice there have been no reports of this being an issue. +Turpentine and Magento-Varnish differ most significantly on the final step. To render the ESI included block separately from the original request quite a bit of data is needed from the original request. Things like the block's name, what design/theme was active, and (most importantly) the registry keys that the block needs. Magento-Varnish's approach is that all that data should be saved in the cache, then looked up from the cache when the ESI request came back based on the cache key in the ESI request URL. Unfortunately, this can cause problems if Magento's cache and Varnish's cache are not in sync. For example, if the Magento cache is flushed but the Varnish cache is not, it can lead to Varnish requesting ESI blocks that Magento doesn't have the data to render. With Turpentine, I wanted to avoid this so instead all of the data is [encrypted](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L241) then just included in the ESI URL itself, neatly avoiding the cache syncing issue. There was [some concern](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L266) that the ESI URLs would be too long and cause problems, as the HTTP standard doesn't define a maximum length. Fortunately it seems most webservers and clients use at least a 2048 char limit and in practice there have been no reports of this being an issue. ## I got 99 problems... From 3781c8b9b1a4ec7d1448416ecf40dcdfc5a9a09f Mon Sep 17 00:00:00 2001 From: aheadley Date: Fri, 14 Mar 2014 13:36:35 -0400 Subject: [PATCH 067/311] explicitly coerce admin frontname to string --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 29eef12f6..f63f079a1 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -170,7 +170,7 @@ protected function _getAdminFrontname() { if( Mage::getStoreConfig( 'admin/url/use_custom_path' ) ) { return Mage::getStoreConfig( 'admin/url/custom_path' ); } else { - return Mage::getConfig()->getNode( + return (string)Mage::getConfig()->getNode( 'admin/routers/adminhtml/args/frontName' ); } } From ac3437c4b6f27a769a5c09442d9c2b6e5cdd9894 Mon Sep 17 00:00:00 2001 From: Achim Rosenhagen Date: Sun, 23 Mar 2014 22:13:00 +0100 Subject: [PATCH 068/311] fix addMessage() there is no getItems() function in Mage_Core_Model_Message_Abstract so you have to roll back to your original array( $message ) to get this to work. --- .../community/Nexcessnet/Turpentine/Block/Core/Messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php index 20cf13d4e..3c78bd882 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php @@ -114,7 +114,7 @@ public function addMessages( Mage_Core_Model_Message_Collection $messages ) { */ public function addMessage( Mage_Core_Model_Message_Abstract $message ) { if( $this->_fixMessages() ) { - $this->_saveMessages( $message->getItems() ); + $this->_saveMessages( array( $message ) ); } else { parent::addMessage( $message ); } From 036038620a41c4e2f4b666023d7afeb7fda93804 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Tue, 25 Mar 2014 22:57:27 +0100 Subject: [PATCH 069/311] Added ESI param, now we can cache the messages blocks Previously the messages ESI blocks were not cached because the "messages cleared" event is not reliable. My solution is to cache the messages block only when it does not contain a message (no_text). When a message needs to be communicated to the visitor the "core_session_abstract_add_message" event flushes the block. The block containing the message will not be cached because it does not get passed the "no_text" filter. During the next page visit an esi request is passed to Magento, which serves an empty messages block, which can be cached again. Being able to cache the "global_messages" and the "messages" blocks is a huge improvement, it highly reduces the number of hits on the Magento backend. I have implemented no_text and empty. --- .../Turpentine/controllers/EsiController.php | 13 +++++++++++++ .../frontend/base/default/layout/turpentine_esi.xml | 11 ++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index c409e5d65..ed48c6d20 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -100,10 +100,23 @@ public function getBlockAction() { $appShim->shim_setRequest( $dummyRequest ); $block = $this->_getEsiBlock( $esiData ); if( $block ) { + $blockEsiOptions = $block->getEsiOptions(); $block->setEsiOptions( false ); $resp->setBody( $block->toHtml() ); if( (int)$req->getParam( $esiHelper->getEsiTtlParam() ) > 0 ) { $cacheFlag = true; + if ( isset( $blockEsiOptions['only_cache_if'] ) ) { + switch ( $blockEsiOptions['only_cache_if'] ) { + case 'empty': + $cacheFlag = ( '' === $resp->getBody() ); + break; + case 'no_text': + $cacheFlag = ( '' === trim( strip_tags( $resp->getBody() ) ) ); + break; + default: + $cacheFlag = false; + } + } } if( $esiData->getEsiMethod() == 'ajax' ) { $resp->setHeader( 'Access-Control-Allow-Origin', diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index 08a877ff9..d23839590 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -102,19 +102,14 @@ - - private - ajax - + no_text @@ -122,12 +117,10 @@ private - ajax - + no_text From 55dafb6a7cb19a125ec7d421187baeac247ffb09 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Wed, 26 Mar 2014 00:02:15 +0100 Subject: [PATCH 070/311] Added ESI Decoder utility This tool can be used to decode an ESI request. You can just paste the whole ESI URL and push the button to decode it. Make sure you place this utility on a protected spot on your webserver where only authorized users can use it. --- util/esi-decoder.php | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 util/esi-decoder.php diff --git a/util/esi-decoder.php b/util/esi-decoder.php new file mode 100644 index 000000000..d78ed5068 --- /dev/null +++ b/util/esi-decoder.php @@ -0,0 +1,63 @@ + + + + + ESI Request Decoder + + + +
+
↓ ↓  Paste ESI Data or URL  ↓ ↓
+
+
+
+thaw( $processData ); +?> +
+
+
+ + + \ No newline at end of file From 3f28c9462fcfb084ac04995e459a0d1844ae309c Mon Sep 17 00:00:00 2001 From: Jan-Simon Winkelmann Date: Thu, 3 Apr 2014 15:13:02 +0200 Subject: [PATCH 071/311] Trigger magento layout events when rendering esi blocks as Mage_Core_Controller_Varien_Action->loadLayout() does --- .../Turpentine/controllers/EsiController.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index c409e5d65..14fdefd87 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -173,12 +173,27 @@ protected function _getEsiBlock( $esiData ) { Mage::getSingleton( 'core/design_package' ) ->setPackageName( $esiData->getDesignPackage() ) ->setTheme( $esiData->getDesignTheme() ); + + // dispatch event for adding handles to layout update + Mage::dispatchEvent( + 'controller_action_layout_load_before', + array('action'=>$this, 'layout'=>$layout) + ); + $layoutUpdate = $layout->getUpdate(); $layoutUpdate->load( $this->_swapCustomerHandles( $esiData->getLayoutHandles() ) ); foreach( $esiData->getDummyBlocks() as $blockName ) { $layout->createBlock( 'Mage_Core_Block_Template', $blockName ); } + + if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + Mage::dispatchEvent( + 'controller_action_layout_generate_xml_before', + array('action'=>$this, 'layout'=>$layout) + ); + } + $layout->generateXml(); $blockNode = current( $layout->getNode()->xpath( sprintf( '//block[@name=\'%s\']', @@ -189,18 +204,33 @@ protected function _getEsiBlock( $esiData ) { ->getChildBlockNames( $blockNode ); Mage::getModel( 'turpentine/shim_mage_core_layout' ) ->shim_generateFullBlock( $blockNode ); + + // dispatch event for adding xml layout elements + if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + Mage::dispatchEvent( + 'controller_action_layout_generate_blocks_before', + array('action'=>$this, 'layout'=>$layout) + ); + } foreach( $nodesToGenerate as $nodeName ) { foreach( $layout->getNode()->xpath( sprintf( '//reference[@name=\'%s\']', $nodeName ) ) as $node ) { $layout->generateBlocks( $node ); } } + if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + Mage::dispatchEvent( + 'controller_action_layout_generate_blocks_after', + array('action'=>$this, 'layout'=>$layout) + ); + } $block = $layout->getBlock( $esiData->getNameInLayout() ); } else { Mage::helper( 'turpentine/debug' )->logWarn( 'No block node found with @name="%s"', $esiData->getNameInLayout() ); } + $this->_isLayoutLoaded = true; Varien_Profiler::stop( 'turpentine::controller::esi::_getEsiBlock' ); return $block; } From 1a8f22f47a0bdfdfe63b1c0dbbd98b4be9dd0669 Mon Sep 17 00:00:00 2001 From: aheadley Date: Fri, 4 Apr 2014 12:19:48 -0400 Subject: [PATCH 072/311] move esi-decoder script to contrib/tools --- {util => contrib/tools}/esi-decoder.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {util => contrib/tools}/esi-decoder.php (100%) diff --git a/util/esi-decoder.php b/contrib/tools/esi-decoder.php similarity index 100% rename from util/esi-decoder.php rename to contrib/tools/esi-decoder.php From 24f46db6b2084b84d38858d7b62224dca55feb82 Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Thu, 13 Mar 2014 21:30:05 +0100 Subject: [PATCH 073/311] Fixes missing blocks when defined in a reference instead of the directly. --- .../Turpentine/controllers/EsiController.php | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 14fdefd87..c715dac2c 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -198,13 +198,42 @@ protected function _getEsiBlock( $esiData ) { $blockNode = current( $layout->getNode()->xpath( sprintf( '//block[@name=\'%s\']', $esiData->getNameInLayout() ) ) ); - if( $blockNode instanceof Varien_Simplexml_Element ) { - $nodesToGenerate = Mage::helper( 'turpentine/data' ) - ->setLayout( $layout ) - ->getChildBlockNames( $blockNode ); + + + /** @var Nexcessnet_Turpentine_Helper_Data $turpentineHelper */ + $turpentineHelper = Mage::helper( 'turpentine/data' ) + ->setLayout( $layout ); + + $blockNode = current( $layout->getNode()->xpath( + sprintf('//block[@name=\'%s\']',$esiData->getNameInLayout()) + ) ); + + $nodesToGenerate = array(); + if( $blockNode instanceof Mage_Core_Model_Layout_Element ) { + $nodesToGenerate = $turpentineHelper->getChildBlockNames( $blockNode ); Mage::getModel( 'turpentine/shim_mage_core_layout' ) ->shim_generateFullBlock( $blockNode ); + } else { + Mage::helper( 'turpentine/debug' )->logWarn( + 'No block node found with @name="%s"', + $esiData->getNameInLayout() ); + } + //find addional blocks that aren't defined in the but via + $referenceNodes = $layout->getNode()->xpath( sprintf( + '//reference[@name=\'%s\']', + $esiData->getNameInLayout() ) ); + foreach ($referenceNodes as $referenceNode) { + if ($referenceNode instanceof Mage_Core_Model_Layout_Element) { + $referencesToGenerate = $turpentineHelper + ->getChildBlockNames( $referenceNode ); + $nodesToGenerate = + array_merge($nodesToGenerate, $referencesToGenerate); + } + } + + + if( $blockNode instanceof Mage_Core_Model_Layout_Element ) { // dispatch event for adding xml layout elements if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { Mage::dispatchEvent( @@ -212,24 +241,23 @@ protected function _getEsiBlock( $esiData ) { array('action'=>$this, 'layout'=>$layout) ); } - foreach( $nodesToGenerate as $nodeName ) { + + foreach( array_unique($nodesToGenerate) as $nodeName ) { foreach( $layout->getNode()->xpath( sprintf( '//reference[@name=\'%s\']', $nodeName ) ) as $node ) { $layout->generateBlocks( $node ); } } + $block = $layout->getBlock( $esiData->getNameInLayout() ); + if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { Mage::dispatchEvent( 'controller_action_layout_generate_blocks_after', array('action'=>$this, 'layout'=>$layout) ); } - $block = $layout->getBlock( $esiData->getNameInLayout() ); - } else { - Mage::helper( 'turpentine/debug' )->logWarn( - 'No block node found with @name="%s"', - $esiData->getNameInLayout() ); } + $this->_isLayoutLoaded = true; Varien_Profiler::stop( 'turpentine::controller::esi::_getEsiBlock' ); return $block; From c5cdd97dd0be72fcfd94a0a37d6200437744f146 Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Mon, 17 Mar 2014 12:36:02 +0100 Subject: [PATCH 074/311] Cleaned up EsiController::_getEsiBlock. --- .../Turpentine/controllers/EsiController.php | 92 ++++++++----------- 1 file changed, 36 insertions(+), 56 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index c715dac2c..241840e78 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -149,7 +149,7 @@ public function postDispatch() { * Generate the ESI block * * @param Varien_Object $esiData - * @return Mage_Core_Block_Template + * @return Mage_Core_Block_Template|null */ protected function _getEsiBlock( $esiData ) { $block = null; @@ -173,32 +173,13 @@ protected function _getEsiBlock( $esiData ) { Mage::getSingleton( 'core/design_package' ) ->setPackageName( $esiData->getDesignPackage() ) ->setTheme( $esiData->getDesignTheme() ); - - // dispatch event for adding handles to layout update - Mage::dispatchEvent( - 'controller_action_layout_load_before', - array('action'=>$this, 'layout'=>$layout) - ); - $layoutUpdate = $layout->getUpdate(); $layoutUpdate->load( $this->_swapCustomerHandles( $esiData->getLayoutHandles() ) ); foreach( $esiData->getDummyBlocks() as $blockName ) { $layout->createBlock( 'Mage_Core_Block_Template', $blockName ); } - - if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { - Mage::dispatchEvent( - 'controller_action_layout_generate_xml_before', - array('action'=>$this, 'layout'=>$layout) - ); - } - $layout->generateXml(); - $blockNode = current( $layout->getNode()->xpath( sprintf( - '//block[@name=\'%s\']', - $esiData->getNameInLayout() ) ) ); - /** @var Nexcessnet_Turpentine_Helper_Data $turpentineHelper */ $turpentineHelper = Mage::helper( 'turpentine/data' ) @@ -208,56 +189,55 @@ protected function _getEsiBlock( $esiData ) { sprintf('//block[@name=\'%s\']',$esiData->getNameInLayout()) ) ); - $nodesToGenerate = array(); - if( $blockNode instanceof Mage_Core_Model_Layout_Element ) { - $nodesToGenerate = $turpentineHelper->getChildBlockNames( $blockNode ); - Mage::getModel( 'turpentine/shim_mage_core_layout' ) - ->shim_generateFullBlock( $blockNode ); - } else { + if( ! ($blockNode instanceof Mage_Core_Model_Layout_Element) ) { Mage::helper( 'turpentine/debug' )->logWarn( - 'No block node found with @name="%s"', - $esiData->getNameInLayout() ); + 'No block node found with @name="%s"', + $esiData->getNameInLayout() ); + return null; } + $nodesToGenerate = $turpentineHelper->getChildBlockNames( $blockNode ); + Mage::getModel( 'turpentine/shim_mage_core_layout' ) + ->shim_generateFullBlock( $blockNode ); + //find addional blocks that aren't defined in the but via $referenceNodes = $layout->getNode()->xpath( sprintf( '//reference[@name=\'%s\']', $esiData->getNameInLayout() ) ); - foreach ($referenceNodes as $referenceNode) { - if ($referenceNode instanceof Mage_Core_Model_Layout_Element) { - $referencesToGenerate = $turpentineHelper - ->getChildBlockNames( $referenceNode ); - $nodesToGenerate = - array_merge($nodesToGenerate, $referencesToGenerate); + if ($referenceNodes) { + foreach ($referenceNodes as $referenceNode) { + if ($referenceNode instanceof Mage_Core_Model_Layout_Element) { + $referencesToGenerate = $turpentineHelper + ->getChildBlockNames( $referenceNode ); + $nodesToGenerate = + array_merge($nodesToGenerate, $referencesToGenerate); + } } } + // dispatch event for adding xml layout elements + if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + Mage::dispatchEvent( + 'controller_action_layout_generate_blocks_before', + array('action'=>$this, 'layout'=>$layout) + ); + } - if( $blockNode instanceof Mage_Core_Model_Layout_Element ) { - // dispatch event for adding xml layout elements - if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { - Mage::dispatchEvent( - 'controller_action_layout_generate_blocks_before', - array('action'=>$this, 'layout'=>$layout) - ); - } - - foreach( array_unique($nodesToGenerate) as $nodeName ) { - foreach( $layout->getNode()->xpath( sprintf( - '//reference[@name=\'%s\']', $nodeName ) ) as $node ) { - $layout->generateBlocks( $node ); - } + foreach( array_unique($nodesToGenerate) as $nodeName ) { + foreach( $layout->getNode()->xpath( sprintf( + '//reference[@name=\'%s\']', $nodeName ) ) as $node ) { + $layout->generateBlocks( $node ); } - $block = $layout->getBlock( $esiData->getNameInLayout() ); + } + $block = $layout->getBlock( $esiData->getNameInLayout() ); - if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { - Mage::dispatchEvent( - 'controller_action_layout_generate_blocks_after', - array('action'=>$this, 'layout'=>$layout) - ); - } + if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + Mage::dispatchEvent( + 'controller_action_layout_generate_blocks_after', + array('action'=>$this, 'layout'=>$layout) + ); } - + $this->_isLayoutLoaded = true; Varien_Profiler::stop( 'turpentine::controller::esi::_getEsiBlock' ); return $block; From 86001b770d7067270ee0a7ccec4636d3411ead8a Mon Sep 17 00:00:00 2001 From: Paul Hachmang Date: Mon, 7 Apr 2014 12:18:32 +0200 Subject: [PATCH 075/311] Re-added missing events. --- .../Turpentine/controllers/EsiController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 241840e78..154ae9340 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -173,12 +173,26 @@ protected function _getEsiBlock( $esiData ) { Mage::getSingleton( 'core/design_package' ) ->setPackageName( $esiData->getDesignPackage() ) ->setTheme( $esiData->getDesignTheme() ); + + // dispatch event for adding handles to layout update + Mage::dispatchEvent( + 'controller_action_layout_load_before', + array('action'=>$this, 'layout'=>$layout) + ); + $layoutUpdate = $layout->getUpdate(); $layoutUpdate->load( $this->_swapCustomerHandles( $esiData->getLayoutHandles() ) ); foreach( $esiData->getDummyBlocks() as $blockName ) { $layout->createBlock( 'Mage_Core_Block_Template', $blockName ); } + + if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + Mage::dispatchEvent( + 'controller_action_layout_generate_xml_before', + array('action'=>$this, 'layout'=>$layout) + ); + } $layout->generateXml(); /** @var Nexcessnet_Turpentine_Helper_Data $turpentineHelper */ From 3a6a030517c8cd1fca8c7adf928cd5acc44df0b7 Mon Sep 17 00:00:00 2001 From: "Damian A. Pastorini" Date: Mon, 7 Apr 2014 09:08:10 -0300 Subject: [PATCH 076/311] Refactored cache types validation. --- .../Turpentine/Block/Adminhtml/Cache/Grid.php | 39 ++++++++++++------- .../default/default/layout/turpentine.xml | 3 -- .../default/default/turpentine/cache-fix.js | 18 --------- 3 files changed, 26 insertions(+), 34 deletions(-) delete mode 100644 skin/adminhtml/default/default/turpentine/cache-fix.js diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php b/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php index 5da139385..07a045dcc 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php @@ -9,23 +9,36 @@ class Nexcessnet_Turpentine_Block_Adminhtml_Cache_Grid extends Mage_Adminhtml_Bl { /** - * Decorate status column values - * - * @return string + * Prepare grid collection */ - public function decorateStatus($value, $row, $column, $isExport) + protected function _prepareCollection() { - $class = ''; - if (isset($this->_invalidatedTypes[$row->getId()])) { - $cell = ''.$this->__('Invalidated').''; - } else { - if ($row->getStatus()) { - $cell = ''.$value.''; - } else { - $cell = ''.$value.''; + parent::_prepareCollection(); + $collection = $this->getCollection(); + $turpentineEnabled = false; + $fullPageEnabled = false; + foreach ($collection as $key=>$item) + { + if($item->getStatus()==1 && ($item->getId()=='turpentine_pages' || $item->getId()=='turpentine_esi_blocks')) + { + $turpentineEnabled = true; } + if($item->getStatus()==1 && $item->getId()=='full_page') + { + $fullPageEnabled = true; + } + } + if($turpentineEnabled) + { + $collection->removeItemByKey('full_page'); + } + if($fullPageEnabled) + { + $collection->removeItemByKey('turpentine_pages'); + $collection->removeItemByKey('turpentine_esi_blocks'); } - return $cell; + $this->setCollection($collection); + return $this; } } diff --git a/app/design/adminhtml/default/default/layout/turpentine.xml b/app/design/adminhtml/default/default/layout/turpentine.xml index f0e96d49f..c960780b7 100644 --- a/app/design/adminhtml/default/default/layout/turpentine.xml +++ b/app/design/adminhtml/default/default/layout/turpentine.xml @@ -19,9 +19,6 @@ --> - - skin_jsturpentine/cache-fix.js - Date: Tue, 8 Apr 2014 17:08:41 +0200 Subject: [PATCH 077/311] Add config option to control stripping of whitespaces from generated VCL files --- .../Nexcessnet/Turpentine/Helper/Data.php | 26 ++++++++++++++++ .../Model/Config/Select/StripWhitespace.php | 31 +++++++++++++++++++ .../Turpentine/Model/Varnish/Admin.php | 3 +- .../Model/Varnish/Configurator/Abstract.php | 2 +- .../Model/Varnish/Configurator/Version2.php | 5 +-- .../Model/Varnish/Configurator/Version3.php | 5 +-- .../Varnish/ManagementController.php | 6 ++-- .../Nexcessnet/Turpentine/etc/system.xml | 10 ++++++ 8 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index b680efba1..730293928 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -270,6 +270,32 @@ public function getAutoApplyOnSave() { 'turpentine_varnish/general/auto_apply_on_save' ); } + /** + * Get config value specifying when to strip VCL whitespaces + * + * @return string + */ + public function getStripVclWhitespace() { + return Mage::getStoreConfig( + 'turpentine_varnish/general/strip_vcl_whitespace' ); + } + + /** + * Check if VCL whitespaces should be stripped for the given action + * + * @param string $action can be either "apply", "save" or "download" + * @return bool + */ + public function shouldStripVclWhitespace($action) { + $configValue = $this->getStripVclWhitespace(); + if ( $configValue==='always' ) { + return true; + } elseif ( $configValue==='apply' && $action==='apply' ) { + return true; + } + return false; + } + /** * Get the cookie name for the Varnish bypass * diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php new file mode 100644 index 000000000..4aa1889fc --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php @@ -0,0 +1,31 @@ + 'always', 'label' => $helper->__( 'Always' ) ), + array( 'value' => 'apply', 'label' => $helper->__( 'Only when applying directly to Varnish' ) ), + array( 'value' => 'never', 'label' => $helper->__( 'Never' ) ), + ); + } +} \ No newline at end of file diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 833dba850..aadcf0a88 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -99,13 +99,14 @@ public function flushContentType( $contentType ) { */ public function applyConfig() { $result = array(); + $helper = Mage::helper( 'turpentine' ); foreach( Mage::helper( 'turpentine/varnish' )->getSockets() as $socket ) { $cfgr = Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract::getFromSocket( $socket ); $socketName = $socket->getConnectionString(); if( is_null( $cfgr ) ) { $result[$socketName] = 'Failed to load configurator'; } else { - $vcl = $cfgr->generate(); + $vcl = $cfgr->generate( $helper->shouldStripVclWhitespace('apply') ); $vclName = Mage::helper( 'turpentine/data' ) ->secureHash( microtime() ); try { 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 f63f079a1..3f45252ae 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -71,7 +71,7 @@ public function __construct( $options=array() ) { $this->_options = array_merge( $this->_options, $options ); } - abstract public function generate(); + abstract public function generate($doClean=true); // abstract protected function _getTemplateVars(); /** diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php index d778e05ed..2ac5e2e62 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php @@ -27,13 +27,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version2 /** * Generate the Varnish 2.1-compatible VCL * + * @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) * @return string */ - public function generate() { + public function generate($doClean=true) { $tplFile = $this->_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), $this->_getTemplateVars() ); - return $this->_cleanVcl( $vcl ); + return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; } protected function _getAdvancedSessionValidation() { diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php index 5e80ca641..be6c7a382 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php @@ -27,13 +27,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3 /** * Generate the Varnish 3.0-compatible VCL * + * @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) * @return string */ - public function generate() { + public function generate($doClean=true) { $tplFile = $this->_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), $this->_getTemplateVars() ); - return $this->_cleanVcl( $vcl ); + return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; } protected function _getAdvancedSessionValidation() { diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php index 69fceade6..1db2b4d5a 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php @@ -157,7 +157,8 @@ public function saveConfigAction() { } else { Mage::dispatchEvent( 'turpentine_varnish_save_config', array( 'cfgr' => $cfgr ) ); - $result = $cfgr->save( $cfgr->generate() ); + $result = $cfgr->save( $cfgr->generate( + Mage::helper('turpentine')->shouldStripVclWhitespace('save') ) ); if( $result[0] ) { $this->_getSession() ->addSuccess( Mage::helper('turpentine') @@ -183,7 +184,8 @@ public function getConfigAction() { $this->_getSession()->addError( $this->__( 'Failed to load configurator' ) ); $this->_redirect( '*/cache' ); } else { - $vcl = $cfgr->generate(); + $vcl = $cfgr->generate( + Mage::helper( 'turpentine' )->shouldStripVclWhitespace('download') ); $this->getResponse() ->setHttpResponseCode( 200 ) ->setHeader( 'Content-Type', 'text/plain', true ) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 280171cc6..21de3942a 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -52,6 +52,16 @@ 0 0 + + + If whitespace stripping is disabled, generated VCL files will get larger and may exceed the cli_buffer varnish config. + select + turpentine/config_select_stripWhitespace + 25 + 1 + 0 + 0 + It is a major security vulnerability, to leave this enabled on production sites From b0a8de201b621d88cdb405d6817d87d544d8dbd5 Mon Sep 17 00:00:00 2001 From: Jan-Simon Winkelmann Date: Tue, 8 Apr 2014 17:08:41 +0200 Subject: [PATCH 078/311] Add config option to control stripping of whitespaces from generated VCL files --- .../Nexcessnet/Turpentine/Helper/Data.php | 26 ++++++++++++++++ .../Model/Config/Select/StripWhitespace.php | 31 +++++++++++++++++++ .../Turpentine/Model/Varnish/Admin.php | 3 +- .../Model/Varnish/Configurator/Abstract.php | 2 +- .../Model/Varnish/Configurator/Version2.php | 5 +-- .../Model/Varnish/Configurator/Version3.php | 5 +-- .../Varnish/ManagementController.php | 6 ++-- .../Nexcessnet/Turpentine/etc/config.xml | 1 + .../Nexcessnet/Turpentine/etc/system.xml | 10 ++++++ 9 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index b680efba1..730293928 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -270,6 +270,32 @@ public function getAutoApplyOnSave() { 'turpentine_varnish/general/auto_apply_on_save' ); } + /** + * Get config value specifying when to strip VCL whitespaces + * + * @return string + */ + public function getStripVclWhitespace() { + return Mage::getStoreConfig( + 'turpentine_varnish/general/strip_vcl_whitespace' ); + } + + /** + * Check if VCL whitespaces should be stripped for the given action + * + * @param string $action can be either "apply", "save" or "download" + * @return bool + */ + public function shouldStripVclWhitespace($action) { + $configValue = $this->getStripVclWhitespace(); + if ( $configValue==='always' ) { + return true; + } elseif ( $configValue==='apply' && $action==='apply' ) { + return true; + } + return false; + } + /** * Get the cookie name for the Varnish bypass * diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php new file mode 100644 index 000000000..4aa1889fc --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php @@ -0,0 +1,31 @@ + 'always', 'label' => $helper->__( 'Always' ) ), + array( 'value' => 'apply', 'label' => $helper->__( 'Only when applying directly to Varnish' ) ), + array( 'value' => 'never', 'label' => $helper->__( 'Never' ) ), + ); + } +} \ No newline at end of file diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 833dba850..aadcf0a88 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -99,13 +99,14 @@ public function flushContentType( $contentType ) { */ public function applyConfig() { $result = array(); + $helper = Mage::helper( 'turpentine' ); foreach( Mage::helper( 'turpentine/varnish' )->getSockets() as $socket ) { $cfgr = Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract::getFromSocket( $socket ); $socketName = $socket->getConnectionString(); if( is_null( $cfgr ) ) { $result[$socketName] = 'Failed to load configurator'; } else { - $vcl = $cfgr->generate(); + $vcl = $cfgr->generate( $helper->shouldStripVclWhitespace('apply') ); $vclName = Mage::helper( 'turpentine/data' ) ->secureHash( microtime() ); try { 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 f63f079a1..3f45252ae 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -71,7 +71,7 @@ public function __construct( $options=array() ) { $this->_options = array_merge( $this->_options, $options ); } - abstract public function generate(); + abstract public function generate($doClean=true); // abstract protected function _getTemplateVars(); /** diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php index d778e05ed..2ac5e2e62 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php @@ -27,13 +27,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version2 /** * Generate the Varnish 2.1-compatible VCL * + * @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) * @return string */ - public function generate() { + public function generate($doClean=true) { $tplFile = $this->_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), $this->_getTemplateVars() ); - return $this->_cleanVcl( $vcl ); + return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; } protected function _getAdvancedSessionValidation() { diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php index 5e80ca641..be6c7a382 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php @@ -27,13 +27,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3 /** * Generate the Varnish 3.0-compatible VCL * + * @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) * @return string */ - public function generate() { + public function generate($doClean=true) { $tplFile = $this->_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), $this->_getTemplateVars() ); - return $this->_cleanVcl( $vcl ); + return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; } protected function _getAdvancedSessionValidation() { diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php index 69fceade6..1db2b4d5a 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php @@ -157,7 +157,8 @@ public function saveConfigAction() { } else { Mage::dispatchEvent( 'turpentine_varnish_save_config', array( 'cfgr' => $cfgr ) ); - $result = $cfgr->save( $cfgr->generate() ); + $result = $cfgr->save( $cfgr->generate( + Mage::helper('turpentine')->shouldStripVclWhitespace('save') ) ); if( $result[0] ) { $this->_getSession() ->addSuccess( Mage::helper('turpentine') @@ -183,7 +184,8 @@ public function getConfigAction() { $this->_getSession()->addError( $this->__( 'Failed to load configurator' ) ); $this->_redirect( '*/cache' ); } else { - $vcl = $cfgr->generate(); + $vcl = $cfgr->generate( + Mage::helper( 'turpentine' )->shouldStripVclWhitespace('download') ); $this->getResponse() ->setHttpResponseCode( 200 ) ->setHeader( 'Content-Type', 'text/plain', true ) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index c7e97727e..c689b447e 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -27,6 +27,7 @@ 1 + always 0 0 1 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 280171cc6..21de3942a 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -52,6 +52,16 @@ 0 0 + + + If whitespace stripping is disabled, generated VCL files will get larger and may exceed the cli_buffer varnish config. + select + turpentine/config_select_stripWhitespace + 25 + 1 + 0 + 0 + It is a major security vulnerability, to leave this enabled on production sites From 1f8408e32b60868feb8426307fb11f6db5ff0b9c Mon Sep 17 00:00:00 2001 From: Jan-Simon Winkelmann Date: Thu, 10 Apr 2014 23:23:12 +0200 Subject: [PATCH 079/311] Use rewrite to override default form key handling rather than include a local version of Mage_Core_Model_Session in the turpentine dist --- .../Turpentine/Model/Core/Session.php | 45 ++++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 5 ++ app/code/local/Mage/Core/Model/Session.php | 69 ------------------- 3 files changed, 50 insertions(+), 69 deletions(-) create mode 100644 app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php delete mode 100644 app/code/local/Mage/Core/Model/Session.php diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php new file mode 100644 index 000000000..cd3993f4d --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php @@ -0,0 +1,45 @@ +init('core', $name); + } + + /** + * Retrieve Session Form Key + * + * @return string A 16 bit unique key for forms + */ + public function getFormKey() + { + if (Mage::registry('replace_form_key') && + !Mage::app()->getRequest()->getParam('form_key', false)) { + // flag request for ESI processing + Mage::register('turpentine_esi_flag', true, true); + return '{{form_key_esi_placeholder}}'; + } else { + return parent::getFormKey(); + } + } +} diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index c689b447e..753264b7b 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -126,6 +126,11 @@ Nexcessnet_Turpentine_Model + + + Nexcessnet_Turpentine_Model_Core_Session + + diff --git a/app/code/local/Mage/Core/Model/Session.php b/app/code/local/Mage/Core/Model/Session.php deleted file mode 100644 index 4c701738f..000000000 --- a/app/code/local/Mage/Core/Model/Session.php +++ /dev/null @@ -1,69 +0,0 @@ -init('core', $name); - } - - /** - * Retrieve Session Form Key - * - * @return string A 16 bit unique key for forms - */ - public function getFormKey() - { - if (Mage::registry('replace_form_key') && - !Mage::app()->getRequest()->getParam('form_key', false)) { - // flag request for ESI processing - Mage::register('turpentine_esi_flag', true, true); - return '{{form_key_esi_placeholder}}'; - } else { - return $this->real_getFormKey(); - } - } - - public function real_getFormKey() - { - if (!$this->getData('_form_key')) { - $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); - } - return $this->getData('_form_key'); - } -} From 8cb2594aaa99c864ff23910a4a8f981300bce0e8 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Sun, 4 May 2014 02:25:21 +0200 Subject: [PATCH 080/311] Fix for search input field on search results page If the search input box is inside the header, it needs to contain the current search string after searching. Before this fix, the header ESI block was cached, so this did not work. The search string was wrong or not showing. --- .../base/default/layout/turpentine_esi.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index d23839590..1ba06d47a 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -177,6 +177,25 @@ --> + + + + + + + + private + page + 0 + + + + From f8df82d10d848030043655f97263e1bcbd6a3c4d Mon Sep 17 00:00:00 2001 From: Jan-Simon Winkelmann Date: Tue, 6 May 2014 11:04:20 +0200 Subject: [PATCH 081/311] Implement custom logging as per issue #510 --- .../Nexcessnet/Turpentine/Helper/Debug.php | 31 ++++++++++++++++++- .../Nexcessnet/Turpentine/etc/config.xml | 4 +++ .../Nexcessnet/Turpentine/etc/system.xml | 30 ++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php b/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php index 5c27702b9..03bae0ea8 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php @@ -135,10 +135,39 @@ public function logValue( $value, $name=null ) { */ protected function _log( $level, $message ) { $message = 'TURPENTINE: ' . $message; - Mage::log( $message, $level ); + Mage::log( $message, $level, $this->_getLogFileName() ); return $message; } + /** + * Get the name of the log file to use + * @return string + */ + protected function _getLogFileName() { + if ( $this->useCustomLogFile() ) { + return $this->getCustomLogFileName(); + } + return ''; + } + + /** + * Check if custom log file should be used + * @return bool + */ + public function useCustomLogFile() { + return Mage::getStoreConfigFlag( + 'turpentine_varnish/logging/use_custom_log_file' ); + } + + /** + * Get custom log file name + * @return string + */ + public function getCustomLogFileName() { + return (string)Mage::getStoreConfig( + 'turpentine_varnish/logging/custom_log_file_name' ); + } + /** * Format a list of function arguments for the backtrace * diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index c689b447e..44b8aa6b0 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -35,6 +35,10 @@ 0 0 + + 0 + turpentine.log + auto 127.0.0.1:6082 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 21de3942a..91f8677de 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -124,6 +124,36 @@ + + + 15 + 1 + 0 + 0 + + + + Log to custom log file rather than system.log + select + turpentine/config_select_toggle + 10 + 1 + 0 + 0 + + + + text + 20 + 1 + 0 + 0 + + 1 + + + + text From a50beae5e0853c66522f301736c36c7a03368825 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 8 May 2014 12:45:17 +0100 Subject: [PATCH 082/311] add feature to purge URL to admin interface --- .../turpentine/varnish_management.phtml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml b/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml index f4a8a0f05..a3cbf36c0 100644 --- a/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml +++ b/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml @@ -109,6 +109,25 @@ + + +
+ getBlockHtml('formkey')?> + + +
+ + + getChildHtml(); ?> From 7479093c7e1024c218053dbd1077870270181f14 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 8 May 2014 12:55:57 +0100 Subject: [PATCH 083/311] match margin of the labels --- .../default/template/turpentine/varnish_management.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml b/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml index a3cbf36c0..400e0e52a 100644 --- a/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml +++ b/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml @@ -119,7 +119,7 @@ __('Flush matching URLs') ?> - + From dd394200ef9e0b8817f935a38bb216bf2dfa9e45 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 8 May 2014 13:00:42 +0100 Subject: [PATCH 085/311] still not happy with the label --- .../default/template/turpentine/varnish_management.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml b/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml index d84663773..7a430d703 100644 --- a/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml +++ b/app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml @@ -119,12 +119,12 @@ __('Flush matching URLs') ?> - + From 7c0b77e8b54b83a52c47d5708b05ad49b36841a6 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Fri, 9 May 2014 01:04:04 +0200 Subject: [PATCH 086/311] Added decoding of referrer to the ESI Decoder Utility Also improved it a little and added explanation. --- contrib/tools/esi-decoder.php | 44 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/contrib/tools/esi-decoder.php b/contrib/tools/esi-decoder.php index d78ed5068..4fb272219 100644 --- a/contrib/tools/esi-decoder.php +++ b/contrib/tools/esi-decoder.php @@ -1,6 +1,19 @@
-
↓ ↓  Paste ESI Data or URL  ↓ ↓
-
+ +
getEsiDataParam(), '|' ); + if ( preg_match('|'.$dataPreg.'/([\w\.\-]+=*)|', $data, $matches) ) { $processData = $matches[1]; } $dataHelper = Mage::helper( 'turpentine/data' ); $esiDataArray = $dataHelper->thaw( $processData ); ?> +
=  DATA  =
-
+
getEsiReferrerParam(), '|' ); + if ( preg_match('|'.$refPreg.'/([\w\.\-]+),*|', $data, $matches) ): + $processData = $matches[1]; +?> +
=  REFERRER  =
+
+
urlBase64Decode( $processData ) ); ?>
+
+ From 1c7b92078da6501779c7116cc577f9fed62b0183 Mon Sep 17 00:00:00 2001 From: Jan-Simon Winkelmann Date: Wed, 14 May 2014 16:48:59 +0200 Subject: [PATCH 087/311] Allow for Double-Slash (//) comments in VCL files and strip them when trimming whitespaces. Fixes issue #535 --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 1 + app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl | 2 +- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 2 +- 3 files changed, 3 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 3f45252ae..29d5d2034 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -484,6 +484,7 @@ protected function _cleanVcl( $dirtyVcl ) { protected function _cleanVclHelper( $line ) { return $line && ( substr( $line, 0, 1 ) != '#' || + substr( $line, 0, 2 ) != '//' || substr( $line, 0, 8 ) == '#include' ); } diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 8a557e12b..c82fbdee5 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -20,7 +20,7 @@ ## Custom C Code C{ - # @source app/code/community/Nexcessnet/Turpentine/misc/uuid.c + // @source app/code/community/Nexcessnet/Turpentine/misc/uuid.c {{custom_c_code}} }C diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 278a6d79f..10f3d3f8a 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -20,7 +20,7 @@ ## Custom C Code C{ - # @source app/code/community/Nexcessnet/Turpentine/misc/uuid.c + // @source app/code/community/Nexcessnet/Turpentine/misc/uuid.c {{custom_c_code}} }C From 325e8a37d348887a964a65d4df19733c988c8b85 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Tue, 27 May 2014 23:59:06 +0200 Subject: [PATCH 088/311] Issue #544. Improved 'fix_product_toolbar" setting I discovered the ''fix_product_toolbar" setting already fixed the issue, except when the first visitor already has list view preferences stored in his catalog session. So I fixed that, and improved the setting's description. --- .../Turpentine/Block/Catalog/Product/List/Toolbar.php | 5 +++++ app/code/community/Nexcessnet/Turpentine/etc/system.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Catalog/Product/List/Toolbar.php b/app/code/community/Nexcessnet/Turpentine/Block/Catalog/Product/List/Toolbar.php index d6c458ce5..c89ed981c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Catalog/Product/List/Toolbar.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Catalog/Product/List/Toolbar.php @@ -25,5 +25,10 @@ class Nexcessnet_Turpentine_Block_Catalog_Product_List_Toolbar extends public function _construct() { parent::_construct(); $this->disableParamsMemorizing(); + // Remove params that may have been memorized before this fix was active. + Mage::getSingleton('catalog/session')->unsSortOrder(); + Mage::getSingleton('catalog/session')->unsSortDirection(); + Mage::getSingleton('catalog/session')->unsDisplayMode(); + Mage::getSingleton('catalog/session')->unsLimitPage(); } } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 21de3942a..9ea39037a 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -94,7 +94,7 @@ - Enable this to prevent caching the products-per-page setting in the product list + Enable this to prevent caching the visitor's view preferences of the product list select turpentine/config_select_toggle 65 From 4d4a2c86258cc098474371ff104bc055fde7d3fe Mon Sep 17 00:00:00 2001 From: aheadley Date: Mon, 30 Jun 2014 12:27:54 -0400 Subject: [PATCH 089/311] Fixed typo in technical notes filename --- TECHINCAL_NOTES.md => TECHNICAL_NOTES.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TECHINCAL_NOTES.md => TECHNICAL_NOTES.md (100%) diff --git a/TECHINCAL_NOTES.md b/TECHNICAL_NOTES.md similarity index 100% rename from TECHINCAL_NOTES.md rename to TECHNICAL_NOTES.md From 5d22a8deb12c703e5d646fd9c81ea597fe962d05 Mon Sep 17 00:00:00 2001 From: Lyndon Hook Date: Fri, 11 Jul 2014 10:12:39 +1000 Subject: [PATCH 090/311] Include theme specific handles to ESI data for dynamic layout update cache keys --- .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index d92b2eb94..f4f396d38 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -376,9 +376,9 @@ protected function _getBlockLayoutHandles( $block ) { // check if this handle has any block or reference tags that // refer to this block or a child block, unless the handle name // is blank - if( $handle !== '' && + if( $handle !== '' && ( strpos($handle, 'THEME') === 0 || $layoutXml->xpath( sprintf( - '//%s//*[@name=\'%s\']', $handle, $blockName ) ) ) { + '//%s//*[@name=\'%s\']', $handle, $blockName ) ) ) ) { $activeHandles[] = $handle; } } From f57b3c72db43335bdfcf840501213ec093d8c7ff Mon Sep 17 00:00:00 2001 From: Konrad Skrzynski Date: Fri, 18 Jul 2014 16:01:08 +0100 Subject: [PATCH 091/311] Fixed mispelled function name --- .../community/Nexcessnet/Turpentine/Model/Varnish/Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 833dba850..b4343641a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -154,7 +154,7 @@ protected function _testEsiSyntaxParam( $socket ) { } } else { // error - Mage::helper( 'turpentine/debug' )->logWarning( + Mage::helper( 'turpentine/debug' )->logWarn( 'Failed to parse param.show output to check esi_syntax value' ); $result = true; } From f0531b77a99298223077e32093ffda12dc9fd469 Mon Sep 17 00:00:00 2001 From: Konrad Skrzynski Date: Fri, 18 Jul 2014 16:30:36 +0100 Subject: [PATCH 092/311] Refactored debug helper to use direct calls instead of resolving function names with the magic method to speed up logging. Updated log function attributes handling to mitigate risk of incorrect vsprintf usage (issue #495). modified: app/code/community/Nexcessnet/Turpentine/Helper/Debug.php --- .../Nexcessnet/Turpentine/Helper/Debug.php | 139 ++++++++++++++---- 1 file changed, 107 insertions(+), 32 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php b/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php index 5c27702b9..471426872 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php @@ -21,41 +21,116 @@ class Nexcessnet_Turpentine_Helper_Debug extends Mage_Core_Helper_Abstract { /** - * Handle log* functions + * Logs errors * - * @param string $name - * @param array $args - * @return mixed + * @param $message + * @return string */ - public function __call( $name, $args ) { - if( substr( $name, 0, 3 ) === 'log' ) { - try { - $message = vsprintf( @$args[0], @array_slice( $args, 1 ) ); - } catch( Exception $e ) { - return parent::__call( $name, $args ); - } - switch( substr( $name, 3 ) ) { - case 'Error': - return $this->_log( Zend_Log::ERR, $message ); - case 'Warn': - return $this->_log( Zend_Log::WARN, $message ); - case 'Notice': - return $this->_log( Zend_Log::NOTICE, $message ); - case 'Info': - return $this->_log( Zend_Log::INFO, $message ); - case 'Debug': - if( Mage::helper( 'turpentine/varnish' ) - ->getVarnishDebugEnabled() ) { - return $this->_log( Zend_Log::DEBUG, $message ); - } else { - return; - } - default: - break; - } + public function logError( $message ) + { + if ( func_num_args() > 1 ) { + $message = $this->_prepareLogMessage( func_get_args() ); + } + + return $this->_log( Zend_Log::ERR, $message ); + } + + /** + * Logs warnings + * + * @param $message + * @return string + */ + public function logWarn( $message ) + { + if ( func_num_args() > 1 ) { + $message = $this->_prepareLogMessage( func_get_args() ); + } + + return $this->_log( Zend_Log::WARN, $message ); + } + + /** + * Logs notices + * + * @param $message + * @return string + */ + public function logNotice( $message ) + { + if ( func_num_args() > 1 ) { + $message = $this->_prepareLogMessage( func_get_args() ); + } + + return $this->_log( Zend_Log::NOTICE, $message ); + } + + /** + * Logs info. + * + * @param $message + * @return string + */ + public function logInfo( $message ) + { + if ( func_num_args() > 1 ) { + $message = $this->_prepareLogMessage( func_get_args() ); + } + + return $this->_log( Zend_Log::INFO, $message ); + } + + /** + * Logs debug. + * + * @param $message + * @return string + */ + public function logDebug( $message ) + { + if( ! Mage::helper( 'turpentine/varnish' )->getVarnishDebugEnabled() ) { + return; + } + + if ( func_num_args() > 1 ) { + $message = $this->_prepareLogMessage( func_get_args() ); } - // return parent::__call( $name, $args ); - return null; + + return $this->_log( Zend_Log::DEBUG, $message ); + } + + /** + * Prepares advanced log message. + * + * @param array $args + * @return string + */ + protected function _prepareLogMessage( array $args ) + { + $pattern = $args[0]; + $substitutes = array_slice( $args, 1 ); + + if ( ! $this->_validatePattern( $pattern, $substitutes ) ) { + return $pattern; + } + + return vsprintf( $pattern, $substitutes ); + } + + /** + * Validates string and attributes for substitution as per sprintf function. + * + * NOTE: this could be implemented as shown at + * http://stackoverflow.com/questions/2053664/how-to-check-that-vsprintf-has-the-correct-number-of-arguments-before-running + * although IMHO it's too time consuming to validate the patterns. + * + * @param string $pattern + * @param array $arguments + * @return bool + */ + protected function _validatePattern( $pattern, $arguments ) + { + return true; } /** From e2b7441f743fb94b916a1e0cdaca4b76d73653b5 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Fri, 15 Aug 2014 08:31:25 +0100 Subject: [PATCH 093/311] check if path isset before using it --- .../community/Nexcessnet/Turpentine/Model/Dummy/Request.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php b/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php index 39840a271..3f58a10dc 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php @@ -528,7 +528,9 @@ protected function _initFakeSuperGlobals() { protected function _fixupFakeSuperGlobals( $uri ) { $parsedUrl = parse_url( $uri ); - $this->SERVER['REQUEST_URI'] = $parsedUrl['path']; + if ( isset($parsedUrl['path']) ) { + $this->SERVER['REQUEST_URI'] = $parsedUrl['path']; + } if( isset( $parsedUrl['query'] ) && $parsedUrl['query'] ) { $this->SERVER['QUERY_STRING'] = $parsedUrl['query']; $this->SERVER['REQUEST_URI'] .= '?' . $this->SERVER['QUERY_STRING']; From 27e9503305e8a4e81a57208a0c0f6ae90ab00be8 Mon Sep 17 00:00:00 2001 From: aheadley Date: Fri, 26 Sep 2014 16:43:50 -0400 Subject: [PATCH 094/311] update changelog for 0.6.1 release --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b41a9fa5..10ed2bc7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -353,3 +353,22 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#443] Fixed caching of static assets when the *Add Store Code to Urls* option is enabled (thanks @jeroenvermeulen) * [#345] Fixed compatibility with Magento CE 1.8 and EE 1.13 + +### RELEASE-0.6.1 + + * [#471] Fixed `addMessage()` in messages block (@arosenhagen) + * [#445] Update `Cron.php` for compatibility with MageWorx_XSitemap (@evensisftw) + * [#474] Add ESI decoder utility (@jeroenvermeulen) + * [#485] Trigger layout events when rendering ESI blocks (@eth8505) + * [#490] Fix missing ESI blocks when they are defined in a reference instead + of a block (@paales) + * [#472] Added `` ESI parameter for caching flash message + blocks (@jeroenvermeulen) + * [#494] Added option to control the stripping of whitespace from generated + VCLs (@eth8505) + * [#549] Enabling the `fix_product_toolbar` option now clears previously set + view preferences (@jeroenvermeulen) + * [#529] Added decoding of the referrer to the ESI decoder + utility (@jeroenvermeulen) + * [#536] Allow `//` (double slash) comments in VCL files and strip them when + trimming whitespace (@eth8505) From 8cc3e233a6a4cb7eee0e4fbe06814f66464bf422 Mon Sep 17 00:00:00 2001 From: aheadley Date: Tue, 30 Sep 2014 12:42:28 -0400 Subject: [PATCH 095/311] fix vcl stripping logic --- .../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 29d5d2034..d9b2288c3 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -483,8 +483,8 @@ protected function _cleanVcl( $dirtyVcl ) { */ protected function _cleanVclHelper( $line ) { return $line && - ( substr( $line, 0, 1 ) != '#' || - substr( $line, 0, 2 ) != '//' || + ( ( substr( $line, 0, 1 ) != '#' && + substr( $line, 0, 2 ) != '//' ) || substr( $line, 0, 8 ) == '#include' ); } From 0a4d2675add584670af235ed2f30418a243cadde Mon Sep 17 00:00:00 2001 From: aheadley Date: Wed, 1 Oct 2014 12:50:32 -0400 Subject: [PATCH 096/311] bump version to 0.6.1 --- 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 c689b447e..aa99aad86 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.0 + 0.6.1 From 8c0c782bbd17bc3035f4f913bc7635e7a6f5afe3 Mon Sep 17 00:00:00 2001 From: Marshall Date: Fri, 6 Mar 2015 19:27:27 -0800 Subject: [PATCH 097/311] Added customer_group access option to cache based on customer group --- .../Turpentine/Model/Observer/Esi.php | 29 +++++++++++++++++-- .../Nexcessnet/Turpentine/etc/config.xml | 16 ++++++++++ .../Nexcessnet/Turpentine/misc/version-2.vcl | 6 ++++ .../Nexcessnet/Turpentine/misc/version-3.vcl | 6 ++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index d92b2eb94..c11c6eb72 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -20,6 +20,31 @@ */ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer { + /** + * Set a cookie with the customer group id when customer logs in + * + * Events: customer_login + * + * @param Varien_Object $eventObject + * @return null + */ + public function setCustomerGroupCookie( $eventObject ) { + $customer = $eventObject->getCustomer(); + $cookie = Mage::getSingleton('core/cookie'); + $cookie->set('customer_group', $customer->getGroupId()); + } + + /** + * Destroy the cookie with the customer group when customer logs out + * + * Events: customer_logout + * + * @param Varien_Object $eventObject + * @return null + */ + public function removeCustomerGroupCookie( $eventObject ) { + Mage::getSingleton('core/cookie')->delete('customer_group'); + } /** * Check the ESI flag and set the ESI header if needed @@ -293,7 +318,7 @@ protected function _getEsiData( $blockObject, $esiOptions ) { $esiData->setBlockType( get_class( $blockObject ) ); $esiData->setLayoutHandles( $this->_getBlockLayoutHandles( $blockObject ) ); $esiData->setEsiMethod( $esiOptions[$methodParam] ); - if( $esiOptions[$cacheTypeParam] == 'private' ) { + if( $esiOptions[$cacheTypeParam] == 'private' || $esiOptions[$cacheTypeParam] == 'customer_group' ) { if( is_array( @$esiOptions['flush_events'] ) ) { $esiData->setFlushEvents( array_merge( $esiHelper->getDefaultCacheClearEvents(), @@ -411,7 +436,7 @@ protected function _getDefaultEsiOptions( $options ) { // set the default TTL if( !isset( $options[$ttlParam] ) ) { - if( $options[$cacheTypeParam] == 'private' ) { + if( $options[$cacheTypeParam] == 'private' || $esiOptions[$cacheTypeParam] == 'customer_group' ) { switch( $options[$methodParam] ) { case 'ajax': $options[$ttlParam] = '0'; diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index aa99aad86..1baab5f61 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -210,6 +210,22 @@ + + + + turpentine/observer_esi + setCustomerGroupCookie + + + + + + + turpentine/observer_esi + removeCustomerGroupCookie + + + + + + + Nexcessnet_Turpentine_Block_Poll_ActivePoll + + diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index d23839590..532319fcd 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -96,6 +96,7 @@ private + ajax From 4a58deafef1892ede21a4d84f1d84c41f86a440b Mon Sep 17 00:00:00 2001 From: aricwatson Date: Wed, 27 May 2015 16:54:25 -0400 Subject: [PATCH 107/311] updated changelog with poll fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d103430d..59442b4cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -381,4 +381,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#740] Do not return pipe for OPTIONS straight away (@ashsmith) * [#598] Ensure POST request gets normalized data (@melvyn-sopacua) * [#739] Ban CMS Page after a CMS Revision has been updated (@ashsmith) - + * Added fix for community poll problems From a3b4c3b421dfd01cf93b2081bd79bb6aaa7c82c2 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Wed, 27 May 2015 16:57:32 -0400 Subject: [PATCH 108/311] Merge branch 'pr/516' into devel Fixes multiple sessions generated on first page visit Fix for #470 --- CHANGELOG.md | 1 + app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59442b4cc..df0434b13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -382,3 +382,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#598] Ensure POST request gets normalized data (@melvyn-sopacua) * [#739] Ban CMS Page after a CMS Revision has been updated (@ashsmith) * Added fix for community poll problems + * [#516] Fixes multiple sessions generated on first page visit (@jharrisonau) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 22815a4c9..064c51c19 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -157,8 +157,8 @@ sub vcl_recv { error 403 "External ESI requests are not allowed"; } } - # no frontend cookie was sent to us - if (req.http.Cookie !~ "frontend=") { + # 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 || req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") { # it's a crawler, give it a fake cookie From 778601d21d9d888620c5f4ef60ab767d2114e2c8 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Mon, 8 Jun 2015 15:20:14 -0400 Subject: [PATCH 109/311] Merge branch 'pr/796' into devel Ignore additional GET Parameters in Varnish Cache via Configuration (@thampe) --- CHANGELOG.md | 1 + .../Model/Varnish/Configurator/Abstract.php | 10 ++++++++++ .../community/Nexcessnet/Turpentine/etc/config.xml | 1 + .../community/Nexcessnet/Turpentine/etc/system.xml | 11 ++++++++++- .../Nexcessnet/Turpentine/misc/version-2.vcl | 7 ++++--- .../Nexcessnet/Turpentine/misc/version-3.vcl | 7 ++++--- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df0434b13..3645910c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -383,3 +383,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#739] Ban CMS Page after a CMS Revision has been updated (@ashsmith) * Added fix for community poll problems * [#516] Fixes multiple sessions generated on first page visit (@jharrisonau) + * [#796] Ignore additional GET Parameters in Varnish Cache via Configuration (@thampe) 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 cdb156fb3..8d65cb96a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -322,6 +322,14 @@ protected function _getGetParamExcludes() { Mage::getStoreConfig( 'turpentine_vcl/params/get_params' ) ) ); } + protected function _getIgnoreGetParameters() + { + /** @var Nexcessnet_Turpentine_Helper_Data $helper */ + $helper = Mage::helper('turpentine'); + $ignoredParameters = $helper->cleanExplode(',', Mage::getStoreConfig( 'turpentine_vcl/params/ignore_get_params')); + return implode( '|', $ignoredParameters); + } + /** * Get the Force Static Caching option * @@ -619,8 +627,10 @@ protected function _getTemplateVars() { 'url_base_regex' => $this->getBaseUrlPathRegex(), 'url_excludes' => $this->_getUrlExcludes(), 'get_param_excludes' => $this->_getGetParamExcludes(), + 'get_param_ignored' => $this->_getIgnoreGetParameters(), 'default_ttl' => $this->_getDefaultTtl(), 'enable_get_excludes' => ($this->_getGetParamExcludes() ? 'true' : 'false'), + 'enable_get_ignored' => ($this->_getIgnoreGetParameters()) ? 'true' : 'false', 'debug_headers' => $this->_getEnableDebugHeaders(), 'grace_period' => $this->_getGracePeriod(), 'force_cache_static' => $this->_getForceCacheStatic(), diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 4613ff617..7d4ee8dbb 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -69,6 +69,7 @@ __SID,XDEBUG_PROFILE + utm_source,utm_medium,utm_campaign,utm_content,utm_term,gclid,cx,ie,cof,siteurl 1 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 9ea39037a..219a9426a 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -400,8 +400,17 @@ 10 1 0 - 0 + 0 + + + Comma-separated list of GET variables that will be ignored for caching + textarea + 20 + 1 + 0 + 0 + diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 822827054..055f8cd3b 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -192,11 +192,12 @@ sub vcl_recv { req.url ~ "(?:[?&](?:{{get_param_excludes}})(?=[&=]|$))") { return (pass); } - if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") { - # Strip out Google related parameters - set req.url = regsuball(req.url, "(?:(\?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=[^&]+", "\1"); + if ({{enable_get_ignored}} && req.url ~ "[?&]({{get_param_ignored}})=") { + # Strip out ignored GET related parameters + set req.url = regsuball(req.url, "(?:(\?)?|&)(?:{{get_param_ignored}})=[^&]+", "\1"); set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); } + return (lookup); } diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 064c51c19..f06e91c58 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -190,12 +190,13 @@ sub vcl_recv { # TODO: should this be pass or pipe? return (pass); } - if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") { - # Strip out Google related parameters - set req.url = regsuball(req.url, "(?:(\?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=[^&]+", "\1"); + if ({{enable_get_ignored}} && req.url ~ "[?&]({{get_param_ignored}})=") { + # Strip out Ignored GET parameters + set req.url = regsuball(req.url, "(?:(\?)?|&)(?:{{get_param_ignored}})=[^&]+", "\1"); set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); } + # everything else checks out, try and pull from the cache return (lookup); } From de7cc14594d19d12fdc22db6a684684191d7b93b Mon Sep 17 00:00:00 2001 From: aricwatson Date: Mon, 8 Jun 2015 15:31:04 -0400 Subject: [PATCH 110/311] Merge branch 'pr/626' into devel Fix for dummy blocks not working (@jeroenvermeulen) --- CHANGELOG.md | 2 ++ .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3645910c5..479765386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -384,3 +384,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * Added fix for community poll problems * [#516] Fixes multiple sessions generated on first page visit (@jharrisonau) * [#796] Ignore additional GET Parameters in Varnish Cache via Configuration (@thampe) + * [#626] Fix for dummy blocks not working (@jeroenvermeulen) + diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index d92b2eb94..ab015c750 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -307,7 +307,11 @@ protected function _getEsiData( $blockObject, $esiOptions ) { $esiData->setParentUrl( Mage::app()->getRequest()->getRequestString() ); } if( is_array( $esiOptions['dummy_blocks'] ) ) { - $esiData->setDummyBlocks( $esiOptions['dummy_blocks'] ); + $dummyBlocks = array(); + foreach( $esiOptions['dummy_blocks'] as $key => $value ) { + $dummyBlocks[] = ( empty($value) && !is_numeric($key) ) ? $key : $value; + } + $esiData->setDummyBlocks( $dummyBlocks ); } else { Mage::helper( 'turpentine/debug' )->logWarn( 'Invalid dummy_blocks for block: %s', From 8b4bee216419cdd9a04a928159a8d9ea1ed6c0fb Mon Sep 17 00:00:00 2001 From: aricwatson Date: Tue, 9 Jun 2015 11:10:23 -0400 Subject: [PATCH 111/311] Merge branch 'pr/719' into devel Replace connect20/nexcessnet_turpentine package (@ihor-sviziev) --- CHANGELOG.md | 2 +- composer.json | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 479765386..75a605225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -385,4 +385,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#516] Fixes multiple sessions generated on first page visit (@jharrisonau) * [#796] Ignore additional GET Parameters in Varnish Cache via Configuration (@thampe) * [#626] Fix for dummy blocks not working (@jeroenvermeulen) - + * [#719) Replace connect20/nexcessnet_turpentine package in composer.json (@ihor-sviziev) diff --git a/composer.json b/composer.json index f203b99f6..fbc63ad77 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,9 @@ "email": "aheadley@nexcess.net" } ], + "replace": { + "connect20/nexcessnet_turpentine": "self.version" + }, "require": { "magento-hackathon/magento-composer-installer": "*" } From c9a003a95a49628dec502646f1f3021c304f783e Mon Sep 17 00:00:00 2001 From: aricwatson Date: Wed, 10 Jun 2015 13:48:49 -0400 Subject: [PATCH 112/311] Bump version to 0.6.2 --- 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 7d4ee8dbb..d50d43b0c 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.1 + 0.6.2 From 8f6acc5a2e2921a5d24e54afc8ad793cb685105a Mon Sep 17 00:00:00 2001 From: Barry Carlyon Date: Fri, 19 Jun 2015 12:34:42 +0100 Subject: [PATCH 113/311] Fix messages returning a empty
    --- .../community/Nexcessnet/Turpentine/Block/Core/Messages.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php index 3c78bd882..924a9de06 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php @@ -204,6 +204,10 @@ protected function _toHtml() { $html = $this->_real_toHtml(); } $this->_directCall = false; + + if (count($this->getMessages()) == 0) { + return ''; + } return $html; } From 4b7e376697781d7e7a5aeab72523ddce876ac2a2 Mon Sep 17 00:00:00 2001 From: Barry Carlyon Date: Fri, 19 Jun 2015 12:38:50 +0100 Subject: [PATCH 114/311] Tweak logging for empty getNameInLayout --- .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index ab015c750..c164aecc0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -196,7 +196,7 @@ public function injectEsi( $eventObject ) { if( $esiHelper->getEsiBlockLogEnabled() ) { $debugHelper->logInfo( 'Checking ESI block candidate: %s', - $blockObject->getNameInLayout() ); + $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); } if( $esiHelper->shouldResponseUseEsi() && $blockObject instanceof Mage_Core_Block_Template && @@ -205,11 +205,11 @@ public function injectEsi( $eventObject ) { // admin blocks are not allowed to be cached for now $debugHelper->logWarn( 'Ignoring attempt to inject adminhtml block: %s', - $blockObject->getNameInLayout() ); + $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); return; } elseif( $esiHelper->getEsiBlockLogEnabled() ) { $debugHelper->logInfo( 'Block check passed, injecting block: %s', - $blockObject->getNameInLayout() ); + $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); } Varien_Profiler::start( 'turpentine::observer::esi::injectEsi' ); $ttlParam = $esiHelper->getEsiTtlParam(); From c99015248a6c17504cf2e268ea5b8ce51a0cd270 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 23 Jun 2015 13:41:36 +0000 Subject: [PATCH 115/311] refs 499 added real_getFormKey() to Session.php --- .../Nexcessnet/Turpentine/Model/Core/Session.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php index cd3993f4d..7b2afa444 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php @@ -42,4 +42,12 @@ public function getFormKey() return parent::getFormKey(); } } + + public function real_getFormKey() + { + if (!$this->getData('_form_key')) { + $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); + } + return $this->getData('_form_key'); + } } From c1e0cc67769b4576ae2243ce3fb0c3145da6cc96 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 23 Jun 2015 14:33:20 +0000 Subject: [PATCH 116/311] refs new version 0.6.2 (added #499) --- CHANGELOG.md | 4 ++++ app/code/community/Nexcessnet/Turpentine/etc/config.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75a605225..d473b567f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -386,3 +386,7 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#796] Ignore additional GET Parameters in Varnish Cache via Configuration (@thampe) * [#626] Fix for dummy blocks not working (@jeroenvermeulen) * [#719) Replace connect20/nexcessnet_turpentine package in composer.json (@ihor-sviziev) + +### RELEASE-0.6.3 + * [#499] Use rewrite instead of local Session model for form key handling (@eth8505) + diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index ffdfdfcc9..f67896000 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.1 + 0.6.3 From fca51343c8fa7346b399eeb37c758091da394bc7 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 23 Jun 2015 16:17:53 +0000 Subject: [PATCH 117/311] refs fixed Travis CI --- .../Turpentine/controllers/Adminhtml/CacheController.php | 2 +- build/mage-package.xml | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php index 00a46b621..d5b13c6fa 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php @@ -4,7 +4,7 @@ * Date: 08/01/14 */ -require_once 'Mage/Adminhtml/controllers/CacheController.php'; +require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS.'CacheController.php'; class Nexcessnet_Turpentine_Adminhtml_CacheController extends Mage_Adminhtml_CacheController { diff --git a/build/mage-package.xml b/build/mage-package.xml index 5c2286c26..7e97facc7 100644 --- a/build/mage-package.xml +++ b/build/mage-package.xml @@ -60,7 +60,6 @@ magecommunity - magelocal magedesign magedesign magedesign @@ -69,7 +68,6 @@ Nexcessnet/Turpentine - Mage/Core/Model/Session.php adminhtml/default/default/layout/turpentine.xml adminhtml/default/default/template/turpentine frontend/base/default/layout/turpentine_esi.xml @@ -79,7 +77,6 @@ dir file - file dir file dir From 96ae3f18f14eeee972f47229c83f5bddaeb320b5 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 23 Jun 2015 17:28:22 +0000 Subject: [PATCH 118/311] refs #817 added message to show the user what is going on. --- .../Turpentine/controllers/Adminhtml/CacheController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php index d5b13c6fa..74ca7cfce 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php @@ -29,7 +29,10 @@ public function massEnableAction() if($allTypes['turpentine_pages']==1 || $allTypes['turpentine_esi_blocks']==1) { $allTypes['full_page'] = 0; - } + Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Full page cache has been disabled since Varnish cache is enabled.")); + } else if ($allTypes['full_page']==1) { + Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Turpentine cache has been disabled since Full Page cache is enabled.")); + } // disable FPC when Varnish cache is enabled. Mage::app()->saveUseCache($allTypes); $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("%s cache type(s) enabled.", $updatedTypes)); From f034cba25971228b148100603cf70409436e7763 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 23 Jun 2015 17:58:04 +0000 Subject: [PATCH 119/311] refs #817 added to CHANGELOG.md. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d473b567f..440676c4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -389,4 +389,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess ### RELEASE-0.6.3 * [#499] Use rewrite instead of local Session model for form key handling (@eth8505) - + * [#817] Damian/cache management extended. Added validations for EE and Full Page cache (@damian-pastorini) From 6fc0a951aee2cf6207515ea30182e20239113f32 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Wed, 24 Jun 2015 13:04:44 +0000 Subject: [PATCH 120/311] refs #821 fixed config.xml to prevent 404 page when applying VCL. --- app/code/community/Nexcessnet/Turpentine/etc/config.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index ade40d496..49e82ed8c 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -403,7 +403,6 @@ Nexcessnet_Turpentine - Nexcessnet_Turpentine_Adminhtml From 0d297eb90a9d4fb4d173514a248a5387274fac22 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Wed, 24 Jun 2015 17:13:56 +0000 Subject: [PATCH 121/311] refs #521 added to changelog. --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 440676c4f..23bd93b3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -389,4 +389,6 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess ### RELEASE-0.6.3 * [#499] Use rewrite instead of local Session model for form key handling (@eth8505) - * [#817] Damian/cache management extended. Added validations for EE and Full Page cache (@damian-pastorini) + * [#817] Damian/cache management extended. Added validations for EE and Full Page cache (@damian-pastorini) + * [#521] Fix for search input field on search results page (@jeroenvermeulen) + From 42dfd51a813f6d2adbe1e7c9b78a78265647a53a Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Wed, 24 Jun 2015 17:55:22 +0000 Subject: [PATCH 122/311] refs EOL for PHP 5.5. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d861b4d87..5b015828a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ language: php php: - - 5.2 - 5.3 - 5.4 - 5.5 + - 5.6 install: - sudo apt-get install -qq python-markdown libxml-xpath-perl build-essential From f6a874ed6af93e34a016841055aeeec6029f81f7 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Wed, 24 Jun 2015 15:31:42 -0400 Subject: [PATCH 123/311] fix for #801 - recently viewed products Needed an ESI policy for left.reports.product.viewed --- .../base/default/layout/turpentine_esi.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index 9bcc07fb1..1ca2f9b6e 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -198,6 +198,20 @@ + + + + + + private + + + + + + + + From 616cacbc84cbb8f66ba678c8632afc1fd5046314 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Thu, 25 Jun 2015 13:39:56 -0400 Subject: [PATCH 124/311] Updated to include recently viewed products fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23bd93b3f..1526bb6d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -391,4 +391,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#499] Use rewrite instead of local Session model for form key handling (@eth8505) * [#817] Damian/cache management extended. Added validations for EE and Full Page cache (@damian-pastorini) * [#521] Fix for search input field on search results page (@jeroenvermeulen) + * Fix for recently viewed products block in CE 1.9.1 (Issue #801) From 99084c6471b4dc24673c72f2abd140fc0ea73aeb Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Fri, 26 Jun 2015 13:39:04 +0000 Subject: [PATCH 125/311] refs CHANGELOG.md #522. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1526bb6d0..a450bb9e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -392,4 +392,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#817] Damian/cache management extended. Added validations for EE and Full Page cache (@damian-pastorini) * [#521] Fix for search input field on search results page (@jeroenvermeulen) * Fix for recently viewed products block in CE 1.9.1 (Issue #801) - + * [#522] Custom log file (issue #510) (@eth8505) From 21c3b824fea52c9789f41f519928165e8f5980bf Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Fri, 26 Jun 2015 13:48:26 +0000 Subject: [PATCH 126/311] refs Comment for field #522. --- app/code/community/Nexcessnet/Turpentine/etc/system.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index bb7da8623..fce48ecfd 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -145,7 +145,8 @@ text 20 - 1 + Only enter a file name, no paths. + 1 0 0 From 006c1ceac20fe91915ef37e2c96bf77819305f89 Mon Sep 17 00:00:00 2001 From: Vladimir Samsonov Date: Tue, 30 Jun 2015 09:28:22 +0200 Subject: [PATCH 127/311] refs #84, #345, #435, #477, #690, #774 Fixed dublicated frontend cookie bug (or unconfirmed-bug?) --- .../Model/Varnish/Configurator/Abstract.php | 21 +++++++++++++++++++ .../Nexcessnet/Turpentine/misc/version-3.vcl | 4 ++++ 2 files changed, 25 insertions(+) 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 8d65cb96a..a40d8bc80 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -195,6 +195,26 @@ protected function _getNormalizeHostTarget() { } } + /** + * Get hosts as regex + * + * ex: base_url: example.com + * path_regex: (example.com|example.net) + * + * @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 )); + + $pattern = '('.implode('|', $hosts).')'; + return $pattern; + } + /** * Get the base url path regex * @@ -625,6 +645,7 @@ 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(), diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index f06e91c58..e65b00d4f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -157,6 +157,10 @@ sub vcl_recv { error 403 "External ESI requests are not allowed"; } } + # if host is not allowed in magento pass to backend + if (req.url !~ "{{allowed_hosts_regex}}") { + return (pass); + } # 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 07c8edb334312daadee28bc76386935e0f99f419 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Tue, 30 Jun 2015 15:29:24 +0100 Subject: [PATCH 128/311] Add OS X .DS_Store and nbproject to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 997f34855..ceb029c4a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ build/*.tgz build/*.html app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl .idea +.DS_Store +nbproject/ From e2317a8f7c884b9e9891a7b82b39033191894d7e Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 30 Jun 2015 14:35:25 -0500 Subject: [PATCH 129/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a450bb9e0..3d2e08571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -393,3 +393,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#521] Fix for search input field on search results page (@jeroenvermeulen) * Fix for recently viewed products block in CE 1.9.1 (Issue #801) * [#522] Custom log file (issue #510) (@eth8505) + * [#836] Add OS X .DS_Store and nbproject to gitignore (@cbb7123) + * [#832] Fixed duplicated frontend cookie bug (@mabigo) From 21cb6ec771323539aece0f23b4a9c5697f4f0e3f Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Wed, 1 Jul 2015 13:43:52 +0000 Subject: [PATCH 130/311] refs CHANGELOG.md. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d2e08571..edd172303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -395,3 +395,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#522] Custom log file (issue #510) (@eth8505) * [#836] Add OS X .DS_Store and nbproject to gitignore (@cbb7123) * [#832] Fixed duplicated frontend cookie bug (@mabigo) + * [#527] Feature/admin clear specific page (@craigcarnell) From af52c83c2ba30293fcbd555c498775c9b5df73eb Mon Sep 17 00:00:00 2001 From: mbalparda Date: Wed, 1 Jul 2015 11:49:56 -0500 Subject: [PATCH 131/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index edd172303..c02f2bd5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -396,3 +396,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#836] Add OS X .DS_Store and nbproject to gitignore (@cbb7123) * [#832] Fixed duplicated frontend cookie bug (@mabigo) * [#527] Feature/admin clear specific page (@craigcarnell) + * [#838] Added customer_group access option to cache based on customer group (@pejoo) From a8fb03edef44c347ab9ecbdc34acbfc68d7b04d2 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 3 Jul 2015 09:35:10 -0500 Subject: [PATCH 132/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c02f2bd5e..c81bafc7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -397,3 +397,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#832] Fixed duplicated frontend cookie bug (@mabigo) * [#527] Feature/admin clear specific page (@craigcarnell) * [#838] Added customer_group access option to cache based on customer group (@pejoo) + * [#825] Fix messages returning a empty "
      " (@BarryCarlyon) From c91a93baec9def9119305a45c1ecb0bdd86df60a Mon Sep 17 00:00:00 2001 From: aricwatson Date: Tue, 7 Jul 2015 09:09:24 -0400 Subject: [PATCH 133/311] Fixes bug in PR 838 - wrong variable name --- app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 92b45d909..5df64fe06 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -444,7 +444,7 @@ protected function _getDefaultEsiOptions( $options ) { // set the default TTL if( !isset( $options[$ttlParam] ) ) { - if( $options[$cacheTypeParam] == 'private' || $esiOptions[$cacheTypeParam] == 'customer_group' ) { + if( $options[$cacheTypeParam] == 'private' || $options[$cacheTypeParam] == 'customer_group' ) { switch( $options[$methodParam] ) { case 'ajax': $options[$ttlParam] = '0'; From c1d421e45791c8cd36ce6fca8bdebcf9ce3e7cc6 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Tue, 7 Jul 2015 10:40:41 -0400 Subject: [PATCH 134/311] fix for PR 832 - check host rather than URL in vcl --- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index f14eb83c7..71ac9fab0 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -158,7 +158,7 @@ sub vcl_recv { } } # if host is not allowed in magento pass to backend - if (req.url !~ "{{allowed_hosts_regex}}") { + if (req.http.host !~ "{{allowed_hosts_regex}}") { return (pass); } # no frontend cookie was sent to us AND this is not an ESI or AJAX call From 26f833f9f52355bd89f338c225e5c056bcf72928 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Tue, 7 Jul 2015 10:41:09 -0400 Subject: [PATCH 135/311] escape quotes in allowed hosts regex --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a40d8bc80..432157d1c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -211,7 +211,7 @@ public function getAllowedHostsRegex() { $hosts = array_values(array_unique( $hosts )); - $pattern = '('.implode('|', $hosts).')'; + $pattern = '('.implode('|', array_map("preg_quote", $hosts)).')'; return $pattern; } From 99605b277b20c48cd91683ef4e590e99ac3da640 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 7 Jul 2015 11:33:04 -0500 Subject: [PATCH 136/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c81bafc7f..f8efff790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -397,4 +397,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#832] Fixed duplicated frontend cookie bug (@mabigo) * [#527] Feature/admin clear specific page (@craigcarnell) * [#838] Added customer_group access option to cache based on customer group (@pejoo) - * [#825] Fix messages returning a empty "
        " (@BarryCarlyon) + * [#825] Fix messages returning a empty "ul" (@BarryCarlyon) + * [#826] Tweak logging for empty getNameInLayout (@BarryCarlyon) From 66615b7cc987854e8671911ab6c3aa22afb808a2 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Tue, 7 Jul 2015 15:49:31 -0400 Subject: [PATCH 137/311] Removed session generation Fixes issues #806, #345 and many others related to extra sessions, empty carts, etc. Causes Varnish to be bypassed on first page load for new sessions. --- .../community/Nexcessnet/Turpentine/misc/version-3.vcl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 71ac9fab0..55801b236 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -46,6 +46,7 @@ import std; ## Custom Subroutines +/* -- REMOVED sub generate_session { # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID # from SID URL param @@ -72,7 +73,7 @@ sub generate_session { } else { set req.http.Cookie = req.http.X-Varnish-Faked-Session; } -} +} sub generate_session_expires { # sets X-Varnish-Cookie-Expires to now + esi_private_ttl in format: @@ -92,7 +93,7 @@ sub generate_session_expires { ); }C } - +-- */ ## Varnish Subroutines sub vcl_recv { @@ -169,7 +170,8 @@ sub vcl_recv { set req.http.Cookie = "frontend=crawler-session"; } else { # it's a real user, make up a new session for them - call generate_session; + # call generate_session; + return (pipe); } } if ({{force_cache_static}} && @@ -351,7 +353,7 @@ sub vcl_fetch { sub vcl_deliver { if (req.http.X-Varnish-Faked-Session) { # need to set the set-cookie header since we just made it out of thin air - call generate_session_expires; + # call generate_session_expires; set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session + "; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/"; if (req.http.Host) { From 4bdac9721ad1a3be09a38ccf41a1822ccadb0c60 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Wed, 8 Jul 2015 10:11:46 -0500 Subject: [PATCH 138/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8efff790..00ba16d58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -399,3 +399,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#838] Added customer_group access option to cache based on customer group (@pejoo) * [#825] Fix messages returning a empty "ul" (@BarryCarlyon) * [#826] Tweak logging for empty getNameInLayout (@BarryCarlyon) + * [#843] Check if path isset before using it (@craigcarnell) From 2668e1307dc40a5a1376abc2b41ec58bd9664d86 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Wed, 8 Jul 2015 13:26:22 -0400 Subject: [PATCH 139/311] Updated changelog for session generation removal update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00ba16d58..78d53c82e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -400,3 +400,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#825] Fix messages returning a empty "ul" (@BarryCarlyon) * [#826] Tweak logging for empty getNameInLayout (@BarryCarlyon) * [#843] Check if path isset before using it (@craigcarnell) + * Removed session generation code in VCL - see issue #345 \ No newline at end of file From 445f2b24d620aa9f82ae2377c2f2aeae015e66ba Mon Sep 17 00:00:00 2001 From: mbalparda Date: Wed, 8 Jul 2015 14:10:23 -0500 Subject: [PATCH 140/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78d53c82e..98c0d3d44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -400,4 +400,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#825] Fix messages returning a empty "ul" (@BarryCarlyon) * [#826] Tweak logging for empty getNameInLayout (@BarryCarlyon) * [#843] Check if path isset before using it (@craigcarnell) - * Removed session generation code in VCL - see issue #345 \ No newline at end of file + * Removed session generation code in VCL - see issue #345 + * [#586] Updated debug helper (@magedev) From de5abee0a68daafe647c2df669011998eff9da4b Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Thu, 9 Jul 2015 21:57:40 +0200 Subject: [PATCH 141/311] Fix for HTTPS ESI URLs The config setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS. Varnish 3 will treat HTTPS URLs as relative, leading to a 404 in Magento, leading to recursive ESI includes. --- app/code/community/Nexcessnet/Turpentine/Helper/Esi.php | 5 ++++- .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index 7f2c3a73d..135e300ef 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -357,7 +357,10 @@ public function getFormKeyEsiUrl() { $this->getEsiScopeParam() => 'global', $this->getEsiCacheTypeParam() => 'private', ); - return Mage::getUrl( 'turpentine/esi/getFormKey', $urlOptions ); + $esiUrl = Mage::getUrl( 'turpentine/esi/getFormKey', $urlOptions ); + // setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS + $esiUrl = preg_replace( '|^https://|i', 'http://', $esiUrl ); + return $esiUrl; } /** diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 006448eb5..670d6b2f9 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -286,6 +286,10 @@ public function injectEsi( $eventObject ) { } $esiUrl = Mage::getUrl( 'turpentine/esi/getBlock', $urlOptions ); + if( $esiOptions[$methodParam] == 'esi' ) { + // setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS + $esiUrl = preg_replace( '|^https://|i', 'http://', $esiUrl ); + } $blockObject->setEsiUrl( $esiUrl ); // avoid caching the ESI template output to prevent the double-esi- // include/"ESI processing not enabled" bug From 9b793c8f6196200ac983764bb6720f68f9e3fd97 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Fri, 10 Jul 2015 09:01:31 -0400 Subject: [PATCH 142/311] Remove 'set poll' log messages - fixes #845 --- .../community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php index 9d0d9b4d5..8e66ba08a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php @@ -23,9 +23,6 @@ class Nexcessnet_Turpentine_Block_Poll_Activepoll extends Mage_Poll_Block_Active public function setTemplate($template) { - $debugHelper = Mage::helper( 'turpentine/debug' ); - $debugHelper->logInfo('Set poll template'); - $this->_template = $template; $this->setPollTemplate('turpentine/ajax.phtml', 'poll' ); $this->setPollTemplate('turpentine/ajax.phtml', 'results' ); From 90da78e626a1061b1b3a114335bc715edf5eae9b Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 10 Jul 2015 14:37:30 -0500 Subject: [PATCH 143/311] refs Fix from Deivison Arthur for formKey issues and switch between fixes. --- .../Nexcessnet/Turpentine/Helper/Data.php | 10 ++++++ .../Turpentine/Model/Observer/Esi.php | 25 +++++++++++++ .../Model/Varnish/Configurator/Abstract.php | 23 ++++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 35 +++++++++++++++++++ .../Nexcessnet/Turpentine/etc/system.xml | 10 ++++++ .../Nexcessnet/Turpentine/misc/version-3.vcl | 3 +- 6 files changed, 105 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index 730293928..e9220fb2f 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -270,6 +270,16 @@ public function getAutoApplyOnSave() { 'turpentine_varnish/general/auto_apply_on_save' ); } + /** + * Get config value specifying when to strip VCL whitespaces + * + * @return string + */ + public function getVclFix() { + return Mage::getStoreConfig( + 'turpentine_varnish/general/vcl_fix' ); + } + /** * Get config value specifying when to strip VCL whitespaces * diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 006448eb5..b492a9ca5 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -520,4 +520,29 @@ protected function _checkIsNotEsiUrl( $url ) { protected function _checkIsEsiUrl( $url ) { return !$this->_checkIsNotEsiUrl( $url ); } + + public function hookToControllerActionPreDispatch($observer) { + if(Mage::helper( 'turpentine/data')->getVclFix() == 0 && $observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') { + Mage::dispatchEvent("add_to_cart_before", array('request' => $observer->getControllerAction()->getRequest())); + } + } + + public function hookToControllerActionPostDispatch($observer) { + if($observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') { + Mage::dispatchEvent("add_to_cart_after", array('request' => $observer->getControllerAction()->getRequest())); + } + } + + public function hookToAddToCartBefore($observer) { + //Mage::log("hookToAddToCartBefore-antes ".print_r($observer->getEvent()->getRequest()->getParams(),true)." will be added to cart.", null, 'carrinho.log', true); + $key = Mage::getSingleton('core/session')->getFormKey(); + $observer->getEvent()->getRequest()->setParam('form_key', $key); + $request = $observer->getEvent()->getRequest()->getParams(); + //Mage::log("hookToAddToCartBefore ".print_r($request,true)." will be added to cart.", null, 'carrinho.log', true); + } + + public function hookToAddToCartAfter($observer) { + $request = $observer->getEvent()->getRequest()->getParams(); + //Mage::log("hookToAddToCartAfter ".print_r($request,true)." is added to cart.", null, 'carrinho.log', true); + } } 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 432157d1c..a618a55ef 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -350,6 +350,27 @@ protected function _getIgnoreGetParameters() return implode( '|', $ignoredParameters); } + /** + * Get the Generate Session Expires + * + * @return string + */ + protected function _getGenerateSession() { + return Mage::getStoreConfig( 'turpentine_vcl/general/vcl_fix' ) + ? '# call generate_session' : 'call generate_session;'; + } + + + /** + * Get the Generate Session Expires + * + * @return string + */ + protected function _getGenerateSessionExpires() { + return Mage::getStoreConfig( 'turpentine_vcl/general/vcl_fix' ) + ? '# call generate_session_expires' : 'call generate_session_expires;'; + } + /** * Get the Force Static Caching option * @@ -655,6 +676,8 @@ protected function _getTemplateVars() { 'debug_headers' => $this->_getEnableDebugHeaders(), 'grace_period' => $this->_getGracePeriod(), 'force_cache_static' => $this->_getForceCacheStatic(), + 'generate_session_expires' => $this->_getGenerateSessionExpires(), + 'generate_session' => $this->_getGenerateSession(), 'static_extensions' => $this->_getStaticExtensions(), 'static_ttl' => $this->_getStaticTtl(), 'url_ttls' => $this->_getUrlTtls(), diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index d1da4f9ed..2541069be 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -29,6 +29,7 @@ 1 always 0 + 1 0 1 0 @@ -416,6 +417,40 @@ + + + + + turpentine/observer_esi + hookToControllerActionPreDispatch + + + + + + + + turpentine/observer_esi + hookToAddToCartBefore + + + + + diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index fce48ecfd..39232f4bd 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -62,6 +62,16 @@ 0 0 + + + When Yes is selected, a VCL fix will be used. If No is selected, an observer will be used to prevent formKey issues. + select + 28 + adminhtml/system_config_source_enabledisable + 1 + 1 + 1 + It is a major security vulnerability, to leave this enabled on production sites diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 55801b236..af4a1ebbc 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -170,7 +170,7 @@ sub vcl_recv { set req.http.Cookie = "frontend=crawler-session"; } else { # it's a real user, make up a new session for them - # call generate_session; + {{generate_session}}# call generate_session; return (pipe); } } @@ -354,6 +354,7 @@ sub vcl_deliver { if (req.http.X-Varnish-Faked-Session) { # need to set the set-cookie header since we just made it out of thin air # call generate_session_expires; + {{generate_session_expires}} set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session + "; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/"; if (req.http.Host) { From 2b6813d27befe8b5eea6ab6498312ea4dd57c1c0 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 10 Jul 2015 14:51:48 -0500 Subject: [PATCH 144/311] refs Fix from Deivison Arthur for formKey issues and switch between fixes. Added check for vcl sub. --- .../Model/Varnish/Configurator/Abstract.php | 25 ++++++++++++++++++- .../Nexcessnet/Turpentine/misc/version-3.vcl | 4 +-- 2 files changed, 26 insertions(+), 3 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 a618a55ef..3c146c8ea 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -351,7 +351,28 @@ protected function _getIgnoreGetParameters() } /** - * Get the Generate Session Expires + * Get the Generate Session + * + * @return string + */ + protected function _getGenerateSessionStart() { + return Mage::getStoreConfig( 'turpentine_vcl/general/vcl_fix' ) + ? '/* -- REMOVED' : ''; + } + + /** + * Get the Generate Session + * + * @return string + */ + protected function _getGenerateSessionEnd() { + return Mage::getStoreConfig( 'turpentine_vcl/general/vcl_fix' ) + ? '-- */' : ''; + } + + + /** + * Get the Generate Session * * @return string */ @@ -678,6 +699,8 @@ protected function _getTemplateVars() { 'force_cache_static' => $this->_getForceCacheStatic(), 'generate_session_expires' => $this->_getGenerateSessionExpires(), 'generate_session' => $this->_getGenerateSession(), + 'generate_session_start' => $this->_getGenerateSessionStart(), + 'generate_session_end' => $this->_getGenerateSessionEnd(), 'static_extensions' => $this->_getStaticExtensions(), 'static_ttl' => $this->_getStaticTtl(), 'url_ttls' => $this->_getUrlTtls(), diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index af4a1ebbc..ce4583917 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -46,7 +46,7 @@ import std; ## Custom Subroutines -/* -- REMOVED +{{generate_session_start}} sub generate_session { # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID # from SID URL param @@ -93,7 +93,7 @@ sub generate_session_expires { ); }C } --- */ +{{generate_session_end}} ## Varnish Subroutines sub vcl_recv { From bdc29b56a7637d1a04d4f23a58e4b2e253a26d45 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 10 Jul 2015 15:19:02 -0500 Subject: [PATCH 145/311] refs Fix from Deivison Arthur. Fixed typo. --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 8 ++++---- app/code/community/Nexcessnet/Turpentine/etc/system.xml | 2 +- 2 files changed, 5 insertions(+), 5 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 3c146c8ea..ddfc7026a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -356,7 +356,7 @@ protected function _getIgnoreGetParameters() * @return string */ protected function _getGenerateSessionStart() { - return Mage::getStoreConfig( 'turpentine_vcl/general/vcl_fix' ) + return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) ? '/* -- REMOVED' : ''; } @@ -366,7 +366,7 @@ protected function _getGenerateSessionStart() { * @return string */ protected function _getGenerateSessionEnd() { - return Mage::getStoreConfig( 'turpentine_vcl/general/vcl_fix' ) + return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) ? '-- */' : ''; } @@ -377,7 +377,7 @@ protected function _getGenerateSessionEnd() { * @return string */ protected function _getGenerateSession() { - return Mage::getStoreConfig( 'turpentine_vcl/general/vcl_fix' ) + return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) ? '# call generate_session' : 'call generate_session;'; } @@ -388,7 +388,7 @@ protected function _getGenerateSession() { * @return string */ protected function _getGenerateSessionExpires() { - return Mage::getStoreConfig( 'turpentine_vcl/general/vcl_fix' ) + return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) ? '# call generate_session_expires' : 'call generate_session_expires;'; } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 39232f4bd..97b7ec08c 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -64,7 +64,7 @@ - When Yes is selected, a VCL fix will be used. If No is selected, an observer will be used to prevent formKey issues. + When Enable is selected, a VCL fix will be used to prevent formKey issues. If Disable is selected, an observer will be used. select 28 adminhtml/system_config_source_enabledisable From 6d55e1f1e613d4df07858f1f09c1018bbc627b64 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Mon, 13 Jul 2015 11:27:27 +0100 Subject: [PATCH 146/311] Allow to override initial cookie domain for multi-store setups --- .../Model/Varnish/Configurator/Abstract.php | 28 ++++++++++++++++++- .../Nexcessnet/Turpentine/etc/system.xml | 18 ++++++++++++ .../Nexcessnet/Turpentine/misc/version-3.vcl | 17 +++++++++-- 3 files changed, 60 insertions(+), 3 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 432157d1c..e385e28ce 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -633,6 +633,26 @@ protected function _vcl_sub_normalize_host() { 'normalize_host_target' => $this->_getNormalizeHostTarget() ) ); } + /** + * Get the hostname for cookie normalization + * + * @return string + */ + protected function _getNormalizeCookieTarget() { + return trim( Mage::getStoreConfig( + 'turpentine_vcl/normalization/cookie_target' ) ); + } + + /** + * Get the regex for cookie normalization + * + * @return string + */ + protected function _getNormalizeCookieRegex() { + return trim( Mage::getStoreConfig( + 'turpentine_vcl/normalization/cookie_regex' ) ); + } + /** * Build the list of template variables to apply to the VCL template * @@ -686,7 +706,13 @@ protected function _getTemplateVars() { if( Mage::getStoreConfig( 'turpentine_vcl/normalization/host' ) ) { $vars['normalize_host'] = $this->_vcl_sub_normalize_host(); } - + if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_regex' ) ) { + $vars['normalize_cookie_regex'] = $this->_getNormalizeCookieRegex(); + } + 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 ); diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index fce48ecfd..b51a90617 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -336,6 +336,24 @@ 0 0 + + + Cookie regex to match to override initial cookie domain + text + 50 + 1 + 0 + 0 + + + + Domain to force cookies to which the regex matches + text + 60 + 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 55801b236..b01a687c2 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -357,8 +357,21 @@ sub vcl_deliver { set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session + "; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/"; if (req.http.Host) { - set resp.http.Set-Cookie = resp.http.Set-Cookie + - "; domain=" + regsub(req.http.Host, ":\d+$", ""); + if (req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") { + # it's a crawler, no need to share cookies + set resp.http.Set-Cookie = resp.http.Set-Cookie + + "; domain=" + regsub(req.http.Host, ":\d+$", ""); + } else { + # it's a real user, allow sharing of cookies between stores + if(req.http.Host ~ "{{normalize_cookie_regex}}") { + set resp.http.Set-Cookie = resp.http.Set-Cookie + + "; domain={{normalize_cookie_target}}"; + } else { + set resp.http.Set-Cookie = resp.http.Set-Cookie + + "; domain=" + regsub(req.http.Host, ":\d+$", ""); + } + } + } } set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly"; unset resp.http.X-Varnish-Cookie-Expires; From f4b85728d7e1b43ada540d5d1e0bc4592cf5fa29 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Mon, 13 Jul 2015 11:46:47 +0100 Subject: [PATCH 147/311] Replace Nexcessnet_Turpentine_Model_Dummy_Request with Magento model --- app/code/community/Nexcessnet/Turpentine/Helper/Esi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index 7f2c3a73d..338ae300a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -181,7 +181,7 @@ public function getDummyRequest( $url=null ) { if( $url === null ) { $url = $this->getDummyUrl(); } - $request = new Nexcessnet_Turpentine_Model_Dummy_Request( $url ); + $request = Mage::getModel('turpentine/dummy_request', $url); $request->fakeRouterDispatch(); return $request; } From c0b61d1f85b8fa669dd0075a6febfc50d7d27c46 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Mon, 13 Jul 2015 11:53:36 +0100 Subject: [PATCH 148/311] escape | character --- app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php b/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php index 3f58a10dc..52f6d7344 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php @@ -526,6 +526,7 @@ protected function _initFakeSuperGlobals() { * @return null */ protected function _fixupFakeSuperGlobals( $uri ) { + $uri = str_replace('|', urlencode('|'), $uri); $parsedUrl = parse_url( $uri ); if ( isset($parsedUrl['path']) ) { From c4f4411c8495f674191b7025d1bdb7b707cf4f05 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 13 Jul 2015 07:47:14 -0600 Subject: [PATCH 149/311] refs New infra in Travis. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5b015828a..e52205cb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ php: - 5.6 install: - - sudo apt-get install -qq python-markdown libxml-xpath-perl build-essential + - apt-get install -qq python-markdown libxml-xpath-perl build-essential script: - make all From 4d5954737567069e1b2e62a79f190859f0bdd47e Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 13 Jul 2015 07:50:02 -0600 Subject: [PATCH 150/311] refs New infra in Travis. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e52205cb0..d058f1395 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: php - +sudo: false php: - 5.3 - 5.4 From 563cd9a07397a45dff6ef1b72b9e6f682aed21aa Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 13 Jul 2015 07:51:24 -0600 Subject: [PATCH 151/311] refs New infra in Travis. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d058f1395..f4c3d2c74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ php: - 5.6 install: - - apt-get install -qq python-markdown libxml-xpath-perl build-essential + - sudo apt-get install -qq python-markdown libxml-xpath-perl build-essential script: - make all From bfe8411a55f0d3e125cd30fb5332f56035cebc29 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 13 Jul 2015 08:03:57 -0600 Subject: [PATCH 152/311] refs New infra in Travis. --- .travis.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4c3d2c74..199d0e0f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,16 @@ language: php -sudo: false php: - 5.3 - 5.4 - 5.5 - 5.6 -install: - - sudo apt-get install -qq python-markdown libxml-xpath-perl build-essential +addons: + apt: + packages: + - python-markdown + - libxml-xpath-perl + - build-essential script: - make all From 39d30bccec4fbf80180a9e600bed2b6e29d236ee Mon Sep 17 00:00:00 2001 From: Vladimir Samsonov Date: Tue, 14 Jul 2015 07:26:00 +0200 Subject: [PATCH 153/311] [#832] bugfix, reg.url does not contain hostname (leads permanent request pass, 0 hits) --- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index e65b00d4f..8ad463d61 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -158,7 +158,7 @@ sub vcl_recv { } } # if host is not allowed in magento pass to backend - if (req.url !~ "{{allowed_hosts_regex}}") { + if (req.http.host !~ "{{allowed_hosts_regex}}") { return (pass); } # no frontend cookie was sent to us AND this is not an ESI or AJAX call From 902240af9e49b3aaa1ac54f57ee038e9a6f3c6f9 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Tue, 14 Jul 2015 13:04:18 +0100 Subject: [PATCH 154/311] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page --- .../Model/Varnish/Configurator/Abstract.php | 89 +++++++++++++++++++ .../Nexcessnet/Turpentine/etc/system.xml | 29 ++++++ .../Nexcessnet/Turpentine/misc/version-3.vcl | 4 + 3 files changed, 122 insertions(+) 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 432157d1c..e53457bd8 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -633,6 +633,89 @@ protected function _vcl_sub_normalize_host() { 'normalize_host_target' => $this->_getNormalizeHostTarget() ) ); } + /** + * Get the allowed IPs when in maintenance mode + * + * @return string + */ + protected function _vcl_sub_maintenance_allowed_ips() { + if((! $this->_getDebugIps()) || ! Mage::getStoreConfig( 'turpentine_vcl/maintenance/custom_vcl_synth' ) ) { + return false; + } + + switch(Mage::getStoreConfig( 'turpentine_varnish/servers/version' )) { + case 4.0: + $tpl = <<_formatTemplate( $tpl, array( + 'debug_ips' => Mage::getStoreConfig( 'dev/restrict/allow_ips' ) ) ); + } + + /** + * Get the allowed IPs when in maintenance mode + * + * @return string + */ + protected function _vcl_sub_synth() { + if((! $this->_getDebugIps()) || ! Mage::getStoreConfig( 'turpentine_vcl/maintenance/custom_vcl_synth' ) ) { + return false; + } + + switch(Mage::getStoreConfig( 'turpentine_varnish/servers/version' )) { + case 4.0: + $tpl = <<_formatTemplate( $tpl, array( + 'vcl_synth_content' => Mage::getStoreConfig( 'turpentine_vcl/maintenance/custom_vcl_synth' ) ) ); + } + /** * Build the list of template variables to apply to the VCL template * @@ -686,6 +769,12 @@ protected function _getTemplateVars() { if( Mage::getStoreConfig( 'turpentine_vcl/normalization/host' ) ) { $vars['normalize_host'] = $this->_vcl_sub_normalize_host(); } + if( Mage::getStoreConfig( 'turpentine_vcl/maintenance/enable' ) ) { + // in vcl_recv set the allowed IPs otherwise load the vcl_error (v3)/vcl_synth (v4) + $vars['maintenance_allowed_ips'] = $this->_vcl_sub_maintenance_allowed_ips(); + // set the vcl_error from Magento database + $vars['vcl_synth'] = $this->_vcl_sub_synth(); + } $customIncludeFile = $this->_getCustomIncludeFilename(); if( is_readable( $customIncludeFile ) ) { diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index fce48ecfd..f1c2fa606 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -476,6 +476,35 @@ + + + text + 46 + 1 + 0 + 0 + + + + select + turpentine/config_select_toggle + If enabled IP's not in 'developer client restrictions' will receive the following error page + 10 + 1 + 0 + 0 + + + + textarea + Enter full HTML page content + 20 + 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 55801b236..93b72e0fa 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -97,6 +97,8 @@ sub generate_session_expires { ## Varnish Subroutines sub vcl_recv { + {{maintenance_allowed_ips}} + # this always needs to be done so it's up at the top if (req.restarts == 0) { if (req.http.X-Forwarded-For) { @@ -350,6 +352,8 @@ sub vcl_fetch { # else it's not part of Magento so use the default Varnish handling } +{{vcl_synth}} + sub vcl_deliver { if (req.http.X-Varnish-Faked-Session) { # need to set the set-cookie header since we just made it out of thin air From 33e607f65ebba36c50c03a62c3c5ae4c60955635 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Tue, 14 Jul 2015 13:10:24 +0100 Subject: [PATCH 155/311] Correct req.http.X-Forwarded-For check for V3 Users --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e53457bd8..ca6e97ab0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -663,7 +663,7 @@ protected function _vcl_sub_maintenance_allowed_ips() { $tpl = << Date: Tue, 14 Jul 2015 07:34:24 -0600 Subject: [PATCH 156/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98c0d3d44..41c5d8580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -402,3 +402,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#843] Check if path isset before using it (@craigcarnell) * Removed session generation code in VCL - see issue #345 * [#586] Updated debug helper (@magedev) + * [#848] Replace Nexcessnet_Turpentine_Model_Dummy_Request with Magento model (@craigcarnell) \ No newline at end of file From d19f6085043c09feba04901609fe30fd79f75c2b Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 14 Jul 2015 07:36:20 -0600 Subject: [PATCH 157/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41c5d8580..d348e9005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -402,4 +402,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#843] Check if path isset before using it (@craigcarnell) * Removed session generation code in VCL - see issue #345 * [#586] Updated debug helper (@magedev) - * [#848] Replace Nexcessnet_Turpentine_Model_Dummy_Request with Magento model (@craigcarnell) \ No newline at end of file + * [#848] Replace Nexcessnet_Turpentine_Model_Dummy_Request with Magento model (@craigcarnell) + * [#849] escape | character (@craigcarnell) \ No newline at end of file From 453de781c933d0c849d79ec5ec369db4d5aeb59e Mon Sep 17 00:00:00 2001 From: aricwatson Date: Tue, 14 Jul 2015 15:46:44 -0400 Subject: [PATCH 158/311] merged from PR #541 --- TECHNICAL_NOTES.md | 6 +- .../Model/Config/Select/Version.php | 11 +- .../Turpentine/Model/Varnish/Admin.php | 33 +- .../Turpentine/Model/Varnish/Admin/Socket.php | 66 +-- .../Model/Varnish/Configurator/Abstract.php | 5 + .../Model/Varnish/Configurator/Version4.php | 60 +++ .../Nexcessnet/Turpentine/misc/version-4.vcl | 385 ++++++++++++++++++ 7 files changed, 528 insertions(+), 38 deletions(-) create mode 100644 app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php create mode 100644 app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl diff --git a/TECHNICAL_NOTES.md b/TECHNICAL_NOTES.md index bf1b1a434..857bd6ad4 100644 --- a/TECHNICAL_NOTES.md +++ b/TECHNICAL_NOTES.md @@ -39,6 +39,10 @@ Even with the addition of ESI, a client still needs a way to get their session c It sounds simple enough, but Varnish doesn't actually have any easy way to generate unique session tokens. At first, this seemed like a wash but then I remembered that you can actually write straight C code in the VCL for more advanced functionality, such as generating the session token! So that's what Turpentine does: a small C function is included in the VCL to [generate uuids](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/uuid.c), then that function is used to [make a session cookie](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl#L58) if no session cookie was sent in the request, and the cookie is [passed back to the client](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl#L340) in the response so it is sent with future requests. +#### Inline C as of Varnish 4.0 + +As of Varnish 4.0 the inline C functionality is disabled by default. To enable inline C you need to modify Varnish's startup config and add `-p vcc_allow_inline_c=on` to Varnish's startup command. + ### Serializing Registry Data To include the registry data required for ESI block rendering in the ESI URL, Turpentine simply takes a list of the needed registry keys (provided in the layout file) for the block and serializes it using PHP's native [`serialize`](http://us3.php.net/serialize) function which turns stores the data in a string which we can then include in the URL as a simple GET parameter. However, a registry key can be associated with any data type, including whole objects. While `serialize` will typically work on objects there are some edge cases (such as XML documents) that cannot be serialized. In order to accommodate these documents, Turpentine considers some objects to be "[complex registry data](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L441)" and handles those separately from the standard PHP types like string, int, simple classes, etc. Complex registry data is considered to be Magento "models" that correspond to database records and have `getId` methods (typically things like products, categories, etc). Then Turpentine can simply serialize the model's class and ID, then load the model with the ID instead of serializing the entire object. This neatly sidesteps the whole issue of finding a way to serialize objects that are unserializable. @@ -58,7 +62,7 @@ This change effectively broke Turpentine for those Magento versions, and finding 1. Because the form key is located inside HTML attributes (`href="http://example.com/example/action/form_key//"` for example), by default Varnish doesn't see the ESI include tag which completely breaks the buttons and forms that use the form key. 2. How does Magento know when to generate the actual form key, and not the ESI tag that is replaced by the form key. For example, the form key ESI is needed when generating the "Add to Cart" button, but the actual form key is needed both for both the ESI request to pull in the form key, and when that button is clicked so that it can be compared to the form key that was submitted. -The first is solved by a Varnish config change. Adding `-p esi_syntax=0x2` to Varnish's startup command tells it to look for any ESI tags, even if they're not in properly structured HTML syntax (like the example). The second was more tricky, at first it seemed a static list of actions that use the form key would be needed (like the original fix) that could be used to tell the mage/core session class when to generate the form key, and when to generate the form key ESI tag. However, the solution was staring me in the face: the request itself tells you when you need the actual form key, as it's only needed when the request includes the form key in the GET params or POST data to do the comparison between the actual form key, and the form key sent with the request. Thus we can just [check](https://github.com/nexcess/magento-turpentine/blob/master/app/code/local/Mage/Core/Model/Session.php#L53) if the form key was sent in the request and either generate the real form key, or the ESI tag. +The first is solved by a Varnish config change. Adding `-p esi_syntax=0x2` (`-p feature=+esi_ignore_other_elements` as of Varnish 4.0) to Varnish's startup command tells it to look for any ESI tags, even if they're not in properly structured HTML syntax (like the example). The second was more tricky, at first it seemed a static list of actions that use the form key would be needed (like the original fix) that could be used to tell the mage/core session class when to generate the form key, and when to generate the form key ESI tag. However, the solution was staring me in the face: the request itself tells you when you need the actual form key, as it's only needed when the request includes the form key in the GET params or POST data to do the comparison between the actual form key, and the form key sent with the request. Thus we can just [check](https://github.com/nexcess/magento-turpentine/blob/master/app/code/local/Mage/Core/Model/Session.php#L53) if the form key was sent in the request and either generate the real form key, or the ESI tag. ## Closing Time diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php index 488b26c7d..3bdce45a0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php @@ -1,23 +1,23 @@ '2.1', 'label' => $helper->__( '2.1.x' ) ), array( 'value' => '3.0', 'label' => $helper->__( '3.0.x' ) ), + array( 'value' => '4.0', 'label' => $helper->__( '4.0.x' ) ), array( 'value' => 'auto', 'label' => $helper->__( 'Auto' ) ), ); } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 0cb5714e8..cb5ecea88 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -138,22 +138,39 @@ protected function _testEsiSyntaxParam( $socket ) { $result = false; if( $helper->csrfFixupNeeded() ) { - $value = $socket->param_show( 'esi_syntax' ); - if( preg_match( '~(\d)\s+\[bitmap\]~', $value['text'], $match ) ) { - $value = hexdec( $match[1] ); - if( $value & self::MASK_ESI_SYNTAX ) { //bitwise intentional - // setting is correct, all is fine + if ( $socket->getVersion()==='4.0' ) { + $paramName = 'feature'; + $value = $socket->param_show( $paramName ); + $value = explode("\n", $value['text']); + if ( isset($value[1]) && strpos($value[1], '+esi_ignore_other_elements')!==false ) { $result = true; } else { - $session->addWarning( 'Varnish esi_syntax param is ' . + $session->addWarning( 'Varnish feature param is ' . 'not set correctly, please see these instructions ' . 'to fix this warning.' ); } } else { + $paramName = 'esi_syntax'; + $value = $socket->param_show( $paramName ); + if( preg_match( '~(\d)\s+\[bitmap\]~', $value['text'], $match ) ) { + $value = hexdec( $match[1] ); + if( $value & self::MASK_ESI_SYNTAX ) { //bitwise intentional + // setting is correct, all is fine + $result = true; + } else { + $session->addWarning( 'Varnish esi_syntax param is ' . + 'not set correctly, please see these instructions ' . + 'to fix this warning.' ); + } + } + } + + if ( $result===false ) { // error - Mage::helper( 'turpentine/debug' )->logWarn( - 'Failed to parse param.show output to check esi_syntax value' ); + Mage::helper( 'turpentine/debug' )->logWarning( + sprintf('Failed to parse param.show output to check %s value', $paramName ) ); $result = true; } } else { 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 db7580084..595b15384 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -84,10 +84,16 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { // and used const CLI_CMD_LENGTH_LIMIT = 8192; + /** + * Regexp to detect the varnish version number + * @var string + */ + const REGEXP_VARNISH_VERSION = '/^varnish\-(?P\d)\.(?P\d)\.(?P\d) revision (?P[0-9a-f]+)$/'; + /** * VCL config versions, should match config select values */ - static protected $_VERSIONS = array( '2.1', '3.0' ); + static protected $_VERSIONS = array( '2.1', '3.0', '4.0' ); /** * Varnish socket connection @@ -257,8 +263,8 @@ public function isConnected() { * @return string */ public function getVersion() { - if( is_null( $this->_version ) ) { - $this->_version = $this->_determineVersion(); + if ( !$this->isConnected() ) { + $this->_connect(); } return $this->_version; } @@ -331,15 +337,35 @@ protected function _connect() { $challenge = substr( $banner['text'], 0, 32 ); $response = hash( 'sha256', sprintf( "%s\n%s%s\n", $challenge, $this->_authSecret, $challenge ) ); - $this->_command( 'auth', self::CODE_OK, $response ); - } else if( $banner['code'] !== self::CODE_OK ) { + $banner = $this->_command( 'auth', self::CODE_OK, $response ); + } + + if( $banner['code'] !== self::CODE_OK ) { Mage::throwException( 'Varnish admin authentication failed: ' . $banner['text'] ); } + $this->_version = $this->_determineVersion($banner['text']); + return $this->isConnected(); } + protected function _determineVersion($bannerText) { + $bannerText = array_filter(explode("\n", $bannerText)); + if ( count($bannerText)<6 ) { + // Varnish 2.0 does not spit out a banner on connect + Mage::throwException('Varnish versions before 2.1 are not supported'); + } + if ( count($bannerText)<7 ) { + // Varnish before 3.0 does not spit out a version number + return '2.1'; + } elseif ( preg_match(self::REGEXP_VARNISH_VERSION, $bannerText[4], $matches)===1 ) { + return $matches['vmajor'] . '.' . $matches['vminor']; + } else { + Mage::throwException('Unable to detect varnish version'); + } + } + /** * Close the connection (if we're connected) * @@ -367,9 +393,17 @@ protected function _write( $data ) { $dataLength = strlen( $data ); if( $dataLength >= self::CLI_CMD_LENGTH_LIMIT ) { $cliBufferResponse = $this->param_show( 'cli_buffer' ); - if( preg_match( '~^cli_buffer\s+(\d+)\s+\[bytes\]~', - $cliBufferResponse['text'], $match ) ) { + $regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~'; + if ( $this->getVersion()==='4.0' ) { + // Varnish4 supports "16k" style notation + $regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g]{1})?\s+\[bytes\]~'; + } + if( preg_match( $regexp, $cliBufferResponse['text'], $match ) ) { $realLimit = (int)$match[1]; + if ( isset($match[2]) ) { + $factors = array('k'=>1,'m'=>2,'g'=>3); + $realLimit *= pow(1024, $factors[$match[2]]); + } } else { Mage::helper( 'turpentine/debug' )->logWarn( 'Failed to determine Varnish cli_buffer limit, using default' ); @@ -470,6 +504,7 @@ protected function _translateCommandMethod( $verb ) { case '2.1': $command = str_replace( 'ban', 'purge', $command ); break; + case '4.0': case '3.0': $command = str_replace( 'purge', 'ban', $command ); break; @@ -479,21 +514,4 @@ protected function _translateCommandMethod( $verb ) { } return $command; } - - /** - * Guess the Varnish version based on the availability of the 'banner' command - * - * @return string - */ - protected function _determineVersion() { - $resp = $this->_write( 'help' )->_read(); - if( strpos( $resp['text'], 'ban.url' ) !== false ) { - return '3.0'; - } elseif( strpos( $resp['text'], 'purge.url' ) !== false && - strpos( $resp['text'], 'banner' ) ) { - return '2.1'; - } else { - Mage::throwException( 'Unable to determine instance version' ); - } - } } 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 432157d1c..c64dc5674 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -39,6 +39,11 @@ static public function getFromSocket( $socket ) { return null; } switch( $version ) { + case '4.0': + return Mage::getModel( + 'turpentine/varnish_configurator_version4', + array( 'socket' => $socket ) ); + case '3.0': return Mage::getModel( 'turpentine/varnish_configurator_version3', diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php new file mode 100644 index 000000000..6b5fe55d1 --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -0,0 +1,60 @@ +_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); + $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), + $this->_getTemplateVars() ); + return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; + } + + // TODO: Check this + protected function _getAdvancedSessionValidation() { + $validation = ''; + foreach( $this->_getAdvancedSessionValidationTargets() as $target ) { + $validation .= sprintf( 'hash_data(%s);' . PHP_EOL, $target ); + } + return $validation; + } + + /** + * Build the list of template variables to apply to the VCL template + * + * @return array + */ + protected function _getTemplateVars() { + $vars = parent::_getTemplateVars(); + $vars['advanced_session_validation'] = + $this->_getAdvancedSessionValidation(); + return $vars; + } +} diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl new file mode 100644 index 000000000..9fec6690d --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -0,0 +1,385 @@ +vcl 4.0; +# Nexcess.net Turpentine Extension for Magento +# Copyright (C) 2012 Nexcess.net L.L.C. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +## Nexcessnet_Turpentine Varnish v3 VCL Template + +## Custom C Code + +C{ + # @source app/code/community/Nexcessnet/Turpentine/misc/uuid.c + {{custom_c_code}} +}C + +## Imports + +import std; + +## Custom VCL Logic + +{{custom_vcl_include}} + +## Backends + +{{default_backend}} + +{{admin_backend}} + +## ACLs + +{{crawler_acl}} + +{{debug_acl}} + +## Custom Subroutines + +sub generate_session { + # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID + # from SID URL param + if (req.url ~ ".*[&?]SID=([^&]+).*") { + set req.http.X-Varnish-Faked-Session = regsub( + req.url, ".*[&?]SID=([^&]+).*", "frontend=\1"); + } else { + C{ + char uuid_buf [50]; + generate_uuid(uuid_buf); + static const struct gethdr_s VGC_HDR_REQ_VARNISH_FAKED_SESSION = + { HDR_REQ, "\030X-Varnish-Faked-Session:"}; + VRT_SetHdr(ctx, + &VGC_HDR_REQ_VARNISH_FAKED_SESSION, + uuid_buf, + vrt_magic_string_end + ); + }C + } + if (req.http.Cookie) { + # client sent us cookies, just not a frontend cookie. try not to blow + # away the extra cookies + std.collect(req.http.Cookie); + set req.http.Cookie = req.http.X-Varnish-Faked-Session + + "; " + req.http.Cookie; + } else { + set req.http.Cookie = req.http.X-Varnish-Faked-Session; + } +} + +sub generate_session_expires { + # sets X-Varnish-Cookie-Expires to now + esi_private_ttl in format: + # Tue, 19-Feb-2013 00:14:27 GMT + # this isn't threadsafe but it shouldn't matter in this case + C{ + time_t now = time(NULL); + struct tm now_tm = *gmtime(&now); + now_tm.tm_sec += {{esi_private_ttl}}; + mktime(&now_tm); + char date_buf [50]; + strftime(date_buf, sizeof(date_buf)-1, "%a, %d-%b-%Y %H:%M:%S %Z", &now_tm); + static const struct gethdr_s VGC_HDR_RESP_COOKIE_EXPIRES = + { HDR_RESP, "\031X-Varnish-Cookie-Expires:"}; + VRT_SetHdr(ctx, + &VGC_HDR_RESP_COOKIE_EXPIRES, + date_buf, + vrt_magic_string_end + ); + }C +} + +## Varnish Subroutines + +sub vcl_recv { + # this always needs to be done so it's up at the top + if (req.restarts == 0) { + if (req.http.X-Forwarded-For) { + set req.http.X-Forwarded-For = + req.http.X-Forwarded-For + ", " + client.ip; + } else { + set req.http.X-Forwarded-For = client.ip; + } + } + + # We only deal with GET and HEAD by default + # we test this here instead of inside the url base regex section + # so we can disable caching for the entire site if needed + if (!{{enable_caching}} || req.http.Authorization || + req.method !~ "^(GET|HEAD)$" || + req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") { + return (pipe); + } + + # remove double slashes from the URL, for higher cache hit rate + set req.url = regsuball(req.url, "(.*)//+(.*)", "\1/\2"); + + {{normalize_encoding}} + {{normalize_user_agent}} + {{normalize_host}} + + # check if the request is for part of magento + if (req.url ~ "{{url_base_regex}}") { + # set this so Turpentine can see the request passed through Varnish + set req.http.X-Turpentine-Secret-Handshake = "{{secret_handshake}}"; + # use the special admin backend and pipe if it's for the admin section + if (req.url ~ "{{url_base_regex}}{{admin_frontname}}") { + set req.backend_hint = admin; + return (pipe); + } + if (req.http.Cookie ~ "\bcurrency=") { + set req.http.X-Varnish-Currency = regsub( + req.http.Cookie, ".*\bcurrency=([^;]*).*", "\1"); + } + if (req.http.Cookie ~ "\bstore=") { + set req.http.X-Varnish-Store = regsub( + req.http.Cookie, ".*\bstore=([^;]*).*", "\1"); + } + # looks like an ESI request, add some extra vars for further processing + if (req.url ~ "/turpentine/esi/get(?:Block|FormKey)/") { + set req.http.X-Varnish-Esi-Method = regsub( + req.url, ".*/{{esi_method_param}}/(\w+)/.*", "\1"); + set req.http.X-Varnish-Esi-Access = regsub( + req.url, ".*/{{esi_cache_type_param}}/(\w+)/.*", "\1"); + + # throw a forbidden error if debugging is off and a esi block is + # requested by the user (does not apply to ajax blocks) + if (req.http.X-Varnish-Esi-Method == "esi" && req.esi_level == 0 && + !({{debug_headers}} || client.ip ~ debug_acl)) { + return (synth(403, "External ESI requests are not allowed")); + } + } + # no frontend cookie was sent to us + if (req.http.Cookie !~ "frontend=") { + if (client.ip ~ crawler_acl || + req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") { + # it's a crawler, give it a fake cookie + set req.http.Cookie = "frontend=crawler-session"; + } else { + # it's a real user, make up a new session for them + call generate_session; + } + } + if ({{force_cache_static}} && + req.url ~ ".*\.(?:{{static_extensions}})(?=\?|&|$)") { + # don't need cookies for static assets + unset req.http.Cookie; + unset req.http.X-Varnish-Faked-Session; + return (hash); + } + # this doesn't need a enable_url_excludes because we can be reasonably + # certain that cron.php at least will always be in it, so it will + # never be empty + if (req.url ~ "{{url_base_regex}}(?:{{url_excludes}})" || + # user switched stores. we pipe this instead of passing below because + # switching stores doesn't redirect (302), just acts like a link to + # another page (200) so the Set-Cookie header would be removed + req.url ~ "\?.*__from_store=") { + return (pipe); + } + if ({{enable_get_excludes}} && + req.url ~ "(?:[?&](?:{{get_param_excludes}})(?=[&=]|$))") { + # TODO: should this be pass or pipe? + return (pass); + } + if (req.url ~ "[?&](utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") { + # Strip out Google related parameters + set req.url = regsuball(req.url, "(?:(\?)?|&)(?:utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=[^&]+", "\1"); + set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); + } + + # everything else checks out, try and pull from the cache + return (hash); + } + # else it's not part of magento so do default handling (doesn't help + # things underneath magento but we can't detect that) +} + +sub vcl_pipe { + # since we're not going to do any stuff to the response we pretend the + # request didn't pass through Varnish + unset bereq.http.X-Turpentine-Secret-Handshake; + set bereq.http.Connection = "close"; +} + +# sub vcl_pass { +# return (pass); +# } + +sub vcl_hash { + hash_data(req.url); + if (req.http.Host) { + hash_data(req.http.Host); + } else { + hash_data(server.ip); + } + hash_data(req.http.Ssl-Offloaded); + if (req.http.X-Normalized-User-Agent) { + hash_data(req.http.X-Normalized-User-Agent); + } + if (req.http.Accept-Encoding) { + # make sure we give back the right encoding + hash_data(req.http.Accept-Encoding); + } + if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) { + # make sure data is for the right store and currency based on the *store* + # and *currency* cookies + hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency); + } + + if (req.http.X-Varnish-Esi-Access == "private" && + req.http.Cookie ~ "frontend=") { + hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1")); + {{advanced_session_validation}} + + } + return (lookup); +} + +sub vcl_hit { + # this seems to cause cache object contention issues so removed for now + # TODO: use obj.hits % something maybe + # if (obj.hits > 0) { + # set obj.ttl = obj.ttl + {{lru_factor}}s; + # } +} + +# sub vcl_miss { +# return (fetch); +# } + +sub vcl_backend_response { + # set the grace period + set beresp.grace = {{grace_period}}s; + + # Store the URL in the response object, to be able to do lurker friendly bans later + set beresp.http.X-Varnish-Host = bereq.http.host; + set beresp.http.X-Varnish-URL = bereq.url; + + # if it's part of magento... + if (bereq.url ~ "{{url_base_regex}}") { + # we handle the Vary stuff ourselves for now, we'll want to actually + # use this eventually for compatibility with downstream proxies + # TODO: only remove the User-Agent field from this if it exists + unset beresp.http.Vary; + # we pretty much always want to do this + set beresp.do_gzip = true; + + if (beresp.status != 200 && beresp.status != 404) { + # pass anything that isn't a 200 or 404 + set beresp.ttl = {{grace_period}}s; + set beresp.uncacheable = true; + return (deliver); + } else { + # if Magento sent us a Set-Cookie header, we'll put it somewhere + # else for now + if (beresp.http.Set-Cookie) { + set beresp.http.X-Varnish-Set-Cookie = beresp.http.Set-Cookie; + unset beresp.http.Set-Cookie; + } + # we'll set our own cache headers if we need them + unset beresp.http.Cache-Control; + unset beresp.http.Expires; + unset beresp.http.Pragma; + unset beresp.http.Cache; + unset beresp.http.Age; + + if (beresp.http.X-Turpentine-Esi == "1") { + set beresp.do_esi = true; + } + if (beresp.http.X-Turpentine-Cache == "0") { + set beresp.ttl = {{grace_period}}s; + set beresp.uncacheable = true; + return (deliver); + } else { + if ({{force_cache_static}} && + bereq.url ~ ".*\.(?:{{static_extensions}})(?=\?|&|$)") { + # it's a static asset + set beresp.ttl = {{static_ttl}}s; + set beresp.http.Cache-Control = "max-age={{static_ttl}}"; + } elseif (bereq.http.X-Varnish-Esi-Method) { + # it's a ESI request + if (bereq.http.X-Varnish-Esi-Access == "private" && + bereq.http.Cookie ~ "frontend=") { + # set this header so we can ban by session from Turpentine + set beresp.http.X-Varnish-Session = regsub(bereq.http.Cookie, + "^.*?frontend=([^;]*);*.*$", "\1"); + } + if (bereq.http.X-Varnish-Esi-Method == "ajax" && + bereq.http.X-Varnish-Esi-Access == "public") { + set beresp.http.Cache-Control = "max-age=" + regsub( + bereq.url, ".*/{{esi_ttl_param}}/(\d+)/.*", "\1"); + } + set beresp.ttl = std.duration( + regsub( + bereq.url, ".*/{{esi_ttl_param}}/(\d+)/.*", "\1s"), + 300s); + if (beresp.ttl == 0s) { + # this is probably faster than bothering with 0 ttl + # cache objects + set beresp.ttl = {{grace_period}}s; + set beresp.uncacheable = true; + return (deliver); + } + } else { + {{url_ttls}} + } + } + } + # we've done what we need to, send to the client + return (deliver); + } + # else it's not part of Magento so use the default Varnish handling +} + +sub vcl_deliver { + if (req.http.X-Varnish-Faked-Session) { + # need to set the set-cookie header since we just made it out of thin air + call generate_session_expires; + set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session + + "; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/"; + if (req.http.Host) { + set resp.http.Set-Cookie = resp.http.Set-Cookie + + "; domain=" + regsub(req.http.Host, ":\d+$", ""); + } + set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly"; + unset resp.http.X-Varnish-Cookie-Expires; + } + if (req.http.X-Varnish-Esi-Method == "ajax" && req.http.X-Varnish-Esi-Access == "private") { + set resp.http.Cache-Control = "no-cache"; + } + if ({{debug_headers}} || client.ip ~ debug_acl) { + # debugging is on, give some extra info + set resp.http.X-Varnish-Hits = obj.hits; + set resp.http.X-Varnish-Esi-Method = req.http.X-Varnish-Esi-Method; + set resp.http.X-Varnish-Esi-Access = req.http.X-Varnish-Esi-Access; + set resp.http.X-Varnish-Currency = req.http.X-Varnish-Currency; + set resp.http.X-Varnish-Store = req.http.X-Varnish-Store; + } else { + # remove Varnish fingerprints + unset resp.http.X-Varnish; + unset resp.http.Via; + unset resp.http.X-Powered-By; + unset resp.http.Server; + unset resp.http.X-Turpentine-Cache; + unset resp.http.X-Turpentine-Esi; + unset resp.http.X-Turpentine-Flush-Events; + unset resp.http.X-Turpentine-Block; + unset resp.http.X-Varnish-Session; + unset resp.http.X-Varnish-Host; + unset resp.http.X-Varnish-URL; + # this header indicates the session that originally generated a cached + # page. it *must* not be sent to a client in production with lax + # session validation or that session can be hijacked + unset resp.http.X-Varnish-Set-Cookie; + } +} From 86d1aaff0833a119808bbe6774bb9b0b46cdb856 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Wed, 15 Jul 2015 17:07:19 -0400 Subject: [PATCH 159/311] Better escaping of double slashes in urls (for better hitrate) (@joolswills) --- CHANGELOG.md | 3 ++- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d348e9005..2c1744ad8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -403,4 +403,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * Removed session generation code in VCL - see issue #345 * [#586] Updated debug helper (@magedev) * [#848] Replace Nexcessnet_Turpentine_Model_Dummy_Request with Magento model (@craigcarnell) - * [#849] escape | character (@craigcarnell) \ No newline at end of file + * [#849] escape | character (@craigcarnell) + * Better escaping of double slashes in urls (for better hitrate) (@joolswills) \ No newline at end of file diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 55801b236..6f8757b72 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -125,7 +125,7 @@ sub vcl_recv { } # remove double slashes from the URL, for higher cache hit rate - set req.url = regsuball(req.url, "(.*)//+(.*)", "\1/\2"); + set req.url = regsuball(req.url, "([^:])//+", "\1/"); # check if the request is for part of magento if (req.url ~ "{{url_base_regex}}") { From 54b46f1dd47080c0fcece5fd2cf1d6c28a92aa9f Mon Sep 17 00:00:00 2001 From: Chris Grice Date: Fri, 17 Jul 2015 16:13:32 +0100 Subject: [PATCH 160/311] Removing ref to nonexistent file from modman #499 removed app/code/local/Mage/Core/Model/Session.php in place of a rewrite, but didn't remove the reference to this file from modman. This is currently breaking composer installs in some cases. --- modman | 1 - 1 file changed, 1 deletion(-) diff --git a/modman b/modman index 9dabbbac6..e548d16f4 100644 --- a/modman +++ b/modman @@ -2,7 +2,6 @@ app/etc/modules/Nexcessnet_Turpentine.xml app/etc/modules/Nexcessnet_Turpentine.xml app/code/community/Nexcessnet/Turpentine/ app/code/community/Nexcessnet/Turpentine/ -app/code/local/Mage/Core/Model/Session.php app/code/local/Mage/Core/Model/Session.php app/design/adminhtml/default/default/layout/turpentine.xml app/design/adminhtml/default/default/layout/turpentine.xml app/design/adminhtml/default/default/template/turpentine/ app/design/adminhtml/default/default/template/turpentine/ app/design/frontend/base/default/layout/turpentine_esi.xml app/design/frontend/base/default/layout/turpentine_esi.xml From bbe690608179a3e6ed27c965974e02f7173d59af Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 17 Jul 2015 09:19:12 -0600 Subject: [PATCH 161/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c1744ad8..015220c5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -404,4 +404,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#586] Updated debug helper (@magedev) * [#848] Replace Nexcessnet_Turpentine_Model_Dummy_Request with Magento model (@craigcarnell) * [#849] escape | character (@craigcarnell) - * Better escaping of double slashes in urls (for better hitrate) (@joolswills) \ No newline at end of file + * Better escaping of double slashes in urls (for better hitrate) (@joolswills) + * [#860] Removing ref to nonexistent file from modman (@cgrice ) From 33cf171d8e3495718fd3bf41573c4359b6b8400f Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Tue, 21 Jul 2015 00:39:15 +0200 Subject: [PATCH 162/311] Fixed bug in commit 9b0c601: one closing brace too mutch. Also replaced all tabs by spaces. --- .../Nexcessnet/Turpentine/misc/version-3.vcl | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 4692ae525..6b33f4a07 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -160,7 +160,7 @@ sub vcl_recv { } # if host is not allowed in magento pass to backend if (req.http.host !~ "{{allowed_hosts_regex}}") { - return (pass); + return (pass); } # 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) { @@ -359,20 +359,19 @@ sub vcl_deliver { "; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/"; if (req.http.Host) { if (req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") { - # it's a crawler, no need to share cookies + # it's a crawler, no need to share cookies set resp.http.Set-Cookie = resp.http.Set-Cookie + - "; domain=" + regsub(req.http.Host, ":\d+$", ""); + "; domain=" + regsub(req.http.Host, ":\d+$", ""); } else { - # it's a real user, allow sharing of cookies between stores - if(req.http.Host ~ "{{normalize_cookie_regex}}") { - set resp.http.Set-Cookie = resp.http.Set-Cookie + - "; domain={{normalize_cookie_target}}"; - } else { - set resp.http.Set-Cookie = resp.http.Set-Cookie + - "; domain=" + regsub(req.http.Host, ":\d+$", ""); - } - } - } + # it's a real user, allow sharing of cookies between stores + if(req.http.Host ~ "{{normalize_cookie_regex}}") { + set resp.http.Set-Cookie = resp.http.Set-Cookie + + "; domain={{normalize_cookie_target}}"; + } else { + set resp.http.Set-Cookie = resp.http.Set-Cookie + + "; domain=" + regsub(req.http.Host, ":\d+$", ""); + } + } } set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly"; unset resp.http.X-Varnish-Cookie-Expires; From a44b7f1c658c451fbe71ed4e29e3719b996941da Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Tue, 21 Jul 2015 00:06:30 +0200 Subject: [PATCH 163/311] Implemented load balancing support --- .../Model/Config/Select/LoadBalancing.php | 34 +++++ .../Model/Varnish/Configurator/Abstract.php | 125 ++++++++++++++++-- .../Nexcessnet/Turpentine/etc/config.xml | 5 + .../Nexcessnet/Turpentine/etc/system.xml | 61 +++++++++ .../Nexcessnet/Turpentine/misc/version-2.vcl | 3 + .../Nexcessnet/Turpentine/misc/version-3.vcl | 3 + 6 files changed, 223 insertions(+), 8 deletions(-) create mode 100644 app/code/community/Nexcessnet/Turpentine/Model/Config/Select/LoadBalancing.php diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/LoadBalancing.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/LoadBalancing.php new file mode 100644 index 000000000..2a891f0e4 --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/LoadBalancing.php @@ -0,0 +1,34 @@ +'no', 'label'=>$helper->__('No, use only one backend server')), + array('value'=>'yes', 'label'=>$helper->__('Yes, use load balancing')), + array('value'=>'yes_admin', 'label'=>$helper->__('Yes, with separate settings for Admin')), + ); + } +} 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 432157d1c..4cb935036 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -287,10 +287,14 @@ protected function _getDefaultBackend() { 'first_byte_timeout' => $timeout . 's', 'between_bytes_timeout' => $timeout . 's', ); - return $this->_vcl_backend( 'default', - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_host' ), - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_port' ), - $default_options ); + if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) ) { + return $this->_vcl_director( 'default', $default_options ); + } else { + return $this->_vcl_backend( 'default', + Mage::getStoreConfig( 'turpentine_vcl/backend/backend_host' ), + Mage::getStoreConfig( 'turpentine_vcl/backend/backend_port' ), + $default_options ); + } } /** @@ -304,10 +308,14 @@ protected function _getAdminBackend() { 'first_byte_timeout' => $timeout . 's', 'between_bytes_timeout' => $timeout . 's', ); - return $this->_vcl_backend( 'admin', - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_host' ), - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_port' ), - $admin_options ); + if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) ) { + return $this->_vcl_director( 'admin', $admin_options ); + } else { + return $this->_vcl_backend( 'admin', + Mage::getStoreConfig( 'turpentine_vcl/backend/backend_host' ), + Mage::getStoreConfig( 'turpentine_vcl/backend/backend_port' ), + $admin_options ); + } } /** @@ -545,6 +553,107 @@ protected function _vcl_backend( $name, $host, $port, $options=array() ) { return $str; } + /** + * Format a VCL director declaration, for load balancing + * + * @param string $name name of the director, also used to select config settings + * @param array $backendOptions options for each backend + * @return string + */ + protected function _vcl_director( $name, $backendOptions ) { + $tpl = <<cleanExplode( PHP_EOL, + Mage::getStoreConfig( 'turpentine_vcl/backend/backend_nodes_admin' ) ); + $probeUrl = Mage::getStoreConfig( 'turpentine_vcl/backend/backend_probe_url_admin' ); + } else { + $backendNodes = Mage::helper( 'turpentine/data' )->cleanExplode( PHP_EOL, + Mage::getStoreConfig( 'turpentine_vcl/backend/backend_nodes' ) ); + $probeUrl = Mage::getStoreConfig( 'turpentine_vcl/backend/backend_probe_url' ); + } + $backends = ''; + foreach ( $backendNodes as $backendNode ) { + $parts = explode( ':', $backendNode, 2 ); + $host = ( empty($parts[0]) ) ? '127.0.0.1' : $parts[0]; + $port = ( empty($parts[1]) ) ? '80' : $parts[1]; + $backends .= $this->_vcl_director_backend( $host, $port, $probeUrl, $backendOptions ); + } + $vars = array( + 'name' => $name, + 'backends' => $backends + ); + return $this->_formatTemplate( $tpl, $vars ); + } + + /** + * Format a VCL backend declaration to put inside director + * + * @param string $host backend host + * @param string $port backend port + * @param string $probeUrl URL to check if backend is up + * @param array $options extra options for backend + * @return string + */ + protected function _vcl_director_backend( $host, $port, $probeUrl='', $options=array() ) { + $tpl = << $host, + 'port' => $port, + 'probe' => '' + ); + if ( !empty( $probeUrl ) ) { + $vars['probe'] = $this->_vcl_get_probe( $probeUrl ); + } + $str = $this->_formatTemplate( $tpl, $vars ); + foreach( $options as $key => $value ) { + $str .= sprintf( ' .%s = %s;', $key, $value ) . PHP_EOL; + } + $str .= << $urlParts['host'], + 'probe_path' => $urlParts['path'] + ); + return $this->_formatTemplate( $tpl, $vars ); + } + } + /** * Format a VCL ACL declaration * diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index d1da4f9ed..b29876613 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -48,8 +48,13 @@ + no 127.0.0.1 8080 + 127.0.0.1:8080 + + 127.0.0.1:8080 + 300 21600 127.0.0.1 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index fce48ecfd..ee02d2f96 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -229,6 +229,15 @@ 0 0 + + + select + turpentine/config_select_loadBalancing + 05 + 1 + 0 + 0 + text @@ -236,6 +245,9 @@ 1 0 0 + + no + @@ -245,7 +257,56 @@ 1 0 0 + + no + + + + textarea + A list of HOST:PORT pairs of the backend web servers, one per line + 22 + 1 + 0 + 0 + + yes|yes_admin + + + + + URL where Varnish can probe if a node is available. Leave empty to disable probing. + text + 23 + 1 + 0 + 0 + + yes|yes_admin + + + + + textarea + 25 + 1 + 0 + 0 + + yes_admin + + + + + text + 27 + 1 + 0 + 0 + + yes_admin + + text diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 3b9b8cc07..cb63ea02f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -119,6 +119,9 @@ sub vcl_recv { if (req.http.X-Opt-Enable-Caching != "true" || req.http.Authorization || !(req.request ~ "^(GET|HEAD|OPTIONS)$") || req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") { + if (req.url ~ "{{url_base_regex}}{{admin_frontname}}") { + set req.backend = admin; + } return (pipe); } diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 6f8757b72..81b7c136b 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -121,6 +121,9 @@ sub vcl_recv { if (!{{enable_caching}} || req.http.Authorization || req.request !~ "^(GET|HEAD|OPTIONS)$" || req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") { + if (req.url ~ "{{url_base_regex}}{{admin_frontname}}") { + set req.backend = admin; + } return (pipe); } From 42cd7044e41e01bd7ebce968d6b05001838afd3a Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 28 Jul 2015 09:58:33 -0300 Subject: [PATCH 164/311] refs Fixed typo.. --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0beb3c05c..5e29c3402 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -713,7 +713,7 @@ protected function _getTemplateVars() { 'get_param_ignored' => $this->_getIgnoreGetParameters(), 'default_ttl' => $this->_getDefaultTtl(), 'enable_get_excludes' => ($this->_getGetParamExcludes() ? 'true' : 'false'), - 'enable_get_ignored' => ($this->_getIgnoreGetParameters()) ? 'true' : 'false', + 'enable_get_ignored' => ($this->_getIgnoreGetParameters() ? 'true' : 'false'), 'debug_headers' => $this->_getEnableDebugHeaders(), 'grace_period' => $this->_getGracePeriod(), 'force_cache_static' => $this->_getForceCacheStatic(), From 2cf7cbebfe4e99e9c0126f448fa2615c8d94a9d4 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Tue, 28 Jul 2015 12:04:01 -0400 Subject: [PATCH 165/311] Updates for version4 vcl to support turp features/updates --- .../Nexcessnet/Turpentine/misc/version-4.vcl | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 9fec6690d..89629ada7 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -47,6 +47,7 @@ import std; ## Custom Subroutines +{{generate_session_start}} sub generate_session { # generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID # from SID URL param @@ -97,7 +98,7 @@ sub generate_session_expires { ); }C } - +{{generate_session_end}} ## Varnish Subroutines sub vcl_recv { @@ -115,7 +116,7 @@ sub vcl_recv { # we test this here instead of inside the url base regex section # so we can disable caching for the entire site if needed if (!{{enable_caching}} || req.http.Authorization || - req.method !~ "^(GET|HEAD)$" || + req.method !~ "^(GET|HEAD|OPTIONS)$" || req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") { return (pipe); } @@ -158,15 +159,20 @@ sub vcl_recv { return (synth(403, "External ESI requests are not allowed")); } } - # no frontend cookie was sent to us - if (req.http.Cookie !~ "frontend=") { + # if host is not allowed in magento pass to backend + if (req.http.host !~ "{{allowed_hosts_regex}}") { + return (pass); + } + # 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 || req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") { # it's a crawler, give it a fake cookie set req.http.Cookie = "frontend=crawler-session"; } else { # it's a real user, make up a new session for them - call generate_session; + {{generate_session}}# call generate_session; + return (pipe); } } if ({{force_cache_static}} && @@ -197,6 +203,12 @@ sub vcl_recv { set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); } + if ({{enable_get_ignored}} && req.url ~ "[?&]({{get_param_ignored}})=") { + # Strip out Ignored GET parameters + set req.url = regsuball(req.url, "(?:(\?)?|&)(?:{{get_param_ignored}})=[^&]+", "\1"); + set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); + } + # everything else checks out, try and pull from the cache return (hash); } @@ -344,12 +356,24 @@ sub vcl_backend_response { sub vcl_deliver { if (req.http.X-Varnish-Faked-Session) { # need to set the set-cookie header since we just made it out of thin air - call generate_session_expires; + {{generate_session_expires}} set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session + "; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/"; if (req.http.Host) { - set resp.http.Set-Cookie = resp.http.Set-Cookie + + if (req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") { + # it's a crawler, no need to share cookies + set resp.http.Set-Cookie = resp.http.Set-Cookie + "; domain=" + regsub(req.http.Host, ":\d+$", ""); + } else { + # it's a real user, allow sharing of cookies between stores + if(req.http.Host ~ "{{normalize_cookie_regex}}") { + set resp.http.Set-Cookie = resp.http.Set-Cookie + + "; domain={{normalize_cookie_target}}"; + } else { + set resp.http.Set-Cookie = resp.http.Set-Cookie + + "; domain=" + regsub(req.http.Host, ":\d+$", ""); + } + } } set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly"; unset resp.http.X-Varnish-Cookie-Expires; From 82931bf9209be8c85e7d7c4cc88d9baee6a5810e Mon Sep 17 00:00:00 2001 From: aricwatson Date: Wed, 29 Jul 2015 08:17:41 -0400 Subject: [PATCH 166/311] Fixed bad 'logWarning' call --- .../community/Nexcessnet/Turpentine/Model/Varnish/Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index cb5ecea88..a26f5105e 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -169,7 +169,7 @@ protected function _testEsiSyntaxParam( $socket ) { if ( $result===false ) { // error - Mage::helper( 'turpentine/debug' )->logWarning( + Mage::helper( 'turpentine/debug' )->logWarn( sprintf('Failed to parse param.show output to check %s value', $paramName ) ); $result = true; } From 48ad1651456b85bc8b0c8521d9e6892cbcd84201 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 4 Aug 2015 12:32:40 -0300 Subject: [PATCH 167/311] refs Fixed build XML. --- build/mage-package.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/build/mage-package.xml b/build/mage-package.xml index 7e97facc7..29c0bec46 100644 --- a/build/mage-package.xml +++ b/build/mage-package.xml @@ -85,7 +85,6 @@ ~.*~ - ~.*~ ~.*~ From c0fafb84458cba79df40c661ddf85d73c9e2f2bb Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 4 Aug 2015 12:39:58 -0300 Subject: [PATCH 168/311] refs Fixed build XML. --- 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 2541069be..a74f63beb 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.3 + 0.6.4 From 1e67430f6a94004268abab565ae3cae09be59c9c Mon Sep 17 00:00:00 2001 From: Alan Storm Date: Thu, 6 Aug 2015 11:14:19 -0700 Subject: [PATCH 169/311] Explicit cache bypass for progress sections. --- .../base/default/layout/turpentine_esi.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index 1ca2f9b6e..1a78cfb39 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -240,6 +240,22 @@ + + + + + + + + + + + + + + + + From f56f4c79bd7967a9c0fd0e663fdfb11e7668e96f Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 7 Aug 2015 11:08:20 -0300 Subject: [PATCH 170/311] refs #596 added comment to field. --- app/code/community/Nexcessnet/Turpentine/etc/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 822a05d7d..eb3da9967 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -280,7 +280,7 @@ text 50 - Comma-separated list of IPs to serve cached pages to on initial visit + Comma-separated list of IP addresses that should bypass Turpentine's frontend cookie requirement. Also useful for performance testing tools as they also typically don't support cookies. Note - if you are using something like Pound to terminate SSL before Varnish, setting this to the same IP could cause users to end up sharing the crawler session. 1 0 0 From 7c0dc018e2a0daa2ba5e47ccaa7e99b6dcbcd06c Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 7 Aug 2015 11:39:09 -0300 Subject: [PATCH 171/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 015220c5a..9f9404447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -405,4 +405,6 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#848] Replace Nexcessnet_Turpentine_Model_Dummy_Request with Magento model (@craigcarnell) * [#849] escape | character (@craigcarnell) * Better escaping of double slashes in urls (for better hitrate) (@joolswills) - * [#860] Removing ref to nonexistent file from modman (@cgrice ) + * [#860] Removing ref to nonexistent file from modman (@cgrice ) + * [#596] update docs to make an important notice on Crawler IP Addresses setting under Caching Options (@arosenhagen) + * [#878] Explicit cache bypass for progress sections (@astorm) From ab2657cb28b2fd1c772ff1381f933f781cdc7e1b Mon Sep 17 00:00:00 2001 From: aricwatson Date: Mon, 10 Aug 2015 12:57:52 -0400 Subject: [PATCH 172/311] Fix for viewed/compared blocks #801, #803 --- .../Turpentine/Block/Product/Compared.php | 34 +++++++++++++++++++ .../Turpentine/Block/Product/Viewed.php | 32 +++++++++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 12 +++++++ .../base/default/layout/turpentine_esi.xml | 2 ++ 4 files changed, 80 insertions(+) create mode 100644 app/code/community/Nexcessnet/Turpentine/Block/Product/Compared.php create mode 100644 app/code/community/Nexcessnet/Turpentine/Block/Product/Viewed.php diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Product/Compared.php b/app/code/community/Nexcessnet/Turpentine/Block/Product/Compared.php new file mode 100644 index 000000000..12ec356c9 --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Block/Product/Compared.php @@ -0,0 +1,34 @@ +getCount()) { + return $this->renderView(); + } + + $this->setRecentlyComparedProducts($this->getItemsCollection()); + + return parent::_toHtml(); + } +} diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Product/Viewed.php b/app/code/community/Nexcessnet/Turpentine/Block/Product/Viewed.php new file mode 100644 index 000000000..9561243e1 --- /dev/null +++ b/app/code/community/Nexcessnet/Turpentine/Block/Product/Viewed.php @@ -0,0 +1,32 @@ +getCount()) { + return $this->renderView(); + } + $this->setRecentlyViewedProducts($this->getItemsCollection()); + return parent::_toHtml(); + } +} diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index a74f63beb..3a638e1f7 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -131,6 +131,18 @@ Nexcessnet_Turpentine_Block_Poll_ActivePoll + + + + + Nexcessnet_Turpentine_Block_Product_Compared + Nexcessnet_Turpentine_Block_Product_Viewed + + + Nexcessnet_Turpentine_Block_Adminhtml_Cache_Grid diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index 1a78cfb39..f44357b68 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -88,6 +88,8 @@ private + + From 1083f83358ceff4b0487b0c49f98748b2c713451 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 13 Aug 2015 09:39:54 +0100 Subject: [PATCH 173/311] Fix merge conflict --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 8726fb6c7..17cdca062 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -680,7 +680,8 @@ protected function _vcl_sub_normalize_host() { 'normalize_host_target' => $this->_getNormalizeHostTarget() ) ); } - /* Get the hostname for cookie normalization + /** + * Get the hostname for cookie normalization * * @return string */ From 8ac83545023706ad2ef34ca054430bcefe3f3e96 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 17 Aug 2015 10:48:16 -0300 Subject: [PATCH 174/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f9404447..b34a1badf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -408,3 +408,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#860] Removing ref to nonexistent file from modman (@cgrice ) * [#596] update docs to make an important notice on Crawler IP Addresses setting under Caching Options (@arosenhagen) * [#878] Explicit cache bypass for progress sections (@astorm) + * [#844] Fix for HTTPS ESI URLs (@jeroenvermeulen) From 2e2b4bbc1f2866236876be9b3a4b00819ee75d33 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Fri, 21 Aug 2015 00:11:54 +0200 Subject: [PATCH 175/311] Improved ESI Ajax: load async + fixed jQuery fallback. --- .../default/template/turpentine/ajax.phtml | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/app/design/frontend/base/default/template/turpentine/ajax.phtml b/app/design/frontend/base/default/template/turpentine/ajax.phtml index 7248695dc..4756c9f55 100644 --- a/app/design/frontend/base/default/template/turpentine/ajax.phtml +++ b/app/design/frontend/base/default/template/turpentine/ajax.phtml @@ -32,6 +32,9 @@ if( $debugEnabled ) { * be an issue we'll have to go back to using Ajax.Request so the container * block is completely replaced which means no nice appear effect. * + * The 10 ms delay after page load is to make sure the Ajax call is + * executed async so it does not delay DOMContentLoaded. Better for Google. + * * @link http://prototypejs.org/doc/latest/ajax/index.html * @link http://prototypejs.org/doc/latest/ajax/Ajax/Request/index.html * @link http://prototypejs.org/doc/latest/dom/Element/replace/index.html @@ -47,30 +50,34 @@ echo << (function() { var blockTag = {$this->helper('core')->jsonEncode($blockTag)}, esiUrl = {$this->helper('core')->jsonEncode($this->getEsiUrl())}; - if (typeof Ajax === 'object' && typeof Ajax.Updater === 'function') { - new Ajax.Updater( - blockTag, - esiUrl, - { - method: "get", - evalScripts: true, - {$_prototypeFunction}: function() { - $(blockTag).appear({ - duration: 0.3 - }); + if (typeof Ajax === 'object' && typeof Ajax.Updater === 'function' && typeof Event === 'function' ) { + Event.observe( window, "load", function() { setTimeout( function() { + new Ajax.Updater( + blockTag, + esiUrl, + { + method: "get", + evalScripts: true, + {$_prototypeFunction}: function() { + $(blockTag).appear({ + duration: 0.3 + }); + } } - } - ); + ); + }, 10 ); } ); } else if (typeof jQuery === 'function') { - jQuery.ajax( - { - url: esiUrl, - type: "get", - dataType: "html" - } - ).{$_jQueryFunction}(function() { - $(blockTag).fadeIn(300); - }); + jQuery(document).ready( function() { setTimeout( function() { + jQuery.ajax( + { + url: esiUrl, + type: "get", + dataType: "html" + } + ).{$_jQueryFunction}(function(data) { + jQuery('#'+blockTag).html(data).fadeIn(300); + }); + }, 10 ); } ); } })(); From 8d45d8feea7e1b5f86c63c90d6a56e59bef283a8 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 25 Aug 2015 11:33:15 -0400 Subject: [PATCH 176/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b34a1badf..97fd5d556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -409,3 +409,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#596] update docs to make an important notice on Crawler IP Addresses setting under Caching Options (@arosenhagen) * [#878] Explicit cache bypass for progress sections (@astorm) * [#844] Fix for HTTPS ESI URLs (@jeroenvermeulen) + * [#865] Implemented load balancing support (@jeroenvermeulen) From cb986e1686e527aa7cff78b5ea41f01c62d7f26d Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Thu, 27 Aug 2015 00:06:34 +0200 Subject: [PATCH 177/311] Pull request #825 broke the Ajax messages. This commit fixes it. When there were no messages, but there was HTML for the ESI Ajax container, it was thrown. When that happened, there was no ESI container on that page, so messages would never work on that cached page. --- .../Nexcessnet/Turpentine/Block/Core/Messages.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php index 924a9de06..b09ecd45a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php @@ -198,16 +198,17 @@ protected function _toHtml() { } else { $this->_loadMessages(); $this->_loadSavedMessages(); - $html = $this->_real_toHtml(); + if ( count($this->getMessages()) ) { + $html = $this->_real_toHtml(); + } else { + // Prevent returning an empty
          + $html = ''; + } } } else { $html = $this->_real_toHtml(); } $this->_directCall = false; - - if (count($this->getMessages()) == 0) { - return ''; - } return $html; } From 3aa4c967111c929be79f061e97519110c86f03d8 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Thu, 27 Aug 2015 09:41:08 -0400 Subject: [PATCH 178/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97fd5d556..c18e9ee89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -410,3 +410,6 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#878] Explicit cache bypass for progress sections (@astorm) * [#844] Fix for HTTPS ESI URLs (@jeroenvermeulen) * [#865] Implemented load balancing support (@jeroenvermeulen) + +### RELEASE-0.6.5 + * Varnish 4 (@aheadley @aricwatson) From aa8d26f2300887068168f16ef6319f46a8848c7d Mon Sep 17 00:00:00 2001 From: mbalparda Date: Thu, 27 Aug 2015 09:53:41 -0400 Subject: [PATCH 179/311] refs Added PRs to CHANGELOG.md and 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 15a5c7420..2ca4e4fa4 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.4 + 0.6.5 From a202dc8ded039b46f3e1a0bc101cfc864ef84792 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 27 Aug 2015 16:03:17 +0100 Subject: [PATCH 180/311] 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 181/311] 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 182/311] 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 183/311] 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 184/311] 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 1209ee1a62674df82230f1334bd9badeb0caac53 Mon Sep 17 00:00:00 2001 From: Tim Muller Date: Thu, 3 Sep 2015 13:18:59 +0200 Subject: [PATCH 185/311] DetermineVersion 3.0 to 3.0.3 bugfix --- .../Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php | 8 +++++++- 1 file changed, 7 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..65bdd6b36 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -357,7 +357,13 @@ protected function _determineVersion($bannerText) { Mage::throwException('Varnish versions before 2.1 are not supported'); } if ( count($bannerText)<7 ) { - // Varnish before 3.0 does not spit out a version number + // Varnish before 3.0.4 does not spit out a version number + $resp = $this->_write( 'help' )->_read(); + if( strpos( $resp['text'], 'ban.url' ) !== false ) { + // Varnish versions 3.0 through 3.0.3 do not return a version banner. + // To differentiate between 2.1 and 3.0, we check the existence of the ban.url command. + return '3.0'; + } return '2.1'; } elseif ( preg_match(self::REGEXP_VARNISH_VERSION, $bannerText[4], $matches)===1 ) { return $matches['vmajor'] . '.' . $matches['vminor']; From ac0deeb6f83721007ba21b28115f4fa4d7caf12c Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 3 Sep 2015 14:28:31 +0100 Subject: [PATCH 186/311] Add missing maintenance_allowed_ips to version 4 VCL --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index ac3690894..52913cd9f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -102,6 +102,8 @@ sub generate_session_expires { ## Varnish Subroutines sub vcl_recv { + {{maintenance_allowed_ips}} + # this always needs to be done so it's up at the top if (req.restarts == 0) { if (req.http.X-Forwarded-For) { From b29dfce3400a03290f0cdfe58aa6366cbfbbdf6d Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 3 Sep 2015 14:33:49 +0100 Subject: [PATCH 187/311] add missing vcl_synth to version 4 vcl --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 52913cd9f..f81f440b2 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -352,6 +352,8 @@ sub vcl_backend_response { # else it's not part of Magento so use the default Varnish handling } +{{vcl_synth}} + sub vcl_deliver { if (req.http.X-Varnish-Faked-Session) { # need to set the set-cookie header since we just made it out of thin air From 390c6c6861093a1ede4c4f5fdead5ef55d755c40 Mon Sep 17 00:00:00 2001 From: Thomas Hampe Date: Mon, 14 Sep 2015 13:25:55 +0200 Subject: [PATCH 188/311] Send unmodified url to backend server --- .../Model/Varnish/Configurator/Abstract.php | 9 ++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 1 + .../Nexcessnet/Turpentine/etc/system.xml | 14 +++++++++++ .../Nexcessnet/Turpentine/misc/version-2.vcl | 23 ++++++++++++++++++- .../Nexcessnet/Turpentine/misc/version-3.vcl | 17 +++++++++++++- .../Nexcessnet/Turpentine/misc/version-4.vcl | 19 ++++++++++++++- 6 files changed, 80 insertions(+), 3 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 b33feee45..cd94ca891 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -379,6 +379,14 @@ protected function _getIgnoreGetParameters() return implode( '|', $ignoredParameters); } + /** + * @return boolean + */ + protected function _sendUnModifiedUrlToBackend() + { + return Mage::getStoreConfigFlag('turpentine_vcl/params/transfer_unmodified_url'); + } + /** * Get the Generate Session * @@ -844,6 +852,7 @@ protected function _getTemplateVars() { 'default_ttl' => $this->_getDefaultTtl(), 'enable_get_excludes' => ($this->_getGetParamExcludes() ? 'true' : 'false'), 'enable_get_ignored' => ($this->_getIgnoreGetParameters() ? 'true' : 'false'), + 'send_unmodified_url' => ($this->_sendUnModifiedUrlToBackend() ? 'true' : 'false'), 'debug_headers' => $this->_getEnableDebugHeaders(), 'grace_period' => $this->_getGracePeriod(), 'force_cache_static' => $this->_getForceCacheStatic(), diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 2ca4e4fa4..a0794aa9a 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -80,6 +80,7 @@ __SID,XDEBUG_PROFILE utm_source,utm_medium,utm_campaign,utm_content,utm_term,gclid,cx,ie,cof,siteurl + 0 1 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index cc4a7b190..f05686094 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -541,6 +541,20 @@ 0 0 + + + + By default the backend server (webserver / magento) gets a modified URL (without ignored get parameters). + As a result the ignored parameters can not be used by the backend server for uncachable requests, for example a redirect. + By activating this option the backend server gets the the unmodified url, but the cache still uses the modified url for lookups. + + select + adminhtml/system_config_source_yesno + 21 + 1 + 0 + 0 + diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index cb63ea02f..5fa385f5d 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -104,6 +104,13 @@ sub vcl_recv { set req.http.X-Opt-Enable-Caching = "{{enable_caching}}"; set req.http.X-Opt-Force-Static-Caching = "{{force_cache_static}}"; set req.http.X-Opt-Enable-Get-Excludes = "{{enable_get_excludes}}"; + set req.http.X-Opt-Send-Unmodified-Url = "{{send_unmodified_url}}"; + + + if(req.http.X-Opt-Send-Unmodified-Url == "true") { + # save unmodified url + set req.http.X-Varnish-Origin-Url = req.url; + } # Normalize request data before potentially sending things off to the # backend. This ensures all request types get the same information, most @@ -200,7 +207,14 @@ sub vcl_recv { set req.url = regsuball(req.url, "(?:(\?)?|&)(?:{{get_param_ignored}})=[^&]+", "\1"); set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); } - + + + if(req.http.X-Opt-Send-Unmodified-Url == "true") { + # change req.url back and save the modified for cache look-ups in a separate variable + set req.http.X-Varnish-Cache-Url = req.url; + set req.url = req.http.X-Varnish-Origin-Url; + unset req.http.X-Varnish-Origin-Url; + } return (lookup); } @@ -220,6 +234,13 @@ sub vcl_pipe { # } sub vcl_hash { + + if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) { + set req.hash += req.http.X-Varnish-Cache-Url; + } else { + set req.hash += req.url; + } + set req.hash += req.url; if (req.http.Host) { set req.hash += req.http.Host; diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 3b8e3217f..18c721500 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -107,6 +107,11 @@ sub vcl_recv { } } + if({{send_unmodified_url}}) { + # save the unmodified url + set req.http.X-Varnish-Origin-Url = req.url; + } + # Normalize request data before potentially sending things off to the # backend. This ensures all request types get the same information, most # notably POST requests getting a normalized user agent string to empower @@ -202,6 +207,11 @@ sub vcl_recv { set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); } + if({{send_unmodified_url}}) { + set req.http.X-Varnish-Cache-Url = req.url; + set req.url = req.http.X-Varnish-Origin-Url; + unset req.http.X-Varnish-Origin-Url; + } # everything else checks out, try and pull from the cache return (lookup); @@ -222,7 +232,12 @@ sub vcl_pipe { # } sub vcl_hash { - hash_data(req.url); + + if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) { + hash_data(req.http.X-Varnish-Cache-Url); + } else { + hash_data(req.url); + } if (req.http.Host) { hash_data(req.http.Host); } else { diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index ac3690894..4f75aa1af 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -121,6 +121,11 @@ sub vcl_recv { return (pipe); } + if({{send_unmodified_url}}) { + # save the unmodified url + set req.http.X-Varnish-Origin-Url = req.url; + } + # remove double slashes from the URL, for higher cache hit rate set req.url = regsuball(req.url, "(.*)//+(.*)", "\1/\2"); @@ -206,6 +211,12 @@ sub vcl_recv { set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); } + if({{send_unmodified_url}}) { + set req.http.X-Varnish-Cache-Url = req.url; + set req.url = req.http.X-Varnish-Origin-Url; + unset req.http.X-Varnish-Origin-Url; + } + # everything else checks out, try and pull from the cache return (hash); } @@ -225,7 +236,13 @@ sub vcl_pipe { # } sub vcl_hash { - hash_data(req.url); + + if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) { + hash_data(req.http.X-Varnish-Cache-Url); + } else { + hash_data(req.url); + } + if (req.http.Host) { hash_data(req.http.Host); } else { From 08dbebe7f899d6394d0cdece01c4693447b3db05 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 14 Sep 2015 09:44:27 -0300 Subject: [PATCH 189/311] 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 From ba8fa7e8cf362874166ffd46689432999ce90ed5 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 15 Sep 2015 10:06:52 -0300 Subject: [PATCH 190/311] refs Added PRs to CHANGELOG.md and bump version. --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c18e9ee89..ec1da9657 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -413,3 +413,6 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess ### RELEASE-0.6.5 * Varnish 4 (@aheadley @aricwatson) + +### RELEASE-0.6.6 + * [#923] DetermineVersion 3.0 to 3.0.3 bugfix (@timmuller) From bb4c82b6c84b2a6e9db8789046cb72c5974e2b85 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 15 Sep 2015 10:12:24 -0300 Subject: [PATCH 191/311] refs Added PRs to CHANGELOG.md and bump version. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec1da9657..d995971d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -416,3 +416,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess ### RELEASE-0.6.6 * [#923] DetermineVersion 3.0 to 3.0.3 bugfix (@timmuller) + * [#945] Send unmodified url to the backend server (@thampe) From 67363b522849f9e13c537c9416dbab1196b16048 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Thu, 17 Sep 2015 11:13:56 -0300 Subject: [PATCH 192/311] refs Added PRs to CHANGELOG.md and bump version. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d995971d3..a8d5e7867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -417,3 +417,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess ### RELEASE-0.6.6 * [#923] DetermineVersion 3.0 to 3.0.3 bugfix (@timmuller) * [#945] Send unmodified url to the backend server (@thampe) + * [#885] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page (@craigcarnell) From 75d1a58d7b230da6db2907ecc4f91fdfe140ab18 Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 21 Sep 2015 09:58:16 -0300 Subject: [PATCH 193/311] refs Added PRs to CHANGELOG.md and bump version. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8d5e7867..bfb3cdaeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -418,3 +418,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#923] DetermineVersion 3.0 to 3.0.3 bugfix (@timmuller) * [#945] Send unmodified url to the backend server (@thampe) * [#885] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page (@craigcarnell) + * [#955] Include theme specific handles to ESI data (@LyndonHook) From a5f2811300760a7be09fa8ab4bebd2fd64f33d16 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Wed, 23 Sep 2015 12:47:04 +0100 Subject: [PATCH 194/311] only return pipe when vcl_fix is enabled --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 2 +- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 3 +-- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 5 ++--- 3 files changed, 4 insertions(+), 6 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 cd862b140..c154b8e1f 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -415,7 +415,7 @@ protected function _getGenerateSessionEnd() { */ protected function _getGenerateSession() { return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) - ? '# call generate_session' : 'call generate_session;'; + ? 'return (pipe);' : 'call generate_session;'; } diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 78bd68d8f..115c1887f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -177,8 +177,7 @@ sub vcl_recv { set req.http.Cookie = "frontend=crawler-session"; } else { # it's a real user, make up a new session for them - {{generate_session}}# call generate_session; - return (pipe); + {{generate_session}} } } if ({{force_cache_static}} && diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 567f05c22..996028d3a 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -21,7 +21,7 @@ vcl 4.0; ## Custom C Code C{ - # @source app/code/community/Nexcessnet/Turpentine/misc/uuid.c + // @source app/code/community/Nexcessnet/Turpentine/misc/uuid.c {{custom_c_code}} }C @@ -175,8 +175,7 @@ sub vcl_recv { set req.http.Cookie = "frontend=crawler-session"; } else { # it's a real user, make up a new session for them - {{generate_session}}# call generate_session; - return (pipe); + {{generate_session}} } } if ({{force_cache_static}} && From 483b9b33d76a25b7a2aa87c0fbb3973672d6e2f8 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Wed, 23 Sep 2015 13:05:47 +0100 Subject: [PATCH 195/311] fix no such module extendedvarnish crash in admin system --- app/code/community/Nexcessnet/Turpentine/etc/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 51c95cbd9..396871326 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -541,7 +541,7 @@ 0 0 - + By default the backend server (webserver / magento) gets a modified URL (without ignored get parameters). From 88160f1b33fc01a87edafc3bfd32d0c5d0a9fc2e Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Wed, 23 Sep 2015 13:15:06 +0100 Subject: [PATCH 196/311] fix comment in v4 VCL --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 567f05c22..3c0ab960c 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -16,7 +16,7 @@ vcl 4.0; # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -## Nexcessnet_Turpentine Varnish v3 VCL Template +## Nexcessnet_Turpentine Varnish v4 VCL Template ## Custom C Code From a82ba6bbc9e5c087d25a8da4a8500730ba2f933b Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Wed, 23 Sep 2015 17:06:54 +0100 Subject: [PATCH 197/311] use getStoreConfigFlag --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c154b8e1f..393e00d04 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -414,7 +414,7 @@ protected function _getGenerateSessionEnd() { * @return string */ protected function _getGenerateSession() { - return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) + return Mage::getStoreConfigFlag( 'turpentine_varnish/general/vcl_fix' ) ? 'return (pipe);' : 'call generate_session;'; } From 5d6190c5db5caa231407b466ecf359d69aac3ee5 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Wed, 30 Sep 2015 15:17:05 -0400 Subject: [PATCH 198/311] add disable ESI injection option Adds an option to disable ESI injection on specific blocks --- .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 881bf748d..2aeff4c0a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -230,6 +230,11 @@ public function injectEsi( $eventObject ) { if( $esiHelper->shouldResponseUseEsi() && $blockObject instanceof Mage_Core_Block_Template && $esiOptions = $blockObject->getEsiOptions() ) { + + if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) { + return; + } + if( Mage::app()->getStore()->getCode() == 'admin' ) { // admin blocks are not allowed to be cached for now $debugHelper->logWarn( From d7afeffddd10a120928b6a7298bdd676ef9b873c Mon Sep 17 00:00:00 2001 From: Tsvetan Stoychev Date: Sun, 4 Oct 2015 17:12:54 +0200 Subject: [PATCH 199/311] #971 - Fixed bug with wrong return value of ->getSkinUrl() in ESI context. --- .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 2 -- .../Nexcessnet/Turpentine/controllers/EsiController.php | 3 --- 2 files changed, 5 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index c337066e7..6a9af13e3 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -326,8 +326,6 @@ protected function _getEsiData( $blockObject, $esiOptions ) { $esiData = new Varien_Object(); $esiData->setStoreId( Mage::app()->getStore()->getId() ); $esiData->setDesignPackage( Mage::getDesign()->getPackageName() ); - $esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) ); - $esiData->setNameInLayout( $blockObject->getNameInLayout() ); $esiData->setBlockType( get_class( $blockObject ) ); $esiData->setLayoutHandles( $this->_getBlockLayoutHandles( $blockObject ) ); $esiData->setEsiMethod( $esiOptions[$methodParam] ); diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 3bfe0d495..8d2521bba 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -183,9 +183,6 @@ protected function _getEsiBlock( $esiData ) { } } $layout = Mage::getSingleton( 'core/layout' ); - Mage::getSingleton( 'core/design_package' ) - ->setPackageName( $esiData->getDesignPackage() ) - ->setTheme( $esiData->getDesignTheme() ); // dispatch event for adding handles to layout update Mage::dispatchEvent( From 55f147f4660bb421ac2f9bd29e540d34f609310c Mon Sep 17 00:00:00 2001 From: Tsvetan Stoychev Date: Sun, 4 Oct 2015 17:39:07 +0200 Subject: [PATCH 200/311] #971 - Restored a value that was removed by mistake in previous commit. --- app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 6a9af13e3..5124e706e 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -325,7 +325,7 @@ protected function _getEsiData( $blockObject, $esiOptions ) { $methodParam = $esiHelper->getEsiMethodParam(); $esiData = new Varien_Object(); $esiData->setStoreId( Mage::app()->getStore()->getId() ); - $esiData->setDesignPackage( Mage::getDesign()->getPackageName() ); + $esiData->setNameInLayout( $blockObject->getNameInLayout() ); $esiData->setBlockType( get_class( $blockObject ) ); $esiData->setLayoutHandles( $this->_getBlockLayoutHandles( $blockObject ) ); $esiData->setEsiMethod( $esiOptions[$methodParam] ); From 51910a56db92370469af3654cc21e73ef5ac032a Mon Sep 17 00:00:00 2001 From: mbalparda Date: Fri, 9 Oct 2015 09:39:18 -0300 Subject: [PATCH 201/311] refs Added PRs to CHANGELOG.md and bump version. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfb3cdaeb..cb1ac3a99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -419,3 +419,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#945] Send unmodified url to the backend server (@thampe) * [#885] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page (@craigcarnell) * [#955] Include theme specific handles to ESI data (@LyndonHook) + * [#972] Fixed bug with wrong return value of ->getSkinUrl() (@ceckoslab) From c5e7ba20e9d703f3e6832850d90d9479ee0aa19f Mon Sep 17 00:00:00 2001 From: mbalparda Date: Mon, 12 Oct 2015 11:42:38 -0300 Subject: [PATCH 202/311] refs Added PRs to CHANGELOG.md and 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 67e86b0ca..a9fc7eec1 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.6 + 0.6.7 From fa1198d7f76dbc9c8367d6ea3a8263ead99a34e1 Mon Sep 17 00:00:00 2001 From: aricwatson Date: Tue, 13 Oct 2015 14:03:58 -0400 Subject: [PATCH 203/311] Added disableEsiInjection update to changelog Forgot to update changelog when this was merged in. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb1ac3a99..09c912622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -419,4 +419,5 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#945] Send unmodified url to the backend server (@thampe) * [#885] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page (@craigcarnell) * [#955] Include theme specific handles to ESI data (@LyndonHook) - * [#972] Fixed bug with wrong return value of ->getSkinUrl() (@ceckoslab) + * [#972] Fixed bug with wrong return value of ->getSkinUrl() (@ceckoslab) + * [#951] Added 'disableEsiInjection' ESI policy option. From 2cbfb6a3730bd279280c5ac7ac6e70c5b2f2338e Mon Sep 17 00:00:00 2001 From: mbalparda Date: Thu, 15 Oct 2015 09:39:30 -0300 Subject: [PATCH 204/311] refs Added Scrutinizer. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1a9d5d59a..54c8dcfa5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # [Nexcess.net](https://www.nexcess.net/) Turpentine Extension for Magento [![Build Status](https://travis-ci.org/nexcess/magento-turpentine.png?branch=master,devel)](https://travis-ci.org/nexcess/magento-turpentine) +[![Scrutinizer](https://scrutinizer-ci.com/g/nexcess/magento-turpentine/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nexcess/magento-turpentine/) Turpentine is a full page cache extension for [Magento](https://www.magentocommerce.com/) that works with [Varnish](https://www.varnish-cache.org/), a very fast caching reverse-proxy. By From f944c8ed44a436d0828fd2b136255c7b696ff241 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Thu, 15 Oct 2015 13:11:14 +0000 Subject: [PATCH 205/311] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- .../Turpentine/Block/Adminhtml/Cache/Grid.php | 8 +- .../Turpentine/Block/Core/Messages.php | 130 +++--- .../Turpentine/Block/Management.php | 10 +- .../Turpentine/Block/Poll/ActivePoll.php | 4 +- .../Turpentine/Block/Product/Compared.php | 2 +- .../Turpentine/Block/Product/Viewed.php | 2 +- .../Nexcessnet/Turpentine/Helper/Ban.php | 24 +- .../Nexcessnet/Turpentine/Helper/Cron.php | 124 +++--- .../Nexcessnet/Turpentine/Helper/Data.php | 180 ++++---- .../Nexcessnet/Turpentine/Helper/Debug.php | 197 +++++---- .../Nexcessnet/Turpentine/Helper/Esi.php | 139 +++--- .../Nexcessnet/Turpentine/Helper/Varnish.php | 66 +-- .../Model/Config/Select/StripWhitespace.php | 6 +- .../Model/Config/Select/Version.php | 2 +- .../Turpentine/Model/Core/Session.php | 6 +- .../Turpentine/Model/Dummy/Request.php | 175 ++++---- .../Turpentine/Model/Observer/Ban.php | 230 +++++----- .../Turpentine/Model/Observer/Cron.php | 42 +- .../Turpentine/Model/Observer/Debug.php | 12 +- .../Turpentine/Model/Observer/Esi.php | 270 ++++++------ .../Turpentine/Model/Observer/Varnish.php | 70 +-- .../Model/PageCache/Container/Notices.php | 4 +- .../Nexcessnet/Turpentine/Model/Session.php | 37 +- .../Turpentine/Model/Shim/Mage/Core/App.php | 74 ++-- .../Model/Shim/Mage/Core/Config.php | 4 +- .../Model/Shim/Mage/Core/Layout.php | 16 +- .../Turpentine/Model/Varnish/Admin.php | 68 +-- .../Turpentine/Model/Varnish/Admin/Socket.php | 221 +++++----- .../Model/Varnish/Configurator/Abstract.php | 404 +++++++++--------- .../Model/Varnish/Configurator/Version2.php | 2 +- .../Model/Varnish/Configurator/Version3.php | 14 +- .../Model/Varnish/Configurator/Version4.php | 2 +- .../controllers/Adminhtml/CacheController.php | 12 +- .../Turpentine/controllers/EsiController.php | 220 +++++----- .../Varnish/ManagementController.php | 120 +++--- contrib/tools/esi-decoder.php | 40 +- util/varnishadm.php | 22 +- 37 files changed, 1479 insertions(+), 1480 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php b/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php index 07a045dcc..d25bb7b78 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php @@ -19,20 +19,20 @@ protected function _prepareCollection() $fullPageEnabled = false; foreach ($collection as $key=>$item) { - if($item->getStatus()==1 && ($item->getId()=='turpentine_pages' || $item->getId()=='turpentine_esi_blocks')) + if ($item->getStatus() == 1 && ($item->getId() == 'turpentine_pages' || $item->getId() == 'turpentine_esi_blocks')) { $turpentineEnabled = true; } - if($item->getStatus()==1 && $item->getId()=='full_page') + if ($item->getStatus() == 1 && $item->getId() == 'full_page') { $fullPageEnabled = true; } } - if($turpentineEnabled) + if ($turpentineEnabled) { $collection->removeItemByKey('full_page'); } - if($fullPageEnabled) + if ($fullPageEnabled) { $collection->removeItemByKey('turpentine_pages'); $collection->removeItemByKey('turpentine_esi_blocks'); diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php index b09ecd45a..d330623e4 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php @@ -25,13 +25,13 @@ class Nexcessnet_Turpentine_Block_Core_Messages extends Mage_Core_Block_Messages * can't use null because that is the default so no way to tell between * the default and not actually calling it */ - const NO_SINGLE_RENDER_TYPE = -1; + const NO_SINGLE_RENDER_TYPE = -1; /** * Hold the message type to call getHtml with * @var mixed */ - protected $_singleRenderType = null; + protected $_singleRenderType = null; /** * Sentinel to check if the toHtml method was skipped (getGroupedHtml was @@ -41,7 +41,7 @@ class Nexcessnet_Turpentine_Block_Core_Messages extends Mage_Core_Block_Messages * * @var boolean */ - protected $_directCall = false; + protected $_directCall = false; /** * List of session types to load messages from for the "messages" block. @@ -65,10 +65,10 @@ class Nexcessnet_Turpentine_Block_Core_Messages extends Mage_Core_Block_Messages * * @var array */ - protected $_usedStorageTypes = array( 'core/session' ); + protected $_usedStorageTypes = array('core/session'); public function _prepareLayout() { - if( $this->_fixMessages() ) { + if ($this->_fixMessages()) { /* do nothing */ return $this; } else { @@ -82,11 +82,11 @@ public function _prepareLayout() { * @param Mage_Core_Model_Message_Collection $messages * @return Mage_Core_Block_Messages */ - public function setMessages( Mage_Core_Model_Message_Collection $messages ) { - if( $this->_fixMessages() ) { - $this->_saveMessages( $messages->getItems() ); + public function setMessages(Mage_Core_Model_Message_Collection $messages) { + if ($this->_fixMessages()) { + $this->_saveMessages($messages->getItems()); } else { - parent::setMessages( $messages ); + parent::setMessages($messages); } return $this; } @@ -97,11 +97,11 @@ public function setMessages( Mage_Core_Model_Message_Collection $messages ) { * @param Mage_Core_Model_Message_Collection $messages * @return Mage_Core_Block_Messages */ - public function addMessages( Mage_Core_Model_Message_Collection $messages ) { - if( $this->_fixMessages() ) { - $this->_saveMessages( $messages->getItems() ); + public function addMessages(Mage_Core_Model_Message_Collection $messages) { + if ($this->_fixMessages()) { + $this->_saveMessages($messages->getItems()); } else { - parent::addMessages( $messages ); + parent::addMessages($messages); } return $this; } @@ -112,11 +112,11 @@ public function addMessages( Mage_Core_Model_Message_Collection $messages ) { * @param Mage_Core_Model_Message_Abstract $message * @return Mage_Core_Block_Messages */ - public function addMessage( Mage_Core_Model_Message_Abstract $message ) { - if( $this->_fixMessages() ) { - $this->_saveMessages( array( $message ) ); + public function addMessage(Mage_Core_Model_Message_Abstract $message) { + if ($this->_fixMessages()) { + $this->_saveMessages(array($message)); } else { - parent::addMessage( $message ); + parent::addMessage($message); } return $this; } @@ -125,12 +125,11 @@ public function addMessage( Mage_Core_Model_Message_Abstract $message ) { * Override this in case some dumb layout decides to use it instead of the * standard toHtml stuff * - * @param mixed $type=self::NO_SINGLE_RENDER_TYPE * @return string */ - public function getHtml( $type=self::NO_SINGLE_RENDER_TYPE ) { + public function getHtml($type = self::NO_SINGLE_RENDER_TYPE) { $this->_singleRenderType = $type; - return $this->_handleDirectCall( 'getHtml' )->toHtml(); + return $this->_handleDirectCall('getHtml')->toHtml(); } /** @@ -140,7 +139,7 @@ public function getHtml( $type=self::NO_SINGLE_RENDER_TYPE ) { * @return string */ public function getGroupedHtml() { - return $this->_handleDirectCall( 'getGroupedHtml' )->toHtml(); + return $this->_handleDirectCall('getGroupedHtml')->toHtml(); } /** @@ -150,37 +149,38 @@ public function getGroupedHtml() { * * @param string $type */ - public function addStorageType( $type ) { + public function addStorageType($type) { $this->_usedStorageTypes[] = $type; } /** * Load layout options * - * @return null + * @param string $methodCalled + * @return Nexcessnet_Turpentine_Block_Core_Messages */ - protected function _handleDirectCall( $methodCalled ) { + protected function _handleDirectCall($methodCalled) { // this doesn't actually do anything because _real_toHtml() won't be // called in this request context (unless the flash message isn't // actually supposed to be ajax/esi'd in) $this->_directCall = $methodCalled; - if( $this->_fixMessages() ) { + if ($this->_fixMessages()) { $layout = $this->getLayout(); - $layoutUpdate = $layout->getUpdate()->load( 'default' ); - if( Mage::app()->useCache( 'layout' ) ) { + $layoutUpdate = $layout->getUpdate()->load('default'); + if (Mage::app()->useCache('layout')) { // this is skipped in the layout update load() if the "layout" // cache is enabled, which seems to cause the esi layout stuff // to not load, so we manually do it here - foreach( $layoutUpdate->getHandles() as $handle ) { - $layoutUpdate->merge( $handle ); + foreach ($layoutUpdate->getHandles() as $handle) { + $layoutUpdate->merge($handle); } } $layout->generateXml(); - $layoutShim = Mage::getSingleton( 'turpentine/shim_mage_core_layout' ); - foreach( $layout->getNode()->xpath( - sprintf( '//reference[@name=\'%s\']/action', - $this->getNameInLayout() ) ) as $node ) { - $layoutShim->shim_generateAction( $node ); + $layoutShim = Mage::getSingleton('turpentine/shim_mage_core_layout'); + foreach ($layout->getNode()->xpath( + sprintf('//reference[@name=\'%s\']/action', + $this->getNameInLayout()) ) as $node) { + $layoutShim->shim_generateAction($node); } } return $this; @@ -192,13 +192,13 @@ protected function _handleDirectCall( $methodCalled ) { * @return string */ protected function _toHtml() { - if( $this->_fixMessages() ) { - if( $this->_shouldUseInjection() ) { + if ($this->_fixMessages()) { + if ($this->_shouldUseInjection()) { $html = $this->renderView(); } else { $this->_loadMessages(); $this->_loadSavedMessages(); - if ( count($this->getMessages()) ) { + if (count($this->getMessages())) { $html = $this->_real_toHtml(); } else { // Prevent returning an empty
            @@ -219,7 +219,7 @@ protected function _toHtml() { */ protected function _hasInjectOptions() { return $this->getEsiOptions() && - Mage::helper( 'turpentine/esi' )->shouldResponseUseEsi(); + Mage::helper('turpentine/esi')->shouldResponseUseEsi(); } /** @@ -241,7 +241,7 @@ protected function _shouldUseInjection() { * @return boolean */ protected function _hasTemplateSet() { - return (bool)$this->getTemplate(); + return (bool) $this->getTemplate(); } /** @@ -249,10 +249,10 @@ protected function _hasTemplateSet() { * * @return null */ - protected function _saveMessages( $messages ) { - if( $this->_fixMessages() && !$this->_isEsiRequest() ) { - Mage::getSingleton( 'turpentine/session' ) - ->saveMessages( $this->getNameInLayout(), $messages ); + protected function _saveMessages($messages) { + if ($this->_fixMessages() && ! $this->_isEsiRequest()) { + Mage::getSingleton('turpentine/session') + ->saveMessages($this->getNameInLayout(), $messages); } } @@ -262,14 +262,14 @@ protected function _saveMessages( $messages ) { * @return null */ protected function _loadMessages() { - if( $this->getNameInLayout() == 'messages' ) { - foreach( $this->_messageStorageTypes as $type ) { - $storage = sprintf( '%s/session', $type ); - $this->addStorageType( $storage ); - $this->_loadMessagesFromStorage( $storage ); + if ($this->getNameInLayout() == 'messages') { + foreach ($this->_messageStorageTypes as $type) { + $storage = sprintf('%s/session', $type); + $this->addStorageType($storage); + $this->_loadMessagesFromStorage($storage); } } else { - $this->_loadMessagesFromStorage( 'core/session' ); + $this->_loadMessagesFromStorage('core/session'); } } @@ -279,9 +279,9 @@ protected function _loadMessages() { * @return null */ protected function _loadSavedMessages() { - $session = Mage::getSingleton( 'turpentine/session' ); - foreach( $session->loadMessages( $this->getNameInLayout() ) as $msg ) { - parent::addMessage( $msg ); + $session = Mage::getSingleton('turpentine/session'); + foreach ($session->loadMessages($this->getNameInLayout()) as $msg) { + parent::addMessage($msg); } $this->_clearMessages(); } @@ -292,10 +292,10 @@ protected function _loadSavedMessages() { * @param string $type * @return null */ - protected function _loadMessagesFromStorage( $type ) { - foreach( Mage::getSingleton( $type ) - ->getMessages( true )->getItems() as $msg ) { - parent::addMessage( $msg ); + protected function _loadMessagesFromStorage($type) { + foreach (Mage::getSingleton($type) + ->getMessages(true)->getItems() as $msg) { + parent::addMessage($msg); } } @@ -305,8 +305,8 @@ protected function _loadMessagesFromStorage( $type ) { * @return null */ protected function _clearMessages() { - Mage::getSingleton( 'turpentine/session' ) - ->clearMessages( $this->getNameInLayout() ); + Mage::getSingleton('turpentine/session') + ->clearMessages($this->getNameInLayout()); } /** @@ -315,8 +315,8 @@ protected function _clearMessages() { * @return string */ protected function _real_toHtml() { - if( !$this->_directCall ) { - switch( $this->getNameInLayout() ) { + if ( ! $this->_directCall) { + switch ($this->getNameInLayout()) { case 'global_messages': $this->_directCall = 'getHtml'; break; @@ -326,9 +326,9 @@ protected function _real_toHtml() { break; } } - switch( $this->_directCall ) { + switch ($this->_directCall) { case 'getHtml': - $html = parent::getHtml( $this->_singleRenderType ); + $html = parent::getHtml($this->_singleRenderType); $this->_singleRenderType = self::NO_SINGLE_RENDER_TYPE; break; case 'getGroupedHtml': @@ -346,7 +346,7 @@ protected function _real_toHtml() { * @return bool */ protected function _fixMessages() { - return Mage::helper( 'turpentine/esi' )->shouldFixFlashMessages(); + return Mage::helper('turpentine/esi')->shouldFixFlashMessages(); } /** @@ -358,7 +358,7 @@ protected function _fixMessages() { * @return boolean */ protected function _isEsiRequest() { - return is_a( Mage::app()->getRequest(), - 'Nexcessnet_Turpentine_Model_Dummy_Request' ); + return is_a(Mage::app()->getRequest(), + 'Nexcessnet_Turpentine_Model_Dummy_Request'); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Management.php b/app/code/community/Nexcessnet/Turpentine/Block/Management.php index 34a1452f0..ff66045b4 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Management.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Management.php @@ -34,7 +34,7 @@ public function __construct() { * @return string */ public function getFlushAllUrl() { - return $this->getUrl( '*/varnish_management/flushAll' ); + return $this->getUrl('*/varnish_management/flushAll'); } /** @@ -43,7 +43,7 @@ public function getFlushAllUrl() { * @return string */ public function getFlushPartialUrl() { - return $this->getUrl( '*/varnish_management/flushPartial' ); + return $this->getUrl('*/varnish_management/flushPartial'); } /** @@ -52,7 +52,7 @@ public function getFlushPartialUrl() { * @return string */ public function getFlushContentTypeUrl() { - return $this->getUrl( '*/varnish_management/flushContentType' ); + return $this->getUrl('*/varnish_management/flushContentType'); } /** @@ -61,7 +61,7 @@ public function getFlushContentTypeUrl() { * @return string */ public function getApplyConfigUrl() { - return $this->getUrl( '*/varnish_management/applyConfig' ); + return $this->getUrl('*/varnish_management/applyConfig'); } /** @@ -88,7 +88,7 @@ public function getGetConfigUrl() { * @param string $type * @return string */ - public function getSwitchNavigationUrl( $type ) { + public function getSwitchNavigationUrl($type) { return $this->getUrl('*/varnish_management/switchNavigation', array('type' => $type)); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php index 8e66ba08a..e4f9810f7 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php @@ -24,8 +24,8 @@ class Nexcessnet_Turpentine_Block_Poll_Activepoll extends Mage_Poll_Block_Active public function setTemplate($template) { $this->_template = $template; - $this->setPollTemplate('turpentine/ajax.phtml', 'poll' ); - $this->setPollTemplate('turpentine/ajax.phtml', 'results' ); + $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); + $this->setPollTemplate('turpentine/ajax.phtml', 'results'); return $this; } } diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Product/Compared.php b/app/code/community/Nexcessnet/Turpentine/Block/Product/Compared.php index 12ec356c9..76201db74 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Product/Compared.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Product/Compared.php @@ -23,7 +23,7 @@ class Nexcessnet_Turpentine_Block_Product_Compared extends Mage_Reports_Block_Pr protected function _toHtml() { - if (!$this->getCount()) { + if ( ! $this->getCount()) { return $this->renderView(); } diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Product/Viewed.php b/app/code/community/Nexcessnet/Turpentine/Block/Product/Viewed.php index 9561243e1..bc9e228d3 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Product/Viewed.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Product/Viewed.php @@ -23,7 +23,7 @@ class Nexcessnet_Turpentine_Block_Product_Viewed extends Mage_Reports_Block_Prod protected function _toHtml() { - if (!$this->getCount()) { + if ( ! $this->getCount()) { return $this->renderView(); } $this->setRecentlyViewedProducts($this->getItemsCollection()); diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Ban.php b/app/code/community/Nexcessnet/Turpentine/Helper/Ban.php index a468ebc44..fabcb3549 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Ban.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Ban.php @@ -27,20 +27,20 @@ class Nexcessnet_Turpentine_Helper_Ban extends Mage_Core_Helper_Abstract { * @param Mage_Catalog_Model_Product $product * @return string */ - public function getProductBanRegex( $product ) { + public function getProductBanRegex($product) { $urlPatterns = array(); - foreach( $this->getParentProducts( $product ) as $parentProduct ) { - if ( $parentProduct->getUrlKey() ) { + foreach ($this->getParentProducts($product) as $parentProduct) { + if ($parentProduct->getUrlKey()) { $urlPatterns[] = $parentProduct->getUrlKey(); } } - if ( $product->getUrlKey() ) { + if ($product->getUrlKey()) { $urlPatterns[] = $product->getUrlKey(); } - if ( empty($urlPatterns) ) { + if (empty($urlPatterns)) { $urlPatterns[] = "##_NEVER_MATCH_##"; } - $pattern = sprintf( '(?:%s)', implode( '|', $urlPatterns ) ); + $pattern = sprintf('(?:%s)', implode('|', $urlPatterns)); return $pattern; } @@ -50,13 +50,13 @@ public function getProductBanRegex( $product ) { * @param Mage_Catalog_Model_Product $childProduct * @return array */ - public function getParentProducts( $childProduct ) { + public function getParentProducts($childProduct) { $parentProducts = array(); - foreach( array( 'configurable', 'grouped' ) as $pType ) { - foreach( Mage::getModel( 'catalog/product_type_' . $pType ) - ->getParentIdsByChild( $childProduct->getId() ) as $parentId ) { - $parentProducts[] = Mage::getModel( 'catalog/product' ) - ->load( $parentId ); + foreach (array('configurable', 'grouped') as $pType) { + foreach (Mage::getModel('catalog/product_type_'.$pType) + ->getParentIdsByChild($childProduct->getId()) as $parentId) { + $parentProducts[] = Mage::getModel('catalog/product') + ->load($parentId); } } return $parentProducts; diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php index 9489edb6a..6c30a5be6 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php @@ -51,7 +51,7 @@ public function getRunTime() { * @return int */ public function getAllowedRunTime() { - return (int)ini_get( 'max_execution_time' ); + return (int) ini_get('max_execution_time'); } /** @@ -61,8 +61,8 @@ public function getAllowedRunTime() { * @param string $url * @return bool */ - public function addUrlToCrawlerQueue( $url ) { - return $this->addUrlsToCrawlerQueue( array( $url ) ); + public function addUrlToCrawlerQueue($url) { + return $this->addUrlsToCrawlerQueue(array($url)); } /** @@ -72,18 +72,18 @@ public function addUrlToCrawlerQueue( $url ) { * @param array $urls * @return int */ - public function addUrlsToCrawlerQueue( array $urls ) { + public function addUrlsToCrawlerQueue(array $urls) { // TODO: remove this debug message - if( $this->getCrawlerDebugEnabled() ) { - foreach( $urls as $url ) { - Mage::helper( 'turpentine/debug' )->log( + if ($this->getCrawlerDebugEnabled()) { + foreach ($urls as $url) { + Mage::helper('turpentine/debug')->log( 'Adding URL to queue: %s', $url ); } } $oldQueue = $this->_readUrlQueue(); - $newQueue = array_unique( array_merge( $oldQueue, $urls ) ); - $this->_writeUrlQueue( $newQueue ); - $diff = count( $newQueue ) - count( $oldQueue ); + $newQueue = array_unique(array_merge($oldQueue, $urls)); + $this->_writeUrlQueue($newQueue); + $diff = count($newQueue) - count($oldQueue); return $diff; } @@ -94,8 +94,8 @@ public function addUrlsToCrawlerQueue( array $urls ) { */ public function getNextUrl() { $urls = $this->_readUrlQueue(); - $nextUrl = array_shift( $urls ); - $this->_writeUrlQueue( $urls ); + $nextUrl = array_shift($urls); + $this->_writeUrlQueue($urls); return $nextUrl; } @@ -114,15 +114,15 @@ public function getUrlQueue() { * @return Varien_Http_Client */ public function getCrawlerClient() { - if( is_null( $this->_crawlerClient ) ) { - $this->_crawlerClient = new Varien_Http_Client( null, array( + if (is_null($this->_crawlerClient)) { + $this->_crawlerClient = new Varien_Http_Client(null, array( 'useragent' => sprintf( 'Nexcessnet_Turpentine/%s Magento/%s Varien_Http_Client', - Mage::helper( 'turpentine/data' )->getVersion(), + Mage::helper('turpentine/data')->getVersion(), Mage::getVersion() ), 'keepalive' => true, - ) ); - $this->_crawlerClient->setCookie( 'frontend', 'crawler-session' ); + )); + $this->_crawlerClient->setCookie('frontend', 'crawler-session'); } return $this->_crawlerClient; } @@ -133,7 +133,7 @@ public function getCrawlerClient() { * @return bool */ public function getCrawlerEnabled() { - return Mage::getStoreConfig( 'turpentine_varnish/general/crawler_enable' ); + return Mage::getStoreConfig('turpentine_varnish/general/crawler_enable'); } /** @@ -142,7 +142,7 @@ public function getCrawlerEnabled() { * @return bool */ public function getCrawlerDebugEnabled() { - return Mage::getStoreConfig( 'turpentine_varnish/general/crawler_debug' ); + return Mage::getStoreConfig('turpentine_varnish/general/crawler_debug'); } /** @@ -157,31 +157,31 @@ public function getAllUrls() { Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, ); - foreach( Mage::app()->getStores() as $storeId => $store ) { - Mage::app()->setCurrentStore( $store ); - $baseUrl = $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_LINK ); + foreach (Mage::app()->getStores() as $storeId => $store) { + Mage::app()->setCurrentStore($store); + $baseUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); $urls[] = $baseUrl; - foreach( Mage::getModel( 'catalog/category' ) - ->getCollection( $storeId ) + foreach (Mage::getModel('catalog/category') + ->getCollection($storeId) ->addIsActiveFilter() - as $cat ) { + as $cat) { $urls[] = $cat->getUrl(); - foreach( $cat->getProductCollection( $storeId ) - ->addUrlRewrite( $cat->getId() ) - ->addAttributeToFilter( 'visibility', $visibility ) - as $prod ) { + foreach ($cat->getProductCollection($storeId) + ->addUrlRewrite($cat->getId()) + ->addAttributeToFilter('visibility', $visibility) + as $prod) { $urls[] = $prod->getProductUrl(); } } $sitemap = (Mage::getConfig()->getNode('modules/MageWorx_XSitemap') !== FALSE) ? 'xsitemap/cms_page' : 'sitemap/cms_page'; - foreach( Mage::getResourceModel( $sitemap ) - ->getCollection( $storeId ) as $item ) { - $urls[] = $baseUrl . $item->getUrl(); + foreach (Mage::getResourceModel($sitemap) + ->getCollection($storeId) as $item) { + $urls[] = $baseUrl.$item->getUrl(); } } - Mage::app()->setCurrentStore( $origStore ); - return array_unique( $urls ); + Mage::app()->setCurrentStore($origStore); + return array_unique($urls); } /** @@ -190,23 +190,23 @@ public function getAllUrls() { * @param Mage_Catalog_Model_Product $product * @return int */ - public function addProductToCrawlerQueue( $product ) { + public function addProductToCrawlerQueue($product) { $productUrls = array(); $origStore = Mage::app()->getStore(); - foreach( Mage::app()->getStores() as $storeId => $store ) { - Mage::app()->setCurrentStore( $store ); + foreach (Mage::app()->getStores() as $storeId => $store) { + Mage::app()->setCurrentStore($store); $baseUrl = $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_LINK ); $productUrls[] = $product->getProductUrl(); - foreach( $product->getCategoryIds() as $catId ) { - $cat = Mage::getModel( 'catalog/category' )->load( $catId ); - $productUrls[] = rtrim( $baseUrl, '/' ) . '/' . - ltrim( $product->getUrlModel() - ->getUrlPath( $product, $cat ), '/' ); + foreach ($product->getCategoryIds() as $catId) { + $cat = Mage::getModel('catalog/category')->load($catId); + $productUrls[] = rtrim($baseUrl, '/').'/'. + ltrim($product->getUrlModel() + ->getUrlPath($product, $cat), '/'); } } - Mage::app()->setCurrentStore( $origStore ); - return $this->addUrlsToCrawlerQueue( $productUrls ); + Mage::app()->setCurrentStore($origStore); + return $this->addUrlsToCrawlerQueue($productUrls); } /** @@ -215,15 +215,15 @@ public function addProductToCrawlerQueue( $product ) { * @param Mage_Catalog_Model_Category $category * @return int */ - public function addCategoryToCrawlerQueue( $category ) { + public function addCategoryToCrawlerQueue($category) { $catUrls = array(); $origStore = Mage::app()->getStore(); - foreach( Mage::app()->getStores() as $storeId => $store ) { - Mage::app()->setCurrentStore( $store ); + foreach (Mage::app()->getStores() as $storeId => $store) { + Mage::app()->setCurrentStore($store); $catUrls[] = $category->getUrl(); } - Mage::app()->setCurrentStore( $origStore ); - return $this->addUrlsToCrawlerQueue( $catUrls ); + Mage::app()->setCurrentStore($origStore); + return $this->addUrlsToCrawlerQueue($catUrls); } /** @@ -232,18 +232,18 @@ public function addCategoryToCrawlerQueue( $category ) { * @param int $cmsPageId * @return int */ - public function addCmsPageToCrawlerQueue( $cmsPageId ) { - $page = Mage::getModel( 'cms/page' )->load( $cmsPageId ); + public function addCmsPageToCrawlerQueue($cmsPageId) { + $page = Mage::getModel('cms/page')->load($cmsPageId); $pageUrls = array(); $origStore = Mage::app()->getStore(); - foreach( Mage::app()->getStores() as $storeId => $store ) { - Mage::app()->setCurrentStore( $store ); - $page->setStoreId( $storeId ); - $pageUrls[] = Mage::getUrl( null, - array( '_direct' => $page->getIdentifier() ) ); + foreach (Mage::app()->getStores() as $storeId => $store) { + Mage::app()->setCurrentStore($store); + $page->setStoreId($storeId); + $pageUrls[] = Mage::getUrl(null, + array('_direct' => $page->getIdentifier())); } - Mage::app()->setCurrentStore( $origStore ); - return $this->addUrlsToCrawlerQueue( $pageUrls ); + Mage::app()->setCurrentStore($origStore); + return $this->addUrlsToCrawlerQueue($pageUrls); } /** @@ -253,8 +253,8 @@ public function addCmsPageToCrawlerQueue( $cmsPageId ) { */ protected function _readUrlQueue() { $readQueue = @unserialize( - Mage::app()->loadCache( self::CRAWLER_URLS_CACHE_ID ) ); - if( !is_array( $readQueue ) ) { + Mage::app()->loadCache(self::CRAWLER_URLS_CACHE_ID) ); + if ( ! is_array($readQueue)) { // This is the first time the queue has been read since the last // cache flush (or the queue is corrupt) // Returning an empty array here would be the proper behavior, @@ -271,8 +271,8 @@ protected function _readUrlQueue() { * @param array $urls * @return null */ - protected function _writeUrlQueue( array $urls ) { + protected function _writeUrlQueue(array $urls) { return Mage::app()->saveCache( - serialize( $urls ), self::CRAWLER_URLS_CACHE_ID ); + serialize($urls), self::CRAWLER_URLS_CACHE_ID ); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index e9220fb2f..2f5b1ad63 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -25,7 +25,7 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract { * Contains a newly generated v4 uuid whenever read, possibly not available * on all kernels */ - const UUID_SOURCE = '/proc/sys/kernel/random/uuid'; + const UUID_SOURCE = '/proc/sys/kernel/random/uuid'; /** * Compression level for serialization compression @@ -38,21 +38,21 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract { /** * Hash algorithm to use in various cryptographic methods */ - const HASH_ALGORITHM = 'sha256'; + const HASH_ALGORITHM = 'sha256'; /** * Cookie name for the Varnish bypass * * @var string */ - const BYPASS_COOKIE_NAME = 'varnish_bypass'; + const BYPASS_COOKIE_NAME = 'varnish_bypass'; /** * encryption singleton thing * * @var Mage_Core_Model_Encryption */ - protected $_crypt = null; + protected $_crypt = null; /** * Like built-in explode() but applies trim to each exploded element and @@ -62,9 +62,9 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract { * @param string $data [description] * @return array */ - public function cleanExplode( $token, $data ) { - return array_filter( array_map( 'trim', - explode( $token, trim( $data ) ) ) ); + public function cleanExplode($token, $data) { + return array_filter(array_map('trim', + explode($token, trim($data)))); } /** @@ -73,32 +73,32 @@ public function cleanExplode( $token, $data ) { * @return string */ public function generateUuid() { - if( is_readable( self::UUID_SOURCE ) ) { - $uuid = trim( file_get_contents( self::UUID_SOURCE ) ); - } elseif( function_exists( 'mt_rand' ) ) { + if (is_readable(self::UUID_SOURCE)) { + $uuid = trim(file_get_contents(self::UUID_SOURCE)); + } elseif (function_exists('mt_rand')) { /** * Taken from stackoverflow answer, possibly not the fastest or * strictly standards compliant * @link http://stackoverflow.com/a/2040279 */ - $uuid = sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" - mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), + mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 16 bits for "time_mid" - mt_rand( 0, 0xffff ), + mt_rand(0, 0xffff), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 - mt_rand( 0, 0x0fff ) | 0x4000, + mt_rand(0, 0x0fff) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 - mt_rand( 0, 0x3fff ) | 0x8000, + mt_rand(0, 0x3fff) | 0x8000, // 48 bits for "node" - mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); } else { // chosen by dice roll, guaranteed to be random @@ -114,7 +114,7 @@ public function generateUuid() { */ public function getVersion() { return Mage::getConfig() - ->getModuleConfig( 'Nexcessnet_Turpentine' )->version; + ->getModuleConfig('Nexcessnet_Turpentine')->version; } /** @@ -127,11 +127,11 @@ public function getVersion() { * @param string $str * @return string */ - public function urlBase64Encode( $str ) { + public function urlBase64Encode($str) { return str_replace( - array( '/', '+' ), - array( '.', '-' ), - base64_encode( $str ) ); + array('/', '+'), + array('.', '-'), + base64_encode($str) ); } /** @@ -140,11 +140,11 @@ public function urlBase64Encode( $str ) { * @param string $str * @return string */ - public function urlBase64Decode( $str ) { + public function urlBase64Decode($str) { return base64_decode( str_replace( - array( '.', '-' ), - array( '/', '+' ), + array('.', '-'), + array('/', '+'), $str ) ); } @@ -157,14 +157,14 @@ public function urlBase64Decode( $str ) { * @param mixed $data * @return string */ - public function freeze( $data ) { - Varien_Profiler::start( 'turpentine::helper::data::freeze' ); + public function freeze($data) { + Varien_Profiler::start('turpentine::helper::data::freeze'); $frozenData = $this->urlBase64Encode( $this->_getCrypt()->encrypt( gzdeflate( - serialize( $data ), + serialize($data), self::COMPRESSION_LEVEL ) ) ); - Varien_Profiler::stop( 'turpentine::helper::data::freeze' ); + Varien_Profiler::stop('turpentine::helper::data::freeze'); return $frozenData; } @@ -174,13 +174,13 @@ public function freeze( $data ) { * @param string $data * @return mixed */ - public function thaw( $data ) { - Varien_Profiler::start( 'turpentine::helper::data::thaw' ); + public function thaw($data) { + Varien_Profiler::start('turpentine::helper::data::thaw'); $thawedData = unserialize( gzinflate( $this->_getCrypt()->decrypt( - $this->urlBase64Decode( $data ) ) ) ); - Varien_Profiler::stop( 'turpentine::helper::data::thaw' ); + $this->urlBase64Decode($data) ) ) ); + Varien_Profiler::stop('turpentine::helper::data::thaw'); return $thawedData; } @@ -190,9 +190,9 @@ public function thaw( $data ) { * @param string $data * @return string */ - public function secureHash( $data ) { + public function secureHash($data) { $salt = $this->_getCryptKey(); - return hash( self::HASH_ALGORITHM, sprintf( '%s:%s', $salt, $data ) ); + return hash(self::HASH_ALGORITHM, sprintf('%s:%s', $salt, $data)); } /** @@ -201,8 +201,8 @@ public function secureHash( $data ) { * @param string $data * @return string */ - public function getHmac( $data ) { - return hash_hmac( self::HASH_ALGORITHM, $data, $this->_getCryptKey() ); + public function getHmac($data) { + return hash_hmac(self::HASH_ALGORITHM, $data, $this->_getCryptKey()); } /** @@ -211,8 +211,8 @@ public function getHmac( $data ) { * @param array $key * @return string */ - public function getCacheKeyHash( $key ) { - return sha1( implode( '|', array_values( $key ) ) ); + public function getCacheKeyHash($key) { + return sha1(implode('|', array_values($key))); } /** @@ -221,8 +221,8 @@ public function getCacheKeyHash( $key ) { * @param Mage_Core_Model_Layout_Element $blockNode * @return array */ - public function getChildBlockNames( $blockNode ) { - return array_unique( $this->_getChildBlockNames( $blockNode ) ); + public function getChildBlockNames($blockNode) { + return array_unique($this->_getChildBlockNames($blockNode)); } /** @@ -231,12 +231,12 @@ public function getChildBlockNames( $blockNode ) { * @param string|object $model * @return string */ - public function getModelName( $model ) { - if( is_object( $model ) ) { - $model = get_class( $model ); + public function getModelName($model) { + if (is_object($model)) { + $model = get_class($model); } - return strtolower( preg_replace( - '~^[^_]+_([^_]+)_Model_(.+)$~', '$1/$2', $model ) ); + return strtolower(preg_replace( + '~^[^_]+_([^_]+)_Model_(.+)$~', '$1/$2', $model )); } /** @@ -245,7 +245,7 @@ public function getModelName( $model ) { * @return bool */ public function useFlashMessagesFix() { - return (bool)Mage::getStoreConfig( + return (bool) Mage::getStoreConfig( 'turpentine_varnish/general/ajax_messages' ); } @@ -256,7 +256,7 @@ public function useFlashMessagesFix() { * @return bool */ public function useProductListToolbarFix() { - return (bool)Mage::getStoreConfig( + return (bool) Mage::getStoreConfig( 'turpentine_varnish/general/fix_product_toolbar' ); } @@ -266,7 +266,7 @@ public function useProductListToolbarFix() { * @return bool */ public function getAutoApplyOnSave() { - return (bool)Mage::getStoreConfig( + return (bool) Mage::getStoreConfig( 'turpentine_varnish/general/auto_apply_on_save' ); } @@ -280,31 +280,31 @@ public function getVclFix() { 'turpentine_varnish/general/vcl_fix' ); } - /** - * Get config value specifying when to strip VCL whitespaces - * - * @return string - */ - public function getStripVclWhitespace() { - return Mage::getStoreConfig( - 'turpentine_varnish/general/strip_vcl_whitespace' ); - } - - /** - * Check if VCL whitespaces should be stripped for the given action - * - * @param string $action can be either "apply", "save" or "download" - * @return bool - */ - public function shouldStripVclWhitespace($action) { - $configValue = $this->getStripVclWhitespace(); - if ( $configValue==='always' ) { - return true; - } elseif ( $configValue==='apply' && $action==='apply' ) { - return true; - } - return false; - } + /** + * Get config value specifying when to strip VCL whitespaces + * + * @return string + */ + public function getStripVclWhitespace() { + return Mage::getStoreConfig( + 'turpentine_varnish/general/strip_vcl_whitespace' ); + } + + /** + * Check if VCL whitespaces should be stripped for the given action + * + * @param string $action can be either "apply", "save" or "download" + * @return bool + */ + public function shouldStripVclWhitespace($action) { + $configValue = $this->getStripVclWhitespace(); + if ( $configValue==='always' ) { + return true; + } elseif ( $configValue==='apply' && $action==='apply' ) { + return true; + } + return false; + } /** * Get the cookie name for the Varnish bypass @@ -321,19 +321,19 @@ public function getBypassCookieName() { * @param Mage_Core_Model_Layout_Element $blockNode * @return array */ - protected function _getChildBlockNames( $blockNode ) { - Varien_Profiler::start( 'turpentine::helper::data::_getChildBlockNames' ); - if( $blockNode instanceof Mage_Core_Model_Layout_Element ) { - $blockNames = array( (string)$blockNode['name'] ); - foreach( $blockNode->xpath( './block | ./reference' ) as $childBlockNode ) { - $blockNames = array_merge( $blockNames, - $this->_getChildBlockNames( $childBlockNode ) ); - if( $this->getLayout() instanceof Varien_Simplexml_Config ) { - foreach( $this->getLayout()->getNode()->xpath( sprintf( - '//reference[@name=\'%s\']', (string)$childBlockNode['name'] ) ) - as $childBlockLayoutNode ) { - $blockNames = array_merge( $blockNames, - $this->_getChildBlockNames( $childBlockLayoutNode ) ); + protected function _getChildBlockNames($blockNode) { + Varien_Profiler::start('turpentine::helper::data::_getChildBlockNames'); + if ($blockNode instanceof Mage_Core_Model_Layout_Element) { + $blockNames = array((string) $blockNode['name']); + foreach ($blockNode->xpath('./block | ./reference') as $childBlockNode) { + $blockNames = array_merge($blockNames, + $this->_getChildBlockNames($childBlockNode)); + if ($this->getLayout() instanceof Varien_Simplexml_Config) { + foreach ($this->getLayout()->getNode()->xpath(sprintf( + '//reference[@name=\'%s\']', (string) $childBlockNode['name'] )) + as $childBlockLayoutNode) { + $blockNames = array_merge($blockNames, + $this->_getChildBlockNames($childBlockLayoutNode)); } } @@ -341,7 +341,7 @@ protected function _getChildBlockNames( $blockNode ) { } else { $blockNames = array(); } - Varien_Profiler::stop( 'turpentine::helper::data::_getChildBlockNames' ); + Varien_Profiler::stop('turpentine::helper::data::_getChildBlockNames'); return $blockNames; } @@ -354,9 +354,9 @@ protected function _getChildBlockNames( $blockNode ) { * @return Mage_Core_Model_Encryption */ protected function _getCrypt() { - if( is_null( $this->_crypt ) ) { + if (is_null($this->_crypt)) { $this->_crypt = Varien_Crypt::factory() - ->init( $this->_getCryptKey() ); + ->init($this->_getCryptKey()); } return $this->_crypt; } @@ -367,6 +367,6 @@ protected function _getCrypt() { * @return string */ protected function _getCryptKey() { - return (string)Mage::getConfig()->getNode( 'global/crypt/key' ); + return (string) Mage::getConfig()->getNode('global/crypt/key'); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php b/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php index 0a62ca8fe..4fbb7ed61 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php @@ -26,13 +26,13 @@ class Nexcessnet_Turpentine_Helper_Debug extends Mage_Core_Helper_Abstract { * @param $message * @return string */ - public function logError( $message ) + public function logError($message) { - if ( func_num_args() > 1 ) { - $message = $this->_prepareLogMessage( func_get_args() ); + if (func_num_args() > 1) { + $message = $this->_prepareLogMessage(func_get_args()); } - return $this->_log( Zend_Log::ERR, $message ); + return $this->_log(Zend_Log::ERR, $message); } /** @@ -41,13 +41,13 @@ public function logError( $message ) * @param $message * @return string */ - public function logWarn( $message ) + public function logWarn($message) { - if ( func_num_args() > 1 ) { - $message = $this->_prepareLogMessage( func_get_args() ); + if (func_num_args() > 1) { + $message = $this->_prepareLogMessage(func_get_args()); } - return $this->_log( Zend_Log::WARN, $message ); + return $this->_log(Zend_Log::WARN, $message); } /** @@ -56,13 +56,13 @@ public function logWarn( $message ) * @param $message * @return string */ - public function logNotice( $message ) + public function logNotice($message) { - if ( func_num_args() > 1 ) { - $message = $this->_prepareLogMessage( func_get_args() ); + if (func_num_args() > 1) { + $message = $this->_prepareLogMessage(func_get_args()); } - return $this->_log( Zend_Log::NOTICE, $message ); + return $this->_log(Zend_Log::NOTICE, $message); } /** @@ -71,13 +71,13 @@ public function logNotice( $message ) * @param $message * @return string */ - public function logInfo( $message ) + public function logInfo($message) { - if ( func_num_args() > 1 ) { - $message = $this->_prepareLogMessage( func_get_args() ); + if (func_num_args() > 1) { + $message = $this->_prepareLogMessage(func_get_args()); } - return $this->_log( Zend_Log::INFO, $message ); + return $this->_log(Zend_Log::INFO, $message); } /** @@ -86,17 +86,17 @@ public function logInfo( $message ) * @param $message * @return string */ - public function logDebug( $message ) + public function logDebug($message) { - if( ! Mage::helper( 'turpentine/varnish' )->getVarnishDebugEnabled() ) { + if ( ! Mage::helper('turpentine/varnish')->getVarnishDebugEnabled()) { return; } - if ( func_num_args() > 1 ) { - $message = $this->_prepareLogMessage( func_get_args() ); + if (func_num_args() > 1) { + $message = $this->_prepareLogMessage(func_get_args()); } - return $this->_log( Zend_Log::DEBUG, $message ); + return $this->_log(Zend_Log::DEBUG, $message); } /** @@ -105,16 +105,16 @@ public function logDebug( $message ) * @param array $args * @return string */ - protected function _prepareLogMessage( array $args ) + protected function _prepareLogMessage(array $args) { $pattern = $args[0]; - $substitutes = array_slice( $args, 1 ); + $substitutes = array_slice($args, 1); - if ( ! $this->_validatePattern( $pattern, $substitutes ) ) { + if ( ! $this->_validatePattern($pattern, $substitutes)) { return $pattern; } - return vsprintf( $pattern, $substitutes ); + return vsprintf($pattern, $substitutes); } /** @@ -128,7 +128,7 @@ protected function _prepareLogMessage( array $args ) * @param array $arguments * @return bool */ - protected function _validatePattern( $pattern, $arguments ) + protected function _validatePattern($pattern, $arguments) { return true; } @@ -138,12 +138,12 @@ protected function _validatePattern( $pattern, $arguments ) * * @param mixed $value */ - public function dump( $value ) { - Mage::register( 'turpentine_nocache_flag', true, true ); - $this->logValue( $value ); - echo '
            ' . PHP_EOL;
            -        var_dump( $value );
            -        echo '
            ' . PHP_EOL; + public function dump($value) { + Mage::register('turpentine_nocache_flag', true, true); + $this->logValue($value); + echo '
            '.PHP_EOL;
            +        var_dump($value);
            +        echo '
            '.PHP_EOL; } /** @@ -153,52 +153,51 @@ public function dump( $value ) { * @param mixed ... * @return null */ - public function log( $message ) { + public function log($message) { $args = func_get_args(); - return call_user_func_array( array( $this, 'logDebug' ), $args ); + return call_user_func_array(array($this, 'logDebug'), $args); } /** * Log a backtrace, can pass a already generated backtrace to use * - * @param array $backTrace=null + * @param array $backTrace * @return null */ - public function logBackTrace( $backTrace=null ) { - if( is_null( $backTrace ) ) { + public function logBackTrace($backTrace = null) { + if (is_null($backTrace)) { $backTrace = debug_backtrace(); - array_shift( $backTrace ); + array_shift($backTrace); } - $btuuid = Mage::helper( 'turpentine/data' )->generateUuid(); - $this->log( 'TRACEBACK: START ** %s **', $btuuid ); - $this->log( 'TRACEBACK: URL: %s', $_SERVER['REQUEST_URI'] ); - for( $i=0; $i < count($backTrace); $i++ ) { + $btuuid = Mage::helper('turpentine/data')->generateUuid(); + $this->log('TRACEBACK: START ** %s **', $btuuid); + $this->log('TRACEBACK: URL: %s', $_SERVER['REQUEST_URI']); + for ($i = 0; $i < count($backTrace); $i++) { $line = $backTrace[$i]; - $this->log( 'TRACEBACK: #%02d: %s:%d', - $i, $line['file'], $line['line'] ); - $this->log( 'TRACEBACK: ==> %s%s%s(%s)', - (is_object( @$line['object'] ) ? - get_class( $line['object'] ) : @$line['class'] ), + $this->log('TRACEBACK: #%02d: %s:%d', + $i, $line['file'], $line['line']); + $this->log('TRACEBACK: ==> %s%s%s(%s)', + (is_object(@$line['object']) ? + get_class($line['object']) : @$line['class']), @$line['type'], $line['function'], - $this->_backtrace_formatArgs( $line['args'] ) ); + $this->_backtrace_formatArgs($line['args'])); } - $this->log( 'TRACEBACK: END ** %s **', $btuuid ); + $this->log('TRACEBACK: END ** %s **', $btuuid); } /** * Like var_dump to the log * * @param mixed $value - * @param string $name=null * @return null */ - public function logValue( $value, $name=null ) { - if( is_null( $name ) ) { + public function logValue($value, $name = null) { + if (is_null($name)) { $name = 'VALUE'; } - $this->log( '%s => %s', $name, - $this->_backtrace_formatArgsHelper( $value ) ); + $this->log('%s => %s', $name, + $this->_backtrace_formatArgsHelper($value)); } /** @@ -208,40 +207,40 @@ public function logValue( $value, $name=null ) { * @param string $message * @return string */ - protected function _log( $level, $message ) { - $message = 'TURPENTINE: ' . $message; - Mage::log( $message, $level, $this->_getLogFileName() ); + protected function _log($level, $message) { + $message = 'TURPENTINE: '.$message; + Mage::log($message, $level, $this->_getLogFileName()); return $message; } - /** - * Get the name of the log file to use - * @return string - */ - protected function _getLogFileName() { - if ( $this->useCustomLogFile() ) { - return $this->getCustomLogFileName(); - } - return ''; - } + /** + * Get the name of the log file to use + * @return string + */ + protected function _getLogFileName() { + if ( $this->useCustomLogFile() ) { + return $this->getCustomLogFileName(); + } + return ''; + } - /** - * Check if custom log file should be used - * @return bool - */ - public function useCustomLogFile() { - return Mage::getStoreConfigFlag( - 'turpentine_varnish/logging/use_custom_log_file' ); - } + /** + * Check if custom log file should be used + * @return bool + */ + public function useCustomLogFile() { + return Mage::getStoreConfigFlag( + 'turpentine_varnish/logging/use_custom_log_file' ); + } - /** - * Get custom log file name - * @return string - */ - public function getCustomLogFileName() { - return (string)Mage::getStoreConfig( - 'turpentine_varnish/logging/custom_log_file_name' ); - } + /** + * Get custom log file name + * @return string + */ + public function getCustomLogFileName() { + return (string)Mage::getStoreConfig( + 'turpentine_varnish/logging/custom_log_file_name' ); + } /** * Format a list of function arguments for the backtrace @@ -249,10 +248,10 @@ public function getCustomLogFileName() { * @param array $args * @return string */ - protected function _backtrace_formatArgs( $args ) { - return implode( ', ', + protected function _backtrace_formatArgs($args) { + return implode(', ', array_map( - array( $this, '_backtrace_formatArgsHelper' ), + array($this, '_backtrace_formatArgsHelper'), $args ) ); @@ -264,25 +263,25 @@ protected function _backtrace_formatArgs( $args ) { * @param mixed $arg * @return null */ - protected function _backtrace_formatArgsHelper( $arg ) { + protected function _backtrace_formatArgsHelper($arg) { $value = $arg; - if( is_object( $arg ) ) { - $value = sprintf( 'OBJECT(%s)', get_class( $arg ) ); - } elseif( is_resource( $arg ) ) { + if (is_object($arg)) { + $value = sprintf('OBJECT(%s)', get_class($arg)); + } elseif (is_resource($arg)) { $value = 'RESOURCE'; - } elseif( is_array( $arg ) ) { + } elseif (is_array($arg)) { $value = 'ARRAY[%s](%s)'; $c = array(); - foreach( $arg as $k => $v ) { - $c[] = sprintf( '%s => %s', $k, - $this->_backtrace_formatArgsHelper( $v ) ); + foreach ($arg as $k => $v) { + $c[] = sprintf('%s => %s', $k, + $this->_backtrace_formatArgsHelper($v)); } - $value = sprintf( $value, count( $arg ), implode( ', ', $c ) ); - } elseif( is_string( $arg ) ) { - $value = sprintf( '\'%s\'', $arg ); - } elseif( is_bool( $arg ) ) { + $value = sprintf($value, count($arg), implode(', ', $c)); + } elseif (is_string($arg)) { + $value = sprintf('\'%s\'', $arg); + } elseif (is_bool($arg)) { $value = $arg ? 'TRUE' : 'FALSE'; - } elseif( is_null( $arg ) ) { + } elseif (is_null($arg)) { $value = 'NULL'; } return $value; diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index 6e150f44b..00250a122 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -41,7 +41,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract { * @return bool */ public function getEsiEnabled() { - return Mage::app()->useCache( $this->getMageCacheName() ); + return Mage::app()->useCache($this->getMageCacheName()); } /** @@ -50,7 +50,7 @@ public function getEsiEnabled() { * @return bool */ public function shouldResponseUseEsi() { - return Mage::helper( 'turpentine/varnish' )->shouldResponseUseVarnish() && + return Mage::helper('turpentine/varnish')->shouldResponseUseVarnish() && $this->getEsiEnabled(); } @@ -60,8 +60,8 @@ public function shouldResponseUseEsi() { * @return null */ public function ensureEsiEnabled() { - if( !$this->shouldResponseUseEsi() ) { - Mage::throwException( 'ESI includes are not enabled' ); + if ( ! $this->shouldResponseUseEsi()) { + Mage::throwException('ESI includes are not enabled'); } } @@ -119,14 +119,14 @@ public function getEsiHmacParam() { return self::ESI_HMAC_PARAM; } - /** - * Get referrer param - * - * @return string - */ - public function getEsiReferrerParam() { - return Mage_Core_Controller_Varien_Action::PARAM_NAME_BASE64_URL; - } + /** + * Get referrer param + * + * @return string + */ + public function getEsiReferrerParam() { + return Mage_Core_Controller_Varien_Action::PARAM_NAME_BASE64_URL; + } /** * Get whether ESI debugging is enabled or not @@ -134,7 +134,7 @@ public function getEsiReferrerParam() { * @return bool */ public function getEsiDebugEnabled() { - return Mage::helper( 'turpentine/varnish' ) + return Mage::helper('turpentine/varnish') ->getVarnishDebugEnabled(); } @@ -144,7 +144,7 @@ public function getEsiDebugEnabled() { * @return bool */ public function getEsiBlockLogEnabled() { - return (bool)Mage::getStoreConfig( + return (bool) Mage::getStoreConfig( 'turpentine_varnish/general/block_debug' ); } @@ -154,7 +154,7 @@ public function getEsiBlockLogEnabled() { * @return bool */ public function shouldFixFlashMessages() { - return Mage::helper( 'turpentine/data' )->useFlashMessagesFix() && + return Mage::helper('turpentine/data')->useFlashMessagesFix() && Mage::app()->getStore()->getCode() !== 'admin'; } @@ -164,7 +164,7 @@ public function shouldFixFlashMessages() { * @return string */ public function getDummyUrl() { - return Mage::getUrl( 'checkout/cart' ); + return Mage::getUrl('checkout/cart'); } /** @@ -174,11 +174,10 @@ public function getDummyUrl() { * turpentine/esi/getBlock while rendering ESI blocks. Not perfect, but may * be good enough * - * @param string $url=null * @return Mage_Core_Controller_Request_Http */ - public function getDummyRequest( $url=null ) { - if( $url === null ) { + public function getDummyRequest($url = null) { + if ($url === null) { $url = $this->getDummyUrl(); } $request = Mage::getModel('turpentine/dummy_request', $url); @@ -198,7 +197,7 @@ public function getMageCacheName() { /** * Get the list of cache clear events to include with every ESI block * - * @return array + * @return string[] */ public function getDefaultCacheClearEvents() { $events = array( @@ -211,19 +210,19 @@ public function getDefaultCacheClearEvents() { /** * Get the list of events that should cause the ESI cache to be cleared * - * @return array + * @return string[] */ public function getCacheClearEvents() { - Varien_Profiler::start( 'turpentine::helper::esi::getCacheClearEvents' ); + Varien_Profiler::start('turpentine::helper::esi::getCacheClearEvents'); $cacheKey = $this->getCacheClearEventsCacheKey(); - $events = @unserialize( Mage::app()->loadCache( $cacheKey ) ); - if( is_null( $events ) || $events === false ) { + $events = @unserialize(Mage::app()->loadCache($cacheKey)); + if (is_null($events) || $events === false) { $events = $this->_loadEsiCacheClearEvents(); - Mage::app()->saveCache( serialize( $events ), $cacheKey, - array( 'LAYOUT_GENERAL_CACHE_TAG' ) ); + Mage::app()->saveCache(serialize($events), $cacheKey, + array('LAYOUT_GENERAL_CACHE_TAG')); } - Varien_Profiler::stop( 'turpentine::helper::esi::getCacheClearEvents' ); - return array_merge( $this->getDefaultCacheClearEvents(), $events ); + Varien_Profiler::stop('turpentine::helper::esi::getCacheClearEvents'); + return array_merge($this->getDefaultCacheClearEvents(), $events); } /** @@ -232,7 +231,7 @@ public function getCacheClearEvents() { * @return string */ public function getDefaultEsiTtl() { - return trim( Mage::getStoreConfig( 'web/cookie/cookie_lifetime' ) ); + return trim(Mage::getStoreConfig('web/cookie/cookie_lifetime')); } /** @@ -242,18 +241,18 @@ public function getDefaultEsiTtl() { * * @return string */ - public function getCorsOrigin( $url=null ) { - if( is_null( $url ) ) { + public function getCorsOrigin($url = null) { + if (is_null($url)) { $baseUrl = Mage::getBaseUrl(); } else { $baseUrl = $url; } - $path = parse_url( $baseUrl, PHP_URL_PATH ); - $domain = parse_url( $baseUrl, PHP_URL_HOST ); + $path = parse_url($baseUrl, PHP_URL_PATH); + $domain = parse_url($baseUrl, PHP_URL_HOST); // there has to be a better way to just strip the path off - return substr( $baseUrl, 0, - strpos( $baseUrl, $path, - strpos( $baseUrl, $domain ) ) ); + return substr($baseUrl, 0, + strpos($baseUrl, $path, + strpos($baseUrl, $domain))); } /** @@ -264,23 +263,23 @@ public function getCorsOrigin( $url=null ) { * @return Mage_Core_Model_Layout_Element|SimpleXMLElement */ public function getLayoutXml() { - Varien_Profiler::start( 'turpentine::helper::esi::getLayoutXml' ); - if( is_null( $this->_layoutXml ) ) { - if( $useCache = Mage::app()->useCache( 'layout' ) ) { + Varien_Profiler::start('turpentine::helper::esi::getLayoutXml'); + if (is_null($this->_layoutXml)) { + if ($useCache = Mage::app()->useCache('layout')) { $cacheKey = $this->getFileLayoutUpdatesXmlCacheKey(); $this->_layoutXml = simplexml_load_string( - Mage::app()->loadCache( $cacheKey ) ); + Mage::app()->loadCache($cacheKey) ); } // this check is redundant if the layout cache is disabled - if( !$this->_layoutXml ) { + if ( ! $this->_layoutXml) { $this->_layoutXml = $this->_loadLayoutXml(); - if( $useCache ) { - Mage::app()->saveCache( $this->_layoutXml->asXML(), - $cacheKey, array( 'LAYOUT_GENERAL_CACHE_TAG' ) ); + if ($useCache) { + Mage::app()->saveCache($this->_layoutXml->asXML(), + $cacheKey, array('LAYOUT_GENERAL_CACHE_TAG')); } } } - Varien_Profiler::stop( 'turpentine::helper::esi::getLayoutXml' ); + Varien_Profiler::stop('turpentine::helper::esi::getLayoutXml'); return $this->_layoutXml; } @@ -291,14 +290,14 @@ public function getLayoutXml() { */ public function getCacheClearEventsCacheKey() { $design = Mage::getDesign(); - return Mage::helper( 'turpentine/data' ) - ->getCacheKeyHash( array( + return Mage::helper('turpentine/data') + ->getCacheKeyHash(array( 'FILE_LAYOUT_ESI_CACHE_EVENTS', $design->getArea(), $design->getPackageName(), - $design->getTheme( 'layout' ), + $design->getTheme('layout'), Mage::app()->getStore()->getId(), - ) ); + )); } /** @@ -308,14 +307,14 @@ public function getCacheClearEventsCacheKey() { */ public function getFileLayoutUpdatesXmlCacheKey() { $design = Mage::getDesign(); - return Mage::helper( 'turpentine/data' ) - ->getCacheKeyHash( array( + return Mage::helper('turpentine/data') + ->getCacheKeyHash(array( 'FILE_LAYOUT_UPDATES_XML', $design->getArea(), $design->getPackageName(), - $design->getTheme( 'layout' ), + $design->getTheme('layout'), Mage::app()->getStore()->getId(), - ) ); + )); } /** @@ -327,8 +326,8 @@ public function getFileLayoutUpdatesXmlCacheKey() { * @param string $url url to pull content from * @return string */ - public function buildEsiIncludeFragment( $url ) { - return sprintf( '', $url ); + public function buildEsiIncludeFragment($url) { + return sprintf('', $url); } /** @@ -341,8 +340,8 @@ public function buildEsiIncludeFragment( $url ) { * @param string $content content to be removed * @return string */ - public function buildEsiRemoveFragment( $content ) { - return sprintf( '%s', $content ); + public function buildEsiRemoveFragment($content) { + return sprintf('%s', $content); } /** @@ -357,9 +356,9 @@ public function getFormKeyEsiUrl() { $this->getEsiScopeParam() => 'global', $this->getEsiCacheTypeParam() => 'private', ); - $esiUrl = Mage::getUrl( 'turpentine/esi/getFormKey', $urlOptions ); + $esiUrl = Mage::getUrl('turpentine/esi/getFormKey', $urlOptions); // setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS - $esiUrl = preg_replace( '|^https://|i', 'http://', $esiUrl ); + $esiUrl = preg_replace('|^https://|i', 'http://', $esiUrl); return $esiUrl; } @@ -369,19 +368,19 @@ public function getFormKeyEsiUrl() { * @return array */ protected function _loadEsiCacheClearEvents() { - Varien_Profiler::start( 'turpentine::helper::esi::_loadEsiCacheClearEvents' ); + Varien_Profiler::start('turpentine::helper::esi::_loadEsiCacheClearEvents'); $layoutXml = $this->getLayoutXml(); $events = $layoutXml->xpath( '//action[@method=\'setEsiOptions\']/params/flush_events/*' ); - if( $events ) { - $events = array_unique( array_map( - create_function( '$e', - 'return (string)$e->getName();' ), - $events ) ); + if ($events) { + $events = array_unique(array_map( + create_function('$e', + 'return (string)$e->getName();'), + $events )); } else { $events = array(); } - Varien_Profiler::stop( 'turpentine::helper::esi::_loadEsiCacheClearEvents' ); + Varien_Profiler::stop('turpentine::helper::esi::_loadEsiCacheClearEvents'); return $events; } @@ -391,16 +390,16 @@ protected function _loadEsiCacheClearEvents() { * @return Mage_Core_Model_Layout_Element */ protected function _loadLayoutXml() { - Varien_Profiler::start( 'turpentine::helper::esi::_loadLayoutXml' ); + Varien_Profiler::start('turpentine::helper::esi::_loadLayoutXml'); $design = Mage::getDesign(); - $layoutXml = Mage::getSingleton( 'core/layout' ) + $layoutXml = Mage::getSingleton('core/layout') ->getUpdate() ->getFileLayoutUpdatesXml( $design->getArea(), $design->getPackageName(), - $design->getTheme( 'layout' ), + $design->getTheme('layout'), Mage::app()->getStore()->getId() ); - Varien_Profiler::stop( 'turpentine::helper::esi::_loadLayoutXml' ); + Varien_Profiler::stop('turpentine::helper::esi::_loadLayoutXml'); return $layoutXml; } } diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php index 7ef95c207..80f5fbde5 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Varnish.php @@ -21,7 +21,7 @@ class Nexcessnet_Turpentine_Helper_Varnish extends Mage_Core_Helper_Abstract { - const MAGE_CACHE_NAME = 'turpentine_pages'; + const MAGE_CACHE_NAME = 'turpentine_pages'; /** * Get whether Varnish caching is enabled or not @@ -29,7 +29,7 @@ class Nexcessnet_Turpentine_Helper_Varnish extends Mage_Core_Helper_Abstract { * @return bool */ public function getVarnishEnabled() { - return Mage::app()->useCache( $this->getMageCacheName() ); + return Mage::app()->useCache($this->getMageCacheName()); } /** @@ -38,7 +38,7 @@ public function getVarnishEnabled() { * @return bool */ public function getVarnishDebugEnabled() { - return (bool)Mage::getStoreConfig( + return (bool) Mage::getStoreConfig( 'turpentine_varnish/general/varnish_debug' ); } @@ -50,7 +50,7 @@ public function getVarnishDebugEnabled() { */ public function isRequestFromVarnish() { return $this->getSecretHandshake() == - Mage::app()->getRequest()->getHeader( 'X-Turpentine-Secret-Handshake' ); + Mage::app()->getRequest()->getHeader('X-Turpentine-Secret-Handshake'); } /** @@ -89,18 +89,18 @@ public function getSecretHandshake() { * * @param string $host [description] * @param string|int $port [description] - * @param string $secretKey=null [description] - * @param string $version=null [description] + * @param string $secretKey [description] + * @param string $version [description] * @return Nexcessnet_Turpentine_Model_Varnish_Admin_Socket */ - public function getSocket( $host, $port, $secretKey=null, $version=null ) { - $socket = Mage::getModel( 'turpentine/varnish_admin_socket', - array( 'host' => $host, 'port' => $port ) ); - if( $secretKey ) { - $socket->setAuthSecret( $secretKey ); + public function getSocket($host, $port, $secretKey = null, $version = null) { + $socket = Mage::getModel('turpentine/varnish_admin_socket', + array('host' => $host, 'port' => $port)); + if ($secretKey) { + $socket->setAuthSecret($secretKey); } - if( $version ) { - $socket->setVersion( $version ); + if ($version) { + $socket->setVersion($version); } return $socket; } @@ -112,17 +112,17 @@ public function getSocket( $host, $port, $secretKey=null, $version=null ) { */ public function getSockets() { $sockets = array(); - $servers = Mage::helper( 'turpentine/data' )->cleanExplode( PHP_EOL, - Mage::getStoreConfig( 'turpentine_varnish/servers/server_list' ) ); - $key = str_replace( '\n', PHP_EOL, - Mage::getStoreConfig( 'turpentine_varnish/servers/auth_key' ) ); - $version = Mage::getStoreConfig( 'turpentine_varnish/servers/version' ); - if( $version == 'auto' ) { + $servers = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_varnish/servers/server_list')); + $key = str_replace('\n', PHP_EOL, + Mage::getStoreConfig('turpentine_varnish/servers/auth_key')); + $version = Mage::getStoreConfig('turpentine_varnish/servers/version'); + if ($version == 'auto') { $version = null; } - foreach( $servers as $server ) { - $parts = explode( ':', $server ); - $sockets[] = $this->getSocket( $parts[0], $parts[1], $key, $version ); + foreach ($servers as $server) { + $parts = explode(':', $server); + $sockets[] = $this->getSocket($parts[0], $parts[1], $key, $version); } return $sockets; } @@ -142,7 +142,7 @@ public function getMageCacheName() { * @return string */ public function getDefaultTtl() { - return Mage::getStoreConfig( 'turpentine_vcl/ttls/default_ttl' ); + return Mage::getStoreConfig('turpentine_vcl/ttls/default_ttl'); } /** @@ -152,7 +152,7 @@ public function getDefaultTtl() { * @return bool */ public function shouldFixProductListToolbar() { - return Mage::helper( 'turpentine/data' )->useProductListToolbarFix() && + return Mage::helper('turpentine/data')->useProductListToolbarFix() && Mage::app()->getStore()->getCode() !== 'admin'; } @@ -162,8 +162,8 @@ public function shouldFixProductListToolbar() { * @return boolean */ public function isBypassEnabled() { - $cookieName = Mage::helper( 'turpentine/data' )->getBypassCookieName(); - $cookieValue = Mage::getModel( 'core/cookie' )->get( $cookieName ); + $cookieName = Mage::helper('turpentine/data')->getBypassCookieName(); + $cookieValue = Mage::getModel('core/cookie')->get($cookieName); return $cookieValue === $this->getSecretHandshake(); } @@ -180,7 +180,7 @@ public function shouldDisplayNotice() { public function getFormKeyFixupActionsList() { $data = Mage::getStoreConfig( 'turpentine_varnish/miscellaneous/formkey_fixup_actions' ); - $actions = array_filter( explode( PHP_EOL, trim( $data ) ) ); + $actions = array_filter(explode(PHP_EOL, trim($data))); return $actions; } @@ -196,21 +196,21 @@ public function getFormKeyFixupActionsList() { public function csrfFixupNeeded() { $result = false; $isEnterprise = false; // ce - if( method_exists( 'Mage', 'getEdition' ) ) { - if( Mage::getEdition() === Mage::EDITION_ENTERPRISE ) { + if (method_exists('Mage', 'getEdition')) { + if (Mage::getEdition() === Mage::EDITION_ENTERPRISE) { $isEnterprise = true; } } else { - if( Mage::getConfig()->getModuleConfig( 'Enterprise_Enterprise' ) ) { + if (Mage::getConfig()->getModuleConfig('Enterprise_Enterprise')) { $isEnterprise = true; } } - if( $isEnterprise ) { - if( version_compare( Mage::getVersion(), '1.13', '>=' ) ) { + if ($isEnterprise) { + if (version_compare(Mage::getVersion(), '1.13', '>=')) { $result = true; } } else { - if( version_compare( Mage::getVersion(), '1.8', '>=' ) ) { + if (version_compare(Mage::getVersion(), '1.8', '>=')) { $result = true; } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php index 4aa1889fc..be5876151 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/StripWhitespace.php @@ -23,9 +23,9 @@ class Nexcessnet_Turpentine_Model_Config_Select_stripWhitespace { public function toOptionArray() { $helper = Mage::helper('turpentine'); return array( - array( 'value' => 'always', 'label' => $helper->__( 'Always' ) ), - array( 'value' => 'apply', 'label' => $helper->__( 'Only when applying directly to Varnish' ) ), - array( 'value' => 'never', 'label' => $helper->__( 'Never' ) ), + array('value' => 'always', 'label' => $helper->__('Always')), + array('value' => 'apply', 'label' => $helper->__('Only when applying directly to Varnish')), + array('value' => 'never', 'label' => $helper->__('Never')), ); } } \ No newline at end of file diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php index 3bdce45a0..df21d3600 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php @@ -25,7 +25,7 @@ public function toOptionArray() { return array( array( 'value' => '2.1', 'label' => $helper->__( '2.1.x' ) ), array( 'value' => '3.0', 'label' => $helper->__( '3.0.x' ) ), - array( 'value' => '4.0', 'label' => $helper->__( '4.0.x' ) ), + array( 'value' => '4.0', 'label' => $helper->__( '4.0.x' ) ), array( 'value' => 'auto', 'label' => $helper->__( 'Auto' ) ), ); } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php index 7b2afa444..63aa888ed 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php @@ -20,7 +20,7 @@ */ class Nexcessnet_Turpentine_Model_Core_Session extends Mage_Core_Model_Session { - public function __construct($data=array()) + public function __construct($data = array()) { $name = isset($data['name']) ? $data['name'] : null; $this->init('core', $name); @@ -34,7 +34,7 @@ public function __construct($data=array()) public function getFormKey() { if (Mage::registry('replace_form_key') && - !Mage::app()->getRequest()->getParam('form_key', false)) { + ! Mage::app()->getRequest()->getParam('form_key', false)) { // flag request for ESI processing Mage::register('turpentine_esi_flag', true, true); return '{{form_key_esi_placeholder}}'; @@ -45,7 +45,7 @@ public function getFormKey() public function real_getFormKey() { - if (!$this->getData('_form_key')) { + if ( ! $this->getData('_form_key')) { $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); } return $this->getData('_form_key'); diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php b/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php index 52f6d7344..ebfd40013 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php @@ -37,18 +37,18 @@ class Nexcessnet_Turpentine_Model_Dummy_Request extends * @return void * @throws Zend_Controller_Request_Exception when invalid URI passed */ - public function __construct( $uri=null ) { + public function __construct($uri = null) { $this->_initFakeSuperGlobals(); - $this->_fixupFakeSuperGlobals( $uri ); + $this->_fixupFakeSuperGlobals($uri); try { - parent::__construct( $uri ); - } catch( Exception $e ) { - Mage::helper( 'turpentine/debug' ) - ->logError( 'Bad URI given to dummy request: ' . $uri ); - Mage::helper( 'turpentine/debug' ) + parent::__construct($uri); + } catch (Exception $e) { + Mage::helper('turpentine/debug') + ->logError('Bad URI given to dummy request: '.$uri); + Mage::helper('turpentine/debug') ->logBackTrace(); - Mage::logException( $e ); - if( Mage::helper( 'turpentine/esi' )->getEsiDebugEnabled() ) { + Mage::logException($e); + if (Mage::helper('turpentine/esi')->getEsiDebugEnabled()) { throw $e; } } @@ -62,23 +62,23 @@ public function __construct( $uri=null ) { * @param string $key * @return mixed */ - public function __get( $key ) { - switch( true ) { - case isset( $this->_params[$key] ): + public function __get($key) { + switch (true) { + case isset($this->_params[$key]): return $this->_params[$key]; - case isset( $this->GET[$key] ): + case isset($this->GET[$key]): return $this->GET[$key]; - case isset( $this->POST[$key] ): + case isset($this->POST[$key]): return $this->POST[$key]; - case isset( $_COOKIE[$key] ): + case isset($_COOKIE[$key]): return $_COOKIE[$key]; case ($key == 'REQUEST_URI'): return $this->getRequestUri(); case ($key == 'PATH_INFO'): return $this->getPathInfo(); - case isset( $this->SERVER[$key] ): + case isset($this->SERVER[$key]): return $this->SERVER[$key]; - case isset( $this->ENV[$key] ): + case isset($this->ENV[$key]): return $this->ENV[$key]; default: return null; @@ -91,19 +91,19 @@ public function __get( $key ) { * @param string $key * @return boolean */ - public function __isset( $key ) { + public function __isset($key) { switch (true) { - case isset( $this->_params[$key] ): + case isset($this->_params[$key]): return true; - case isset( $this->GET[$key] ): + case isset($this->GET[$key]): return true; - case isset( $this->POST[$key] ): + case isset($this->POST[$key]): return true; - case isset( $_COOKIE[$key] ): + case isset($_COOKIE[$key]): return true; - case isset( $this->SERVER[$key] ): + case isset($this->SERVER[$key]): return true; - case isset( $this->ENV[$key] ): + case isset($this->ENV[$key]): return true; default: return false; @@ -117,8 +117,8 @@ public function __isset( $key ) { * @param null|mixed $value * @return Zend_Controller_Request_Http */ - public function setQuery( $spec, $value=null ) { - if ((null === $value) && !is_array($spec)) { + public function setQuery($spec, $value = null) { + if ((null === $value) && ! is_array($spec)) { #require_once 'Zend/Controller/Exception.php'; throw new Zend_Controller_Exception('Invalid value passed to setQuery(); must be either array of values or key/value pair'); } @@ -142,11 +142,11 @@ public function setQuery( $spec, $value=null ) { * @param mixed $default Default value to use if key not found * @return mixed Returns null if key does not exist */ - public function getQuery( $key=null, $default=null ) { - if( null === $key ) { + public function getQuery($key = null, $default = null) { + if (null === $key) { return $this->GET; } - return ( isset( $this->GET[$key] ) ) ? $this->GET[$key] : $default; + return (isset($this->GET[$key])) ? $this->GET[$key] : $default; } /** @@ -159,7 +159,7 @@ public function getQuery( $key=null, $default=null ) { * @param mixed $default Default value to use if key not found * @return mixed Returns null if key does not exist */ - public function getPost( $key=null, $default=null ) { + public function getPost($key = null, $default = null) { if (null === $key) { return $this->POST; } @@ -176,7 +176,7 @@ public function getPost( $key=null, $default=null ) { * @param mixed $default Default value to use if key not found * @return mixed Returns null if key does not exist */ - public function getServer( $key=null, $default=null ) { + public function getServer($key = null, $default = null) { if (null === $key) { return $this->SERVER; } @@ -193,7 +193,7 @@ public function getServer( $key=null, $default=null ) { * @param mixed $default Default value to use if key not found * @return mixed Returns null if key does not exist */ - public function getEnv( $key=null, $default=null ) { + public function getEnv($key = null, $default = null) { if (null === $key) { return $this->ENV; } @@ -210,14 +210,14 @@ public function getEnv( $key=null, $default=null ) { * @return string|false HTTP header value, or false if not found * @throws Zend_Controller_Request_Exception */ - public function getHeader( $header ) { + public function getHeader($header) { if (empty($header)) { #require_once 'Zend/Controller/Request/Exception.php'; throw new Zend_Controller_Request_Exception('An HTTP header name is required'); } // Try to get it from the $_SERVER array first - $temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header)); + $temp = 'HTTP_'.strtoupper(str_replace('-', '_', $header)); if (isset($this->SERVER[$temp])) { return $this->SERVER[$temp]; } @@ -249,7 +249,7 @@ public function getHeader( $header ) { * @param string $requestUri * @return Zend_Controller_Request_Http */ - public function setRequestUri( $requestUri=null ) { + public function setRequestUri($requestUri = null) { if ($requestUri === null) { if (isset($this->SERVER['HTTP_X_REWRITE_URL'])) { // check this first so IIS will catch $requestUri = $this->SERVER['HTTP_X_REWRITE_URL']; @@ -264,19 +264,19 @@ public function setRequestUri( $requestUri=null ) { } elseif (isset($this->SERVER['REQUEST_URI'])) { $requestUri = $this->SERVER['REQUEST_URI']; // Http proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path - $schemeAndHttpHost = $this->getScheme() . '://' . $this->getHttpHost(); + $schemeAndHttpHost = $this->getScheme().'://'.$this->getHttpHost(); if (strpos($requestUri, $schemeAndHttpHost) === 0) { $requestUri = substr($requestUri, strlen($schemeAndHttpHost)); } } elseif (isset($this->SERVER['ORIG_PATH_INFO'])) { // IIS 5.0, PHP as CGI $requestUri = $this->SERVER['ORIG_PATH_INFO']; - if (!empty($this->SERVER['QUERY_STRING'])) { - $requestUri .= '?' . $this->SERVER['QUERY_STRING']; + if ( ! empty($this->SERVER['QUERY_STRING'])) { + $requestUri .= '?'.$this->SERVER['QUERY_STRING']; } } else { return $this; } - } elseif (!is_string($requestUri)) { + } elseif ( ! is_string($requestUri)) { return $this; } else { // Set GET items, if available @@ -312,8 +312,8 @@ public function setRequestUri( $requestUri=null ) { * @param mixed $baseUrl * @return Zend_Controller_Request_Http */ - public function setBaseUrl( $baseUrl=null ) { - if ((null !== $baseUrl) && !is_string($baseUrl)) { + public function setBaseUrl($baseUrl = null) { + if ((null !== $baseUrl) && ! is_string($baseUrl)) { return $this; } @@ -338,7 +338,7 @@ public function setBaseUrl( $baseUrl=null ) { $baseUrl = ''; do { $seg = $segs[$index]; - $baseUrl = '/' . $seg . $baseUrl; + $baseUrl = '/'.$seg.$baseUrl; ++$index; } while (($last > $index) && (false !== ($pos = strpos($path, $baseUrl))) && (0 != $pos)); } @@ -364,7 +364,7 @@ public function setBaseUrl( $baseUrl=null ) { } $basename = basename($baseUrl); - if (empty($basename) || !strpos($truncatedRequestUri, $basename)) { + if (empty($basename) || ! strpos($truncatedRequestUri, $basename)) { // no match whatsoever; set it blank $this->_baseUrl = ''; return $this; @@ -390,7 +390,7 @@ public function setBaseUrl( $baseUrl=null ) { * @param string|null $basePath * @return Zend_Controller_Request_Http */ - public function setBasePath( $basePath=null ) { + public function setBasePath($basePath = null) { if ($basePath === null) { $filename = (isset($this->SERVER['SCRIPT_FILENAME'])) ? basename($this->SERVER['SCRIPT_FILENAME']) @@ -430,7 +430,7 @@ public function setBasePath( $basePath=null ) { * @param mixed $default Default value to use if key not found * @return mixed */ - public function getParam( $key, $default=null ) { + public function getParam($key, $default = null) { $keyName = (null !== ($alias = $this->getAlias($key))) ? $alias : $key; $paramSources = $this->getParamSources(); @@ -478,8 +478,8 @@ public function getParams() { * @param bool $trimPort * @return string */ - public function getHttpHost( $trimPort=true ) { - if (!isset($this->SERVER['HTTP_HOST'])) { + public function getHttpHost($trimPort = true) { + if ( ! isset($this->SERVER['HTTP_HOST'])) { return false; } if ($trimPort) { @@ -497,11 +497,10 @@ public function getHttpHost( $trimPort=true ) { * * @return Mage_Core_Controller_Request_Http */ - public function setPost( $key, $value=null ) { + public function setPost($key, $value = null) { if (is_array($key)) { $this->POST = $key; - } - else { + } else { $this->POST[$key] = $value; } return $this; @@ -525,30 +524,30 @@ protected function _initFakeSuperGlobals() { * @param string $uri * @return null */ - protected function _fixupFakeSuperGlobals( $uri ) { + protected function _fixupFakeSuperGlobals($uri) { $uri = str_replace('|', urlencode('|'), $uri); - $parsedUrl = parse_url( $uri ); + $parsedUrl = parse_url($uri); - if ( isset($parsedUrl['path']) ) { + if (isset($parsedUrl['path'])) { $this->SERVER['REQUEST_URI'] = $parsedUrl['path']; } - if( isset( $parsedUrl['query'] ) && $parsedUrl['query'] ) { + if (isset($parsedUrl['query']) && $parsedUrl['query']) { $this->SERVER['QUERY_STRING'] = $parsedUrl['query']; - $this->SERVER['REQUEST_URI'] .= '?' . $this->SERVER['QUERY_STRING']; + $this->SERVER['REQUEST_URI'] .= '?'.$this->SERVER['QUERY_STRING']; } else { $this->SERVER['QUERY_STRING'] = null; } - parse_str( $this->SERVER['QUERY_STRING'], $this->GET ); - if( isset( $this->SERVER['SCRIPT_URI'] ) ) { - $start = strpos( $this->SERVER['SCRIPT_URI'], '/', 9 ); - $sub = substr( $this->SERVER['SCRIPT_URI'], $start ); + parse_str($this->SERVER['QUERY_STRING'], $this->GET); + if (isset($this->SERVER['SCRIPT_URI'])) { + $start = strpos($this->SERVER['SCRIPT_URI'], '/', 9); + $sub = substr($this->SERVER['SCRIPT_URI'], $start); $this->SERVER['SCRIPT_URI'] = substr( - $this->SERVER['SCRIPT_URI'], 0, $start ) . + $this->SERVER['SCRIPT_URI'], 0, $start ). @str_replace( $this->SERVER['SCRIPT_URL'], $parsedUrl['path'], - $sub, $c=1 ); + $sub, $c = 1 ); } - if( isset( $this->SERVER['SCRIPT_URL'] ) ) { + if (isset($this->SERVER['SCRIPT_URL'])) { $this->SERVER['SCRIPT_URL'] = $parsedUrl['path']; } } @@ -563,14 +562,14 @@ protected function _fixupFakeSuperGlobals( $uri ) { * @return null */ public function fakeRouterDispatch() { - if( $this->_cmsRouterMatch() ) { - Mage::helper( 'turpentine/debug' )->logDebug( 'Matched router: cms' ); - } elseif( $this->_standardRouterMatch() ) { - Mage::helper( 'turpentine/debug' )->logDebug( 'Matched router: standard' ); - } elseif( $this->_defaultRouterMatch() ) { - Mage::helper( 'turpentine/debug' )->logDebug( 'Matched router: default' ); + if ($this->_cmsRouterMatch()) { + Mage::helper('turpentine/debug')->logDebug('Matched router: cms'); + } elseif ($this->_standardRouterMatch()) { + Mage::helper('turpentine/debug')->logDebug('Matched router: standard'); + } elseif ($this->_defaultRouterMatch()) { + Mage::helper('turpentine/debug')->logDebug('Matched router: default'); } else { - Mage::helper( 'turpentine/debug' )->logDebug( 'No router match' ); + Mage::helper('turpentine/debug')->logDebug('No router match'); } } @@ -586,7 +585,7 @@ protected function _defaultRouterMatch() { $actionName = isset($noRoute[2]) ? $noRoute[2] : 'index'; if (Mage::app()->getStore()->isAdmin()) { - $adminFrontName = (string)Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName'); + $adminFrontName = (string) Mage::getConfig()->getNode('admin/routers/adminhtml/args/frontName'); if ($adminFrontName != $moduleName) { $moduleName = 'core'; $controllerName = 'index'; @@ -608,7 +607,7 @@ protected function _defaultRouterMatch() { * @return bool */ protected function _standardRouterMatch() { - $router = Mage::app()->getFrontController()->getRouter( 'standard' ); + $router = Mage::app()->getFrontController()->getRouter('standard'); // $router->fetchDefault(); @@ -626,14 +625,14 @@ protected function _standardRouterMatch() { if ($this->getModuleName()) { $module = $this->getModuleName(); } else { - if (!empty($p[0])) { + if ( ! empty($p[0])) { $module = $p[0]; } else { $module = $router->getFront()->getDefault('module'); $this->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, ''); } } - if (!$module) { + if ( ! $module) { if (Mage::app()->getStore()->isAdmin()) { $module = 'admin'; } else { @@ -661,7 +660,7 @@ protected function _standardRouterMatch() { if ($this->getControllerName()) { $controller = $this->getControllerName(); } else { - if (!empty($p[1])) { + if ( ! empty($p[1])) { $controller = $p[1]; } else { $controller = $front->getDefault('controller'); @@ -677,7 +676,7 @@ protected function _standardRouterMatch() { if ($this->getActionName()) { $action = $this->getActionName(); } else { - $action = !empty($p[2]) ? $p[2] : $front->getDefault('action'); + $action = ! empty($p[2]) ? $p[2] : $front->getDefault('action'); } } @@ -685,21 +684,21 @@ protected function _standardRouterMatch() { // $router->_checkShouldBeSecure($this, '/'.$module.'/'.$controller.'/'.$action); // $controllerClassName = $router->_validateControllerClassName($realModule, $controller); - $controllerClassName = $router->getControllerClassName( $realModule, $controller ); - if (!$controllerClassName) { + $controllerClassName = $router->getControllerClassName($realModule, $controller); + if ( ! $controllerClassName) { continue; } else { - $controllerFileName = $router->getControllerFileName( $realModule, $controller ); - if( !$router->validateControllerFileName( $controllerFileName ) ) { + $controllerFileName = $router->getControllerFileName($realModule, $controller); + if ( ! $router->validateControllerFileName($controllerFileName)) { return false; } - if (!class_exists($controllerClassName, false)) { - if (!file_exists($controllerFileName)) { + if ( ! class_exists($controllerClassName, false)) { + if ( ! file_exists($controllerFileName)) { return false; } include_once $controllerFileName; - if (!class_exists($controllerClassName, false)) { + if ( ! class_exists($controllerClassName, false)) { throw Mage::exception('Mage_Core', Mage::helper('core')->__('Controller file was loaded but class does not exist')); } } @@ -708,7 +707,7 @@ protected function _standardRouterMatch() { // instantiate controller class $controllerInstance = Mage::getControllerInstance($controllerClassName, $this, $front->getResponse()); - if (!$controllerInstance->hasAction($action)) { + if ( ! $controllerInstance->hasAction($action)) { continue; } @@ -719,7 +718,7 @@ protected function _standardRouterMatch() { /** * if we did not found any suitable */ - if (!$found) { + if ( ! $found) { /* if ($router->_noRouteShouldBeApplied()) { $controller = 'index'; @@ -752,7 +751,7 @@ protected function _standardRouterMatch() { // set parameters from pathinfo for ($i = 3, $l = sizeof($p); $i < $l; $i += 2) { - $this->setParam($p[$i], isset($p[$i+1]) ? urldecode($p[$i+1]) : ''); + $this->setParam($p[$i], isset($p[$i + 1]) ? urldecode($p[$i + 1]) : ''); } // dispatch action @@ -768,7 +767,7 @@ protected function _standardRouterMatch() { * @return bool */ protected function _cmsRouterMatch() { - $router = Mage::app()->getFrontController()->getRouter( 'cms' ); + $router = Mage::app()->getFrontController()->getRouter('cms'); $identifier = trim($this->getPathInfo(), '/'); @@ -790,13 +789,13 @@ protected function _cmsRouterMatch() { return true; } - if (!$condition->getContinue()) { + if ( ! $condition->getContinue()) { return false; } $page = Mage::getModel('cms/page'); $pageId = $page->checkIdentifier($identifier, Mage::app()->getStore()->getId()); - if (!$pageId) { + if ( ! $pageId) { return false; } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php index 5bfd8a13c..843f90043 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php @@ -29,12 +29,12 @@ class Nexcessnet_Turpentine_Model_Observer_Ban extends Varien_Event_Observer { * Cache the varnish admin object * @var Nexcessnet_Turpentine_Model_Varnish_Admin */ - protected $_varnishAdmin = null; + protected $_varnishAdmin = null; /** * Flag to prevent doing the ESI cache clear more than once per request * @var boolean */ - protected $_esiClearFlag = array(); + protected $_esiClearFlag = array(); /** * Clear the ESI block cache for a specific client @@ -46,23 +46,23 @@ class Nexcessnet_Turpentine_Model_Observer_Ban extends Varien_Event_Observer { * @param Varien_Object $eventObject * @return null */ - public function banClientEsiCache( $eventObject ) { + public function banClientEsiCache($eventObject) { $eventName = $eventObject->getEvent()->getName(); - if( Mage::helper( 'turpentine/esi' )->getEsiEnabled() && - !in_array( $eventName, $this->_esiClearFlag ) ) { - $sessionId = Mage::app()->getRequest()->getCookie( 'frontend' ); - if( $sessionId ) { + if (Mage::helper('turpentine/esi')->getEsiEnabled() && + ! in_array($eventName, $this->_esiClearFlag)) { + $sessionId = Mage::app()->getRequest()->getCookie('frontend'); + if ($sessionId) { $result = $this->_getVarnishAdmin()->flushExpression( 'obj.http.X-Varnish-Session', '==', $sessionId, '&&', 'obj.http.X-Turpentine-Flush-Events', '~', $eventName ); - Mage::dispatchEvent( 'turpentine_ban_client_esi_cache', $result ); - if( $this->_checkResult( $result ) ) { - Mage::helper( 'turpentine/debug' ) - ->logDebug( 'Cleared ESI cache for client (%s) on event: %s', - $sessionId, $eventName ); + Mage::dispatchEvent('turpentine_ban_client_esi_cache', $result); + if ($this->_checkResult($result)) { + Mage::helper('turpentine/debug') + ->logDebug('Cleared ESI cache for client (%s) on event: %s', + $sessionId, $eventName); } else { - Mage::helper( 'turpentine/debug' ) + Mage::helper('turpentine/debug') ->logWarn( 'Failed to clear Varnish ESI cache for client: %s', $sessionId ); @@ -81,20 +81,20 @@ public function banClientEsiCache( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function banProductPageCache( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { - $banHelper = Mage::helper( 'turpentine/ban' ); + public function banProductPageCache($eventObject) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { + $banHelper = Mage::helper('turpentine/ban'); $product = $eventObject->getProduct(); - $urlPattern = $banHelper->getProductBanRegex( $product ); - $result = $this->_getVarnishAdmin()->flushUrl( $urlPattern ); - Mage::dispatchEvent( 'turpentine_ban_product_cache', $result ); - $cronHelper = Mage::helper( 'turpentine/cron' ); - if( $this->_checkResult( $result ) && - $cronHelper->getCrawlerEnabled() ) { - $cronHelper->addProductToCrawlerQueue( $product ); - foreach( $banHelper->getParentProducts( $product ) - as $parentProduct ) { - $cronHelper->addProductToCrawlerQueue( $parentProduct ); + $urlPattern = $banHelper->getProductBanRegex($product); + $result = $this->_getVarnishAdmin()->flushUrl($urlPattern); + Mage::dispatchEvent('turpentine_ban_product_cache', $result); + $cronHelper = Mage::helper('turpentine/cron'); + if ($this->_checkResult($result) && + $cronHelper->getCrawlerEnabled()) { + $cronHelper->addProductToCrawlerQueue($product); + foreach ($banHelper->getParentProducts($product) + as $parentProduct) { + $cronHelper->addProductToCrawlerQueue($parentProduct); } } } @@ -109,27 +109,27 @@ public function banProductPageCache( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function banProductPageCacheCheckStock( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { + public function banProductPageCacheCheckStock($eventObject) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { $item = $eventObject->getItem(); - if( $item->getStockStatusChangedAutomatically() || - ( $item->getOriginalInventoryQty() <= 0 && + if ($item->getStockStatusChangedAutomatically() || + ($item->getOriginalInventoryQty() <= 0 && $item->getQty() > 0 && - $item->getQtyCorrection() > 0 ) ) { - $banHelper = Mage::helper( 'turpentine/ban' ); - $cronHelper = Mage::helper( 'turpentine/cron' ); - $product = Mage::getModel( 'catalog/product' ) - ->load( $item->getProductId() ); - $urlPattern = $banHelper->getProductBanRegex( $product ); - $result = $this->_getVarnishAdmin()->flushUrl( $urlPattern ); - Mage::dispatchEvent( 'turpentine_ban_product_cache_check_stock', - $result ); - if( $this->_checkResult( $result ) && - $cronHelper->getCrawlerEnabled() ) { - $cronHelper->addProductToCrawlerQueue( $product ); - foreach( $banHelper->getParentProducts( $product ) - as $parentProduct ) { - $cronHelper->addProductToCrawlerQueue( $parentProduct ); + $item->getQtyCorrection() > 0)) { + $banHelper = Mage::helper('turpentine/ban'); + $cronHelper = Mage::helper('turpentine/cron'); + $product = Mage::getModel('catalog/product') + ->load($item->getProductId()); + $urlPattern = $banHelper->getProductBanRegex($product); + $result = $this->_getVarnishAdmin()->flushUrl($urlPattern); + Mage::dispatchEvent('turpentine_ban_product_cache_check_stock', + $result); + if ($this->_checkResult($result) && + $cronHelper->getCrawlerEnabled()) { + $cronHelper->addProductToCrawlerQueue($product); + foreach ($banHelper->getParentProducts($product) + as $parentProduct) { + $cronHelper->addProductToCrawlerQueue($parentProduct); } } } @@ -145,15 +145,15 @@ public function banProductPageCacheCheckStock( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function banCategoryCache( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { + public function banCategoryCache($eventObject) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { $category = $eventObject->getCategory(); - $result = $this->_getVarnishAdmin()->flushUrl( $category->getUrlKey() ); - Mage::dispatchEvent( 'turpentine_ban_category_cache', $result ); - $cronHelper = Mage::helper( 'turpentine/cron' ); - if( $this->_checkResult( $result ) && - $cronHelper->getCrawlerEnabled() ) { - $cronHelper->addCategoryToCrawlerQueue( $category ); + $result = $this->_getVarnishAdmin()->flushUrl($category->getUrlKey()); + Mage::dispatchEvent('turpentine_ban_category_cache', $result); + $cronHelper = Mage::helper('turpentine/cron'); + if ($this->_checkResult($result) && + $cronHelper->getCrawlerEnabled()) { + $cronHelper->addCategoryToCrawlerQueue($category); } } } @@ -168,11 +168,11 @@ public function banCategoryCache( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function banMediaCache( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { - $result = $this->_getVarnishAdmin()->flushUrl( 'media/(?:js|css)/' ); - Mage::dispatchEvent( 'turpentine_ban_media_cache', $result ); - $this->_checkResult( $result ); + public function banMediaCache($eventObject) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { + $result = $this->_getVarnishAdmin()->flushUrl('media/(?:js|css)/'); + Mage::dispatchEvent('turpentine_ban_media_cache', $result); + $this->_checkResult($result); } } @@ -186,12 +186,12 @@ public function banMediaCache( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function banCatalogImagesCache( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { + public function banCatalogImagesCache($eventObject) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { $result = $this->_getVarnishAdmin()->flushUrl( 'media/catalog/product/cache/' ); - Mage::dispatchEvent( 'turpentine_ban_catalog_images_cache', $result ); - $this->_checkResult( $result ); + Mage::dispatchEvent('turpentine_ban_catalog_images_cache', $result); + $this->_checkResult($result); } } @@ -204,15 +204,15 @@ public function banCatalogImagesCache( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function banCmsPageCache( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { + public function banCmsPageCache($eventObject) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { $pageId = $eventObject->getDataObject()->getIdentifier(); - $result = $this->_getVarnishAdmin()->flushUrl( $pageId . '(?:\.html?)?$' ); - Mage::dispatchEvent( 'turpentine_ban_cms_page_cache', $result ); - $cronHelper = Mage::helper( 'turpentine/cron' ); - if( $this->_checkResult( $result ) && - $cronHelper->getCrawlerEnabled() ) { - $cronHelper->addCmsPageToCrawlerQueue( $pageId ); + $result = $this->_getVarnishAdmin()->flushUrl($pageId.'(?:\.html?)?$'); + Mage::dispatchEvent('turpentine_ban_cms_page_cache', $result); + $cronHelper = Mage::helper('turpentine/cron'); + if ($this->_checkResult($result) && + $cronHelper->getCrawlerEnabled()) { + $cronHelper->addCmsPageToCrawlerQueue($pageId); } } } @@ -226,21 +226,21 @@ public function banCmsPageCache( $eventObject ) { * @return null */ public function banCmsPageRevisionCache($eventObject) { - if ( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { $pageId = $eventObject->getDataObject()->getPageId(); - $page = Mage::getModel( 'cms/page' )->load( $pageId ); + $page = Mage::getModel('cms/page')->load($pageId); // Don't do anything if the page isn't found. - if( !$page ) { + if ( ! $page) { return; } $pageIdentifier = $page->getIdentifier(); - $result = $this->_getVarnishAdmin()->flushUrl( $pageIdentifier . '(?:\.html?)?$' ); - Mage::dispatchEvent( 'turpentine_ban_cms_page_cache', $result ); - $cronHelper = Mage::helper( 'turpentine/cron' ); - if( $this->_checkResult( $result ) && - $cronHelper->getCrawlerEnabled() ) { - $cronHelper->addCmsPageToCrawlerQueue( $pageIdentifier ); + $result = $this->_getVarnishAdmin()->flushUrl($pageIdentifier.'(?:\.html?)?$'); + Mage::dispatchEvent('turpentine_ban_cms_page_cache', $result); + $cronHelper = Mage::helper('turpentine/cron'); + if ($this->_checkResult($result) && + $cronHelper->getCrawlerEnabled()) { + $cronHelper->addCmsPageToCrawlerQueue($pageIdentifier); } } } @@ -256,11 +256,11 @@ public function banCmsPageRevisionCache($eventObject) { * @param Varien_Object $eventObject * @return null */ - public function banAllCache( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { + public function banAllCache($eventObject) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { $result = $this->_getVarnishAdmin()->flushAll(); - Mage::dispatchEvent( 'turpentine_ban_all_cache', $result ); - $this->_checkResult( $result ); + Mage::dispatchEvent('turpentine_ban_all_cache', $result); + $this->_checkResult($result); } } @@ -273,20 +273,20 @@ public function banAllCache( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function banCacheType( $eventObject ) { - switch( $eventObject->getType() ) { + public function banCacheType($eventObject) { + switch ($eventObject->getType()) { //note this is the name of the container xml tag in config.xml, // **NOT** the cache tag name - case Mage::helper( 'turpentine/esi' )->getMageCacheName(): - if( Mage::helper( 'turpentine/esi' )->getEsiEnabled() ) { + case Mage::helper('turpentine/esi')->getMageCacheName(): + if (Mage::helper('turpentine/esi')->getEsiEnabled()) { $result = $this->_getVarnishAdmin()->flushUrl( '/turpentine/esi/getBlock/' ); - Mage::dispatchEvent( 'turpentine_ban_esi_cache', $result ); - $this->_checkResult( $result ); + Mage::dispatchEvent('turpentine_ban_esi_cache', $result); + $this->_checkResult($result); } break; - case Mage::helper( 'turpentine/varnish' )->getMageCacheName(): - $this->banAllCache( $eventObject ); + case Mage::helper('turpentine/varnish')->getMageCacheName(): + $this->banAllCache($eventObject); break; } } @@ -297,7 +297,7 @@ public function banCacheType( $eventObject ) { * @param Varien_Object $eventObject * @return bool */ - public function banProductReview( $eventObject ) { + public function banProductReview($eventObject) { $patterns = array(); /* @var $review \Mage_Review_Model_Review*/ $review = $eventObject->getObject(); @@ -305,30 +305,30 @@ public function banProductReview( $eventObject ) { /* @var $productCollection \Mage_Review_Model_Resource_Review_Product_Collection*/ $productCollection = $review->getProductCollection(); - $products = $productCollection->addEntityFilter((int)$review->getEntityPkValue())->getItems(); + $products = $productCollection->addEntityFilter((int) $review->getEntityPkValue())->getItems(); - $productIds = array_unique( array_map( - create_function( '$p', 'return $p->getEntityId();' ), - $products ) ); - $patterns[] = sprintf( '/review/product/list/id/(?:%s)/category/', - implode( '|', array_unique( $productIds ) ) ); - $patterns[] = sprintf( '/review/product/view/id/%d/', - $review->getEntityId() ); + $productIds = array_unique(array_map( + create_function('$p', 'return $p->getEntityId();'), + $products )); + $patterns[] = sprintf('/review/product/list/id/(?:%s)/category/', + implode('|', array_unique($productIds))); + $patterns[] = sprintf('/review/product/view/id/%d/', + $review->getEntityId()); $productPatterns = array(); - foreach ( $products as $p ) { - $urlKey = $p->getUrlModel()->formatUrlKey( $p->getName() ); - if ( $urlKey ) { + foreach ($products as $p) { + $urlKey = $p->getUrlModel()->formatUrlKey($p->getName()); + if ($urlKey) { $productPatterns[] = $urlKey; } } - if ( !empty($productPatterns) ) { - $productPatterns = array_unique( $productPatterns ); - $patterns[] = sprintf( '(?:%s)', implode( '|', $productPatterns ) ); + if ( ! empty($productPatterns)) { + $productPatterns = array_unique($productPatterns); + $patterns[] = sprintf('(?:%s)', implode('|', $productPatterns)); } - $urlPattern = implode( '|', $patterns ); + $urlPattern = implode('|', $patterns); - $result = $this->_getVarnishAdmin()->flushUrl( $urlPattern ); - return $this->_checkResult( $result ); + $result = $this->_getVarnishAdmin()->flushUrl($urlPattern); + return $this->_checkResult($result); } /** @@ -337,11 +337,11 @@ public function banProductReview( $eventObject ) { * @param array $result stored as $socketName => $result * @return bool */ - protected function _checkResult( $result ) { + protected function _checkResult($result) { $rvalue = true; - foreach( $result as $socketName => $value ) { - if( $value !== true ) { - Mage::helper( 'turpentine/debug' )->logWarn( + foreach ($result as $socketName => $value) { + if ($value !== true) { + Mage::helper('turpentine/debug')->logWarn( 'Error in Varnish action result for server [%s]: %s', $socketName, $value ); $rvalue = false; @@ -356,8 +356,8 @@ protected function _checkResult( $result ) { * @return Nexcessnet_Turpentine_Model_Varnish_Admin */ protected function _getVarnishAdmin() { - if( is_null( $this->_varnishAdmin ) ) { - $this->_varnishAdmin = Mage::getModel( 'turpentine/varnish_admin' ); + if (is_null($this->_varnishAdmin)) { + $this->_varnishAdmin = Mage::getModel('turpentine/varnish_admin'); } return $this->_varnishAdmin; } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php index 2b80fbfe6..5542cfca7 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php @@ -26,14 +26,14 @@ class Nexcessnet_Turpentine_Model_Observer_Cron extends Varien_Event_Observer { * * @var int */ - const MAX_CRAWL_TIME = 300; + const MAX_CRAWL_TIME = 300; /** * Amount of time of execution time to leave for other cron processes * * @var int */ - const EXEC_TIME_BUFFER = 15; + const EXEC_TIME_BUFFER = 15; /** * Crawl available URLs in the queue until we get close to max_execution_time @@ -42,19 +42,19 @@ class Nexcessnet_Turpentine_Model_Observer_Cron extends Varien_Event_Observer { * @param Varien_Object $eventObject * @return null */ - public function crawlUrls( $eventObject ) { - $helper = Mage::helper( 'turpentine/cron' ); - if( $helper->getCrawlerEnabled() ) { + public function crawlUrls($eventObject) { + $helper = Mage::helper('turpentine/cron'); + if ($helper->getCrawlerEnabled()) { $maxRunTime = $helper->getAllowedRunTime(); - if( $maxRunTime === 0 ) { + if ($maxRunTime === 0) { $maxRunTime = self::MAX_CRAWL_TIME; } // just in case we have a silly short max_execution_time - $maxRunTime = abs( $maxRunTime - self::EXEC_TIME_BUFFER ); - while( ( $helper->getRunTime() < $maxRunTime ) && - $url = $helper->getNextUrl() ) { - if( !$this->_crawlUrl( $url ) ) { - Mage::helper( 'turpentine/debug' )->logWarn( + $maxRunTime = abs($maxRunTime - self::EXEC_TIME_BUFFER); + while (($helper->getRunTime() < $maxRunTime) && + $url = $helper->getNextUrl()) { + if ( ! $this->_crawlUrl($url)) { + Mage::helper('turpentine/debug')->logWarn( 'Failed to crawl URL: %s', $url ); } } @@ -67,10 +67,10 @@ public function crawlUrls( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function queueAllUrls( $eventObject ) { - $helper = Mage::helper( 'turpentine/cron' ); - if( $helper->getCrawlerEnabled() ) { - $helper->addUrlsToCrawlerQueue( $helper->getAllUrls() ); + public function queueAllUrls($eventObject) { + $helper = Mage::helper('turpentine/cron'); + if ($helper->getCrawlerEnabled()) { + $helper->addUrlsToCrawlerQueue($helper->getAllUrls()); } } @@ -80,14 +80,14 @@ public function queueAllUrls( $eventObject ) { * @param string $url * @return bool */ - protected function _crawlUrl( $url ) { - $client = Mage::helper( 'turpentine/cron' )->getCrawlerClient(); - $client->setUri( $url ); - Mage::helper( 'turpentine/debug' )->logDebug( 'Crawling URL: %s', $url ); + protected function _crawlUrl($url) { + $client = Mage::helper('turpentine/cron')->getCrawlerClient(); + $client->setUri($url); + Mage::helper('turpentine/debug')->logDebug('Crawling URL: %s', $url); try { $response = $client->request(); - } catch( Exception $e ) { - Mage::helper( 'turpentine/debug' )->logWarn( + } catch (Exception $e) { + Mage::helper('turpentine/debug')->logWarn( 'Error crawling URL (%s): %s', $url, $e->getMessage() ); return false; diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Debug.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Debug.php index 03bca7f02..0b5d154c0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Debug.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Debug.php @@ -27,9 +27,9 @@ class Nexcessnet_Turpentine_Model_Observer_Debug extends Varien_Event_Observer { * @param Varien_Object $eventObject * @return null */ - public function logEvent( $eventObject ) { - Mage::helper( 'turpentine/debug' )->log( 'EVENT: %s', - $eventObject->getEvent()->getName() ); + public function logEvent($eventObject) { + Mage::helper('turpentine/debug')->log('EVENT: %s', + $eventObject->getEvent()->getName()); } /** @@ -38,8 +38,8 @@ public function logEvent( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function logBackTrace( $eventObject ) { - $this->logEvent( $eventObject ); - Mage::helper( 'turpentine/debug' )->logBackTrace(); + public function logBackTrace($eventObject) { + $this->logEvent($eventObject); + Mage::helper('turpentine/debug')->logBackTrace(); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 5124e706e..800cfb486 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -28,7 +28,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer { * @param Varien_Object $eventObject * @return null */ - public function setCustomerGroupCookie( $eventObject ) { + public function setCustomerGroupCookie($eventObject) { $customer = $eventObject->getCustomer(); $cookie = Mage::getSingleton('core/cookie'); if (Mage::getStoreConfig('persistent/options/enabled')) { @@ -46,7 +46,7 @@ public function setCustomerGroupCookie( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function removeCustomerGroupCookie( $eventObject ) { + public function removeCustomerGroupCookie($eventObject) { Mage::getSingleton('core/cookie')->delete('customer_group'); } @@ -58,14 +58,14 @@ public function removeCustomerGroupCookie( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function setFlagHeaders( $eventObject ) { + public function setFlagHeaders($eventObject) { $response = $eventObject->getResponse(); - if( Mage::helper( 'turpentine/esi' )->shouldResponseUseEsi() ) { - $response->setHeader( 'X-Turpentine-Esi', - Mage::registry( 'turpentine_esi_flag' ) ? '1' : '0' ); - Mage::helper( 'turpentine/debug' )->logDebug( + if (Mage::helper('turpentine/esi')->shouldResponseUseEsi()) { + $response->setHeader('X-Turpentine-Esi', + Mage::registry('turpentine_esi_flag') ? '1' : '0'); + Mage::helper('turpentine/debug')->logDebug( 'Set ESI flag header to: %s', - ( Mage::registry( 'turpentine_esi_flag' ) ? '1' : '0' ) ); + (Mage::registry('turpentine_esi_flag') ? '1' : '0') ); } } @@ -81,14 +81,14 @@ public function setFlagHeaders( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function checkCacheFlag( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->shouldResponseUseVarnish() ) { + public function checkCacheFlag($eventObject) { + if (Mage::helper('turpentine/varnish')->shouldResponseUseVarnish()) { $layoutXml = $eventObject->getLayout()->getUpdate()->asSimplexml(); - foreach( $layoutXml->xpath( '//turpentine_cache_flag' ) as $node ) { - foreach( $node->attributes() as $attr => $value ) { - if( $attr == 'value' ) { - if( !(string)$value ) { - Mage::register( 'turpentine_nocache_flag', true, true ); + foreach ($layoutXml->xpath('//turpentine_cache_flag') as $node) { + foreach ($node->attributes() as $attr => $value) { + if ($attr == 'value') { + if ( ! (string) $value) { + Mage::register('turpentine_nocache_flag', true, true); return; //only need to set the flag once } } @@ -104,29 +104,29 @@ public function checkCacheFlag( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function checkRedirectUrl( $eventObject ) { - $esiHelper = Mage::helper( 'turpentine/esi' ); + public function checkRedirectUrl($eventObject) { + $esiHelper = Mage::helper('turpentine/esi'); $url = $eventObject->getTransport()->getUrl(); - $referer = Mage::helper( 'core/http' )->getHttpReferer(); + $referer = Mage::helper('core/http')->getHttpReferer(); $dummyUrl = $esiHelper->getDummyUrl(); - $reqUenc = Mage::helper( 'core' )->urlDecode( - Mage::app()->getRequest()->getParam( 'uenc' ) ); - - if( $this->_checkIsEsiUrl( $url ) ) { - if( $this->_checkIsNotEsiUrl( $reqUenc ) && - Mage::getBaseUrl() == $url ) { - $newUrl = $this->_fixupUencUrl( $reqUenc ); - } elseif( $this->_checkIsNotEsiUrl( $referer ) ) { + $reqUenc = Mage::helper('core')->urlDecode( + Mage::app()->getRequest()->getParam('uenc') ); + + if ($this->_checkIsEsiUrl($url)) { + if ($this->_checkIsNotEsiUrl($reqUenc) && + Mage::getBaseUrl() == $url) { + $newUrl = $this->_fixupUencUrl($reqUenc); + } elseif ($this->_checkIsNotEsiUrl($referer)) { $newUrl = $referer; } else { $newUrl = $dummyUrl; } // TODO: make sure this actually looks like a URL - $eventObject->getTransport()->setUrl( $newUrl ); + $eventObject->getTransport()->setUrl($newUrl); } - if( $eventObject->getTransport()->getUrl() != $url ) { - Mage::helper( 'turpentine/debug' )->logDebug( + if ($eventObject->getTransport()->getUrl() != $url) { + Mage::helper('turpentine/debug')->logDebug( 'Detected redirect to ESI URL, changing: %s => %s', $url, $eventObject->getTransport()->getUrl() ); } @@ -138,16 +138,16 @@ public function checkRedirectUrl( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function loadCacheClearEvents( $eventObject ) { - Varien_Profiler::start( 'turpentine::observer::esi::loadCacheClearEvents' ); - $events = Mage::helper( 'turpentine/esi' )->getCacheClearEvents(); - $appShim = Mage::getSingleton( 'turpentine/shim_mage_core_app' ); - foreach( $events as $ccEvent ) { - $appShim->shim_addEventObserver( 'global', $ccEvent, - 'turpentine_ban_' . $ccEvent, 'singleton', - 'turpentine/observer_ban', 'banClientEsiCache' ); + public function loadCacheClearEvents($eventObject) { + Varien_Profiler::start('turpentine::observer::esi::loadCacheClearEvents'); + $events = Mage::helper('turpentine/esi')->getCacheClearEvents(); + $appShim = Mage::getSingleton('turpentine/shim_mage_core_app'); + foreach ($events as $ccEvent) { + $appShim->shim_addEventObserver('global', $ccEvent, + 'turpentine_ban_'.$ccEvent, 'singleton', + 'turpentine/observer_ban', 'banClientEsiCache'); } - Varien_Profiler::stop( 'turpentine::observer::esi::loadCacheClearEvents' ); + Varien_Profiler::stop('turpentine::observer::esi::loadCacheClearEvents'); } /** @@ -160,13 +160,13 @@ public function loadCacheClearEvents( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function addMessagesBlockRewrite( $eventObject ) { - if( Mage::helper( 'turpentine/esi' )->shouldFixFlashMessages() ) { - Varien_Profiler::start( 'turpentine::observer::esi::addMessagesBlockRewrite' ); - Mage::getSingleton( 'turpentine/shim_mage_core_app' ) - ->shim_addClassRewrite( 'block', 'core', 'messages', - 'Nexcessnet_Turpentine_Block_Core_Messages' ); - Varien_Profiler::stop( 'turpentine::observer::esi::addMessagesBlockRewrite' ); + public function addMessagesBlockRewrite($eventObject) { + if (Mage::helper('turpentine/esi')->shouldFixFlashMessages()) { + Varien_Profiler::start('turpentine::observer::esi::addMessagesBlockRewrite'); + Mage::getSingleton('turpentine/shim_mage_core_app') + ->shim_addClassRewrite('block', 'core', 'messages', + 'Nexcessnet_Turpentine_Block_Core_Messages'); + Varien_Profiler::stop('turpentine::observer::esi::addMessagesBlockRewrite'); } } @@ -177,14 +177,14 @@ public function addMessagesBlockRewrite( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function setReplaceFormKeyFlag( $eventObject ) { - $esiHelper = Mage::helper( 'turpentine/esi' ); - $varnishHelper = Mage::helper( 'turpentine/varnish' ); + public function setReplaceFormKeyFlag($eventObject) { + $esiHelper = Mage::helper('turpentine/esi'); + $varnishHelper = Mage::helper('turpentine/varnish'); $request = Mage::app()->getRequest(); - if( $esiHelper->shouldResponseUseEsi() && + if ($esiHelper->shouldResponseUseEsi() && $varnishHelper->csrfFixupNeeded() && - !$request->isPost() ) { - Mage::register( 'replace_form_key', true ); + ! $request->isPost()) { + Mage::register('replace_form_key', true); } } @@ -194,16 +194,16 @@ public function setReplaceFormKeyFlag( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function replaceFormKeyPlaceholder( $eventObject ) { - if( Mage::registry( 'replace_form_key' ) ) { - $esiHelper = Mage::helper( 'turpentine/esi' ); + public function replaceFormKeyPlaceholder($eventObject) { + if (Mage::registry('replace_form_key')) { + $esiHelper = Mage::helper('turpentine/esi'); $response = $eventObject->getResponse(); $responseBody = $response->getBody(); - $responseBody = str_replace( '{{form_key_esi_placeholder}}', + $responseBody = str_replace('{{form_key_esi_placeholder}}', $esiHelper->buildEsiIncludeFragment( $esiHelper->getFormKeyEsiUrl() ), - $responseBody ); - $response->setBody( $responseBody ); + $responseBody); + $response->setBody($responseBody); } } @@ -217,35 +217,35 @@ public function replaceFormKeyPlaceholder( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function injectEsi( $eventObject ) { + public function injectEsi($eventObject) { $blockObject = $eventObject->getBlock(); - $dataHelper = Mage::helper( 'turpentine/data' ); - $esiHelper = Mage::helper( 'turpentine/esi' ); - $debugHelper = Mage::helper( 'turpentine/debug' ); - if( $esiHelper->getEsiBlockLogEnabled() ) { + $dataHelper = Mage::helper('turpentine/data'); + $esiHelper = Mage::helper('turpentine/esi'); + $debugHelper = Mage::helper('turpentine/debug'); + if ($esiHelper->getEsiBlockLogEnabled()) { $debugHelper->logInfo( 'Checking ESI block candidate: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); } - if( $esiHelper->shouldResponseUseEsi() && + if ($esiHelper->shouldResponseUseEsi() && $blockObject instanceof Mage_Core_Block_Template && - $esiOptions = $blockObject->getEsiOptions() ) { + $esiOptions = $blockObject->getEsiOptions()) { if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) { return; } - if( Mage::app()->getStore()->getCode() == 'admin' ) { + if (Mage::app()->getStore()->getCode() == 'admin') { // admin blocks are not allowed to be cached for now $debugHelper->logWarn( 'Ignoring attempt to inject adminhtml block: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); return; - } elseif( $esiHelper->getEsiBlockLogEnabled() ) { - $debugHelper->logInfo( 'Block check passed, injecting block: %s', - $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); + } elseif ($esiHelper->getEsiBlockLogEnabled()) { + $debugHelper->logInfo('Block check passed, injecting block: %s', + $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName()); } - Varien_Profiler::start( 'turpentine::observer::esi::injectEsi' ); + Varien_Profiler::start('turpentine::observer::esi::injectEsi'); $ttlParam = $esiHelper->getEsiTtlParam(); $cacheTypeParam = $esiHelper->getEsiCacheTypeParam(); $dataParam = $esiHelper->getEsiDataParam(); @@ -286,7 +286,7 @@ public function injectEsi( $eventObject ) { } if( $esiOptions[$scopeParam] == 'page' ) { $urlOptions[$referrerParam] = Mage::helper('core')->urlEncode( - Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true)) + Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true)) ); } @@ -317,65 +317,65 @@ public function injectEsi( $eventObject ) { * @param array $esiOptions * @return Varien_Object */ - protected function _getEsiData( $blockObject, $esiOptions ) { - Varien_Profiler::start( 'turpentine::observer::esi::_getEsiData' ); - $esiHelper = Mage::helper( 'turpentine/esi' ); + protected function _getEsiData($blockObject, $esiOptions) { + Varien_Profiler::start('turpentine::observer::esi::_getEsiData'); + $esiHelper = Mage::helper('turpentine/esi'); $cacheTypeParam = $esiHelper->getEsiCacheTypeParam(); $scopeParam = $esiHelper->getEsiScopeParam(); $methodParam = $esiHelper->getEsiMethodParam(); $esiData = new Varien_Object(); - $esiData->setStoreId( Mage::app()->getStore()->getId() ); - $esiData->setNameInLayout( $blockObject->getNameInLayout() ); - $esiData->setBlockType( get_class( $blockObject ) ); - $esiData->setLayoutHandles( $this->_getBlockLayoutHandles( $blockObject ) ); - $esiData->setEsiMethod( $esiOptions[$methodParam] ); - if( $esiOptions[$cacheTypeParam] == 'private' || $esiOptions[$cacheTypeParam] == 'customer_group' ) { - if( is_array( @$esiOptions['flush_events'] ) ) { - $esiData->setFlushEvents( array_merge( + $esiData->setStoreId(Mage::app()->getStore()->getId()); + $esiData->setNameInLayout($blockObject->getNameInLayout()); + $esiData->setBlockType(get_class($blockObject)); + $esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject)); + $esiData->setEsiMethod($esiOptions[$methodParam]); + if ($esiOptions[$cacheTypeParam] == 'private' || $esiOptions[$cacheTypeParam] == 'customer_group') { + if (is_array(@$esiOptions['flush_events'])) { + $esiData->setFlushEvents(array_merge( $esiHelper->getDefaultCacheClearEvents(), - array_keys( $esiOptions['flush_events'] ) ) ); + array_keys($esiOptions['flush_events']) )); } else { $esiData->setFlushEvents( $esiHelper->getDefaultCacheClearEvents() ); } } - if( $esiOptions[$scopeParam] == 'page' ) { - $esiData->setParentUrl( Mage::app()->getRequest()->getRequestString() ); + if ($esiOptions[$scopeParam] == 'page') { + $esiData->setParentUrl(Mage::app()->getRequest()->getRequestString()); } - if( is_array( $esiOptions['dummy_blocks'] ) ) { + if (is_array($esiOptions['dummy_blocks'])) { $dummyBlocks = array(); - foreach( $esiOptions['dummy_blocks'] as $key => $value ) { - $dummyBlocks[] = ( empty($value) && !is_numeric($key) ) ? $key : $value; + foreach ($esiOptions['dummy_blocks'] as $key => $value) { + $dummyBlocks[] = (empty($value) && ! is_numeric($key)) ? $key : $value; } - $esiData->setDummyBlocks( $dummyBlocks ); + $esiData->setDummyBlocks($dummyBlocks); } else { - Mage::helper( 'turpentine/debug' )->logWarn( + Mage::helper('turpentine/debug')->logWarn( 'Invalid dummy_blocks for block: %s', $blockObject->getNameInLayout() ); } $simpleRegistry = array(); $complexRegistry = array(); - if( is_array( $esiOptions['registry_keys'] ) ) { - foreach( $esiOptions['registry_keys'] as $key => $options ) { - $value = Mage::registry( $key ); - if( $value ) { - if( is_object( $value ) && - $value instanceof Mage_Core_Model_Abstract ) { + if (is_array($esiOptions['registry_keys'])) { + foreach ($esiOptions['registry_keys'] as $key => $options) { + $value = Mage::registry($key); + if ($value) { + if (is_object($value) && + $value instanceof Mage_Core_Model_Abstract) { $complexRegistry[$key] = - $this->_getComplexRegistryData( $options, $value ); + $this->_getComplexRegistryData($options, $value); } else { $simpleRegistry[$key] = $value; } } } } else { - Mage::helper( 'turpentine/debug' )->logWarn( + Mage::helper('turpentine/debug')->logWarn( 'Invalid registry_keys for block: %s', $blockObject->getNameInLayout() ); } - $esiData->setSimpleRegistry( $simpleRegistry ); - $esiData->setComplexRegistry( $complexRegistry ); - Varien_Profiler::stop( 'turpentine::observer::esi::_getEsiData' ); + $esiData->setSimpleRegistry($simpleRegistry); + $esiData->setComplexRegistry($complexRegistry); + Varien_Profiler::stop('turpentine::observer::esi::_getEsiData'); return $esiData; } @@ -399,35 +399,35 @@ protected function _getEsiData( $blockObject, $esiOptions ) { * @param Mage_Core_Block_Template $block * @return array */ - protected function _getBlockLayoutHandles( $block ) { - Varien_Profiler::start( 'turpentine::observer::esi::_getBlockLayoutHandles' ); + protected function _getBlockLayoutHandles($block) { + Varien_Profiler::start('turpentine::observer::esi::_getBlockLayoutHandles'); $layout = $block->getLayout(); - $layoutXml = Mage::helper( 'turpentine/esi' )->getLayoutXml(); + $layoutXml = Mage::helper('turpentine/esi')->getLayoutXml(); $activeHandles = array(); // get the xml node representing the block we're working on (from the // default handle probably) - $blockNode = current( $layout->getNode()->xpath( sprintf( + $blockNode = current($layout->getNode()->xpath(sprintf( '//block[@name=\'%s\']', - $block->getNameInLayout() ) ) ); - $childBlocks = Mage::helper( 'turpentine/data' ) - ->getChildBlockNames( $blockNode ); - foreach( $childBlocks as $blockName ) { - foreach( $layout->getUpdate()->getHandles() as $handle ) { + $block->getNameInLayout() ))); + $childBlocks = Mage::helper('turpentine/data') + ->getChildBlockNames($blockNode); + foreach ($childBlocks as $blockName) { + foreach ($layout->getUpdate()->getHandles() as $handle) { // check if this handle has any block or reference tags that // refer to this block or a child block, unless the handle name // is blank - if( $handle !== '' && ( strpos($handle, 'THEME') === 0 || - $layoutXml->xpath( sprintf( - '//%s//*[@name=\'%s\']', $handle, $blockName ) ) ) ) { + if ($handle !== '' && (strpos($handle, 'THEME') === 0 || + $layoutXml->xpath(sprintf( + '//%s//*[@name=\'%s\']', $handle, $blockName )))) { $activeHandles[] = $handle; } } } - if( !$activeHandles ) { + if ( ! $activeHandles) { $activeHandles[] = 'default'; } - Varien_Profiler::stop( 'turpentine::observer::esi::_getBlockLayoutHandles' ); - return array_unique( $activeHandles ); + Varien_Profiler::stop('turpentine::observer::esi::_getBlockLayoutHandles'); + return array_unique($activeHandles); } /** @@ -435,8 +435,8 @@ protected function _getBlockLayoutHandles( $block ) { * * @return array */ - protected function _getDefaultEsiOptions( $options ) { - $esiHelper = Mage::helper( 'turpentine/esi' ); + protected function _getDefaultEsiOptions($options) { + $esiHelper = Mage::helper('turpentine/esi'); $ttlParam = $esiHelper->getEsiTtlParam(); $methodParam = $esiHelper->getEsiMethodParam(); $cacheTypeParam = $esiHelper->getEsiCacheTypeParam(); @@ -447,12 +447,12 @@ protected function _getDefaultEsiOptions( $options ) { 'dummy_blocks' => array(), 'registry_keys' => array(), ); - $options = array_merge( $defaults, $options ); + $options = array_merge($defaults, $options); // set the default TTL - if( !isset( $options[$ttlParam] ) ) { - if( $options[$cacheTypeParam] == 'private' || $options[$cacheTypeParam] == 'customer_group' ) { - switch( $options[$methodParam] ) { + if ( ! isset($options[$ttlParam])) { + if ($options[$cacheTypeParam] == 'private' || $options[$cacheTypeParam] == 'customer_group') { + switch ($options[$methodParam]) { case 'ajax': $options[$ttlParam] = '0'; break; @@ -463,7 +463,7 @@ protected function _getDefaultEsiOptions( $options ) { break; } } else { - $options[$ttlParam] = Mage::helper( 'turpentine/varnish' ) + $options[$ttlParam] = Mage::helper('turpentine/varnish') ->getDefaultTtl(); } } @@ -478,12 +478,12 @@ protected function _getDefaultEsiOptions( $options ) { * @param mixed $value * @return array */ - protected function _getComplexRegistryData( $valueOptions, $value ) { + protected function _getComplexRegistryData($valueOptions, $value) { $idMethod = @$valueOptions['id_method'] ? $valueOptions['id_method'] : 'getId'; $model = @$valueOptions['model'] ? - $valueOptions['model'] : Mage::helper( 'turpentine/data' ) - ->getModelName( $value ); + $valueOptions['model'] : Mage::helper('turpentine/data') + ->getModelName($value); $data = array( 'model' => $model, 'id' => $value->{$idMethod}(), @@ -498,11 +498,11 @@ protected function _getComplexRegistryData( $valueOptions, $value ) { * @param string $uencUrl * @return string */ - protected function _fixupUencUrl( $uencUrl ) { - $esiHelper = Mage::helper( 'turpentine/esi' ); + protected function _fixupUencUrl($uencUrl) { + $esiHelper = Mage::helper('turpentine/esi'); $corsOrigin = $esiHelper->getCorsOrigin(); - if( $corsOrigin != $esiHelper->getCorsOrigin( $uencUrl ) ) { - return $corsOrigin . parse_url( $uencUrl, PHP_URL_PATH ); + if ($corsOrigin != $esiHelper->getCorsOrigin($uencUrl)) { + return $corsOrigin.parse_url($uencUrl, PHP_URL_PATH); } else { return $uencUrl; } @@ -514,8 +514,8 @@ protected function _fixupUencUrl( $uencUrl ) { * @param string $url * @return bool */ - protected function _checkIsNotEsiUrl( $url ) { - return $url && !preg_match( '~/turpentine/esi/getBlock/~', $url ); + protected function _checkIsNotEsiUrl($url) { + return $url && ! preg_match('~/turpentine/esi/getBlock/~', $url); } /** @@ -524,18 +524,18 @@ protected function _checkIsNotEsiUrl( $url ) { * @param string $url * @return bool */ - protected function _checkIsEsiUrl( $url ) { - return !$this->_checkIsNotEsiUrl( $url ); + protected function _checkIsEsiUrl($url) { + return ! $this->_checkIsNotEsiUrl($url); } public function hookToControllerActionPreDispatch($observer) { - if(Mage::helper( 'turpentine/data')->getVclFix() == 0 && $observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') { + if (Mage::helper('turpentine/data')->getVclFix() == 0 && $observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') { Mage::dispatchEvent("add_to_cart_before", array('request' => $observer->getControllerAction()->getRequest())); } } public function hookToControllerActionPostDispatch($observer) { - if($observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') { + if ($observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') { Mage::dispatchEvent("add_to_cart_after", array('request' => $observer->getControllerAction()->getRequest())); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index d2b2d8a9b..d1e9067c1 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -28,15 +28,15 @@ class Nexcessnet_Turpentine_Model_Observer_Varnish extends Varien_Event_Observer * @param mixed $eventObject * @return null */ - public function setCacheFlagHeader( $eventObject ) { + public function setCacheFlagHeader($eventObject) { $response = $eventObject->getResponse(); - if( Mage::helper( 'turpentine/varnish' )->shouldResponseUseVarnish() ) { - $response->setHeader( 'X-Turpentine-Cache', - Mage::registry( 'turpentine_nocache_flag' ) ? '0' : '1' ); - if( Mage::helper( 'turpentine/varnish' )->getVarnishDebugEnabled() ) { - Mage::helper( 'turpentine/debug' )->logDebug( - 'Set Varnish cache flag header to: ' . - ( Mage::registry( 'turpentine_nocache_flag' ) ? '0' : '1' ) ); + if (Mage::helper('turpentine/varnish')->shouldResponseUseVarnish()) { + $response->setHeader('X-Turpentine-Cache', + Mage::registry('turpentine_nocache_flag') ? '0' : '1'); + if (Mage::helper('turpentine/varnish')->getVarnishDebugEnabled()) { + Mage::helper('turpentine/debug')->logDebug( + 'Set Varnish cache flag header to: '. + (Mage::registry('turpentine_nocache_flag') ? '0' : '1') ); } } } @@ -47,11 +47,11 @@ public function setCacheFlagHeader( $eventObject ) { * @param Varien_Object $eventObject * @return null */ - public function addProductListToolbarRewrite( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->shouldFixProductListToolbar() ) { - Mage::getSingleton( 'turpentine/shim_mage_core_app' ) - ->shim_addClassRewrite( 'block', 'catalog', 'product_list_toolbar', - 'Nexcessnet_Turpentine_Block_Catalog_Product_List_Toolbar' ); + public function addProductListToolbarRewrite($eventObject) { + if (Mage::helper('turpentine/varnish')->shouldFixProductListToolbar()) { + Mage::getSingleton('turpentine/shim_mage_core_app') + ->shim_addClassRewrite('block', 'catalog', 'product_list_toolbar', + 'Nexcessnet_Turpentine_Block_Catalog_Product_List_Toolbar'); } } @@ -61,33 +61,33 @@ public function addProductListToolbarRewrite( $eventObject ) { * @param mixed $eventObject * @return null */ - public function adminSystemConfigChangedSection( $eventObject ) { - if( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() && - Mage::helper( 'turpentine/data' )->getAutoApplyOnSave() ) { - $result = Mage::getModel( 'turpentine/varnish_admin' )->applyConfig(); - $session = Mage::getSingleton( 'core/session' ); - foreach( $result as $name => $value ) { - if( $value === true ) { - $session->addSuccess( Mage::helper( 'turpentine/data' ) - ->__( 'VCL successfully applied to: ' . $name ) ); + public function adminSystemConfigChangedSection($eventObject) { + if (Mage::helper('turpentine/varnish')->getVarnishEnabled() && + Mage::helper('turpentine/data')->getAutoApplyOnSave()) { + $result = Mage::getModel('turpentine/varnish_admin')->applyConfig(); + $session = Mage::getSingleton('core/session'); + foreach ($result as $name => $value) { + if ($value === true) { + $session->addSuccess(Mage::helper('turpentine/data') + ->__('VCL successfully applied to: '.$name)); } else { - $session->addError( Mage::helper( 'turpentine/data' ) - ->__( sprintf( 'Failed to apply the VCL to %s: %s', - $name, $value ) ) ); + $session->addError(Mage::helper('turpentine/data') + ->__(sprintf('Failed to apply the VCL to %s: %s', + $name, $value))); } } - $cfgr = Mage::getModel( 'turpentine/varnish_admin' )->getConfigurator(); - if( is_null( $cfgr ) ) { - $session->addError( Mage::helper( 'turpentine/data' ) - ->__( 'Failed to load configurator' ) ); + $cfgr = Mage::getModel('turpentine/varnish_admin')->getConfigurator(); + if (is_null($cfgr)) { + $session->addError(Mage::helper('turpentine/data') + ->__('Failed to load configurator')); } else { - $result = $cfgr->save( $cfgr->generate() ); - if( $result[0] ) { - $session->addSuccess( Mage::helper('turpentine/data' ) - ->__( 'The VCL file has been saved.' ) ); + $result = $cfgr->save($cfgr->generate()); + if ($result[0]) { + $session->addSuccess(Mage::helper('turpentine/data') + ->__('The VCL file has been saved.')); } else { - $session->addError( Mage::helper('turpentine/data' ) - ->__( 'Failed to save the VCL file: ' . $result[1]['message'] ) ); + $session->addError(Mage::helper('turpentine/data') + ->__('Failed to save the VCL file: '.$result[1]['message'])); } } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/PageCache/Container/Notices.php b/app/code/community/Nexcessnet/Turpentine/Model/PageCache/Container/Notices.php index 670aac48f..f5643e069 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/PageCache/Container/Notices.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/PageCache/Container/Notices.php @@ -28,7 +28,7 @@ class Nexcessnet_Turpentine_Model_PageCache_Container_Notices * @param string $content * @return boolean */ - public function applyWithoutApp( &$content ) { + public function applyWithoutApp(&$content) { return false; } @@ -39,7 +39,7 @@ public function applyWithoutApp( &$content ) { */ protected function _renderBlock() { $block = new Nexcessnet_Turpentine_Block_Notices(); - $block->setTemplate( 'turpentine/notices.phtml' ); + $block->setTemplate('turpentine/notices.phtml'); return $block->toHtml(); } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Session.php b/app/code/community/Nexcessnet/Turpentine/Model/Session.php index 3886f8e68..c1b15b219 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Session.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Session.php @@ -22,12 +22,12 @@ class Nexcessnet_Turpentine_Model_Session extends Mage_Core_Model_Session_Abstract { protected $_namespace = 'turpentine'; - public function __construct( $data=array() ) { - $sessionName = isset( $data['name'] ) ? $data['name'] : null; - $this->init( $this->_namespace, $sessionName ); + public function __construct($data = array()) { + $sessionName = isset($data['name']) ? $data['name'] : null; + $this->init($this->_namespace, $sessionName); Mage::dispatchEvent( - sprintf( '%s_session_init', $this->_namespace ), - array( sprintf( '%s_session', $this->_namespace ) => $this ) ); + sprintf('%s_session_init', $this->_namespace), + array(sprintf('%s_session', $this->_namespace) => $this) ); } /** @@ -37,11 +37,11 @@ public function __construct( $data=array() ) { * @param array $messages * @return null */ - public function saveMessages( $blockName, $messages ) { + public function saveMessages($blockName, $messages) { $allMessages = $this->getMessages(); $allMessages[$blockName] = array_merge( - $this->loadMessages( $blockName ), $messages ); - $this->setMessages( $allMessages ); + $this->loadMessages($blockName), $messages ); + $this->setMessages($allMessages); } /** @@ -50,9 +50,9 @@ public function saveMessages( $blockName, $messages ) { * @param string $blockName * @return array */ - public function loadMessages( $blockName ) { + public function loadMessages($blockName) { $messages = $this->getMessages(); - if( is_array( @$messages[$blockName] ) ) { + if (is_array(@$messages[$blockName])) { return $messages[$blockName]; } else { return array(); @@ -65,21 +65,20 @@ public function loadMessages( $blockName ) { * @param string $blockName * @return null */ - public function clearMessages( $blockName ) { + public function clearMessages($blockName) { $messages = $this->getMessages(); - unset( $messages[$blockName] ); - $this->setMessages( $messages ); + unset($messages[$blockName]); + $this->setMessages($messages); } /** * Retrieve the stored messages * - * @param boolean $clear=false * @return array */ - public function getMessages( $clear=false ) { - $messages = $this->getData( 'messages' ); - if( !is_array( $messages ) ) { + public function getMessages($clear = false) { + $messages = $this->getData('messages'); + if ( ! is_array($messages)) { $messages = array(); } return $messages; @@ -90,7 +89,7 @@ public function getMessages( $clear=false ) { * * @param array $messages */ - public function setMessages( $messages ) { - $this->setData( 'messages', $messages ); + public function setMessages($messages) { + $this->setData('messages', $messages); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php index c5898af95..07f1b67e4 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/App.php @@ -35,9 +35,9 @@ class Nexcessnet_Turpentine_Model_Shim_Mage_Core_App extends Mage_Core_Model_App */ public function shim_setRequest(Mage_Core_Controller_Request_Http $request) { $app = $this->_shim_getApp(); - if( method_exists( $app, 'setRequest' ) ) { + if (method_exists($app, 'setRequest')) { // use the real setRequest if it's available - $app->setRequest( $request ); + $app->setRequest($request); } else { $app->_request = $request; } @@ -55,12 +55,12 @@ public function shim_setRequest(Mage_Core_Controller_Request_Http $request) { * @param string $method name of the method to call * @return Nexcessnet_Turpentine_Model_Shim_Mage_Core_App */ - public function shim_addEventObserver( $area, $eventName, $obsName, - $type=null, $class=null, $method=null ) { + public function shim_addEventObserver($area, $eventName, $obsName, + $type = null, $class = null, $method = null) { $eventConfig = new Varien_Simplexml_Config(); - $eventConfig->loadDom( $this->_shim_getEventDom( - $area, $eventName, $obsName, $type, $class, $method ) ); - $this->_shim_getConfig()->extend( $eventConfig, true ); + $eventConfig->loadDom($this->_shim_getEventDom( + $area, $eventName, $obsName, $type, $class, $method )); + $this->_shim_getConfig()->extend($eventConfig, true); // this wouldn't work if PHP had a sane object model $this->_shim_getApp()->_events[$area][$eventName] = null; /* clear the event area cache because by the time this gets executed all events have already been @@ -78,12 +78,12 @@ public function shim_addEventObserver( $area, $eventName, $obsName, * @param string $rewriteTarget full class name to rewrite to * @return Nexcessnet_Turpentine_Model_Shim_Mage_Core_App */ - public function shim_addClassRewrite( $type, $module, $class, - $rewriteTarget ) { + public function shim_addClassRewrite($type, $module, $class, + $rewriteTarget) { $rewriteConfig = new Varien_Simplexml_Config(); - $rewriteConfig->loadDom( $this->_shim_getRewriteDom( - $type, $module, $class, $rewriteTarget ) ); - $this->_shim_getConfig()->extend( $rewriteConfig, true ); + $rewriteConfig->loadDom($this->_shim_getRewriteDom( + $type, $module, $class, $rewriteTarget )); + $this->_shim_getConfig()->extend($rewriteConfig, true); $this->_shim_getConfigShim()->shim_setClassNameCache( $type, $module, $class, $rewriteTarget ); return $this; @@ -100,25 +100,25 @@ public function shim_addClassRewrite( $type, $module, $class, * @param string $method * @return DOMDocument */ - protected function _shim_getEventDom( $area, $eventName, $obsName, - $type=null, $class=null, $method=null ) { - $dom = new DOMDocument( '1.0' ); - $config = $dom->createElement( 'config' ); + protected function _shim_getEventDom($area, $eventName, $obsName, + $type = null, $class = null, $method = null) { + $dom = new DOMDocument('1.0'); + $config = $dom->createElement('config'); $observers = $config - ->appendChild( $dom->createElement( $area ) ) - ->appendChild( $dom->createElement( 'events' ) ) - ->appendChild( $dom->createElement( $eventName ) ) - ->appendChild( $dom->createElement( 'observers' ) ); - $observer = $dom->createElement( $obsName ); - if( $class && $method ) { - if( $type ) { - $observer->appendChild( $dom->createElement( 'type', $type ) ); + ->appendChild($dom->createElement($area)) + ->appendChild($dom->createElement('events')) + ->appendChild($dom->createElement($eventName)) + ->appendChild($dom->createElement('observers')); + $observer = $dom->createElement($obsName); + if ($class && $method) { + if ($type) { + $observer->appendChild($dom->createElement('type', $type)); } - $observer->appendChild( $dom->createElement( 'class', $class ) ); - $observer->appendChild( $dom->createElement( 'method', $method ) ); + $observer->appendChild($dom->createElement('class', $class)); + $observer->appendChild($dom->createElement('method', $method)); } - $observers->appendChild( $observer ); - $dom->appendChild( $config ); + $observers->appendChild($observer); + $dom->appendChild($config); return $dom; } @@ -131,14 +131,14 @@ protected function _shim_getEventDom( $area, $eventName, $obsName, * @param string $className full class name to rewrite to * @return DOMDocument */ - protected function _shim_getRewriteDom( $groupType, $group, $class, $className ) { - $dom = new DOMDocument( '1.0' ); - $dom->appendChild( $dom->createElement( 'config' ) ) - ->appendChild( $dom->createElement( 'global' ) ) - ->appendChild( $dom->createElement( $groupType . 's' ) ) - ->appendChild( $dom->createElement( $group ) ) - ->appendChild( $dom->createElement( 'rewrite' ) ) - ->appendChild( $dom->createElement( $class, $className ) ); + protected function _shim_getRewriteDom($groupType, $group, $class, $className) { + $dom = new DOMDocument('1.0'); + $dom->appendChild($dom->createElement('config')) + ->appendChild($dom->createElement('global')) + ->appendChild($dom->createElement($groupType.'s')) + ->appendChild($dom->createElement($group)) + ->appendChild($dom->createElement('rewrite')) + ->appendChild($dom->createElement($class, $className)); return $dom; } @@ -166,6 +166,6 @@ protected function _shim_getConfig() { * @return Nexcessnet_Turpentine_Model_Shim_Mage_Core_Config */ protected function _shim_getConfigShim() { - return Mage::getModel( 'turpentine/shim_mage_core_config' ); + return Mage::getModel('turpentine/shim_mage_core_config'); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php index 6c7394076..d3a25d0c9 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php @@ -31,7 +31,7 @@ class Nexcessnet_Turpentine_Model_Shim_Mage_Core_Config extends Mage_Core_Model_ * @param string $className full class name to rewrite to * @return string */ - public function shim_setClassNameCache( $groupType, $group, $class, $className ) { + public function shim_setClassNameCache($groupType, $group, $class, $className) { $config = Mage::getConfig(); $prevValue = @$config->_classNameCache[$groupType][$group][$class]; $config->_classNameCache[$groupType][$group][$class] = $className; @@ -45,7 +45,7 @@ public function shim_setClassNameCache( $groupType, $group, $class, $className ) * @param $area string The config area to clear (e.g. 'global') */ public function unsetEventAreaCache($area) { - if(version_compare(Mage::getVersion(),'1.11.0', '>=') // enterprise + if (version_compare(Mage::getVersion(), '1.11.0', '>=') // enterprise || version_compare(Mage::getVersion(), '1.6.0', '>=')) // community unset($this->_eventAreas[$area]); } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Layout.php b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Layout.php index 99417c2a5..f45bfc5d8 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Layout.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Layout.php @@ -26,13 +26,13 @@ class Nexcessnet_Turpentine_Model_Shim_Mage_Core_Layout extends Mage_Core_Model_ * @param Mage_Core_Model_Layout_Element $blockNode * @return null */ - public function shim_generateFullBlock( $blockNode ) { + public function shim_generateFullBlock($blockNode) { $layout = $this->_shim_getLayout(); - if( !( $parent = $blockNode->getParent() ) ) { + if ( ! ($parent = $blockNode->getParent())) { $parent = new Varien_Object(); } - $layout->_generateBlock( $blockNode, $parent ); - return $layout->generateBlocks( $blockNode ); + $layout->_generateBlock($blockNode, $parent); + return $layout->generateBlocks($blockNode); } /** @@ -41,11 +41,11 @@ public function shim_generateFullBlock( $blockNode ) { * @param Mage_Core_Model_Layout_Element $node * @return Mage_Core_Model_Layout */ - public function shim_generateAction( $node ) { - if( !( $parentNode = $node->getParent() ) ) { + public function shim_generateAction($node) { + if ( ! ($parentNode = $node->getParent())) { $parentNode = new Varien_Object(); } - return $this->_shim_getLayout()->_generateAction( $node, $parentNode ); + return $this->_shim_getLayout()->_generateAction($node, $parentNode); } /** @@ -54,6 +54,6 @@ public function shim_generateAction( $node ) { * @return Mage_Core_Model_Layout */ protected function _shim_getLayout() { - return Mage::getSingleton( 'core/layout' ); + return Mage::getSingleton('core/layout'); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index a26f5105e..1543ed66d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -30,7 +30,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin { * @return bool */ public function flushAll() { - return $this->flushUrl( '.*' ); + return $this->flushUrl('.*'); } /** @@ -39,15 +39,15 @@ public function flushAll() { * @param string $subPattern regex to match against URLs * @return bool */ - public function flushUrl( $subPattern ) { + public function flushUrl($subPattern) { $result = array(); - foreach( Mage::helper( 'turpentine/varnish' )->getSockets() as $socket ) { + foreach (Mage::helper('turpentine/varnish')->getSockets() as $socket) { $socketName = $socket->getConnectionString(); try { // We don't use "ban_url" here, because we want to do lurker friendly bans. // Lurker friendly bans get cleaned up, so they don't slow down Varnish. - $socket->ban( 'obj.http.X-Varnish-URL', '~', $subPattern ); - } catch( Mage_Core_Exception $e ) { + $socket->ban('obj.http.X-Varnish-URL', '~', $subPattern); + } catch (Mage_Core_Exception $e) { $result[$socketName] = $e->getMessage(); continue; } @@ -65,11 +65,11 @@ public function flushUrl( $subPattern ) { public function flushExpression() { $args = func_get_args(); $result = array(); - foreach( Mage::helper( 'turpentine/varnish' )->getSockets() as $socket ) { + foreach (Mage::helper('turpentine/varnish')->getSockets() as $socket) { $socketName = $socket->getConnectionString(); try { - call_user_func_array( array( $socket, 'ban' ), $args ); - } catch( Mage_Core_Exception $e ) { + call_user_func_array(array($socket, 'ban'), $args); + } catch (Mage_Core_Exception $e) { $result[$socketName] = $e->getMessage(); continue; } @@ -84,7 +84,7 @@ public function flushExpression() { * @param string $contentType * @return array */ - public function flushContentType( $contentType ) { + public function flushContentType($contentType) { return $this->flushExpression( 'obj.http.Content-Type', '~', $contentType ); } @@ -96,7 +96,7 @@ public function flushContentType( $contentType ) { */ public function applyConfig() { $result = array(); - $helper = Mage::helper( 'turpentine' ); + $helper = Mage::helper( 'turpentine' ); foreach( Mage::helper( 'turpentine/varnish' )->getSockets() as $socket ) { $cfgr = Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract::getFromSocket( $socket ); $socketName = $socket->getConnectionString(); @@ -127,50 +127,50 @@ public function applyConfig() { * @return Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract */ public function getConfigurator() { - $sockets = Mage::helper( 'turpentine/varnish' )->getSockets(); - $cfgr = Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract::getFromSocket( $sockets[0] ); + $sockets = Mage::helper('turpentine/varnish')->getSockets(); + $cfgr = Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract::getFromSocket($sockets[0]); return $cfgr; } - protected function _testEsiSyntaxParam( $socket ) { - $session = Mage::getSingleton( 'adminhtml/session' ); - $helper = Mage::helper( 'turpentine/varnish' ); + protected function _testEsiSyntaxParam($socket) { + $session = Mage::getSingleton('adminhtml/session'); + $helper = Mage::helper('turpentine/varnish'); $result = false; - if( $helper->csrfFixupNeeded() ) { - if ( $socket->getVersion()==='4.0' ) { + if ($helper->csrfFixupNeeded()) { + if ($socket->getVersion() === '4.0') { $paramName = 'feature'; - $value = $socket->param_show( $paramName ); + $value = $socket->param_show($paramName); $value = explode("\n", $value['text']); - if ( isset($value[1]) && strpos($value[1], '+esi_ignore_other_elements')!==false ) { + if (isset($value[1]) && strpos($value[1], '+esi_ignore_other_elements') !== false) { $result = true; } else { - $session->addWarning( 'Varnish feature param is ' . - 'not set correctly, please see these instructions ' . - 'to fix this warning.' ); + $session->addWarning('Varnish feature param is '. + 'not set correctly, please see these instructions '. + 'to fix this warning.'); } } else { $paramName = 'esi_syntax'; - $value = $socket->param_show( $paramName ); - if( preg_match( '~(\d)\s+\[bitmap\]~', $value['text'], $match ) ) { - $value = hexdec( $match[1] ); - if( $value & self::MASK_ESI_SYNTAX ) { //bitwise intentional + $value = $socket->param_show($paramName); + if (preg_match('~(\d)\s+\[bitmap\]~', $value['text'], $match)) { + $value = hexdec($match[1]); + if ($value & self::MASK_ESI_SYNTAX) { //bitwise intentional // setting is correct, all is fine $result = true; } else { - $session->addWarning( 'Varnish esi_syntax param is ' . - 'not set correctly, please see these instructions ' . - 'to fix this warning.' ); + $session->addWarning('Varnish esi_syntax param is '. + 'not set correctly, please see these instructions '. + 'to fix this warning.'); } } } - if ( $result===false ) { + if ($result === false) { // error - Mage::helper( 'turpentine/debug' )->logWarn( - sprintf('Failed to parse param.show output to check %s value', $paramName ) ); + Mage::helper('turpentine/debug')->logWarn( + sprintf('Failed to parse param.show output to check %s value', $paramName) ); $result = true; } } else { 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 68b9540ea..acca508dc 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -82,7 +82,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { // varnish default, can only be changed at Varnish startup time // if data to write is over this limit the actual run-time limit is checked // and used - const CLI_CMD_LENGTH_LIMIT = 8192; + const CLI_CMD_LENGTH_LIMIT = 8192; /** * Regexp to detect the varnish version number @@ -93,7 +93,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { /** * VCL config versions, should match config select values */ - static protected $_VERSIONS = array( '2.1', '3.0', '4.0' ); + static protected $_VERSIONS = array('2.1', '3.0', '4.0'); /** * Varnish socket connection @@ -108,23 +108,23 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { protected $_timeout = 5; protected $_version = null; //auto-detect - public function __construct( array $options=array() ) { - foreach( $options as $key => $value ) { - switch( $key ) { + public function __construct(array $options = array()) { + foreach ($options as $key => $value) { + switch ($key) { case 'host': - $this->setHost( $value ); + $this->setHost($value); break; case 'port': - $this->setPort( $value ); + $this->setPort($value); break; case 'auth_secret': - $this->setAuthSecret( $value ); + $this->setAuthSecret($value); break; case 'timeout': - $this->setTimeout( $value ); + $this->setTimeout($value); break; case 'version': - $this->setVersion( $value ); + $this->setVersion($value); break; default: break; @@ -157,10 +157,10 @@ public function __construct( array $options=array() ) { * @param array $args method args * @return array */ - public function __call( $name, $args ) { - array_unshift( $args, self::CODE_OK ); - array_unshift( $args, $this->_translateCommandMethod( $name ) ); - return call_user_func_array( array( $this, '_command' ), $args ); + public function __call($name, $args) { + array_unshift($args, self::CODE_OK); + array_unshift($args, $this->_translateCommandMethod($name)); + return call_user_func_array(array($this, '_command'), $args); } /** @@ -169,7 +169,7 @@ public function __call( $name, $args ) { * @return string */ public function getConnectionString() { - return sprintf( '%s:%d', $this->getHost(), $this->getPort() ); + return sprintf('%s:%d', $this->getHost(), $this->getPort()); } /** @@ -186,7 +186,7 @@ public function getHost() { * * @param string $host hostname or ip */ - public function setHost( $host ) { + public function setHost($host) { $this->_close(); $this->_host = $host; return $this; @@ -206,9 +206,9 @@ public function getPort() { * * @param int $port */ - public function setPort( $port ) { + public function setPort($port) { $this->_close(); - $this->_port = (int)$port; + $this->_port = (int) $port; return $this; } @@ -217,7 +217,7 @@ public function setPort( $port ) { * * @param string $authSecret */ - public function setAuthSecret( $authSecret=null ) { + public function setAuthSecret($authSecret = null) { $this->_authSecret = $authSecret; return $this; } @@ -227,10 +227,10 @@ public function setAuthSecret( $authSecret=null ) { * * @param int $timeout */ - public function setTimeout( $timeout ) { - $this->_timeout = (int)$timeout; - if( !is_null( $this->_varnishConn ) ) { - stream_set_timeout( $this->_varnishConn, $this->_timeout ); + public function setTimeout($timeout) { + $this->_timeout = (int) $timeout; + if ( ! is_null($this->_varnishConn)) { + stream_set_timeout($this->_varnishConn, $this->_timeout); } return $this; } @@ -240,11 +240,11 @@ public function setTimeout( $timeout ) { * * @param string $version version from $_VERSIONS */ - public function setVersion( $version ) { - if( in_array( $version, self::$_VERSIONS ) ) { + public function setVersion($version) { + if (in_array($version, self::$_VERSIONS)) { $this->_version = $version; } else { - Mage::throwException( 'Unsupported Varnish version: ' . $version ); + Mage::throwException('Unsupported Varnish version: '.$version); } } @@ -254,7 +254,7 @@ public function setVersion( $version ) { * @return boolean */ public function isConnected() { - return !is_null( $this->_varnishConn ); + return ! is_null($this->_varnishConn); } /** @@ -263,7 +263,7 @@ public function isConnected() { * @return string */ public function getVersion() { - if ( !$this->isConnected() ) { + if ( ! $this->isConnected()) { $this->_connect(); } return $this->_version; @@ -273,7 +273,7 @@ public function getVersion() { * Stop the Varnish instance */ public function quit() { - $this->_command( 'quit', self::CODE_CLOSE ); + $this->_command('quit', self::CODE_CLOSE); $this->_close(); } @@ -283,8 +283,8 @@ public function quit() { * @return boolean */ public function status() { - $response = $this->_command( 'status' ); - if( !preg_match( '~Child in state (\w+)~', $response['text'], $match ) ) { + $response = $this->_command('status'); + if ( ! preg_match('~Child in state (\w+)~', $response['text'], $match)) { return false; } else { return $match[1] === 'running'; @@ -297,8 +297,8 @@ public function status() { * @return $this */ public function stop() { - if( $this->status() ) { - $this->_command( 'stop' ); + if ($this->status()) { + $this->_command('stop'); } return $this; } @@ -309,40 +309,40 @@ public function stop() { * @return $this */ public function start() { - $this->_command( 'start' ); + $this->_command('start'); return $this; } /** * Establish a connection to the configured Varnish instance * - * @return array + * @return boolean */ protected function _connect() { - $this->_varnishConn = fsockopen( $this->_host, $this->_port, $errno, - $errstr, $this->_timeout ); - if( !is_resource( $this->_varnishConn ) ) { - Mage::throwException( sprintf( + $this->_varnishConn = fsockopen($this->_host, $this->_port, $errno, + $errstr, $this->_timeout); + if ( ! is_resource($this->_varnishConn)) { + Mage::throwException(sprintf( 'Failed to connect to Varnish on [%s:%d]: (%d) %s', - $this->_host, $this->_port, $errno, $errstr ) ); + $this->_host, $this->_port, $errno, $errstr )); } - stream_set_blocking( $this->_varnishConn, 1 ); - stream_set_timeout( $this->_varnishConn, $this->_timeout ); + stream_set_blocking($this->_varnishConn, 1); + stream_set_timeout($this->_varnishConn, $this->_timeout); //varnish 2.0 doesn't spit out a banner on connection, this will need //to be changed if 2.0 support is ever added $banner = $this->_read(); - if( $banner['code'] === self::CODE_AUTH ) { - $challenge = substr( $banner['text'], 0, 32 ); - $response = hash( 'sha256', sprintf( "%s\n%s%s\n", $challenge, - $this->_authSecret, $challenge ) ); - $banner = $this->_command( 'auth', self::CODE_OK, $response ); + if ($banner['code'] === self::CODE_AUTH) { + $challenge = substr($banner['text'], 0, 32); + $response = hash('sha256', sprintf("%s\n%s%s\n", $challenge, + $this->_authSecret, $challenge)); + $banner = $this->_command('auth', self::CODE_OK, $response); } - if( $banner['code'] !== self::CODE_OK ) { - Mage::throwException( 'Varnish admin authentication failed: ' . - $banner['text'] ); + if ($banner['code'] !== self::CODE_OK) { + Mage::throwException('Varnish admin authentication failed: '. + $banner['text']); } if ($this->_version == null) { // If autodetecting @@ -352,23 +352,26 @@ protected function _connect() { return $this->isConnected(); } + /** + * @param string $bannerText + */ protected function _determineVersion($bannerText) { $bannerText = array_filter(explode("\n", $bannerText)); - if ( count($bannerText)<6 ) { + if (count($bannerText) < 6) { // Varnish 2.0 does not spit out a banner on connect Mage::throwException('Varnish versions before 2.1 are not supported'); } - if ( count($bannerText)<7 ) { + if (count($bannerText) < 7) { // Varnish before 3.0.4 does not spit out a version number - $resp = $this->_write( 'help' )->_read(); - if( strpos( $resp['text'], 'ban.url' ) !== false ) { + $resp = $this->_write('help')->_read(); + if (strpos($resp['text'], 'ban.url') !== false) { // Varnish versions 3.0 through 3.0.3 do not return a version banner. // To differentiate between 2.1 and 3.0, we check the existence of the ban.url command. return '3.0'; } return '2.1'; - } elseif ( preg_match(self::REGEXP_VARNISH_VERSION, $bannerText[4], $matches)===1 ) { - return $matches['vmajor'] . '.' . $matches['vminor']; + } elseif (preg_match(self::REGEXP_VARNISH_VERSION, $bannerText[4], $matches) === 1) { + return $matches['vmajor'].'.'.$matches['vminor']; } else { Mage::throwException('Unable to detect varnish version'); } @@ -380,8 +383,8 @@ protected function _determineVersion($bannerText) { * @return $this */ protected function _close() { - if( $this->isConnected() ) { - fclose( $this->_varnishConn ); + if ($this->isConnected()) { + fclose($this->_varnishConn); $this->_varnishConn = null; } return $this; @@ -393,39 +396,39 @@ protected function _close() { * @param string $data data to write * @return $this */ - protected function _write( $data ) { - if( is_null( $this->_varnishConn ) ) { + protected function _write($data) { + if (is_null($this->_varnishConn)) { $this->_connect(); } - $data = rtrim( $data ) . PHP_EOL; - $dataLength = strlen( $data ); - if( $dataLength >= self::CLI_CMD_LENGTH_LIMIT ) { - $cliBufferResponse = $this->param_show( 'cli_buffer' ); + $data = rtrim($data).PHP_EOL; + $dataLength = strlen($data); + if ($dataLength >= self::CLI_CMD_LENGTH_LIMIT) { + $cliBufferResponse = $this->param_show('cli_buffer'); $regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~'; - if ( $this->getVersion()==='4.0' ) { + if ($this->getVersion() === '4.0') { // Varnish4 supports "16k" style notation $regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g]{1})?\s+\[bytes\]~'; } - if( preg_match( $regexp, $cliBufferResponse['text'], $match ) ) { - $realLimit = (int)$match[1]; - if ( isset($match[2]) ) { - $factors = array('k'=>1,'m'=>2,'g'=>3); + if (preg_match($regexp, $cliBufferResponse['text'], $match)) { + $realLimit = (int) $match[1]; + if (isset($match[2])) { + $factors = array('k'=>1, 'm'=>2, 'g'=>3); $realLimit *= pow(1024, $factors[$match[2]]); } } else { - Mage::helper( 'turpentine/debug' )->logWarn( + Mage::helper('turpentine/debug')->logWarn( 'Failed to determine Varnish cli_buffer limit, using default' ); $realLimit = self::CLI_CMD_LENGTH_LIMIT; } - if( $dataLength >= $realLimit ) { - Mage::throwException( sprintf( + if ($dataLength >= $realLimit) { + Mage::throwException(sprintf( 'Varnish data to write over length limit by %d characters', - $dataLength - $realLimit ) ); + $dataLength - $realLimit )); } } - if( ( $byteCount = fwrite( $this->_varnishConn, $data ) ) !== $dataLength ) { - Mage::throwException( sprintf( 'Varnish socket write error: %d != %d', - $byteCount, $dataLength ) ); + if (($byteCount = fwrite($this->_varnishConn, $data)) !== $dataLength) { + Mage::throwException(sprintf('Varnish socket write error: %d != %d', + $byteCount, $dataLength)); } return $this; } @@ -438,29 +441,29 @@ protected function _write( $data ) { protected function _read() { $code = null; $len = -1; - while( !feof( $this->_varnishConn ) ) { - $response = fgets( $this->_varnishConn, self::READ_CHUNK_SIZE ); - if( empty( $response ) ) { - $streamMeta = stream_get_meta_data( $this->_varnishConn ); - if( $streamMeta['timed_out'] ) { - Mage::throwException( 'Varnish admin socket timeout' ); + while ( ! feof($this->_varnishConn)) { + $response = fgets($this->_varnishConn, self::READ_CHUNK_SIZE); + if (empty($response)) { + $streamMeta = stream_get_meta_data($this->_varnishConn); + if ($streamMeta['timed_out']) { + Mage::throwException('Varnish admin socket timeout'); } } - if( preg_match( '~^(\d{3}) (\d+)~', $response, $match ) ) { - $code = (int)$match[1]; - $len = (int)$match[2]; + if (preg_match('~^(\d{3}) (\d+)~', $response, $match)) { + $code = (int) $match[1]; + $len = (int) $match[2]; break; } } - if( is_null( $code ) ) { - Mage::throwException( 'Failed to read response code from Varnish' ); + if (is_null($code)) { + Mage::throwException('Failed to read response code from Varnish'); } else { - $response = array( 'code' => $code, 'text' => '' ); - while( !feof( $this->_varnishConn ) && - strlen( $response['text'] ) < $len ) { - $response['text'] .= fgets( $this->_varnishConn, - self::READ_CHUNK_SIZE ); + $response = array('code' => $code, 'text' => ''); + while ( ! feof($this->_varnishConn) && + strlen($response['text']) < $len) { + $response['text'] .= fgets($this->_varnishConn, + self::READ_CHUNK_SIZE); } return $response; } @@ -469,32 +472,32 @@ protected function _read() { /** * [_command description] * @param string $verb command name - * @param integer $okCode=200 code that indicates command was successful + * @param integer $okCode code that indicates command was successful * @param string ... command args * @return array */ - protected function _command( $verb, $okCode=200 ) { + protected function _command($verb, $okCode = 200) { $params = func_get_args(); //remove $verb - array_shift( $params ); + array_shift($params); //remove $okCode (if it exists) - array_shift( $params ); + array_shift($params); $cleanedParams = array(); - foreach( $params as $param ) { - $cp = addcslashes( $param, "\"\\" ); - $cp = str_replace( PHP_EOL, '\n', $cp ); - $cleanedParams[] = sprintf( '"%s"', $cp ); + foreach ($params as $param) { + $cp = addcslashes($param, "\"\\"); + $cp = str_replace(PHP_EOL, '\n', $cp); + $cleanedParams[] = sprintf('"%s"', $cp); } - $data = implode( ' ', array_merge( - array( sprintf( '"%s"', $verb ) ), - $cleanedParams ) ); - $response = $this->_write( $data )->_read(); - if( $response['code'] !== $okCode && !is_null( $okCode ) ) { - Mage::helper( 'turpentine/debug' )->logDebug( + $data = implode(' ', array_merge( + array(sprintf('"%s"', $verb)), + $cleanedParams )); + $response = $this->_write($data)->_read(); + if ($response['code'] !== $okCode && ! is_null($okCode)) { + Mage::helper('turpentine/debug')->logDebug( 'Error on Varnish command: %s', $data ); - Mage::throwException( sprintf( + Mage::throwException(sprintf( "Got unexpected response code from Varnish: %d\n%s", - $response['code'], $response['text'] ) ); + $response['code'], $response['text'] )); } else { return $response; } @@ -512,7 +515,7 @@ protected function _translateCommandMethod( $verb ) { case '2.1': $command = str_replace( 'ban', 'purge', $command ); break; - case '4.0': + case '4.0': case '3.0': $command = str_replace( 'purge', 'ban', $command ); break; 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 393e00d04..c4808ef47 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -21,7 +21,7 @@ abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract { - const VCL_CUSTOM_C_CODE_FILE = 'uuid.c'; + const VCL_CUSTOM_C_CODE_FILE = 'uuid.c'; /** * Get the correct version of a configurator from a socket @@ -29,31 +29,31 @@ abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract { * @param Nexcessnet_Turpentine_Model_Varnish_Admin_Socket $socket * @return Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract */ - static public function getFromSocket( $socket ) { + static public function getFromSocket($socket) { try { $version = $socket->getVersion(); - } catch( Mage_Core_Exception $e ) { - Mage::getSingleton( 'core/session' ) - ->addError( 'Error determining Varnish version: ' . - $e->getMessage() ); + } catch (Mage_Core_Exception $e) { + Mage::getSingleton('core/session') + ->addError('Error determining Varnish version: '. + $e->getMessage()); return null; } - switch( $version ) { + switch ($version) { case '4.0': return Mage::getModel( 'turpentine/varnish_configurator_version4', - array( 'socket' => $socket ) ); + array('socket' => $socket) ); case '3.0': return Mage::getModel( 'turpentine/varnish_configurator_version3', - array( 'socket' => $socket ) ); + array('socket' => $socket) ); case '2.1': return Mage::getModel( 'turpentine/varnish_configurator_version2', - array( 'socket' => $socket ) ); + array('socket' => $socket) ); default: - Mage::throwException( 'Unsupported Varnish version' ); + Mage::throwException('Unsupported Varnish version'); } } @@ -72,11 +72,11 @@ static public function getFromSocket( $socket ) { 'vcl_template' => null, ); - public function __construct( $options=array() ) { - $this->_options = array_merge( $this->_options, $options ); + public function __construct($options = array()) { + $this->_options = array_merge($this->_options, $options); } - abstract public function generate($doClean=true); + abstract public function generate($doClean = true); // abstract protected function _getTemplateVars(); /** @@ -85,22 +85,22 @@ abstract public function generate($doClean=true); * @param string $generatedConfig config generated by @generate * @return null */ - public function save( $generatedConfig ) { + public function save($generatedConfig) { $filename = $this->_getVclFilename(); - $dir = dirname( $filename ); - if( !is_dir( $dir ) ) { + $dir = dirname($filename); + if ( ! is_dir($dir)) { // this umask is probably redundant, but just in case... - if( !mkdir( $dir, 0777 & ~umask(), true ) ) { + if ( ! mkdir($dir, 0777 & ~umask(), true)) { $err = error_get_last(); - return array( false, $err ); + return array(false, $err); } } - if( strlen( $generatedConfig ) !== - file_put_contents( $filename, $generatedConfig ) ) { + if (strlen($generatedConfig) !== + file_put_contents($filename, $generatedConfig)) { $err = error_get_last(); - return array( false, $err ); + return array(false, $err); } - return array( true, null ); + return array(true, null); } /** @@ -109,9 +109,9 @@ public function save( $generatedConfig ) { * @param string $baseFilename * @return string */ - protected function _getVclTemplateFilename( $baseFilename ) { - $extensionDir = Mage::getModuleDir( '', 'Nexcessnet_Turpentine' ); - return sprintf( '%s/misc/%s', $extensionDir, $baseFilename ); + protected function _getVclTemplateFilename($baseFilename) { + $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); + return sprintf('%s/misc/%s', $extensionDir, $baseFilename); } /** @@ -121,8 +121,8 @@ protected function _getVclTemplateFilename( $baseFilename ) { */ protected function _getVclFilename() { return $this->_formatTemplate( - Mage::getStoreConfig( 'turpentine_varnish/servers/config_file' ), - array( 'root_dir' => Mage::getBaseDir() ) ); + Mage::getStoreConfig('turpentine_varnish/servers/config_file'), + array('root_dir' => Mage::getBaseDir()) ); } /** @@ -132,8 +132,8 @@ protected function _getVclFilename() { */ protected function _getCustomIncludeFilename() { return $this->_formatTemplate( - Mage::getStoreConfig( 'turpentine_varnish/servers/custom_include_file' ), - array( 'root_dir' => Mage::getBaseDir() ) ); + Mage::getStoreConfig('turpentine_varnish/servers/custom_include_file'), + array('root_dir' => Mage::getBaseDir()) ); } /** @@ -144,13 +144,13 @@ protected function _getCustomIncludeFilename() { * @param array $vars array of key => value replacements * @return string */ - protected function _formatTemplate( $template, array $vars ) { - $needles = array_map( create_function( '$k', 'return "{{".$k."}}";' ), - array_keys( $vars ) ); - $replacements = array_values( $vars ); + protected function _formatTemplate($template, array $vars) { + $needles = array_map(create_function('$k', 'return "{{".$k."}}";'), + array_keys($vars)); + $replacements = array_values($vars); // do replacements, then delete unused template vars - return preg_replace( '~{{[^}]+}}~', '', - str_replace( $needles, $replacements, $template ) ); + return preg_replace('~{{[^}]+}}~', '', + str_replace($needles, $replacements, $template)); } /** @@ -159,8 +159,8 @@ protected function _formatTemplate( $template, array $vars ) { * @param string $subroutine subroutine name * @return string */ - protected function _vcl_call( $subroutine ) { - return sprintf( 'call %s;', $subroutine ); + protected function _vcl_call($subroutine) { + return sprintf('call %s;', $subroutine); } /** @@ -172,10 +172,10 @@ protected function _vcl_call( $subroutine ) { * @return string */ protected function _getAdminFrontname() { - if( Mage::getStoreConfig( 'admin/url/use_custom_path' ) ) { - return Mage::getStoreConfig( 'admin/url/custom_path' ); + if (Mage::getStoreConfig('admin/url/use_custom_path')) { + return Mage::getStoreConfig('admin/url/custom_path'); } else { - return (string)Mage::getConfig()->getNode( + return (string) Mage::getConfig()->getNode( 'admin/routers/adminhtml/args/frontName' ); } } @@ -186,14 +186,14 @@ protected function _getAdminFrontname() { * @return string */ protected function _getNormalizeHostTarget() { - $configHost = trim( Mage::getStoreConfig( - 'turpentine_vcl/normalization/host_target' ) ); - if( $configHost ) { + $configHost = trim(Mage::getStoreConfig( + 'turpentine_vcl/normalization/host_target' )); + if ($configHost) { return $configHost; } else { - $baseUrl = parse_url( Mage::getBaseUrl() ); - if( isset( $baseUrl['port'] ) ) { - return sprintf( '%s:%d', $baseUrl['host'], $baseUrl['port'] ); + $baseUrl = parse_url(Mage::getBaseUrl()); + if (isset($baseUrl['port'])) { + return sprintf('%s:%d', $baseUrl['host'], $baseUrl['port']); } else { return $baseUrl['host']; } @@ -210,11 +210,11 @@ protected function _getNormalizeHostTarget() { */ 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 ); + 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_values(array_unique($hosts)); $pattern = '('.implode('|', array_map("preg_quote", $hosts)).')'; return $pattern; @@ -232,8 +232,8 @@ protected function _vcl_sub_allowed_hosts_regex() { return (pass); } EOS; - return $this->_formatTemplate( $tpl, array( - 'allowed_hosts_regex' => $this->getAllowedHostsRegex() ) ); + return $this->_formatTemplate($tpl, array( + 'allowed_hosts_regex' => $this->getAllowedHostsRegex() )); } /** @@ -246,9 +246,9 @@ protected function _vcl_sub_allowed_hosts_regex() { */ public function getBaseUrlPathRegex() { $pattern = '^(%s)(?:(?:index|litespeed)\\.php/)?'; - return sprintf( $pattern, implode( '|', - array_map( create_function( '$x', 'return preg_quote($x,"|");' ), - $this->_getBaseUrlPaths() ) ) ); + return sprintf($pattern, implode('|', + array_map(create_function('$x', 'return preg_quote($x,"|");'), + $this->_getBaseUrlPaths()))); } /** @@ -258,22 +258,22 @@ public function getBaseUrlPathRegex() { */ protected function _getBaseUrlPaths() { $paths = array(); - $linkTypes = array( Mage_Core_Model_Store::URL_TYPE_LINK, + $linkTypes = array(Mage_Core_Model_Store::URL_TYPE_LINK, Mage_Core_Model_Store::URL_TYPE_JS, Mage_Core_Model_Store::URL_TYPE_SKIN, - Mage_Core_Model_Store::URL_TYPE_MEDIA ); - foreach( Mage::app()->getStores() as $store ) { - foreach( $linkTypes as $linkType ) { - $paths[] = parse_url( $store->getBaseUrl( $linkType , false ), - PHP_URL_PATH ); - $paths[] = parse_url( $store->getBaseUrl( $linkType , true ), - PHP_URL_PATH ); + Mage_Core_Model_Store::URL_TYPE_MEDIA); + foreach (Mage::app()->getStores() as $store) { + foreach ($linkTypes as $linkType) { + $paths[] = parse_url($store->getBaseUrl($linkType, false), + PHP_URL_PATH); + $paths[] = parse_url($store->getBaseUrl($linkType, true), + PHP_URL_PATH); } } - $paths = array_unique( $paths ); - usort( $paths, create_function( '$a, $b', - 'return strlen( $b ) - strlen( $a );' ) ); - return array_values( $paths ); + $paths = array_unique($paths); + usort($paths, create_function('$a, $b', + 'return strlen( $b ) - strlen( $a );')); + return array_values($paths); } /** @@ -283,9 +283,9 @@ protected function _getBaseUrlPaths() { * @return string */ protected function _getUrlExcludes() { - $urls = Mage::getStoreConfig( 'turpentine_vcl/urls/url_blacklist' ); - return implode( '|', array_merge( array( $this->_getAdminFrontname(), 'api' ), - Mage::helper( 'turpentine/data' )->cleanExplode( PHP_EOL, $urls ) ) ); + $urls = Mage::getStoreConfig('turpentine_vcl/urls/url_blacklist'); + return implode('|', array_merge(array($this->_getAdminFrontname(), 'api'), + Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, $urls))); } /** @@ -294,7 +294,7 @@ protected function _getUrlExcludes() { * @return string */ protected function _getDefaultTtl() { - return Mage::helper( 'turpentine/varnish' )->getDefaultTtl(); + return Mage::helper('turpentine/varnish')->getDefaultTtl(); } /** @@ -303,18 +303,18 @@ protected function _getDefaultTtl() { * @return string */ protected function _getDefaultBackend() { - $timeout = Mage::getStoreConfig( 'turpentine_vcl/backend/frontend_timeout' ); + $timeout = Mage::getStoreConfig('turpentine_vcl/backend/frontend_timeout'); $default_options = array( - 'first_byte_timeout' => $timeout . 's', - 'between_bytes_timeout' => $timeout . 's', + 'first_byte_timeout' => $timeout.'s', + 'between_bytes_timeout' => $timeout.'s', ); - if ( Mage::getStoreConfig( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) { - return $this->_vcl_director( 'default', $default_options ); + if (Mage::getStoreConfig('turpentine_vcl/backend/load_balancing') != 'no') { + return $this->_vcl_director('default', $default_options); } else { - return $this->_vcl_backend( 'default', - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_host' ), - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_port' ), - $default_options ); + return $this->_vcl_backend('default', + Mage::getStoreConfig('turpentine_vcl/backend/backend_host'), + Mage::getStoreConfig('turpentine_vcl/backend/backend_port'), + $default_options); } } @@ -324,18 +324,18 @@ protected function _getDefaultBackend() { * @return string */ protected function _getAdminBackend() { - $timeout = Mage::getStoreConfig( 'turpentine_vcl/backend/admin_timeout' ); + $timeout = Mage::getStoreConfig('turpentine_vcl/backend/admin_timeout'); $admin_options = array( - 'first_byte_timeout' => $timeout . 's', - 'between_bytes_timeout' => $timeout . 's', + 'first_byte_timeout' => $timeout.'s', + 'between_bytes_timeout' => $timeout.'s', ); - if ( Mage::getStoreConfig( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) { - return $this->_vcl_director( 'admin', $admin_options ); + if (Mage::getStoreConfig('turpentine_vcl/backend/load_balancing') != 'no') { + return $this->_vcl_director('admin', $admin_options); } else { - return $this->_vcl_backend( 'admin', - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_host' ), - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_port' ), - $admin_options ); + return $this->_vcl_backend('admin', + Mage::getStoreConfig('turpentine_vcl/backend/backend_host'), + Mage::getStoreConfig('turpentine_vcl/backend/backend_port'), + $admin_options); } } @@ -348,7 +348,7 @@ protected function _getAdminBackend() { * @return string */ protected function _getGracePeriod() { - return Mage::getStoreConfig( 'turpentine_vcl/ttls/grace_period' ); + return Mage::getStoreConfig('turpentine_vcl/ttls/grace_period'); } /** @@ -357,7 +357,7 @@ protected function _getGracePeriod() { * @return string */ protected function _getEnableDebugHeaders() { - return Mage::getStoreConfig( 'turpentine_varnish/general/varnish_debug' ) + return Mage::getStoreConfig('turpentine_varnish/general/varnish_debug') ? 'true' : 'false'; } @@ -367,16 +367,16 @@ protected function _getEnableDebugHeaders() { * @return string */ protected function _getGetParamExcludes() { - return implode( '|', Mage::helper( 'turpentine/data' )->cleanExplode( ',', - Mage::getStoreConfig( 'turpentine_vcl/params/get_params' ) ) ); + return implode('|', Mage::helper('turpentine/data')->cleanExplode(',', + Mage::getStoreConfig('turpentine_vcl/params/get_params'))); } protected function _getIgnoreGetParameters() { /** @var Nexcessnet_Turpentine_Helper_Data $helper */ $helper = Mage::helper('turpentine'); - $ignoredParameters = $helper->cleanExplode(',', Mage::getStoreConfig( 'turpentine_vcl/params/ignore_get_params')); - return implode( '|', $ignoredParameters); + $ignoredParameters = $helper->cleanExplode(',', Mage::getStoreConfig('turpentine_vcl/params/ignore_get_params')); + return implode('|', $ignoredParameters); } /** @@ -393,7 +393,7 @@ protected function _sendUnModifiedUrlToBackend() * @return string */ protected function _getGenerateSessionStart() { - return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) + return Mage::getStoreConfig('turpentine_varnish/general/vcl_fix') ? '/* -- REMOVED' : ''; } @@ -403,7 +403,7 @@ protected function _getGenerateSessionStart() { * @return string */ protected function _getGenerateSessionEnd() { - return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) + return Mage::getStoreConfig('turpentine_varnish/general/vcl_fix') ? '-- */' : ''; } @@ -414,7 +414,7 @@ protected function _getGenerateSessionEnd() { * @return string */ protected function _getGenerateSession() { - return Mage::getStoreConfigFlag( 'turpentine_varnish/general/vcl_fix' ) + return Mage::getStoreConfigFlag('turpentine_varnish/general/vcl_fix') ? 'return (pipe);' : 'call generate_session;'; } @@ -425,7 +425,7 @@ protected function _getGenerateSession() { * @return string */ protected function _getGenerateSessionExpires() { - return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' ) + return Mage::getStoreConfig('turpentine_varnish/general/vcl_fix') ? '# call generate_session_expires' : 'call generate_session_expires;'; } @@ -435,7 +435,7 @@ protected function _getGenerateSessionExpires() { * @return string */ protected function _getForceCacheStatic() { - return Mage::getStoreConfig( 'turpentine_vcl/static/force_static' ) + return Mage::getStoreConfig('turpentine_vcl/static/force_static') ? 'true' : 'false'; } @@ -445,8 +445,8 @@ protected function _getForceCacheStatic() { * @return string */ protected function _getStaticExtensions() { - return implode( '|', Mage::helper( 'turpentine/data' )->cleanExplode( ',', - Mage::getStoreConfig( 'turpentine_vcl/static/exts' ) ) ); + return implode('|', Mage::helper('turpentine/data')->cleanExplode(',', + Mage::getStoreConfig('turpentine_vcl/static/exts'))); } /** @@ -455,7 +455,7 @@ protected function _getStaticExtensions() { * @return string */ protected function _getStaticTtl() { - return Mage::getStoreConfig( 'turpentine_vcl/ttls/static_ttl' ); + return Mage::getStoreConfig('turpentine_vcl/ttls/static_ttl'); } /** @@ -465,22 +465,22 @@ protected function _getStaticTtl() { */ protected function _getUrlTtls() { $str = array(); - $configTtls = Mage::helper( 'turpentine/data' )->cleanExplode( PHP_EOL, - Mage::getStoreConfig( 'turpentine_vcl/ttls/url_ttls' ) ); + $configTtls = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/ttls/url_ttls')); $ttls = array(); - foreach( $configTtls as $line ) { - $ttls[] = explode( ',', trim( $line ) ); + foreach ($configTtls as $line) { + $ttls[] = explode(',', trim($line)); } - foreach( $ttls as $ttl ) { - $str[] = sprintf( 'if (bereq.url ~ "%s%s") { set beresp.ttl = %ds; }', - $this->getBaseUrlPathRegex(), $ttl[0], $ttl[1] ); + foreach ($ttls as $ttl) { + $str[] = sprintf('if (bereq.url ~ "%s%s") { set beresp.ttl = %ds; }', + $this->getBaseUrlPathRegex(), $ttl[0], $ttl[1]); } - $str = implode( ' else ', $str ); - if( $str ) { - $str .= sprintf( ' else { set beresp.ttl = %ds; }', - $this->_getDefaultTtl() ); + $str = implode(' else ', $str); + if ($str) { + $str .= sprintf(' else { set beresp.ttl = %ds; }', + $this->_getDefaultTtl()); } else { - $str = sprintf( 'set beresp.ttl = %ds;', $this->_getDefaultTtl() ); + $str = sprintf('set beresp.ttl = %ds;', $this->_getDefaultTtl()); } return $str; } @@ -491,7 +491,7 @@ protected function _getUrlTtls() { * @return string */ protected function _getEnableCaching() { - return Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ? + return Mage::helper('turpentine/varnish')->getVarnishEnabled() ? 'true' : 'false'; } @@ -501,8 +501,8 @@ protected function _getEnableCaching() { * @return array */ protected function _getDebugIps() { - return Mage::helper( 'turpentine/data' )->cleanExplode( ',', - Mage::getStoreConfig( 'dev/restrict/allow_ips' ) ); + return Mage::helper('turpentine/data')->cleanExplode(',', + Mage::getStoreConfig('dev/restrict/allow_ips')); } /** @@ -511,8 +511,8 @@ protected function _getDebugIps() { * @return array */ protected function _getCrawlerIps() { - return Mage::helper( 'turpentine/data' )->cleanExplode( ',', - Mage::getStoreConfig( 'turpentine_vcl/backend/crawlers' ) ); + return Mage::helper('turpentine/data')->cleanExplode(',', + Mage::getStoreConfig('turpentine_vcl/backend/crawlers')); } /** @@ -521,10 +521,10 @@ protected function _getCrawlerIps() { * @return string */ protected function _getCrawlerUserAgents() { - return implode( '|', Mage::helper( 'turpentine/data' ) - ->cleanExplode( ',', + return implode('|', Mage::helper('turpentine/data') + ->cleanExplode(',', Mage::getStoreConfig( - 'turpentine_vcl/backend/crawler_user_agents' ) ) ); + 'turpentine_vcl/backend/crawler_user_agents' ))); } /** @@ -535,7 +535,7 @@ protected function _getCrawlerUserAgents() { * @return string */ protected function _getLruFactor() { - return Mage::getStoreConfig( 'turpentine_vcl/ttls/lru_factor' ); + return Mage::getStoreConfig('turpentine_vcl/ttls/lru_factor'); } /** @@ -548,19 +548,19 @@ protected function _getLruFactor() { */ protected function _getAdvancedSessionValidationTargets() { $validation = array(); - if( Mage::getStoreConfig( 'web/session/use_remote_addr' ) ) { + if (Mage::getStoreConfig('web/session/use_remote_addr')) { $validation[] = 'client.ip'; } - if( Mage::getStoreConfig( 'web/session/use_http_via' ) ) { + if (Mage::getStoreConfig('web/session/use_http_via')) { $validation[] = 'req.http.Via'; } - if( Mage::getStoreConfig( 'web/session/use_http_x_forwarded_for' ) ) { + if (Mage::getStoreConfig('web/session/use_http_x_forwarded_for')) { $validation[] = 'req.http.X-Forwarded-For'; } - if( Mage::getStoreConfig( + if (Mage::getStoreConfig( 'web/session/use_http_user_agent' ) && - !Mage::getStoreConfig( - 'turpentine_vcl/normalization/user_agent' ) ) { + ! Mage::getStoreConfig( + 'turpentine_vcl/normalization/user_agent' )) { $validation[] = 'req.http.User-Agent'; } return $validation; @@ -572,12 +572,12 @@ protected function _getAdvancedSessionValidationTargets() { * @param string $dirtyVcl generated vcl * @return string */ - protected function _cleanVcl( $dirtyVcl ) { - return implode( PHP_EOL, + protected function _cleanVcl($dirtyVcl) { + return implode(PHP_EOL, array_filter( - Mage::helper( 'turpentine/data' ) - ->cleanExplode( PHP_EOL, $dirtyVcl ), - array( $this, '_cleanVclHelper' ) + Mage::helper('turpentine/data') + ->cleanExplode(PHP_EOL, $dirtyVcl), + array($this, '_cleanVclHelper') ) ); } @@ -588,11 +588,11 @@ protected function _cleanVcl( $dirtyVcl ) { * @param string $line * @return bool */ - protected function _cleanVclHelper( $line ) { + protected function _cleanVclHelper($line) { return $line && - ( ( substr( $line, 0, 1 ) != '#' && - substr( $line, 0, 2 ) != '//' ) || - substr( $line, 0, 8 ) == '#include' ); + ((substr($line, 0, 1) != '#' && + substr($line, 0, 2) != '//') || + substr($line, 0, 8) == '#include'); } /** @@ -604,7 +604,7 @@ protected function _cleanVclHelper( $line ) { * @param array $options options * @return string */ - protected function _vcl_backend( $name, $host, $port, $options=array() ) { + protected function _vcl_backend($name, $host, $port, $options = array()) { $tpl = << $port, 'name' => $name, ); - $str = $this->_formatTemplate( $tpl, $vars ); - foreach( $options as $key => $value ) { - $str .= sprintf( ' .%s = %s;', $key, $value ) . PHP_EOL; + $str = $this->_formatTemplate($tpl, $vars); + foreach ($options as $key => $value) { + $str .= sprintf(' .%s = %s;', $key, $value).PHP_EOL; } - $str .= '}' . PHP_EOL; + $str .= '}'.PHP_EOL; return $str; } @@ -631,33 +631,33 @@ protected function _vcl_backend( $name, $host, $port, $options=array() ) { * @param array $backendOptions options for each backend * @return string */ - protected function _vcl_director( $name, $backendOptions ) { + protected function _vcl_director($name, $backendOptions) { $tpl = <<cleanExplode( PHP_EOL, - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_nodes_admin' ) ); - $probeUrl = Mage::getStoreConfig( 'turpentine_vcl/backend/backend_probe_url_admin' ); + if ('admin' == $name && 'yes_admin' == Mage::getStoreConfig('turpentine_vcl/backend/load_balancing')) { + $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes_admin')); + $probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url_admin'); } else { - $backendNodes = Mage::helper( 'turpentine/data' )->cleanExplode( PHP_EOL, - Mage::getStoreConfig( 'turpentine_vcl/backend/backend_nodes' ) ); - $probeUrl = Mage::getStoreConfig( 'turpentine_vcl/backend/backend_probe_url' ); + $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); + $probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url'); } $backends = ''; - foreach ( $backendNodes as $backendNode ) { - $parts = explode( ':', $backendNode, 2 ); - $host = ( empty($parts[0]) ) ? '127.0.0.1' : $parts[0]; - $port = ( empty($parts[1]) ) ? '80' : $parts[1]; - $backends .= $this->_vcl_director_backend( $host, $port, $probeUrl, $backendOptions ); + foreach ($backendNodes as $backendNode) { + $parts = explode(':', $backendNode, 2); + $host = (empty($parts[0])) ? '127.0.0.1' : $parts[0]; + $port = (empty($parts[1])) ? '80' : $parts[1]; + $backends .= $this->_vcl_director_backend($host, $port, $probeUrl, $backendOptions); } $vars = array( 'name' => $name, 'backends' => $backends ); - return $this->_formatTemplate( $tpl, $vars ); + return $this->_formatTemplate($tpl, $vars); } /** @@ -669,7 +669,7 @@ protected function _vcl_director( $name, $backendOptions ) { * @param array $options extra options for backend * @return string */ - protected function _vcl_director_backend( $host, $port, $probeUrl='', $options=array() ) { + protected function _vcl_director_backend($host, $port, $probeUrl = '', $options = array()) { $tpl = << $port, 'probe' => '' ); - if ( !empty( $probeUrl ) ) { - $vars['probe'] = $this->_vcl_get_probe( $probeUrl ); + if ( ! empty($probeUrl)) { + $vars['probe'] = $this->_vcl_get_probe($probeUrl); } - $str = $this->_formatTemplate( $tpl, $vars ); - foreach( $options as $key => $value ) { - $str .= sprintf( ' .%s = %s;', $key, $value ) . PHP_EOL; + $str = $this->_formatTemplate($tpl, $vars); + foreach ($options as $key => $value) { + $str .= sprintf(' .%s = %s;', $key, $value).PHP_EOL; } $str .= << $urlParts['host'], 'probe_path' => $urlParts['path'] ); - return $this->_formatTemplate( $tpl, $vars ); + return $this->_formatTemplate($tpl, $vars); } } @@ -732,18 +732,18 @@ protected function _vcl_get_probe( $probeUrl ) { * @param array $hosts list of hosts to add to the ACL * @return string */ - protected function _vcl_acl( $name, array $hosts ) { + protected function _vcl_acl($name, array $hosts) { $tpl = << $name, - 'hosts' => implode( "\n ", array_map( $fmtHost, $hosts ) ), + 'hosts' => implode("\n ", array_map($fmtHost, $hosts)), ); - return $this->_formatTemplate( $tpl, $vars ); + return $this->_formatTemplate($tpl, $vars); } /** @@ -809,8 +809,8 @@ protected function _vcl_sub_normalize_host() { set req.http.Host = "{{normalize_host_target}}"; EOS; - return $this->_formatTemplate( $tpl, array( - 'normalize_host_target' => $this->_getNormalizeHostTarget() ) ); + return $this->_formatTemplate($tpl, array( + 'normalize_host_target' => $this->_getNormalizeHostTarget() )); } /** @@ -819,8 +819,8 @@ protected function _vcl_sub_normalize_host() { * @return string */ protected function _getNormalizeCookieTarget() { - return trim( Mage::getStoreConfig( - 'turpentine_vcl/normalization/cookie_target' ) ); + return trim(Mage::getStoreConfig( + 'turpentine_vcl/normalization/cookie_target' )); } /** @@ -829,8 +829,8 @@ protected function _getNormalizeCookieTarget() { * @return string */ protected function _getNormalizeCookieRegex() { - return trim( Mage::getStoreConfig( - 'turpentine_vcl/normalization/cookie_regex' ) ); + return trim(Mage::getStoreConfig( + 'turpentine_vcl/normalization/cookie_regex' )); } /** @@ -839,11 +839,11 @@ protected function _getNormalizeCookieRegex() { * @return string */ protected function _vcl_sub_maintenance_allowed_ips() { - if((! $this->_getDebugIps()) || ! Mage::getStoreConfig( 'turpentine_vcl/maintenance/custom_vcl_synth' ) ) { + if (( ! $this->_getDebugIps()) || ! Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth')) { return false; } - switch(Mage::getStoreConfig( 'turpentine_varnish/servers/version' )) { + switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) { case 4.0: $tpl = <<_formatTemplate( $tpl, array( - 'debug_ips' => Mage::getStoreConfig( 'dev/restrict/allow_ips' ) ) ); + return $this->_formatTemplate($tpl, array( + 'debug_ips' => Mage::getStoreConfig('dev/restrict/allow_ips') )); } /** @@ -884,7 +884,7 @@ protected function _vcl_sub_maintenance_allowed_ips() { */ protected function _vcl_sub_synth() { - if ((!$this->_getDebugIps()) || !Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth')) { + if (( ! $this->_getDebugIps()) || ! Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth')) { return false; } @@ -950,46 +950,46 @@ protected function _getTemplateVars() { 'static_ttl' => $this->_getStaticTtl(), 'url_ttls' => $this->_getUrlTtls(), 'enable_caching' => $this->_getEnableCaching(), - 'crawler_acl' => $this->_vcl_acl( 'crawler_acl', - $this->_getCrawlerIps() ), + 'crawler_acl' => $this->_vcl_acl('crawler_acl', + $this->_getCrawlerIps()), 'esi_cache_type_param' => - Mage::helper( 'turpentine/esi' )->getEsiCacheTypeParam(), + Mage::helper('turpentine/esi')->getEsiCacheTypeParam(), 'esi_method_param' => - Mage::helper( 'turpentine/esi' )->getEsiMethodParam(), - 'esi_ttl_param' => Mage::helper( 'turpentine/esi' )->getEsiTtlParam(), - 'secret_handshake' => Mage::helper( 'turpentine/varnish' ) + Mage::helper('turpentine/esi')->getEsiMethodParam(), + 'esi_ttl_param' => Mage::helper('turpentine/esi')->getEsiTtlParam(), + 'secret_handshake' => Mage::helper('turpentine/varnish') ->getSecretHandshake(), 'crawler_user_agent_regex' => $this->_getCrawlerUserAgents(), // 'lru_factor' => $this->_getLruFactor(), - 'debug_acl' => $this->_vcl_acl( 'debug_acl', - $this->_getDebugIps() ), + 'debug_acl' => $this->_vcl_acl('debug_acl', + $this->_getDebugIps()), 'custom_c_code' => file_get_contents( - $this->_getVclTemplateFilename( self::VCL_CUSTOM_C_CODE_FILE ) ), - 'esi_private_ttl' => Mage::helper( 'turpentine/esi' ) + $this->_getVclTemplateFilename(self::VCL_CUSTOM_C_CODE_FILE) ), + 'esi_private_ttl' => Mage::helper('turpentine/esi') ->getDefaultEsiTtl(), ); - if( (bool)Mage::getStoreConfig( 'turpentine_vcl/urls/bypass_cache_store_url') ) { + 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' ) ) { + if (Mage::getStoreConfig('turpentine_vcl/normalization/encoding')) { $vars['normalize_encoding'] = $this->_vcl_sub_normalize_encoding(); } - if( Mage::getStoreConfig( 'turpentine_vcl/normalization/user_agent' ) ) { + if (Mage::getStoreConfig('turpentine_vcl/normalization/user_agent')) { $vars['normalize_user_agent'] = $this->_vcl_sub_normalize_user_agent(); } - if( Mage::getStoreConfig( 'turpentine_vcl/normalization/host' ) ) { + if (Mage::getStoreConfig('turpentine_vcl/normalization/host')) { $vars['normalize_host'] = $this->_vcl_sub_normalize_host(); } - if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_regex' ) ) { + if (Mage::getStoreConfig('turpentine_vcl/normalization/cookie_regex')) { $vars['normalize_cookie_regex'] = $this->_getNormalizeCookieRegex(); } - if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_target' ) ) { + if (Mage::getStoreConfig('turpentine_vcl/normalization/cookie_target')) { $vars['normalize_cookie_target'] = $this->_getNormalizeCookieTarget(); } - if( Mage::getStoreConfig( 'turpentine_vcl/maintenance/enable' ) ) { + if (Mage::getStoreConfig('turpentine_vcl/maintenance/enable')) { // in vcl_recv set the allowed IPs otherwise load the vcl_error (v3)/vcl_synth (v4) $vars['maintenance_allowed_ips'] = $this->_vcl_sub_maintenance_allowed_ips(); // set the vcl_error from Magento database @@ -997,8 +997,8 @@ protected function _getTemplateVars() { } $customIncludeFile = $this->_getCustomIncludeFilename(); - if( is_readable( $customIncludeFile ) ) { - $vars['custom_vcl_include'] = file_get_contents( $customIncludeFile ); + if (is_readable($customIncludeFile)) { + $vars['custom_vcl_include'] = file_get_contents($customIncludeFile); } return $vars; diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php index 2ac5e2e62..4b9136473 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php @@ -34,7 +34,7 @@ public function generate($doClean=true) { $tplFile = $this->_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), $this->_getTemplateVars() ); - return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; + return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; } protected function _getAdvancedSessionValidation() { diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php index be6c7a382..745ec6076 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php @@ -30,17 +30,17 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3 * @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) * @return string */ - public function generate($doClean=true) { - $tplFile = $this->_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); - $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), - $this->_getTemplateVars() ); - return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; + public function generate($doClean = true) { + $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + $vcl = $this->_formatTemplate(file_get_contents($tplFile), + $this->_getTemplateVars()); + return $doClean ? $this->_cleanVcl($vcl) : $vcl; } protected function _getAdvancedSessionValidation() { $validation = ''; - foreach( $this->_getAdvancedSessionValidationTargets() as $target ) { - $validation .= sprintf( 'hash_data(%s);' . PHP_EOL, $target ); + foreach ($this->_getAdvancedSessionValidationTargets() as $target) { + $validation .= sprintf('hash_data(%s);'.PHP_EOL, $target); } return $validation; } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 6b5fe55d1..08641fa24 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -37,7 +37,7 @@ public function generate($doClean=true) { return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; } - // TODO: Check this + // TODO: Check this protected function _getAdvancedSessionValidation() { $validation = ''; foreach( $this->_getAdvancedSessionValidationTargets() as $target ) { diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php index 74ca7cfce..5161fb5b3 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php @@ -1,8 +1,8 @@ addSuccess(Mage::helper('adminhtml')->__("Full page cache has been disabled since Varnish cache is enabled.")); + Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Full page cache has been disabled since Varnish cache is enabled.")); } else if ($allTypes['full_page']==1) { - Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Turpentine cache has been disabled since Full Page cache is enabled.")); - } + Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Turpentine cache has been disabled since Full Page cache is enabled.")); + } // disable FPC when Varnish cache is enabled. Mage::app()->saveUseCache($allTypes); $this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("%s cache type(s) enabled.", $updatedTypes)); diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 8d2521bba..fb66776ab 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -27,7 +27,7 @@ class Nexcessnet_Turpentine_EsiController extends Mage_Core_Controller_Front_Act * @return null */ public function indexAction() { - $this->getResponse()->setRedirect( Mage::getBaseUrl() ); + $this->getResponse()->setRedirect(Mage::getBaseUrl()); } /** @@ -38,16 +38,16 @@ public function indexAction() { public function getFormKeyAction() { $resp = $this->getResponse(); $resp->setBody( - Mage::getSingleton( 'core/session' )->real_getFormKey() ); - $resp->setHeader( 'X-Turpentine-Cache', '1' ); - $resp->setHeader( 'X-Turpentine-Flush-Events', - implode( ',', Mage::helper( 'turpentine/esi' ) - ->getDefaultCacheClearEvents() ) ); - $resp->setHeader( 'X-Turpentine-Block', 'form_key' ); - Mage::register( 'turpentine_nocache_flag', false, true ); + Mage::getSingleton('core/session')->real_getFormKey() ); + $resp->setHeader('X-Turpentine-Cache', '1'); + $resp->setHeader('X-Turpentine-Flush-Events', + implode(',', Mage::helper('turpentine/esi') + ->getDefaultCacheClearEvents())); + $resp->setHeader('X-Turpentine-Block', 'form_key'); + Mage::register('turpentine_nocache_flag', false, true); - Mage::helper( 'turpentine/debug' )->logDebug( 'Generated form_key: %s', - $resp->getBody() ); + Mage::helper('turpentine/debug')->logDebug('Generated form_key: %s', + $resp->getBody()); } /** @@ -58,89 +58,89 @@ public function getFormKeyAction() { public function getBlockAction() { $resp = $this->getResponse(); $cacheFlag = false; - if( Mage::helper( 'turpentine/esi' )->shouldResponseUseEsi() ) { + if (Mage::helper('turpentine/esi')->shouldResponseUseEsi()) { $req = $this->getRequest(); - $esiHelper = Mage::helper( 'turpentine/esi' ); - $dataHelper = Mage::helper( 'turpentine/data' ); - $debugHelper = Mage::helper( 'turpentine/debug' ); - $esiDataHmac = $req->getParam( $esiHelper->getEsiHmacParam() ); - $esiDataParamValue = $req->getParam( $esiHelper->getEsiDataParam() ); - if( $esiDataHmac !== ( $hmac = $dataHelper->getHmac( $esiDataParamValue ) ) ) { - $debugHelper->logWarn( 'ESI data HMAC mismatch, expected (%s) but received (%s)', - $hmac, $esiDataHmac ); - $resp->setHttpResponseCode( 500 ); - $resp->setBody( 'ESI data is not valid' ); - } elseif( !( $esiDataArray = $dataHelper->thaw( $esiDataParamValue ) ) ) { - $debugHelper->logWarn( 'Invalid ESI data in URL: %s', - $esiDataParamValue ); - $resp->setHttpResponseCode( 500 ); - $resp->setBody( 'ESI data is not valid' ); - } elseif( !$esiHelper->getEsiDebugEnabled() && + $esiHelper = Mage::helper('turpentine/esi'); + $dataHelper = Mage::helper('turpentine/data'); + $debugHelper = Mage::helper('turpentine/debug'); + $esiDataHmac = $req->getParam($esiHelper->getEsiHmacParam()); + $esiDataParamValue = $req->getParam($esiHelper->getEsiDataParam()); + if ($esiDataHmac !== ($hmac = $dataHelper->getHmac($esiDataParamValue))) { + $debugHelper->logWarn('ESI data HMAC mismatch, expected (%s) but received (%s)', + $hmac, $esiDataHmac); + $resp->setHttpResponseCode(500); + $resp->setBody('ESI data is not valid'); + } elseif ( ! ($esiDataArray = $dataHelper->thaw($esiDataParamValue))) { + $debugHelper->logWarn('Invalid ESI data in URL: %s', + $esiDataParamValue); + $resp->setHttpResponseCode(500); + $resp->setBody('ESI data is not valid'); + } elseif ( ! $esiHelper->getEsiDebugEnabled() && $esiDataArray['esi_method'] !== - $req->getParam( $esiHelper->getEsiMethodParam() ) ) { - $resp->setHttpResponseCode( 403 ); - $resp->setBody( 'ESI method mismatch' ); - $debugHelper->logWarn( 'Blocking change of ESI method: %s -> %s', + $req->getParam($esiHelper->getEsiMethodParam())) { + $resp->setHttpResponseCode(403); + $resp->setBody('ESI method mismatch'); + $debugHelper->logWarn('Blocking change of ESI method: %s -> %s', $esiDataArray['esi_method'], - $req->getParam( $esiHelper->getEsiMethodParam() ) ); + $req->getParam($esiHelper->getEsiMethodParam())); } else { - $esiData = new Varien_Object( $esiDataArray ); + $esiData = new Varien_Object($esiDataArray); $origRequest = Mage::app()->getRequest(); Mage::app()->setCurrentStore( - Mage::app()->getStore( $esiData->getStoreId() ) ); - $appShim = Mage::getModel( 'turpentine/shim_mage_core_app' ); - if( $referer = $this->_getRefererUrl() ) { - $referer = htmlspecialchars_decode( $referer ); - $dummyRequest = Mage::helper( 'turpentine/esi' ) - ->getDummyRequest( $referer ); + Mage::app()->getStore($esiData->getStoreId()) ); + $appShim = Mage::getModel('turpentine/shim_mage_core_app'); + if ($referer = $this->_getRefererUrl()) { + $referer = htmlspecialchars_decode($referer); + $dummyRequest = Mage::helper('turpentine/esi') + ->getDummyRequest($referer); } else { - $dummyRequest = Mage::helper( 'turpentine/esi' ) + $dummyRequest = Mage::helper('turpentine/esi') ->getDummyRequest(); } - $appShim->shim_setRequest( $dummyRequest ); - $block = $this->_getEsiBlock( $esiData ); - if( $block ) { + $appShim->shim_setRequest($dummyRequest); + $block = $this->_getEsiBlock($esiData); + if ($block) { $blockEsiOptions = $block->getEsiOptions(); - $block->setEsiOptions( false ); - $resp->setBody( $block->toHtml() ); - if( (int)$req->getParam( $esiHelper->getEsiTtlParam() ) > 0 ) { + $block->setEsiOptions(false); + $resp->setBody($block->toHtml()); + if ((int) $req->getParam($esiHelper->getEsiTtlParam()) > 0) { $cacheFlag = true; - if ( isset( $blockEsiOptions['only_cache_if'] ) ) { - switch ( $blockEsiOptions['only_cache_if'] ) { + if (isset($blockEsiOptions['only_cache_if'])) { + switch ($blockEsiOptions['only_cache_if']) { case 'empty': - $cacheFlag = ( '' === $resp->getBody() ); + $cacheFlag = ('' === $resp->getBody()); break; case 'no_text': - $cacheFlag = ( '' === trim( strip_tags( $resp->getBody() ) ) ); + $cacheFlag = ('' === trim(strip_tags($resp->getBody()))); break; default: $cacheFlag = false; } } } - if( $esiData->getEsiMethod() == 'ajax' ) { - $resp->setHeader( 'Access-Control-Allow-Origin', - $esiHelper->getCorsOrigin() ); + if ($esiData->getEsiMethod() == 'ajax') { + $resp->setHeader('Access-Control-Allow-Origin', + $esiHelper->getCorsOrigin()); } - if( !is_null( $flushEvents = $esiData->getFlushEvents() ) ) { - $resp->setHeader( 'X-Turpentine-Flush-Events', - implode( ',', $flushEvents ) ); + if ( ! is_null($flushEvents = $esiData->getFlushEvents())) { + $resp->setHeader('X-Turpentine-Flush-Events', + implode(',', $flushEvents)); } - if( $esiHelper->getEsiDebugEnabled() ) { - $resp->setHeader( 'X-Turpentine-Block', - $block->getNameInLayout() ); + if ($esiHelper->getEsiDebugEnabled()) { + $resp->setHeader('X-Turpentine-Block', + $block->getNameInLayout()); } } else { - $resp->setHttpResponseCode( 404 ); - $resp->setBody( 'ESI block not found' ); + $resp->setHttpResponseCode(404); + $resp->setBody('ESI block not found'); } - $appShim->shim_setRequest( $origRequest ); + $appShim->shim_setRequest($origRequest); } } else { - $resp->setHttpResponseCode( 403 ); - $resp->setBody( 'ESI includes are not enabled' ); + $resp->setHttpResponseCode(403); + $resp->setBody('ESI includes are not enabled'); } - Mage::register( 'turpentine_nocache_flag', !$cacheFlag, true ); + Mage::register('turpentine_nocache_flag', ! $cacheFlag, true); } /** @@ -152,10 +152,10 @@ public function getBlockAction() { * @return null */ public function postDispatch() { - $flag = $this->getFlag( '', self::FLAG_NO_START_SESSION ); - $this->setFlag( '', self::FLAG_NO_START_SESSION, true ); + $flag = $this->getFlag('', self::FLAG_NO_START_SESSION); + $this->setFlag('', self::FLAG_NO_START_SESSION, true); parent::postDispatch(); - $this->setFlag( '', self::FLAG_NO_START_SESSION, $flag ); + $this->setFlag('', self::FLAG_NO_START_SESSION, $flag); } /** @@ -164,25 +164,25 @@ public function postDispatch() { * @param Varien_Object $esiData * @return Mage_Core_Block_Template|null */ - protected function _getEsiBlock( $esiData ) { + protected function _getEsiBlock($esiData) { $block = null; - Varien_Profiler::start( 'turpentine::controller::esi::_getEsiBlock' ); - foreach( $esiData->getSimpleRegistry() as $key => $value ) { - Mage::register( $key, $value, true ); + Varien_Profiler::start('turpentine::controller::esi::_getEsiBlock'); + foreach ($esiData->getSimpleRegistry() as $key => $value) { + Mage::register($key, $value, true); } - foreach( $esiData->getComplexRegistry() as $key => $data ) { - $value = Mage::getModel( $data['model'] ); - if( !is_object( $value ) ) { - Mage::helper( 'turpentine/debug' )->logWarn( + foreach ($esiData->getComplexRegistry() as $key => $data) { + $value = Mage::getModel($data['model']); + if ( ! is_object($value)) { + Mage::helper('turpentine/debug')->logWarn( 'Failed to register key/model: %s as %s(%s)', $key, $data['model'], $data['id'] ); continue; } else { - $value->load( $data['id'] ); - Mage::register( $key, $value, true ); + $value->load($data['id']); + Mage::register($key, $value, true); } } - $layout = Mage::getSingleton( 'core/layout' ); + $layout = Mage::getSingleton('core/layout'); // dispatch event for adding handles to layout update Mage::dispatchEvent( @@ -191,13 +191,13 @@ protected function _getEsiBlock( $esiData ) { ); $layoutUpdate = $layout->getUpdate(); - $layoutUpdate->load( $this->_swapCustomerHandles( - $esiData->getLayoutHandles() ) ); - foreach( $esiData->getDummyBlocks() as $blockName ) { - $layout->createBlock( 'Mage_Core_Block_Template', $blockName ); + $layoutUpdate->load($this->_swapCustomerHandles( + $esiData->getLayoutHandles() )); + foreach ($esiData->getDummyBlocks() as $blockName) { + $layout->createBlock('Mage_Core_Block_Template', $blockName); } - if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { Mage::dispatchEvent( 'controller_action_layout_generate_xml_before', array('action'=>$this, 'layout'=>$layout) @@ -206,33 +206,33 @@ protected function _getEsiBlock( $esiData ) { $layout->generateXml(); /** @var Nexcessnet_Turpentine_Helper_Data $turpentineHelper */ - $turpentineHelper = Mage::helper( 'turpentine/data' ) - ->setLayout( $layout ); + $turpentineHelper = Mage::helper('turpentine/data') + ->setLayout($layout); - $blockNode = current( $layout->getNode()->xpath( - sprintf('//block[@name=\'%s\']',$esiData->getNameInLayout()) - ) ); + $blockNode = current($layout->getNode()->xpath( + sprintf('//block[@name=\'%s\']', $esiData->getNameInLayout()) + )); - if( ! ($blockNode instanceof Mage_Core_Model_Layout_Element) ) { - Mage::helper( 'turpentine/debug' )->logWarn( + if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { + Mage::helper('turpentine/debug')->logWarn( 'No block node found with @name="%s"', $esiData->getNameInLayout() ); return null; } - $nodesToGenerate = $turpentineHelper->getChildBlockNames( $blockNode ); - Mage::getModel( 'turpentine/shim_mage_core_layout' ) - ->shim_generateFullBlock( $blockNode ); + $nodesToGenerate = $turpentineHelper->getChildBlockNames($blockNode); + Mage::getModel('turpentine/shim_mage_core_layout') + ->shim_generateFullBlock($blockNode); //find addional blocks that aren't defined in the but via - $referenceNodes = $layout->getNode()->xpath( sprintf( + $referenceNodes = $layout->getNode()->xpath(sprintf( '//reference[@name=\'%s\']', - $esiData->getNameInLayout() ) ); + $esiData->getNameInLayout() )); if ($referenceNodes) { foreach ($referenceNodes as $referenceNode) { if ($referenceNode instanceof Mage_Core_Model_Layout_Element) { $referencesToGenerate = $turpentineHelper - ->getChildBlockNames( $referenceNode ); + ->getChildBlockNames($referenceNode); $nodesToGenerate = array_merge($nodesToGenerate, $referencesToGenerate); } @@ -240,22 +240,22 @@ protected function _getEsiBlock( $esiData ) { } // dispatch event for adding xml layout elements - if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { Mage::dispatchEvent( 'controller_action_layout_generate_blocks_before', array('action'=>$this, 'layout'=>$layout) ); } - foreach( array_unique($nodesToGenerate) as $nodeName ) { - foreach( $layout->getNode()->xpath( sprintf( - '//reference[@name=\'%s\']', $nodeName ) ) as $node ) { - $layout->generateBlocks( $node ); + foreach (array_unique($nodesToGenerate) as $nodeName) { + foreach ($layout->getNode()->xpath(sprintf( + '//reference[@name=\'%s\']', $nodeName )) as $node) { + $layout->generateBlocks($node); } } - $block = $layout->getBlock( $esiData->getNameInLayout() ); + $block = $layout->getBlock($esiData->getNameInLayout()); - if(!$this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { + if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { Mage::dispatchEvent( 'controller_action_layout_generate_blocks_after', array('action'=>$this, 'layout'=>$layout) @@ -263,7 +263,7 @@ protected function _getEsiBlock( $esiData ) { } $this->_isLayoutLoaded = true; - Varien_Profiler::stop( 'turpentine::controller::esi::_getEsiBlock' ); + Varien_Profiler::stop('turpentine::controller::esi::_getEsiBlock'); return $block; } @@ -277,13 +277,13 @@ protected function _getEsiBlock( $esiData ) { * @param array $handles * @return array */ - protected function _swapCustomerHandles( $handles ) { - if( Mage::helper( 'customer' )->isLoggedIn() ) { - $replacement = array( 'customer_logged_out', 'customer_logged_in' ); + protected function _swapCustomerHandles($handles) { + if (Mage::helper('customer')->isLoggedIn()) { + $replacement = array('customer_logged_out', 'customer_logged_in'); } else { - $replacement = array( 'customer_logged_in', 'customer_logged_out' ); + $replacement = array('customer_logged_in', 'customer_logged_out'); } - if( ( $pos = array_search( $replacement[0], $handles ) ) !== false ) { + if (($pos = array_search($replacement[0], $handles)) !== false) { $handles[$pos] = $replacement[1]; } return $handles; diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php index 1db2b4d5a..a5bbd7e65 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php @@ -44,20 +44,20 @@ public function indexAction() { * @return null */ public function flushAllAction() { - Mage::dispatchEvent( 'turpentine_varnish_flush_all' ); - $result = Mage::getModel( 'turpentine/varnish_admin' )->flushAll(); - foreach( $result as $name => $value ) { - if( $value === true ) { + Mage::dispatchEvent('turpentine_varnish_flush_all'); + $result = Mage::getModel('turpentine/varnish_admin')->flushAll(); + foreach ($result as $name => $value) { + if ($value === true) { $this->_getSession() - ->addSuccess( Mage::helper( 'turpentine/data' ) - ->__( 'Flushed Varnish cache for: ' ) . $name ); + ->addSuccess(Mage::helper('turpentine/data') + ->__('Flushed Varnish cache for: ').$name); } else { $this->_getSession() - ->addError( Mage::helper( 'turpentine/data' ) - ->__( 'Error flushing Varnish cache on: ' ) . $name ); + ->addError(Mage::helper('turpentine/data') + ->__('Error flushing Varnish cache on: ').$name); } } - $this->_redirect( '*/cache' ); + $this->_redirect('*/cache'); } /** @@ -68,27 +68,27 @@ public function flushAllAction() { */ public function flushPartialAction() { $postData = $this->getRequest()->getPost(); - if( !isset( $postData['pattern'] ) ) { - $this->_getSession()->addError( $this->__( 'Missing URL post data' ) ); + if ( ! isset($postData['pattern'])) { + $this->_getSession()->addError($this->__('Missing URL post data')); } else { $pattern = $postData['pattern']; - Mage::dispatchEvent( 'turpentine_varnish_flush_partial', - array( 'pattern' => $pattern ) ); - $result = Mage::getModel( 'turpentine/varnish_admin' ) - ->flushUrl( $pattern ); - foreach( $result as $name => $value ) { - if( $value === true ) { + Mage::dispatchEvent('turpentine_varnish_flush_partial', + array('pattern' => $pattern)); + $result = Mage::getModel('turpentine/varnish_admin') + ->flushUrl($pattern); + foreach ($result as $name => $value) { + if ($value === true) { $this->_getSession() - ->addSuccess( Mage::helper( 'turpentine/data' ) - ->__( 'Flushed matching URLs for: ' ) . $name ); + ->addSuccess(Mage::helper('turpentine/data') + ->__('Flushed matching URLs for: ').$name); } else { $this->_getSession() - ->addError( Mage::helper( 'turpentine/data' ) - ->__( 'Error flushing matching URLs on: ' ) . $name ); + ->addError(Mage::helper('turpentine/data') + ->__('Error flushing matching URLs on: ').$name); } } } - $this->_redirect( '*/cache' ); + $this->_redirect('*/cache'); } /** @@ -98,23 +98,23 @@ public function flushPartialAction() { */ public function flushContentTypeAction() { $postData = $this->getRequest()->getPost(); - if( !isset( $postData['ctype'] ) ) { - $this->_getSession()->addError( $this->__( 'Missing URL post data' ) ); + if ( ! isset($postData['ctype'])) { + $this->_getSession()->addError($this->__('Missing URL post data')); } else { $ctype = $postData['ctype']; - Mage::dispatchEvent( 'turpentine_varnish_flush_content_type', - array( 'ctype' => $ctype ) ); - $result = Mage::getModel( 'turpentine/varnish_admin' ) - ->flushContentType( $ctype ); - foreach( $result as $name => $value ) { - if( $value === true ) { + Mage::dispatchEvent('turpentine_varnish_flush_content_type', + array('ctype' => $ctype)); + $result = Mage::getModel('turpentine/varnish_admin') + ->flushContentType($ctype); + foreach ($result as $name => $value) { + if ($value === true) { $this->_getSession() - ->addSuccess( Mage::helper( 'turpentine/data' ) - ->__( 'Flushed matching content-types for: ' ) . $name ); + ->addSuccess(Mage::helper('turpentine/data') + ->__('Flushed matching content-types for: ').$name); } else { $this->_getSession() - ->addError( Mage::helper( 'turpentine/data' ) - ->__( 'Error flushing matching content-types on: ' ) . $name ); + ->addError(Mage::helper('turpentine/data') + ->__('Error flushing matching content-types on: ').$name); } } } @@ -127,18 +127,18 @@ public function flushContentTypeAction() { * @return null */ public function applyConfigAction() { - Mage::dispatchEvent( 'turpentine_varnish_apply_config' ); - $result = Mage::getModel( 'turpentine/varnish_admin' )->applyConfig(); - foreach( $result as $name => $value ) { - if( $value === true ) { + Mage::dispatchEvent('turpentine_varnish_apply_config'); + $result = Mage::getModel('turpentine/varnish_admin')->applyConfig(); + foreach ($result as $name => $value) { + if ($value === true) { $this->_getSession() - ->addSuccess( Mage::helper( 'turpentine' ) - ->__( 'VCL successfully applied to ' . $name ) ); + ->addSuccess(Mage::helper('turpentine') + ->__('VCL successfully applied to '.$name)); } else { $this->_getSession() - ->addError( Mage::helper( 'turpentine' ) - ->__( sprintf( 'Failed to apply the VCL to %s: %s', - $name, $value ) ) ); + ->addError(Mage::helper('turpentine') + ->__(sprintf('Failed to apply the VCL to %s: %s', + $name, $value))); } } $this->_redirect('*/cache'); @@ -158,7 +158,7 @@ public function saveConfigAction() { Mage::dispatchEvent( 'turpentine_varnish_save_config', array( 'cfgr' => $cfgr ) ); $result = $cfgr->save( $cfgr->generate( - Mage::helper('turpentine')->shouldStripVclWhitespace('save') ) ); + Mage::helper('turpentine')->shouldStripVclWhitespace('save') ) ); if( $result[0] ) { $this->_getSession() ->addSuccess( Mage::helper('turpentine') @@ -185,7 +185,7 @@ public function getConfigAction() { $this->_redirect( '*/cache' ); } else { $vcl = $cfgr->generate( - Mage::helper( 'turpentine' )->shouldStripVclWhitespace('download') ); + Mage::helper( 'turpentine' )->shouldStripVclWhitespace('download') ); $this->getResponse() ->setHttpResponseCode( 200 ) ->setHeader( 'Content-Type', 'text/plain', true ) @@ -203,39 +203,39 @@ public function getConfigAction() { * @return void */ public function switchNavigationAction() { - $type = $this->getRequest()->get( 'type' ); - if( is_null( $type ) ) { - $this->_redirect( 'noRoute' ); + $type = $this->getRequest()->get('type'); + if (is_null($type)) { + $this->_redirect('noRoute'); return; } - $cookieName = Mage::helper( 'turpentine' )->getBypassCookieName(); - $cookieModel = Mage::getModel( 'core/cookie' ); - $adminSession = Mage::getSingleton( 'adminhtml/session' ); + $cookieName = Mage::helper('turpentine')->getBypassCookieName(); + $cookieModel = Mage::getModel('core/cookie'); + $adminSession = Mage::getSingleton('adminhtml/session'); - switch( $type ) { + switch ($type) { case 'default': $cookieModel->set( $cookieName, - Mage::helper( 'turpentine/varnish' )->getSecretHandshake(), + Mage::helper('turpentine/varnish')->getSecretHandshake(), null, // period null, // path null, // domain false, // secure true ); // httponly - $adminSession->addSuccess( Mage::helper( 'turpentine/data' ) - ->__( 'The Varnish bypass cookie has been successfully added.' ) ); + $adminSession->addSuccess(Mage::helper('turpentine/data') + ->__('The Varnish bypass cookie has been successfully added.')); break; case 'varnish': - $cookieModel->delete( $cookieName ); - $adminSession->addSuccess( Mage::helper( 'turpentine/data' ) - ->__( 'The Varnish bypass cookie has been successfully removed.' ) ); + $cookieModel->delete($cookieName); + $adminSession->addSuccess(Mage::helper('turpentine/data') + ->__('The Varnish bypass cookie has been successfully removed.')); break; default: - $adminSession->addError( Mage::helper( 'turpentine/data' ) - ->__( 'The given navigation type is not supported!' ) ); + $adminSession->addError(Mage::helper('turpentine/data') + ->__('The given navigation type is not supported!')); break; } diff --git a/contrib/tools/esi-decoder.php b/contrib/tools/esi-decoder.php index 7e066ac20..20ae29055 100644 --- a/contrib/tools/esi-decoder.php +++ b/contrib/tools/esi-decoder.php @@ -1,31 +1,31 @@ @@ -79,9 +79,9 @@ $esiDataArray = $dataHelper->thaw( $processData ); $showContentUrl = Mage::getUrl( 'turpentine/esi/getBlock', array( 'method' => 'esi', - 'ttl' => 0, - 'hmac' => $dataHelper->getHmac( $processData ), - 'data' => $processData ) ); + 'ttl' => 0, + 'hmac' => $dataHelper->getHmac( $processData ), + 'data' => $processData ) ); ?>
            =  DATA  =
            diff --git a/util/varnishadm.php b/util/varnishadm.php index 535f61cf5..efa39c383 100755 --- a/util/varnishadm.php +++ b/util/varnishadm.php @@ -20,7 +20,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -require_once( dirname( $_SERVER['argv'][0] ) . '/abstract.php' ); +require_once(dirname($_SERVER['argv'][0]).'/abstract.php'); class Turpentine_Shell_Varnishadm extends Mage_Shell_Abstract { /** @@ -30,16 +30,16 @@ class Turpentine_Shell_Varnishadm extends Mage_Shell_Abstract { */ protected function _parseArgs() { $this->_args = array_slice( - array_filter( $_SERVER['argv'], - create_function( '$e', - 'return $e != \'--\';' ) ), + array_filter($_SERVER['argv'], + create_function('$e', + 'return $e != \'--\';')), 1 ); return $this; } protected function _write() { $args = func_get_args(); - return call_user_func_array( 'printf', $args ); + return call_user_func_array('printf', $args); } /** @@ -48,13 +48,13 @@ protected function _write() { * @return null */ public function run() { - $command = str_replace( '.', '_', $this->_args[0] ); - $params = array_slice( $this->_args, 1 ); - foreach( Mage::helper( 'turpentine/varnish' )->getSockets() as $socket ) { - $response = call_user_func_array( array( $socket, $command ), $params ); - $this->_write( "=== Result from server [%s]: %d ===\n%s\n", + $command = str_replace('.', '_', $this->_args[0]); + $params = array_slice($this->_args, 1); + foreach (Mage::helper('turpentine/varnish')->getSockets() as $socket) { + $response = call_user_func_array(array($socket, $command), $params); + $this->_write("=== Result from server [%s]: %d ===\n%s\n", $socket->getConnectionString(), $response['code'], - $response['text'] ); + $response['text']); } } From e419a546dc81982d30142acd6c1283eaf9dbb438 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Thu, 15 Oct 2015 13:25:05 +0000 Subject: [PATCH 206/311] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- .../Nexcessnet/Turpentine/Helper/Data.php | 4 +- .../Nexcessnet/Turpentine/Helper/Debug.php | 4 +- .../Model/Config/Select/Version.php | 8 ++-- .../Turpentine/Model/Observer/Esi.php | 44 +++++++++--------- .../Model/Shim/Mage/Core/Config.php | 4 +- .../Turpentine/Model/Varnish/Admin.php | 24 +++++----- .../Turpentine/Model/Varnish/Admin/Socket.php | 14 +++--- .../Model/Varnish/Configurator/Version2.php | 14 +++--- .../Model/Varnish/Configurator/Version4.php | 14 +++--- .../controllers/Adminhtml/CacheController.php | 4 +- .../Varnish/ManagementController.php | 46 +++++++++---------- contrib/tools/esi-decoder.php | 28 +++++------ 12 files changed, 105 insertions(+), 103 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index 2f5b1ad63..040252c15 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -298,9 +298,9 @@ public function getStripVclWhitespace() { */ public function shouldStripVclWhitespace($action) { $configValue = $this->getStripVclWhitespace(); - if ( $configValue==='always' ) { + if ($configValue === 'always') { return true; - } elseif ( $configValue==='apply' && $action==='apply' ) { + } elseif ($configValue === 'apply' && $action === 'apply') { return true; } return false; diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php b/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php index 4fbb7ed61..102120dd5 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Debug.php @@ -218,7 +218,7 @@ protected function _log($level, $message) { * @return string */ protected function _getLogFileName() { - if ( $this->useCustomLogFile() ) { + if ($this->useCustomLogFile()) { return $this->getCustomLogFileName(); } return ''; @@ -238,7 +238,7 @@ public function useCustomLogFile() { * @return string */ public function getCustomLogFileName() { - return (string)Mage::getStoreConfig( + return (string) Mage::getStoreConfig( 'turpentine_varnish/logging/custom_log_file_name' ); } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php index df21d3600..e88251213 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php @@ -23,10 +23,10 @@ class Nexcessnet_Turpentine_Model_Config_Select_Version { public function toOptionArray() { $helper = Mage::helper('turpentine'); return array( - array( 'value' => '2.1', 'label' => $helper->__( '2.1.x' ) ), - array( 'value' => '3.0', 'label' => $helper->__( '3.0.x' ) ), - array( 'value' => '4.0', 'label' => $helper->__( '4.0.x' ) ), - array( 'value' => 'auto', 'label' => $helper->__( 'Auto' ) ), + array('value' => '2.1', 'label' => $helper->__('2.1.x')), + array('value' => '3.0', 'label' => $helper->__('3.0.x')), + array('value' => '4.0', 'label' => $helper->__('4.0.x')), + array('value' => 'auto', 'label' => $helper->__('Auto')), ); } } \ No newline at end of file diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 800cfb486..1e37fc8a9 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -254,59 +254,59 @@ public function injectEsi($eventObject) { $scopeParam = $esiHelper->getEsiScopeParam(); $referrerParam = $esiHelper->getEsiReferrerParam(); - $esiOptions = $this->_getDefaultEsiOptions( $esiOptions ); + $esiOptions = $this->_getDefaultEsiOptions($esiOptions); // change the block's template to the stripped down ESI template - switch( $esiOptions[$methodParam] ) { + switch ($esiOptions[$methodParam]) { case 'ajax': - $blockObject->setTemplate( 'turpentine/ajax.phtml' ); + $blockObject->setTemplate('turpentine/ajax.phtml'); break; case 'esi': default: - $blockObject->setTemplate( 'turpentine/esi.phtml' ); + $blockObject->setTemplate('turpentine/esi.phtml'); // flag request for ESI processing - Mage::register( 'turpentine_esi_flag', true, true ); + Mage::register('turpentine_esi_flag', true, true); } // esi data is the data needed to regenerate the ESI'd block - $esiData = $this->_getEsiData( $blockObject, $esiOptions )->toArray(); - ksort( $esiData ); - $frozenData = $dataHelper->freeze( $esiData ); + $esiData = $this->_getEsiData($blockObject, $esiOptions)->toArray(); + ksort($esiData); + $frozenData = $dataHelper->freeze($esiData); $urlOptions = array( $methodParam => $esiOptions[$methodParam], $cacheTypeParam => $esiOptions[$cacheTypeParam], $ttlParam => $esiOptions[$ttlParam], - $hmacParam => $dataHelper->getHmac( $frozenData ), + $hmacParam => $dataHelper->getHmac($frozenData), $dataParam => $frozenData, ); - if( $esiOptions[$methodParam] == 'ajax' ) { + if ($esiOptions[$methodParam] == 'ajax') { $urlOptions['_secure'] = Mage::app()->getStore() ->isCurrentlySecure(); } - if( $esiOptions[$scopeParam] == 'page' ) { - $urlOptions[$referrerParam] = Mage::helper('core')->urlEncode( + if ($esiOptions[$scopeParam] == 'page') { + $urlOptions[$referrerParam] = Mage::helper('core')->urlEncode( Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true)) ); } - $esiUrl = Mage::getUrl( 'turpentine/esi/getBlock', $urlOptions ); - if( $esiOptions[$methodParam] == 'esi' ) { + $esiUrl = Mage::getUrl('turpentine/esi/getBlock', $urlOptions); + if ($esiOptions[$methodParam] == 'esi') { // setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS - $esiUrl = preg_replace( '|^https://|i', 'http://', $esiUrl ); + $esiUrl = preg_replace('|^https://|i', 'http://', $esiUrl); } - $blockObject->setEsiUrl( $esiUrl ); + $blockObject->setEsiUrl($esiUrl); // avoid caching the ESI template output to prevent the double-esi- // include/"ESI processing not enabled" bug - foreach( array( 'lifetime', 'tags', 'key' ) as $dataKey ) { - $blockObject->unsetData( 'cache_' . $dataKey ); + foreach (array('lifetime', 'tags', 'key') as $dataKey) { + $blockObject->unsetData('cache_'.$dataKey); } - if( strlen( $esiUrl ) > 2047 ) { - Mage::helper( 'turpentine/debug' )->logWarn( + if (strlen($esiUrl) > 2047) { + Mage::helper('turpentine/debug')->logWarn( 'ESI url is probably too long (%d > 2047 characters): %s', - strlen( $esiUrl ), $esiUrl ); + strlen($esiUrl), $esiUrl ); } - Varien_Profiler::stop( 'turpentine::observer::esi::injectEsi' ); + Varien_Profiler::stop('turpentine::observer::esi::injectEsi'); } // else handle the block like normal and cache it inline with the page } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php index d3a25d0c9..eee96bfd9 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Shim/Mage/Core/Config.php @@ -46,8 +46,10 @@ public function shim_setClassNameCache($groupType, $group, $class, $className) { */ public function unsetEventAreaCache($area) { if (version_compare(Mage::getVersion(), '1.11.0', '>=') // enterprise - || version_compare(Mage::getVersion(), '1.6.0', '>=')) // community + || version_compare(Mage::getVersion(), '1.6.0', '>=')) { + // community unset($this->_eventAreas[$area]); + } } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 1543ed66d..6dbb2115d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -96,22 +96,22 @@ public function flushContentType($contentType) { */ public function applyConfig() { $result = array(); - $helper = Mage::helper( 'turpentine' ); - foreach( Mage::helper( 'turpentine/varnish' )->getSockets() as $socket ) { - $cfgr = Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract::getFromSocket( $socket ); + $helper = Mage::helper('turpentine'); + foreach (Mage::helper('turpentine/varnish')->getSockets() as $socket) { + $cfgr = Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract::getFromSocket($socket); $socketName = $socket->getConnectionString(); - if( is_null( $cfgr ) ) { + if (is_null($cfgr)) { $result[$socketName] = 'Failed to load configurator'; } else { - $vcl = $cfgr->generate( $helper->shouldStripVclWhitespace('apply') ); - $vclName = Mage::helper( 'turpentine/data' ) - ->secureHash( microtime() ); + $vcl = $cfgr->generate($helper->shouldStripVclWhitespace('apply')); + $vclName = Mage::helper('turpentine/data') + ->secureHash(microtime()); try { - $this->_testEsiSyntaxParam( $socket ); - $socket->vcl_inline( $vclName, $vcl ); - sleep( 1 ); //this is probably not really needed - $socket->vcl_use( $vclName ); - } catch( Mage_Core_Exception $e ) { + $this->_testEsiSyntaxParam($socket); + $socket->vcl_inline($vclName, $vcl); + sleep(1); //this is probably not really needed + $socket->vcl_use($vclName); + } catch (Mage_Core_Exception $e) { $result[$socketName] = $e->getMessage(); continue; } 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 acca508dc..4c6e14b48 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -509,19 +509,19 @@ protected function _command($verb, $okCode = 200) { * @param string $verb command to check * @return string */ - protected function _translateCommandMethod( $verb ) { - $command = str_replace( '_', '.', $verb ); - switch( $this->getVersion() ) { + protected function _translateCommandMethod($verb) { + $command = str_replace('_', '.', $verb); + switch ($this->getVersion()) { case '2.1': - $command = str_replace( 'ban', 'purge', $command ); + $command = str_replace('ban', 'purge', $command); break; case '4.0': case '3.0': - $command = str_replace( 'purge', 'ban', $command ); + $command = str_replace('purge', 'ban', $command); break; default: - Mage::throwException( 'Unrecognized Varnish version: ' . - $this->_version ); + Mage::throwException('Unrecognized Varnish version: '. + $this->_version); } return $command; } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php index 4b9136473..170153981 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php @@ -30,17 +30,17 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version2 * @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) * @return string */ - public function generate($doClean=true) { - $tplFile = $this->_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); - $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), - $this->_getTemplateVars() ); - return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; + public function generate($doClean = true) { + $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + $vcl = $this->_formatTemplate(file_get_contents($tplFile), + $this->_getTemplateVars()); + return $doClean ? $this->_cleanVcl($vcl) : $vcl; } protected function _getAdvancedSessionValidation() { $validation = ''; - foreach( $this->_getAdvancedSessionValidationTargets() as $target ) { - $validation .= sprintf( 'set req.hash += %s;' . PHP_EOL, $target ); + foreach ($this->_getAdvancedSessionValidationTargets() as $target) { + $validation .= sprintf('set req.hash += %s;'.PHP_EOL, $target); } return $validation; } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 08641fa24..273c09f1a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -30,18 +30,18 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version4 * @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) * @return string */ - public function generate($doClean=true) { - $tplFile = $this->_getVclTemplateFilename( self::VCL_TEMPLATE_FILE ); - $vcl = $this->_formatTemplate( file_get_contents( $tplFile ), - $this->_getTemplateVars() ); - return $doClean ? $this->_cleanVcl( $vcl ) : $vcl; + public function generate($doClean = true) { + $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + $vcl = $this->_formatTemplate(file_get_contents($tplFile), + $this->_getTemplateVars()); + return $doClean ? $this->_cleanVcl($vcl) : $vcl; } // TODO: Check this protected function _getAdvancedSessionValidation() { $validation = ''; - foreach( $this->_getAdvancedSessionValidationTargets() as $target ) { - $validation .= sprintf( 'hash_data(%s);' . PHP_EOL, $target ); + foreach ($this->_getAdvancedSessionValidationTargets() as $target) { + $validation .= sprintf('hash_data(%s);'.PHP_EOL, $target); } return $validation; } diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php index 5161fb5b3..561e4c930 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php @@ -26,11 +26,11 @@ public function massEnableAction() } if ($updatedTypes > 0) { // disable FPC when Varnish cache is enabled: - if($allTypes['turpentine_pages']==1 || $allTypes['turpentine_esi_blocks']==1) + if ($allTypes['turpentine_pages'] == 1 || $allTypes['turpentine_esi_blocks'] == 1) { $allTypes['full_page'] = 0; Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Full page cache has been disabled since Varnish cache is enabled.")); - } else if ($allTypes['full_page']==1) { + } else if ($allTypes['full_page'] == 1) { Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Turpentine cache has been disabled since Full Page cache is enabled.")); } // disable FPC when Varnish cache is enabled. diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php index a5bbd7e65..0472d4e62 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php @@ -150,23 +150,23 @@ public function applyConfigAction() { * @return null */ public function saveConfigAction() { - $cfgr = Mage::getModel( 'turpentine/varnish_admin' )->getConfigurator(); - if( is_null( $cfgr ) ) { + $cfgr = Mage::getModel('turpentine/varnish_admin')->getConfigurator(); + if (is_null($cfgr)) { $this->_getSession()->addError( - $this->__( 'Failed to load configurator' ) ); + $this->__('Failed to load configurator') ); } else { - Mage::dispatchEvent( 'turpentine_varnish_save_config', - array( 'cfgr' => $cfgr ) ); - $result = $cfgr->save( $cfgr->generate( - Mage::helper('turpentine')->shouldStripVclWhitespace('save') ) ); - if( $result[0] ) { + Mage::dispatchEvent('turpentine_varnish_save_config', + array('cfgr' => $cfgr)); + $result = $cfgr->save($cfgr->generate( + Mage::helper('turpentine')->shouldStripVclWhitespace('save') )); + if ($result[0]) { $this->_getSession() - ->addSuccess( Mage::helper('turpentine') - ->__('The VCL file has been saved.' ) ); + ->addSuccess(Mage::helper('turpentine') + ->__('The VCL file has been saved.')); } else { $this->_getSession() - ->addError( Mage::helper('turpentine') - ->__('Failed to save the VCL file: ' . $result[1]['message'] ) ); + ->addError(Mage::helper('turpentine') + ->__('Failed to save the VCL file: '.$result[1]['message'])); } } $this->_redirect('*/cache'); @@ -178,21 +178,21 @@ public function saveConfigAction() { * @return $this */ public function getConfigAction() { - $cfgr = Mage::getModel( 'turpentine/varnish_admin' ) + $cfgr = Mage::getModel('turpentine/varnish_admin') ->getConfigurator(); - if( is_null( $cfgr ) ) { - $this->_getSession()->addError( $this->__( 'Failed to load configurator' ) ); - $this->_redirect( '*/cache' ); + if (is_null($cfgr)) { + $this->_getSession()->addError($this->__('Failed to load configurator')); + $this->_redirect('*/cache'); } else { $vcl = $cfgr->generate( - Mage::helper( 'turpentine' )->shouldStripVclWhitespace('download') ); + Mage::helper('turpentine')->shouldStripVclWhitespace('download') ); $this->getResponse() - ->setHttpResponseCode( 200 ) - ->setHeader( 'Content-Type', 'text/plain', true ) - ->setHeader( 'Content-Length', strlen( $vcl ) ) - ->setHeader( 'Content-Disposition', - 'attachment; filename=default.vcl' ) - ->setBody( $vcl ); + ->setHttpResponseCode(200) + ->setHeader('Content-Type', 'text/plain', true) + ->setHeader('Content-Length', strlen($vcl)) + ->setHeader('Content-Disposition', + 'attachment; filename=default.vcl') + ->setBody($vcl); return $this; } } diff --git a/contrib/tools/esi-decoder.php b/contrib/tools/esi-decoder.php index 20ae29055..cf2bb6685 100644 --- a/contrib/tools/esi-decoder.php +++ b/contrib/tools/esi-decoder.php @@ -68,33 +68,33 @@
            getEsiDataParam(), '|' ); - if ( preg_match('|'.$dataPreg.'/([\w\.\-]+=*)|', $data, $matches) ) { + $esiHelper = Mage::helper('turpentine/esi'); + $dataPreg = preg_quote($esiHelper->getEsiDataParam(), '|'); + if (preg_match('|'.$dataPreg.'/([\w\.\-]+=*)|', $data, $matches)) { $processData = $matches[1]; } - $dataHelper = Mage::helper( 'turpentine/data' ); - $esiDataArray = $dataHelper->thaw( $processData ); - $showContentUrl = Mage::getUrl( 'turpentine/esi/getBlock', - array( 'method' => 'esi', + $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 ) ); + 'hmac' => $dataHelper->getHmac($processData), + 'data' => $processData)); ?>
            =  DATA  =
            -
            +
            getEsiReferrerParam(), '|' ); - if ( preg_match('|'.$refPreg.'/([\w\.\-]+),*|', $data, $matches) ): + $refPreg = preg_quote($esiHelper->getEsiReferrerParam(), '|'); + if (preg_match('|'.$refPreg.'/([\w\.\-]+),*|', $data, $matches)): $processData = $matches[1]; ?>
            =  REFERRER  =
            -
            urlBase64Decode( $processData ) ); ?>
            +
            urlBase64Decode($processData)); ?>
            Date: Sun, 25 Oct 2015 13:15:18 +0100 Subject: [PATCH 207/311] Ban Observer - Fix an issue on ban product review (check if varnish is enabled was missing on banProductReview method) --- .../Turpentine/Model/Observer/Ban.php | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php index 5bfd8a13c..7c613a846 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php @@ -298,37 +298,39 @@ public function banCacheType( $eventObject ) { * @return bool */ public function banProductReview( $eventObject ) { - $patterns = array(); - /* @var $review \Mage_Review_Model_Review*/ - $review = $eventObject->getObject(); - - /* @var $productCollection \Mage_Review_Model_Resource_Review_Product_Collection*/ - $productCollection = $review->getProductCollection(); - - $products = $productCollection->addEntityFilter((int)$review->getEntityPkValue())->getItems(); + if ( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) { + $patterns = array(); + /* @var $review \Mage_Review_Model_Review */ + $review = $eventObject->getObject(); + + /* @var $productCollection \Mage_Review_Model_Resource_Review_Product_Collection */ + $productCollection = $review->getProductCollection(); - $productIds = array_unique( array_map( - create_function( '$p', 'return $p->getEntityId();' ), - $products ) ); - $patterns[] = sprintf( '/review/product/list/id/(?:%s)/category/', - implode( '|', array_unique( $productIds ) ) ); - $patterns[] = sprintf( '/review/product/view/id/%d/', - $review->getEntityId() ); - $productPatterns = array(); - foreach ( $products as $p ) { - $urlKey = $p->getUrlModel()->formatUrlKey( $p->getName() ); - if ( $urlKey ) { - $productPatterns[] = $urlKey; + $products = $productCollection->addEntityFilter((int)$review->getEntityPkValue())->getItems(); + + $productIds = array_unique(array_map( + create_function('$p', 'return $p->getEntityId();'), + $products)); + $patterns[] = sprintf('/review/product/list/id/(?:%s)/category/', + implode('|', array_unique($productIds))); + $patterns[] = sprintf('/review/product/view/id/%d/', + $review->getEntityId()); + $productPatterns = array(); + foreach ($products as $p) { + $urlKey = $p->getUrlModel()->formatUrlKey($p->getName()); + if ($urlKey) { + $productPatterns[] = $urlKey; + } } - } - if ( !empty($productPatterns) ) { - $productPatterns = array_unique( $productPatterns ); - $patterns[] = sprintf( '(?:%s)', implode( '|', $productPatterns ) ); - } - $urlPattern = implode( '|', $patterns ); + if (!empty($productPatterns)) { + $productPatterns = array_unique($productPatterns); + $patterns[] = sprintf('(?:%s)', implode('|', $productPatterns)); + } + $urlPattern = implode('|', $patterns); - $result = $this->_getVarnishAdmin()->flushUrl( $urlPattern ); - return $this->_checkResult( $result ); + $result = $this->_getVarnishAdmin()->flushUrl($urlPattern); + return $this->_checkResult($result); + } } /** From d2a30abb54139ccab5b56de701666cce6ef6c886 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Thu, 5 Nov 2015 16:41:50 +0000 Subject: [PATCH 208/311] Invalidating cms pages with url enging with slash Invalidating cms pages with url enging with slash. Like: http://domain.com/about-us/ --- app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php | 2 +- 1 file changed, 1 insertion(+), 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 843f90043..420c61e5b 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php @@ -235,7 +235,7 @@ public function banCmsPageRevisionCache($eventObject) { return; } $pageIdentifier = $page->getIdentifier(); - $result = $this->_getVarnishAdmin()->flushUrl($pageIdentifier.'(?:\.html?)?$'); + $result = $this->_getVarnishAdmin()->flushUrl($pageIdentifier.'(?:\.html?)?/?$'); Mage::dispatchEvent('turpentine_ban_cms_page_cache', $result); $cronHelper = Mage::helper('turpentine/cron'); if ($this->_checkResult($result) && From 97b3fb9609b7ab287f181bac4f9cb8af57e2d2d0 Mon Sep 17 00:00:00 2001 From: Sergey Ivashchenko Date: Thu, 5 Nov 2015 16:45:34 +0000 Subject: [PATCH 209/311] Update Ban.php --- .../community/Nexcessnet/Turpentine/Model/Observer/Ban.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php index 420c61e5b..83ff52ceb 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php @@ -207,7 +207,7 @@ public function banCatalogImagesCache($eventObject) { public function banCmsPageCache($eventObject) { if (Mage::helper('turpentine/varnish')->getVarnishEnabled()) { $pageId = $eventObject->getDataObject()->getIdentifier(); - $result = $this->_getVarnishAdmin()->flushUrl($pageId.'(?:\.html?)?$'); + $result = $this->_getVarnishAdmin()->flushUrl($pageId.'(?:\.html?)?\/?$'); Mage::dispatchEvent('turpentine_ban_cms_page_cache', $result); $cronHelper = Mage::helper('turpentine/cron'); if ($this->_checkResult($result) && @@ -235,7 +235,7 @@ public function banCmsPageRevisionCache($eventObject) { return; } $pageIdentifier = $page->getIdentifier(); - $result = $this->_getVarnishAdmin()->flushUrl($pageIdentifier.'(?:\.html?)?/?$'); + $result = $this->_getVarnishAdmin()->flushUrl($pageIdentifier.'(?:\.html?)?$'); Mage::dispatchEvent('turpentine_ban_cms_page_cache', $result); $cronHelper = Mage::helper('turpentine/cron'); if ($this->_checkResult($result) && From 13a7988b3b0fe7262289cd7456ff7626c321e58c Mon Sep 17 00:00:00 2001 From: mbalparda Date: Tue, 10 Nov 2015 16:46:06 -0300 Subject: [PATCH 210/311] refs Added PRs to CHANGELOG.md and bump version. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09c912622..b85a8142b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -421,3 +421,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#955] Include theme specific handles to ESI data (@LyndonHook) * [#972] Fixed bug with wrong return value of ->getSkinUrl() (@ceckoslab) * [#951] Added 'disableEsiInjection' ESI policy option. + * [#1005 ] Invalidating cms pages with url enging with slash. (@sivaschenko) From 8a788e86f1c632a64e15f7df73c121147162f1b5 Mon Sep 17 00:00:00 2001 From: Paul Partington Date: Wed, 18 Nov 2015 12:27:36 +0000 Subject: [PATCH 211/311] Add the form key to wishlist submit to prevent 403 errors. --- .../Turpentine/Model/Observer/Esi.php | 17 +++++++++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 5124e706e..805ea0baa 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -532,6 +532,9 @@ public function hookToControllerActionPreDispatch($observer) { if(Mage::helper( 'turpentine/data')->getVclFix() == 0 && $observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') { Mage::dispatchEvent("add_to_cart_before", array('request' => $observer->getControllerAction()->getRequest())); } + if ($observer->getEvent()->getControllerAction()->getFullActionName() == 'wishlist_index_index') { + Mage::dispatchEvent('wishlist_index_index_before', array('request' => $observer->getControllerAction()->getRequest())); + } } public function hookToControllerActionPostDispatch($observer) { @@ -552,4 +555,18 @@ public function hookToAddToCartAfter($observer) { $request = $observer->getEvent()->getRequest()->getParams(); //Mage::log("hookToAddToCartAfter ".print_r($request,true)." is added to cart.", null, 'carrinho.log', true); } + + /** + * Set the form key on the add to wishlist request + * + * @param $observer + * + * @return Nexcessnet_Turpentine_Model_Observer_Esi + */ + public function hookToAddToWishlistBefore($observer) + { + $key = Mage::getSingleton('core/session')->getFormKey(); + $observer->getEvent()->getRequest()->setParam('form_key', $key); + return $this; + } } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index a9fc7eec1..5e814f690 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -468,6 +468,14 @@ + + + + turpentine/observer_esi + >hookToAddToWishlistBefore + + + From ae50f395597326fa800ff7ed9930432ed7111604 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Tue, 1 Dec 2015 13:49:09 -0500 Subject: [PATCH 212/311] Added search results flush event to resolve Issue #938 --- app/design/frontend/base/default/layout/turpentine_esi.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index f44357b68..276137966 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -44,6 +44,7 @@ + From 3e3bb425967526c0ea7870f19e7236bdcf8fabf3 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Tue, 1 Dec 2015 21:51:42 +0100 Subject: [PATCH 213/311] Improved helper function getModelName() It did not work in case an extension used in config.xml: MyPackage_MyExtension_Model Because then the class guessed by getModelName($product) is: `myextension/product` while it should be `mygroupname/product`. I made the function check if the guess is a valid model. If not: the right value is quite hard to look up, so I decided to return `MyPackage_MyExtension_Model_Product` in this example. --- .../Nexcessnet/Turpentine/Helper/Data.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index 040252c15..6515feee9 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -231,12 +231,20 @@ public function getChildBlockNames($blockNode) { * @param string|object $model * @return string */ - public function getModelName($model) { - if (is_object($model)) { - $model = get_class($model); + public function getModelName( $model ) { + if( is_object( $model ) ) { + $model = get_class( $model ); } - return strtolower(preg_replace( - '~^[^_]+_([^_]+)_Model_(.+)$~', '$1/$2', $model )); + // This guess may work if the extension uses its lowercased name as model group name. + $result = strtolower( preg_replace( + '~^[^_]+_([^_]+)_Model_(.+)$~', '$1/$2', $model ) ); + // This check is not expensive because the answer should come from Magento's classNameCache + $checkModel = Mage::getConfig()->getModelClassName($result); + if ( 'Mage_' == substr($checkModel,0,5) && !class_exists($result) ) { + // Fallback to full model name. + $result = $model; + } + return $result; } /** From f57f39ca539ccb73b5bbf7b7dea49d1a3d7b1d86 Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Mon, 7 Dec 2015 14:23:13 +0100 Subject: [PATCH 214/311] prime checkout and light checkout compatibility --- .../base/default/layout/turpentine_esi.xml | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index 276137966..d8c18dae4 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -283,6 +283,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 23f49fab3433abf53fb05fec0400e3bbc148cd5e Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Mon, 14 Dec 2015 00:10:23 +0100 Subject: [PATCH 215/311] "Use Simple Hash" option for static files When enabled: Always serve the same version of a static file. Ignore domain, cookies and browser version. Saves memory and lowers cache misses. Thanks to @toonvd for the idea of this improvement. Improved some use of booleans in Varnish version 2.1 config --- .../Model/Varnish/Configurator/Abstract.php | 11 +++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 1 + .../Nexcessnet/Turpentine/etc/system.xml | 13 +++++++++++++ .../Nexcessnet/Turpentine/misc/version-2.vcl | 19 ++++++++++++++++--- .../Nexcessnet/Turpentine/misc/version-3.vcl | 11 +++++++++++ .../Nexcessnet/Turpentine/misc/version-4.vcl | 11 +++++++++++ 6 files changed, 63 insertions(+), 3 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 c4808ef47..86805aea8 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -439,6 +439,16 @@ protected function _getForceCacheStatic() { ? 'true' : 'false'; } + /** + * Get the Force Static Caching option + * + * @return string + */ + protected function _getSimpleHashStatic() { + return Mage::getStoreConfig('turpentine_vcl/static/simple_hash') + ? 'true' : 'false'; + } + /** * Format the list of static cache extensions * @@ -942,6 +952,7 @@ protected function _getTemplateVars() { 'debug_headers' => $this->_getEnableDebugHeaders(), 'grace_period' => $this->_getGracePeriod(), 'force_cache_static' => $this->_getForceCacheStatic(), + 'simple_hash_static' => $this->_getSimpleHashStatic(), 'generate_session_expires' => $this->_getGenerateSessionExpires(), 'generate_session' => $this->_getGenerateSession(), 'generate_session_start' => $this->_getGenerateSessionStart(), diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 5e814f690..9f15c241f 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -85,6 +85,7 @@ 1 css,js,jpe?g,png,gif,ico,swf + 1 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 396871326..fcbaf2c17 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -587,6 +587,19 @@ 0 0 + + + Always serve the same version of a static file. Ignore domain, cookies and browser version. Saves memory and lowers cache misses. + + 1 + + select + turpentine/config_select_toggle + 30 + 1 + 0 + 0 + diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 5fa385f5d..d581be09e 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -100,9 +100,11 @@ sub vcl_recv { } # varnish 2.1 doesn't support bare booleans so we have to add these - # as headers to the req so they've available throught the VCL + # as headers to the req so they've available through the VCL set req.http.X-Opt-Enable-Caching = "{{enable_caching}}"; set req.http.X-Opt-Force-Static-Caching = "{{force_cache_static}}"; + set req.http.X-Opt-Simple-Hash-Static = "{{simple_hash_static}}"; + set req.http.X-Opt-Enable-Get-Ignored = "{{enable_get_ignored}}"; set req.http.X-Opt-Enable-Get-Excludes = "{{enable_get_excludes}}"; set req.http.X-Opt-Send-Unmodified-Url = "{{send_unmodified_url}}"; @@ -186,6 +188,7 @@ sub vcl_recv { # don't need cookies for static assets remove req.http.Cookie; remove req.http.X-Varnish-Faked-Session; + set req.http.X-Varnish-Static = "1"; return (lookup); } # this doesn't need a enable_url_excludes because we can be reasonably @@ -202,7 +205,7 @@ sub vcl_recv { req.url ~ "(?:[?&](?:{{get_param_excludes}})(?=[&=]|$))") { return (pass); } - if ({{enable_get_ignored}} && req.url ~ "[?&]({{get_param_ignored}})=") { + if (req.http.X-Opt-Enable-Get-Ignored == "true" && req.url ~ "[?&]({{get_param_ignored}})=") { # Strip out ignored GET related parameters set req.url = regsuball(req.url, "(?:(\?)?|&)(?:{{get_param_ignored}})=[^&]+", "\1"); set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1"); @@ -234,8 +237,18 @@ sub vcl_pipe { # } sub vcl_hash { + # For static files we keep the hash simple and don't add the domain. + # This saves memory when a static file is used on multiple domains. + if (req.http.X-Opt-Simple-Hash-Static == "true" && req.http.X-Varnish-Static) { + set req.hash += req.url; + if (req.http.Accept-Encoding) { + # make sure we give back the right encoding + set req.hash += req.http.Accept-Encoding; + } + return (hash); + } - if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) { + if(req.http.X-Opt-Send-Unmodified-Url == "true" && req.http.X-Varnish-Cache-Url) { set req.hash += req.http.X-Varnish-Cache-Url; } else { set req.hash += req.url; diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 115c1887f..10219981e 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -185,6 +185,7 @@ sub vcl_recv { # don't need cookies for static assets unset req.http.Cookie; unset req.http.X-Varnish-Faked-Session; + set req.http.X-Varnish-Static = 1; return (lookup); } # this doesn't need a enable_url_excludes because we can be reasonably @@ -233,6 +234,16 @@ sub vcl_pipe { # } sub vcl_hash { + # For static files we keep the hash simple and don't add the domain. + # This saves memory when a static file is used on multiple domains. + if ({{simple_hash_static}} && req.http.X-Varnish-Static) { + hash_data(req.url); + if (req.http.Accept-Encoding) { + # make sure we give back the right encoding + hash_data(req.http.Accept-Encoding); + } + return (hash); + } if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) { hash_data(req.http.X-Varnish-Cache-Url); diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index ca782c605..874bd65e1 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -183,6 +183,7 @@ sub vcl_recv { # don't need cookies for static assets unset req.http.Cookie; unset req.http.X-Varnish-Faked-Session; + set req.http.X-Varnish-Static = 1; return (hash); } # this doesn't need a enable_url_excludes because we can be reasonably @@ -237,6 +238,16 @@ sub vcl_pipe { # } sub vcl_hash { + # For static files we keep the hash simple and don't add the domain. + # This saves memory when a static file is used on multiple domains. + if ({{simple_hash_static}} && req.http.X-Varnish-Static) { + hash_data(req.url); + if (req.http.Accept-Encoding) { + # make sure we give back the right encoding + hash_data(req.http.Accept-Encoding); + } + return (lookup); + } if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) { hash_data(req.http.X-Varnish-Cache-Url); From 9f4178cfaabc9079f1557f41a08124d6857d8d8d Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Thu, 17 Dec 2015 15:17:52 -0500 Subject: [PATCH 216/311] Moved the custom include vcl to bottom Custom included VCL is now included at the bottom of the generated VCL --- .../community/Nexcessnet/Turpentine/misc/version-3.vcl | 9 +++++---- .../community/Nexcessnet/Turpentine/misc/version-4.vcl | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 115c1887f..57aa03a04 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -28,10 +28,6 @@ C{ import std; -## Custom VCL Logic - -{{custom_vcl_include}} - ## Backends {{default_backend}} @@ -423,3 +419,8 @@ sub vcl_deliver { unset resp.http.X-Varnish-Set-Cookie; } } + +## Custom VCL Logic + +{{custom_vcl_include}} + diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index ca782c605..4c07d7f9e 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -29,10 +29,6 @@ C{ import std; -## Custom VCL Logic - -{{custom_vcl_include}} - ## Backends {{default_backend}} @@ -424,3 +420,7 @@ sub vcl_deliver { unset resp.http.X-Varnish-Set-Cookie; } } + +## Custom VCL Logic + +{{custom_vcl_include}} From fdc1d16ac3658efec2bb17adda6e38155a82d3bd Mon Sep 17 00:00:00 2001 From: miguelbalparda Date: Wed, 30 Dec 2015 10:55:45 -0300 Subject: [PATCH 217/311] refs Added PRs to CHANGELOG.md. --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b85a8142b..5965578fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -421,4 +421,9 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#955] Include theme specific handles to ESI data (@LyndonHook) * [#972] Fixed bug with wrong return value of ->getSkinUrl() (@ceckoslab) * [#951] Added 'disableEsiInjection' ESI policy option. - * [#1005 ] Invalidating cms pages with url enging with slash. (@sivaschenko) + * [#1005] Invalidating cms pages with url enging with slash. (@sivaschenko) + * [#1020] Add the form key to wishlist submit to prevent 403 errors. (@paulpartington) + * [#1036] Prime Checkout and Light Checkout Compatibility. (@sprankhub) + * [#1050] Use Simple Hash" option for static files. (@jeroenvermeulen) + * [#1031] Improved helper function getModelName(). (@jeroenvermeulen) + From d1de03f71da5a58a7225327b6be88d3e1f19cf37 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Tue, 5 Jan 2016 18:03:30 -0500 Subject: [PATCH 218/311] Added ESI policy for cookie notice block --- .../frontend/base/default/layout/turpentine_esi.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index d8c18dae4..9cd985aad 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -138,6 +138,16 @@ + + + + + private + no_text + + + + From d5dc273b011d8eb58627670d75c5bc8e48f49104 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Wed, 6 Jan 2016 17:36:42 +0100 Subject: [PATCH 219/311] Fix for crawler lock problem with CM_RedisSession Turpentine sets the fake cookie 'frontend=crawler-session' when a crawler is detected. This causes lock problems with Cm_RedisSession, because all crawler hits are requesting the same session lock. Cm_RedisSession provides the define CM_REDISSESSION_LOCKING_ENABLED to overrule if locking should be enabled. I added an 'controller_front_init_before' event listener to set this define if the fake session cookie exists. --- .../Turpentine/Model/Observer/Varnish.php | 16 ++++++++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index d1e9067c1..be6ecb3cc 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -55,6 +55,22 @@ public function addProductListToolbarRewrite($eventObject) { } } + /** + * Turpentine sets the fake cookie 'frontend=crawler-session' when a crawler is detected. + * This causes lock problems with Cm_RedisSession, because all crawler hits are requesting the same session lock. + * Cm_RedisSession provides the define CM_REDISSESSION_LOCKING_ENABLED to overrule if locking should be enabled. + * + * @param $eventObject + * @return null + */ + public function fixCmRedisSessionLocks($eventObject) { + if (Mage::helper('core')->isModuleEnabled('Cm_RedisSession')) { + if (!empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend']) { + define('CM_REDISSESSION_LOCKING_ENABLED', false); + } + } + } + /** * Re-apply and save Varnish configuration on config change * diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 9f15c241f..23ed88e1f 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -302,6 +302,10 @@ turpentine/observer_varnish addProductListToolbarRewrite + + turpentine/observer_varnish + fixCmRedisSessionLocks + turpentine/observer_esi setReplaceFormKeyFlag From abb5b946efc2bd9c8a1740da183ea55fb3a984ef Mon Sep 17 00:00:00 2001 From: miguelbalparda Date: Thu, 14 Jan 2016 10:49:50 -0300 Subject: [PATCH 220/311] refs Added PRs to CHANGELOG.md and bump version. --- CHANGELOG.md | 7 ++++++- app/code/community/Nexcessnet/Turpentine/etc/config.xml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5965578fe..91bd16ed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -420,10 +420,15 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#885] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page (@craigcarnell) * [#955] Include theme specific handles to ESI data (@LyndonHook) * [#972] Fixed bug with wrong return value of ->getSkinUrl() (@ceckoslab) + +### RELEASE-0.6.7 * [#951] Added 'disableEsiInjection' ESI policy option. * [#1005] Invalidating cms pages with url enging with slash. (@sivaschenko) * [#1020] Add the form key to wishlist submit to prevent 403 errors. (@paulpartington) - * [#1036] Prime Checkout and Light Checkout Compatibility. (@sprankhub) + * [#1036] Prime Checkout and Light Checkout Compatibility. (@sprankhub) * [#1050] Use Simple Hash" option for static files. (@jeroenvermeulen) * [#1031] Improved helper function getModelName(). (@jeroenvermeulen) + * [#1066] Fix for crawler lock problem with CM_RedisSession. (@jeroenvermeulen) +### RELEASE-0.6.8 + * [#1065] Added ESI policy for cookie notice block. (@aricwatson) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 23ed88e1f..e13b425d6 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.7 + 0.6.8 From e7a32446e3514c8efc742b2ad14ce1ba8660ced3 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Thu, 14 Jan 2016 14:02:00 +0000 Subject: [PATCH 221/311] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- .../community/Nexcessnet/Turpentine/Helper/Data.php | 12 ++++++------ .../Nexcessnet/Turpentine/Model/Observer/Varnish.php | 2 +- .../controllers/Adminhtml/CacheController.php | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index 6515feee9..a357b7a47 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -231,16 +231,16 @@ public function getChildBlockNames($blockNode) { * @param string|object $model * @return string */ - public function getModelName( $model ) { - if( is_object( $model ) ) { - $model = get_class( $model ); + public function getModelName($model) { + if (is_object($model)) { + $model = get_class($model); } // This guess may work if the extension uses its lowercased name as model group name. - $result = strtolower( preg_replace( - '~^[^_]+_([^_]+)_Model_(.+)$~', '$1/$2', $model ) ); + $result = strtolower(preg_replace( + '~^[^_]+_([^_]+)_Model_(.+)$~', '$1/$2', $model )); // This check is not expensive because the answer should come from Magento's classNameCache $checkModel = Mage::getConfig()->getModelClassName($result); - if ( 'Mage_' == substr($checkModel,0,5) && !class_exists($result) ) { + if ('Mage_' == substr($checkModel, 0, 5) && ! class_exists($result)) { // Fallback to full model name. $result = $model; } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index be6ecb3cc..7eb51c4e3 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -65,7 +65,7 @@ public function addProductListToolbarRewrite($eventObject) { */ public function fixCmRedisSessionLocks($eventObject) { if (Mage::helper('core')->isModuleEnabled('Cm_RedisSession')) { - if (!empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend']) { + if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend']) { define('CM_REDISSESSION_LOCKING_ENABLED', false); } } diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php index 561e4c930..9beb94935 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php @@ -1,8 +1,8 @@ Date: Wed, 20 Jan 2016 16:47:32 -0500 Subject: [PATCH 222/311] Fix regex check - blank value passed check --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index ac8beb60f..09c2100fe 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -390,7 +390,7 @@ sub vcl_deliver { "; domain=" + regsub(req.http.Host, ":\d+$", ""); } else { # it's a real user, allow sharing of cookies between stores - if(req.http.Host ~ "{{normalize_cookie_regex}}") { + if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") set resp.http.Set-Cookie = resp.http.Set-Cookie + "; domain={{normalize_cookie_target}}"; } else { From 9d1f1cccbaa441bcd3f9995e9653f81086541c86 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Mon, 1 Feb 2016 10:47:37 -0500 Subject: [PATCH 223/311] Fixed missing '}' typo --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 09c2100fe..8e2aef0a0 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -390,7 +390,7 @@ sub vcl_deliver { "; domain=" + regsub(req.http.Host, ":\d+$", ""); } else { # it's a real user, allow sharing of cookies between stores - if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") + if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") { set resp.http.Set-Cookie = resp.http.Set-Cookie + "; domain={{normalize_cookie_target}}"; } else { From ba025294ebee5bfd4926e157206316b4b5295e72 Mon Sep 17 00:00:00 2001 From: miguelbalparda Date: Wed, 3 Feb 2016 10:56:14 -0300 Subject: [PATCH 224/311] refs #1090 syntaxis issues. --- app/code/community/Nexcessnet/Turpentine/etc/config.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index e13b425d6..81f5df7a8 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -53,9 +53,9 @@ 127.0.0.1 8080 127.0.0.1:8080 - + 127.0.0.1:8080 - + 300 21600 127.0.0.1 @@ -477,7 +477,7 @@ turpentine/observer_esi - >hookToAddToWishlistBefore + hookToAddToWishlistBefore From 8b5e2d967e71629271f693526f355257af4c6913 Mon Sep 17 00:00:00 2001 From: Andrew Kett Date: Wed, 10 Feb 2016 10:58:04 +1100 Subject: [PATCH 225/311] add ability to throttle crawler requests --- .../Nexcessnet/Turpentine/Helper/Cron.php | 18 ++++++++++++++ .../Turpentine/Model/Observer/Cron.php | 15 ++++++++++++ .../Nexcessnet/Turpentine/etc/config.xml | 2 ++ .../Nexcessnet/Turpentine/etc/system.xml | 24 +++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php index 6c30a5be6..2b0449161 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php @@ -145,6 +145,24 @@ public function getCrawlerDebugEnabled() { return Mage::getStoreConfig('turpentine_varnish/general/crawler_debug'); } + /** + * Get number of urls to crawl per batch + * + * @return int + */ + public function getCrawlerBatchSize() { + return Mage::getStoreConfig('turpentine_varnish/general/crawler_batchsize'); + } + + /** + * Get time in seconds to wait between url batches + * + * @return int + */ + public function getCrawlerWaitPeriod() { + return Mage::getStoreConfig('turpentine_varnish/general/crawler_batchwait'); + } + /** * Get the list of all URLs * diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php index 5542cfca7..a8852cf3d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php @@ -49,6 +49,11 @@ public function crawlUrls($eventObject) { if ($maxRunTime === 0) { $maxRunTime = self::MAX_CRAWL_TIME; } + + $batchSize = $helper->getCrawlerBatchSize(); + $timeout = $helper->getCrawlerWaitPeriod(); + $crawlCount = 0; + // just in case we have a silly short max_execution_time $maxRunTime = abs($maxRunTime - self::EXEC_TIME_BUFFER); while (($helper->getRunTime() < $maxRunTime) && @@ -57,6 +62,16 @@ public function crawlUrls($eventObject) { Mage::helper('turpentine/debug')->logWarn( 'Failed to crawl URL: %s', $url ); } + + if ($crawlCount > 0 + && $timeout > 0 + && $batchSize > 0 + && $crawlCount%$batchSize == 0 + ) { + Mage::helper('turpentine/debug')->logDebug('Crawled '.$crawlCount.' urls, sleeping for '.$timeout.' seconds'); + sleep($timeout); + } + $crawlCount++; } } } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 81f5df7a8..c149456fb 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -35,6 +35,8 @@ 0 0 0 + 10 + 0 0 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index fcbaf2c17..475286a95 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -132,6 +132,30 @@ 0 0 + + + Number of URLs to crawl per crawler batch. Set to 0 for unlimited + text + 90 + 1 + 0 + 0 + + 1 + + + + + Time in seconds to wait between URL batches + text + 100 + 1 + 0 + 0 + + 1 + + From 695769ffa94d86c43110bc8ffbd9dd7d011fb666 Mon Sep 17 00:00:00 2001 From: Andrew Kett Date: Wed, 10 Feb 2016 11:31:55 +1100 Subject: [PATCH 226/311] fix scrutinizer notice, tidy config --- .../community/Nexcessnet/Turpentine/Model/Observer/Cron.php | 2 +- app/code/community/Nexcessnet/Turpentine/etc/config.xml | 2 +- app/code/community/Nexcessnet/Turpentine/etc/system.xml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php index a8852cf3d..ad7d0f5c1 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Cron.php @@ -66,7 +66,7 @@ public function crawlUrls($eventObject) { if ($crawlCount > 0 && $timeout > 0 && $batchSize > 0 - && $crawlCount%$batchSize == 0 + && $crawlCount % $batchSize == 0 ) { Mage::helper('turpentine/debug')->logDebug('Crawled '.$crawlCount.' urls, sleeping for '.$timeout.' seconds'); sleep($timeout); diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index c149456fb..29a331b50 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -35,7 +35,7 @@ 0 0 0 - 10 + 0 0 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 475286a95..a5960bbd0 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -134,7 +134,7 @@ - Number of URLs to crawl per crawler batch. Set to 0 for unlimited + Number of URLs to crawl per batch, when 0 requests will not be batched text 90 1 @@ -146,7 +146,7 @@ - Time in seconds to wait between URL batches + Time in seconds to wait between batches text 100 1 From b510ee879a3962828dd7fb55a5da4cafcff452e0 Mon Sep 17 00:00:00 2001 From: Barry Carlyon Date: Thu, 3 Mar 2016 09:28:33 +0000 Subject: [PATCH 227/311] As #1114 states. Varien_Object->__call() can't call the extended model's function --- .../Nexcessnet/Turpentine/Model/Core/Session.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php index 63aa888ed..8d3afeb56 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php @@ -50,4 +50,15 @@ public function real_getFormKey() } return $this->getData('_form_key'); } + + /** + * Validates Form key + * + * @param string|null $formKey + * @return bool + */ + public function validateFormKey($formKey) + { + return ($formKey === $this->getFormKey()); + } } From 63861a69a9a4c43acceced416a17a98d023841de Mon Sep 17 00:00:00 2001 From: Barry Carlyon Date: Thu, 3 Mar 2016 09:51:43 +0000 Subject: [PATCH 228/311] Fix #1100 --- .../community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php index e4f9810f7..8322aa069 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php @@ -19,13 +19,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -class Nexcessnet_Turpentine_Block_Poll_Activepoll extends Mage_Poll_Block_ActivePoll { +class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll { public function setTemplate($template) { $this->_template = $template; $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); - $this->setPollTemplate('turpentine/ajax.phtml', 'results'); + $this->setPollTemplate('turpentine/ajax.phtml', 'results'); return $this; } } From 6dca88831ada0f98930da4af9c13ccf5bf8df6a1 Mon Sep 17 00:00:00 2001 From: Barry Carlyon Date: Thu, 3 Mar 2016 16:37:47 +0000 Subject: [PATCH 229/311] fix #1114 The renewFormKey function is also required --- .../Nexcessnet/Turpentine/Model/Core/Session.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php index 8d3afeb56..4078fffb1 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php @@ -51,6 +51,14 @@ public function real_getFormKey() return $this->getData('_form_key'); } + /** + * Creates new Form key + */ + public function renewFormKey() + { + $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); + } + /** * Validates Form key * From 820592ec7253806b3b6cc039e33a74aa08d43d21 Mon Sep 17 00:00:00 2001 From: Andrew Kett Date: Thu, 10 Mar 2016 08:23:40 +1100 Subject: [PATCH 230/311] use pass instead of pipe on non GET requests to improve performance --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 8e2aef0a0..757601a6f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -116,7 +116,7 @@ sub vcl_recv { if (!{{enable_caching}} || req.http.Authorization || req.method !~ "^(GET|HEAD|OPTIONS)$" || req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") { - return (pipe); + return (pass); } if({{send_unmodified_url}}) { From 5779e8e4386cf616eee331b93da3ad8a8452bf58 Mon Sep 17 00:00:00 2001 From: Andrew Kett Date: Tue, 15 Mar 2016 15:03:03 +1100 Subject: [PATCH 231/311] ignore frontend cookie requirement for www.webpagetest.org --- 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 81f5df7a8..ba765a036 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -59,7 +59,7 @@ 300 21600 127.0.0.1 - + 1 From 8b1650545ec449b1c697a01277d643cbfc1069e5 Mon Sep 17 00:00:00 2001 From: Graham Lipsman Date: Wed, 23 Mar 2016 09:13:53 -0600 Subject: [PATCH 232/311] Update TECHNICAL_NOTES.md Link to the appropriate line in https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/etc/config.xml when discussing the observer for `core_block_abstract_to_html_before` --- TECHNICAL_NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TECHNICAL_NOTES.md b/TECHNICAL_NOTES.md index 857bd6ad4..c885b0f6b 100644 --- a/TECHNICAL_NOTES.md +++ b/TECHNICAL_NOTES.md @@ -23,7 +23,7 @@ ESI was originally created so that CDN providers (like Akamai) could serve their However, actually implementing ESI in Magento is horrendously complicated as Magento doesn't seem to have been designed with rendering just a single block, rather than an entire page, which is needed to serve the actual ESI requests from Varnish. Luckily, Hugues Alary did most of the hard work and made it available in his [Magento-Varnish](https://github.com/huguesalary/Magento-Varnish) extension. The core of how both Magento-Varnish and Turpentine work is: 1. The extension has a [layout file](https://github.com/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/layout/turpentine_esi.xml) that tells the extension which blocks should be included via ESI. - 2. The extension waits for the [`core_block_abstract_to_html_before`](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/etc/config.xml#L183) event to trigger during a request, then [examines the block](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L191) the event was fired for and checks whether the block should be included via ESI based on the layout file. + 2. The extension waits for the [`core_block_abstract_to_html_before`](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/etc/config.xml#L228) event to trigger during a request, then [examines the block](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L191) the event was fired for and checks whether the block should be included via ESI based on the layout file. 3. If the block should be ESI included, the block's normal template is replaced by a [special template](https://github.com/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/template/turpentine/esi.phtml) with the ESI include tag that signals Varnish to instead pull the block's content from a separate request. A flag is also added to the request to signal to Varnish that the request should have ESI processing run on it. 4. The response finishes and is sent to Varnish, Varnish sees the ESI flag and sends a request to get the ESI content, which is then [rendered](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php#L58) and sent back to Varnish to be included in the original response. From 1c4fc54a90a12decaeff9742aae74c8d7cf7415b Mon Sep 17 00:00:00 2001 From: Graham Lipsman Date: Wed, 23 Mar 2016 09:17:18 -0600 Subject: [PATCH 233/311] Update TECHNICAL_NOTES.md Link correctly to the referenced `injectEsi` function. --- TECHNICAL_NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TECHNICAL_NOTES.md b/TECHNICAL_NOTES.md index c885b0f6b..5408b8bd5 100644 --- a/TECHNICAL_NOTES.md +++ b/TECHNICAL_NOTES.md @@ -23,7 +23,7 @@ ESI was originally created so that CDN providers (like Akamai) could serve their However, actually implementing ESI in Magento is horrendously complicated as Magento doesn't seem to have been designed with rendering just a single block, rather than an entire page, which is needed to serve the actual ESI requests from Varnish. Luckily, Hugues Alary did most of the hard work and made it available in his [Magento-Varnish](https://github.com/huguesalary/Magento-Varnish) extension. The core of how both Magento-Varnish and Turpentine work is: 1. The extension has a [layout file](https://github.com/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/layout/turpentine_esi.xml) that tells the extension which blocks should be included via ESI. - 2. The extension waits for the [`core_block_abstract_to_html_before`](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/etc/config.xml#L228) event to trigger during a request, then [examines the block](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L191) the event was fired for and checks whether the block should be included via ESI based on the layout file. + 2. The extension waits for the [`core_block_abstract_to_html_before`](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/etc/config.xml#L228) event to trigger during a request, then [examines the block](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php#L220) the event was fired for and checks whether the block should be included via ESI based on the layout file. 3. If the block should be ESI included, the block's normal template is replaced by a [special template](https://github.com/nexcess/magento-turpentine/blob/master/app/design/frontend/base/default/template/turpentine/esi.phtml) with the ESI include tag that signals Varnish to instead pull the block's content from a separate request. A flag is also added to the request to signal to Varnish that the request should have ESI processing run on it. 4. The response finishes and is sent to Varnish, Varnish sees the ESI flag and sends a request to get the ESI content, which is then [rendered](https://github.com/nexcess/magento-turpentine/blob/master/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php#L58) and sent back to Varnish to be included in the original response. From 832bac26f31c4c138eaa9cd79f6642b7256facd7 Mon Sep 17 00:00:00 2001 From: sr972 Date: Wed, 6 Apr 2016 12:22:33 +0200 Subject: [PATCH 234/311] Update Abstract.php If in System > Config > Web > Add Store Code to URLs is enabled and a custom admin path is set, then Turpentine will not bypass actions in Magento backend. This PR checks, if the option is set to active and extends the answer by adding the code from store id 0, which is the admin backend store view. --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 86805aea8..253a5e0c7 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -173,7 +173,11 @@ protected function _vcl_call($subroutine) { */ protected function _getAdminFrontname() { if (Mage::getStoreConfig('admin/url/use_custom_path')) { - return Mage::getStoreConfig('admin/url/custom_path'); + if(Mage::getStoreConfig('web/url/use_store')) { + return Mage::getModel('core/store')->load(0)->getCode() . "/" . Mage::getStoreConfig('admin/url/custom_path'); + } else { + return Mage::getStoreConfig('admin/url/custom_path'); + } } else { return (string) Mage::getConfig()->getNode( 'admin/routers/adminhtml/args/frontName' ); From 15c6b65782f2b8a6b9a27328b3d85c0ba9e06ce5 Mon Sep 17 00:00:00 2001 From: Allard Hoeve Date: Thu, 21 Apr 2016 10:04:42 +0200 Subject: [PATCH 235/311] Support PHP7 --- build/build_package.py | 2 +- build/mage-package.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/build_package.py b/build/build_package.py index b37f0e1a2..928fcf02c 100755 --- a/build/build_package.py +++ b/build/build_package.py @@ -280,7 +280,7 @@ def _build_dependencies_tag(self, dependencies_tag, connect_dom): min_tag.text = connect_dom.findtext('depends_php_min') max_tag = ElementTree.SubElement(php_tag, 'max') max_tag.text = connect_dom.findtext('depends_php_max') - self._logger.debug('Finished adding dependancies') + self._logger.debug('Finished adding dependencies') return dependencies_tag def _get_module_dom(self, ext_name): diff --git a/build/mage-package.xml b/build/mage-package.xml index 29c0bec46..b968a047b 100644 --- a/build/mage-package.xml +++ b/build/mage-package.xml @@ -26,7 +26,7 @@ 5.2.13 - 6.0.0 + 7.1.0 From e312e93bc8b318ce2068f8febae53f60905d191f Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Thu, 21 Apr 2016 10:11:07 -0300 Subject: [PATCH 236/311] Bump version and CHANGELOG.md --- CHANGELOG.md | 9 +++++++++ app/code/community/Nexcessnet/Turpentine/etc/config.xml | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91bd16ed6..cc646b25f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -432,3 +432,12 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess ### RELEASE-0.6.8 * [#1065] Added ESI policy for cookie notice block. (@aricwatson) + * [#1066] Fix for crawler lock problem with CM_RedisSession (@jeroenvermeulen ) + * [#1072] Scrutinizer Auto-Fixes. (@miguelbalparda) + * [#1078] Fix regex check - blank value passed check. (@aricwatson) + * [#1087] Fixed missing '}' typo #1087. (@aricwatson) + * [#1117] Fix #1100. (@GLips) + * [#1155] Update TECHNICAL_NOTES.md. (@GLips) + +### RELEASE-0.6.9 + diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 81f5df7a8..5457759cc 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.8 + 0.6.9 From d3eef2575f9c7ed9ec9e416b4167887080f5f9f6 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Thu, 21 Apr 2016 15:32:31 +0100 Subject: [PATCH 237/311] fix broken cms page override for theme --- .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 2 ++ .../Nexcessnet/Turpentine/controllers/EsiController.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 0ae107d8c..27808cf07 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -325,6 +325,8 @@ protected function _getEsiData($blockObject, $esiOptions) { $methodParam = $esiHelper->getEsiMethodParam(); $esiData = new Varien_Object(); $esiData->setStoreId(Mage::app()->getStore()->getId()); + $esiData->setDesignPackage( Mage::getDesign()->getPackageName() ); + $esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) ); $esiData->setNameInLayout($blockObject->getNameInLayout()); $esiData->setBlockType(get_class($blockObject)); $esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject)); diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index fb66776ab..72911c994 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -183,6 +183,9 @@ protected function _getEsiBlock($esiData) { } } $layout = Mage::getSingleton('core/layout'); + Mage::getSingleton( 'core/design_package' ) + ->setPackageName( $esiData->getDesignPackage() ) + ->setTheme( $esiData->getDesignTheme() ); // dispatch event for adding handles to layout update Mage::dispatchEvent( From f653b8a509fa95ef46d29a7d499d0bdd80b23c0e Mon Sep 17 00:00:00 2001 From: "outdoor on milky.magehost.pro" Date: Tue, 3 May 2016 15:07:35 +0200 Subject: [PATCH 238/311] Feature: Custom file include on top of VLC When multiple subroutines with the same name exist in Varnish, they get concatenated. The existing 'custom_include.vcl' file is appended to the VCL. It can't be used to expand the 'sub vcl_recv' because the existing one contains 'return (pipe)' statements. Whatever you add will not be executed in a lot of situations. I added a 'custom_include_top.vcl' file, which is prepended to the VCL. This allows you to override everything. For example you can include a 'return (pipe)' yourself to skip the default Turpentine VCL :-) --- .gitignore | 3 ++- .../Model/Varnish/Configurator/Abstract.php | 16 +++++++++++----- .../Nexcessnet/Turpentine/etc/config.xml | 1 + .../Nexcessnet/Turpentine/etc/system.xml | 15 ++++++++++++--- .../Nexcessnet/Turpentine/misc/version-2.vcl | 11 ++++++++--- .../Nexcessnet/Turpentine/misc/version-3.vcl | 6 +++++- .../Nexcessnet/Turpentine/misc/version-4.vcl | 6 +++++- 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index ceb029c4a..189a20bc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ build/*.tgz build/*.html -app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl +app/code/community/Nexcessnet/Turpentine/misc/custom_include*.vcl +*~ .idea .DS_Store nbproject/ 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 86805aea8..bafd2b9b2 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -130,9 +130,11 @@ protected function _getVclFilename() { * * @return string */ - protected function _getCustomIncludeFilename() { + protected function _getCustomIncludeFilename($position='') { + $key = 'custom_include_file'; + $key .= ($position) ? '_'.$position : ''; return $this->_formatTemplate( - Mage::getStoreConfig('turpentine_varnish/servers/custom_include_file'), + Mage::getStoreConfig('turpentine_varnish/servers/'.$key), array('root_dir' => Mage::getBaseDir()) ); } @@ -1007,9 +1009,13 @@ protected function _getTemplateVars() { $vars['vcl_synth'] = $this->_vcl_sub_synth(); } - $customIncludeFile = $this->_getCustomIncludeFilename(); - if (is_readable($customIncludeFile)) { - $vars['custom_vcl_include'] = file_get_contents($customIncludeFile); + foreach (array('','top') as $position) { + $customIncludeFile = $this->_getCustomIncludeFilename($position); + if (is_readable($customIncludeFile)) { + $key = 'custom_vcl_include'; + $key .= ($position) ? '_'.$position : ''; + $vars[$key] = file_get_contents($customIncludeFile); + } } return $vars; diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 4fa09bf5f..63beed96a 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -47,6 +47,7 @@ 127.0.0.1:6082 {{root_dir}}/var/default.vcl {{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl + {{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include_top.vcl diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index a5960bbd0..2a04a3642 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -233,14 +233,23 @@ 0 0 - - + + text - Specify where the Varnish VCL customization file should be saved + If this file exists, its content will be prepended to the VCL. 40 1 0 0 + + + + text + If this file exists, its content will be appended to the VCL. + 41 + 1 + 0 + 0 diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index d581be09e..2ce648bef 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -17,6 +17,10 @@ ## Nexcessnet_Turpentine Varnish v2 VCL Template +## Custom VCL Logic - Top + +{{custom_vcl_include_top}} + ## Custom C Code C{ @@ -24,9 +28,6 @@ C{ {{custom_c_code}} }C -## Custom VCL Logic - -{{custom_vcl_include}} ## Backends @@ -426,3 +427,7 @@ sub vcl_deliver { } remove resp.http.X-Opt-Debug-Headers; } + +## Custom VCL Logic - Bottom + +{{custom_vcl_include}} diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 05ac503d2..d40ac9c7f 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -17,6 +17,10 @@ ## Nexcessnet_Turpentine Varnish v3 VCL Template +## Custom VCL Logic - Top + +{{custom_vcl_include_top}} + ## Custom C Code C{ @@ -431,7 +435,7 @@ sub vcl_deliver { } } -## Custom VCL Logic +## Custom VCL Logic - Bottom {{custom_vcl_include}} diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 757601a6f..93c4b4e93 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -18,6 +18,10 @@ vcl 4.0; ## Nexcessnet_Turpentine Varnish v4 VCL Template +## Custom VCL Logic - Top + +{{custom_vcl_include_top}} + ## Custom C Code C{ @@ -432,6 +436,6 @@ sub vcl_deliver { } } -## Custom VCL Logic +## Custom VCL Logic - Bottom {{custom_vcl_include}} From 931516c58e357c02547d637d9f6e085e160c8d22 Mon Sep 17 00:00:00 2001 From: Uwe Kleinmann Date: Tue, 3 May 2016 18:48:10 +0200 Subject: [PATCH 239/311] Add varnish-4-compatible load-balancing configuration including separate admin backends. This is based on the proposed fix by @jdmcd12 in nexcess#937. --- .../Model/Varnish/Configurator/Version4.php | 128 ++++++++++++++++++ .../Nexcessnet/Turpentine/misc/version-4.vcl | 9 +- 2 files changed, 136 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 273c09f1a..4320cb65c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -55,6 +55,134 @@ protected function _getTemplateVars() { $vars = parent::_getTemplateVars(); $vars['advanced_session_validation'] = $this->_getAdvancedSessionValidation(); + + if (Mage::getStoreConfig('turpentine_vcl/backend/load_balancing') != 'no') { + $vars['directors'] = $this->_vcl_directors(); + $vars['admin_backend_hint'] = 'vdir_admin.backend()'; + $vars['set_backend_hint'] = 'set req.backend_hint = vdir.backend();'; + } else { + $vars['directors'] = ''; + $vars['admin_backend_hint'] = 'admin'; + $vars['set_backend_hint'] = ''; + } + return $vars; } + + protected function _vcl_directors() + { + $tpl = <<cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes_admin')); + } else { + $adminBackendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); + } + + $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); + + for($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) { + $tpl .= <<_formatTemplate($tpl, $vars); + } + + /** + * Format a VCL director declaration, for load balancing + * + * @param string $name name of the director, also used to select config settings + * @param array $backendOptions options for each backend + * @return string + */ + protected function _vcl_director($name, $backendOptions) { + $tpl = <<cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes_admin')); + $probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url_admin'); + $prefix = 'admin'; + } else { + $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, + Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); + $probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url'); + + if('admin' == $name) { + $prefix = 'admin'; + } else { + $prefix = ''; + } + } + + $backends = ''; + $number = 0; + foreach ($backendNodes as $backendNode) { + $parts = explode(':', $backendNode, 2); + $host = (empty($parts[0])) ? '127.0.0.1' : $parts[0]; + $port = (empty($parts[1])) ? '80' : $parts[1]; + $backends .= $this->_vcl_director_backend($host, $port, $prefix . $number, $probeUrl, $backendOptions); + + $number++; + } + $vars = array( + 'name' => $name, + 'backends' => $backends + ); + return $this->_formatTemplate($tpl, $vars); + } + + /** + * Format a VCL backend declaration to put inside director + * + * @param string $host backend host + * @param string $port backend port + * @param string $descriptor backend descriptor + * @param string $probeUrl URL to check if backend is up + * @param array $options extra options for backend + * @return string + */ + protected function _vcl_director_backend($host, $port, $descriptor, $probeUrl = '', $options = array()) { + $tpl = << $host, + 'port' => $port, + 'probe' => '' + ); + if ( ! empty($probeUrl)) { + $vars['probe'] = $this->_vcl_get_probe($probeUrl); + } + $str = $this->_formatTemplate($tpl, $vars); + foreach ($options as $key => $value) { + $str .= sprintf(' .%s = %s;', $key, $value).PHP_EOL; + } + $str .= << Date: Wed, 4 May 2016 16:10:47 +0200 Subject: [PATCH 241/311] Revert "Add index.php to matching base url prefix." This reverts commit a20bf5ed103631d6b5d84706a40acac28460b05c. --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 1 - 1 file changed, 1 deletion(-) 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 1d16eeef0..86805aea8 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -270,7 +270,6 @@ protected function _getBaseUrlPaths() { PHP_URL_PATH); } } - $paths[] = "/index.php/"; $paths = array_unique($paths); usort($paths, create_function('$a, $b', 'return strlen( $b ) - strlen( $a );')); From bec41bc416a0e7b2116ea86d5312eeaa518fab1e Mon Sep 17 00:00:00 2001 From: Jan Fervers Date: Thu, 19 May 2016 20:45:01 +0200 Subject: [PATCH 242/311] version-3.vcl normalization, duplicate cookie fix Fix https://github.com/nexcess/magento-turpentine/pull/1078 Issue collection https://github.com/nexcess/magento-turpentine/issues/1180 --- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 05ac503d2..b29e47e51 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -389,7 +389,7 @@ sub vcl_deliver { "; domain=" + regsub(req.http.Host, ":\d+$", ""); } else { # it's a real user, allow sharing of cookies between stores - if(req.http.Host ~ "{{normalize_cookie_regex}}") { + if (req.http.Host ~ "{{normalize_cookie_regex}}" && "{{normalize_cookie_regex}}" ~ "..") { set resp.http.Set-Cookie = resp.http.Set-Cookie + "; domain={{normalize_cookie_target}}"; } else { From 7d44b1de5d1e75db2f94ffeffd449ad0642770e1 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 31 May 2016 10:46:02 -0300 Subject: [PATCH 243/311] Bump version and CHANGELOG.md --- 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 4fa09bf5f..404ca74b5 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.9 + 0.7.0 From 660e8ffbb236c57eb57698c435534a6ba768f3b9 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Wed, 8 Jun 2016 12:18:12 -0400 Subject: [PATCH 244/311] Fix for issue #1093 - poll still displaying when module output disabled --- .../Turpentine/Block/Poll/ActivePoll.php | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php index 8322aa069..56343127f 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php @@ -21,11 +21,19 @@ class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll { - public function setTemplate($template) - { - $this->_template = $template; - $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); - $this->setPollTemplate('turpentine/ajax.phtml', 'results'); - return $this; - } + public function setTemplate($template) + { + if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) && + (!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll'))) + { + $this->_template = $template; + $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); + $this->setPollTemplate('turpentine/ajax.phtml', 'results'); + } + else + { + // Mage_Poll is disabled, so do nothing + } + return $this; + } } From 71dc4d66fda0f2681b66d6828a4d9a3778e99cba Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Wed, 22 Jun 2016 18:36:19 +0000 Subject: [PATCH 245/311] Updated to allow custom VCL templats --- .../Model/Varnish/Configurator/Abstract.php | 21 +++++++++++++++++-- .../Model/Varnish/Configurator/Version3.php | 9 +++++++- .../Model/Varnish/Configurator/Version4.php | 9 +++++++- .../Nexcessnet/Turpentine/etc/config.xml | 1 + .../Nexcessnet/Turpentine/etc/system.xml | 9 ++++++++ 5 files changed, 45 insertions(+), 4 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 86805aea8..d97bf7d26 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -110,8 +110,8 @@ public function save($generatedConfig) { * @return string */ protected function _getVclTemplateFilename($baseFilename) { - $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); - return sprintf('%s/misc/%s', $extensionDir, $baseFilename); + $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); + return sprintf('%s/misc/%s', $extensionDir, $baseFilename); } /** @@ -136,6 +136,23 @@ protected function _getCustomIncludeFilename() { array('root_dir' => Mage::getBaseDir()) ); } + + /** + * Get the custom VCL template, if it exists + * Returns 'null' if the file doesn't exist + * + * @return string + */ + protected function _getCustomTemplateFilename() { + $filePath = $this->_formatTemplate( + Mage::getStoreConfig('turpentine_varnish/servers/custom_vcl_template'), + array('root_dir' => Mage::getBaseDir()) + ); + if (is_file($filePath)) { return $filePath; } + else { return null; } + } + + /** * Format a template string, replacing {{keys}} with the appropriate values * and remove unspecified keys diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php index 745ec6076..2247404b0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php @@ -31,7 +31,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3 * @return string */ public function generate($doClean = true) { - $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + // first, check if a custom template is set + $customTemplate = $this->_getCustomTemplateFilename(); + if ($customTemplate) { + $tplFile = $customTemplate; + } + else { + $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + } $vcl = $this->_formatTemplate(file_get_contents($tplFile), $this->_getTemplateVars()); return $doClean ? $this->_cleanVcl($vcl) : $vcl; diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 273c09f1a..ba5f42826 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -31,7 +31,14 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version4 * @return string */ public function generate($doClean = true) { - $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + // first, check if a custom template is set + $customTemplate = $this->_getCustomTemplateFilename(); + if ($customTemplate) { + $tplFile = $customTemplate; + } + else { + $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); + } $vcl = $this->_formatTemplate(file_get_contents($tplFile), $this->_getTemplateVars()); return $doClean ? $this->_cleanVcl($vcl) : $vcl; diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 404ca74b5..6bc619ebd 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -47,6 +47,7 @@ 127.0.0.1:6082 {{root_dir}}/var/default.vcl {{root_dir}}/app/code/community/Nexcessnet/Turpentine/misc/custom_include.vcl + diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index a5960bbd0..174c57f54 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -242,6 +242,15 @@ 0 0 + + + text + If defined and present, this template will be used instead of the default VCL template appropriate for the version of Varnish. + 50 + 1 + 0 + 0 + From 2fd128e55de5a522cb0eaab6587d43d6d9ddb40f Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Thu, 23 Jun 2016 15:01:31 +0200 Subject: [PATCH 246/311] Issue #1213: ESI-Blocks are missing "global" blocks like formkey --- .../Nexcessnet/Turpentine/controllers/EsiController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index fb66776ab..45c05d908 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -253,6 +253,15 @@ protected function _getEsiBlock($esiData) { $layout->generateBlocks($node); } } + if ($roots = $layout->getNode()->xpath('//block[@name=\'root\']')) { + foreach (array('formkey') as $globalBlock) { + if ($blocks = $layout->getNode()->xpath(sprintf('//block[@name=\'%s\']', $globalBlock))) { + $dummy = $roots[0]->addChild('reference'); + $dummy->appendChild($blocks[0]); + $layout->generateBlocks($dummy); + } + } + } $block = $layout->getBlock($esiData->getNameInLayout()); if ( ! $this->getFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT)) { From 7f5cc3325fa00316a3330c2267c2073128f337dc Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Thu, 23 Jun 2016 20:02:06 +0000 Subject: [PATCH 247/311] Adds and implements option to log all commands sent to Varnish --- .../Turpentine/Model/Varnish/Admin/Socket.php | 3 +++ .../community/Nexcessnet/Turpentine/etc/system.xml | 12 ++++++++++++ 2 files changed, 15 insertions(+) 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 4c6e14b48..3df98e393 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -499,6 +499,9 @@ protected function _command($verb, $okCode = 200) { "Got unexpected response code from Varnish: %d\n%s", $response['code'], $response['text'] )); } else { + if (Mage::getStoreConfig('turpentine_varnish/general/varnish_log_commands')) { + Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: ' . $data); + } return $response; } } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index a5960bbd0..961f9a101 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -82,6 +82,16 @@ 0 0 + + + Log all commands sent to Varnish by Turpentine in the log specified (custom if enabled). Caution - can cause logs to grow quickly! + select + turpentine/config_select_toggle + 45 + 1 + 0 + 0 + Log block names for adding ESI, only enable when needed to avoid performance hit @@ -92,6 +102,8 @@ 0 0 + + Enable fixing the messages block to load via AJAX, disable if you already have an extension that does this From b14b6a9a5e8cec6de8697df4e1d77f144129bfc0 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 28 Jun 2016 20:18:42 -0300 Subject: [PATCH 248/311] Added changelog. --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc646b25f..f58411bb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -440,4 +440,11 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#1155] Update TECHNICAL_NOTES.md. (@GLips) ### RELEASE-0.6.9 + * [#1162] Support PHP7. (@allardhoeve) + * [#1173] Fix load balancing for Varnish 4. (@kleinmann) + * [#1182] Update version-3.vcl normalisation. (@gewaechshaus) + +### RELEASE-0.7.0 + + From 959411d26124da9efd0be33db89c01b7861eac70 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Thu, 7 Jul 2016 20:35:42 +0000 Subject: [PATCH 249/311] Adds more information when considering whether to inject a block --- .../Nexcessnet/Turpentine/Model/Observer/Esi.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 0ae107d8c..86d598fc3 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -226,12 +226,19 @@ public function injectEsi($eventObject) { $debugHelper->logInfo( 'Checking ESI block candidate: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); - } + + $debugHelper->logInfo( "-- block testing: shouldResponseUseEsi = " . $esiHelper->shouldResponseUseEsi()); + $debugHelper->logInfo( "-- block testing: instanceof Mage_Core_Block_Template = " . $blockObject instanceof Mage_Core_Block_Template ); + $debugHelper->logInfo( "-- block testing: Esi Options = " . print_r($blockObject->getEsiOptions(), true) ); + } if ($esiHelper->shouldResponseUseEsi() && $blockObject instanceof Mage_Core_Block_Template && $esiOptions = $blockObject->getEsiOptions()) { if ((isset($esiOptions['disableEsiInjection'])) && ($esiOptions['disableEsiInjection'] == 1)) { + if ($esiHelper->getEsiBlockLogEnabled()) { + $debugHelper->logInfo("-- ESI Injection disabled"); + } return; } From 80bee8dd430150fc7508042eebe7c9c2cb6f9792 Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Mon, 11 Jul 2016 17:07:55 +0000 Subject: [PATCH 250/311] Condensed the UA "buckets" down to just "mobile" and "other" for improved cache hitrate --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 10 ---------- 1 file changed, 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 86805aea8..8bf76e35d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -769,16 +769,6 @@ protected function _vcl_sub_normalize_user_agent() { $tpl = << Date: Wed, 20 Jul 2016 15:31:49 +0000 Subject: [PATCH 251/311] Adds better logging of hash_data calls in vcl_hash --- .../Nexcessnet/Turpentine/misc/version-4.vcl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 757601a6f..b75fc79c9 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -234,48 +234,65 @@ sub vcl_pipe { # } sub vcl_hash { + std.log("vcl_hash start"); + # For static files we keep the hash simple and don't add the domain. # This saves memory when a static file is used on multiple domains. if ({{simple_hash_static}} && req.http.X-Varnish-Static) { + std.log("hash_data static file - req.url: " + req.url); hash_data(req.url); if (req.http.Accept-Encoding) { # make sure we give back the right encoding + std.log("hash_data static file - Accept-Encoding: " + req.http.Accept-Encoding); hash_data(req.http.Accept-Encoding); } + std.log("vcl_hash end return lookup"); return (lookup); } + if({{send_unmodified_url}} && req.http.X-Varnish-Cache-Url) { hash_data(req.http.X-Varnish-Cache-Url); + std.log("hash_data - X-Varnish-Cache-Url: " + req.http.X-Varnish-Cache-Url); } else { hash_data(req.url); + std.log("hash_data - req.url: " + req.url ); } if (req.http.Host) { hash_data(req.http.Host); + std.log("hash_data - req.http.Host: " + req.http.Host); } else { hash_data(server.ip); } + + std.log("hash_data - req.http.Ssl-Offloaded: " + req.http.Ssl-Offloaded); hash_data(req.http.Ssl-Offloaded); + if (req.http.X-Normalized-User-Agent) { hash_data(req.http.X-Normalized-User-Agent); + std.log("hash_data - req.http.X-Normalized-User-Agent: " + req.http.X-Normalized-User-Agent); } if (req.http.Accept-Encoding) { # make sure we give back the right encoding hash_data(req.http.Accept-Encoding); + std.log("hash_data - req.http.Accept-Encoding: " + req.http.Accept-Encoding); } if (req.http.X-Varnish-Store || req.http.X-Varnish-Currency) { # make sure data is for the right store and currency based on the *store* # and *currency* cookies hash_data("s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency); + std.log("hash_data - Store and Currency: " + "s=" + req.http.X-Varnish-Store + "&c=" + req.http.X-Varnish-Currency); } if (req.http.X-Varnish-Esi-Access == "private" && req.http.Cookie ~ "frontend=") { + std.log("hash_data - frontned cookie: " + regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1")); hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1")); {{advanced_session_validation}} } + std.log("vcl_hash end return lookup"); return (lookup); } From e701772b087b17d5a153025711772bedb587a59f Mon Sep 17 00:00:00 2001 From: Aric Watson Date: Wed, 27 Jul 2016 11:42:29 -0400 Subject: [PATCH 252/311] Adds more flexibility/options to warch-cache.sh --- util/warm-cache.sh | 100 +++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 36 deletions(-) diff --git a/util/warm-cache.sh b/util/warm-cache.sh index 4952fe76c..300559803 100755 --- a/util/warm-cache.sh +++ b/util/warm-cache.sh @@ -17,49 +17,77 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -SITEMAP_URL="$1" -TMP_URL_FILE="/tmp/urls_$(cat /proc/sys/kernel/random/uuid).txt" -PROCS="${PROCS-$(grep processor /proc/cpuinfo | wc -l)}" -echo '' | xpath -e '*' &>/dev/null +show_help() +{ + echo "Warm the Varnish page cache by using siege to hit a list of URLs." + echo "Options:" + echo "-u URL source - either the URL of a magento sitemap xml file, or the path to a file containing URLS - one per line" + echo "-a User-Agent to use" + echo "-c Number of concurrent \"users\" - siege will hit this many urls at once. Higher numbers = more server load." -if [ $? -eq 2 ]; then - XPATH_BIN='xpath' -else - XPATH_BIN='xpath -e' +} + +# set defaults +CONC=3 # default concurrency level +TMP_URL_FILE="./urls_$RANDOM.txt" # location to store temporarily URL file +REMOVE_TMP_FILE=1 + +if [ $# -lt 1 ]; then + show_help + exit 1 fi -if [ -z "$SITEMAP_URL" ]; then - cat < +while getopts :u:a:c: opt +do + case "$opt" in + u) URLS="$OPTARG";; + a) AGENT="$OPTARG";; + c) CONC="$OPTARG";; + \?) show_help;; + esac +done - Warm Magento's cache by visiting the URLs in Magento's sitemap - Example: - $0 http://example.com/magento/sitemap.xml -EOF +# process URLS as needed +if [[ $URLS =~ ^http ]]; then #fetch URLs from sitemap URL + + echo '' | xpath -e '*' &>/dev/null - exit 1 -fi + if [ $? -eq 2 ]; then + XPATH_BIN='xpath' + else + XPATH_BIN='xpath -e' + fi -echo "Getting URLs from sitemap..." + echo "Getting URLs from sitemap..." -curl -ks "$SITEMAP_URL" | \ - $XPATH_BIN '/urlset/url/loc/text()' 2>/dev/null | \ + curl -ks "$URLS" | \ + $XPATH_BIN '/urlset/url/loc/text()' 2>/dev/null | \ sed -r 's~http(s)?:~\nhttp\1:~g' | \ - grep -vE '^\s*$' > "$TMP_URL_FILE" - -echo "Warming $(cat $TMP_URL_FILE | wc -l) URLs using $PROCS processes..." - -cat "$TMP_URL_FILE" | \ - xargs -P "$PROCS" -r -n 1 -- \ - siege -b -v -c 1 -r once 2>/dev/null | \ - sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | \ - grep -E '^HTTP' -cat "$TMP_URL_FILE" | \ - xargs -P "$PROCS" -r -n 1 -- \ - siege -H 'Accept-Encoding: gzip' -b -v -c 1 -r once 2>/dev/null | \ - sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | \ - grep -E '^HTTP' - -rm -f "$TMP_URL_FILE" + grep -vE '^\s*$' > "$TMP_URL_FILE" +else + TMP_URL_FILE=$URLS + REMOVE_TMP_FILE=0 + if [ -f $TMP_URL_FILE ]; then + echo "Getting URLs from $TMP_URL_FILE..." + else + echo "No URL file found at $TMP_URL_FILE" + exit 1 + fi +fi + +UA="" +if [[ $AGENT =~ .. ]]; then + UA="-A '$AGENT'" + echo "Warning with User-Agent '$AGENT'" +fi + +echo "Warming $(cat $TMP_URL_FILE | wc -l) URLs using $CONC concurrent users..." +siege -b -v -c $CONC -f $TMP_URL_FILE -r once $UA -H 'Accept-Encoding: gzip' 2>/dev/null + +if [ $REMOVE_TMP_FILE == 1 ]; then + rm -f "$TMP_URL_FILE" +fi + +exit 0 From 8d1e5067ce2f74cfd2a9f33b0f6d2b17ee5b29f6 Mon Sep 17 00:00:00 2001 From: Jan Gantzert Date: Sat, 30 Jul 2016 14:11:13 +0200 Subject: [PATCH 253/311] #838 Add customer_group caching to varnish 4 template --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 757601a6f..14469ce1e 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -276,6 +276,11 @@ sub vcl_hash { {{advanced_session_validation}} } + + if (req.http.X-Varnish-Esi-Access == "customer_group" && + req.http.Cookie ~ "customer_group=") { + hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1")); + } return (lookup); } From 3a92fc3b2936d9968ca8256b7ec8387f3f817e49 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Mon, 8 Aug 2016 22:15:05 +0200 Subject: [PATCH 254/311] Fix for error when you want to use the "std" plugin in your 'custom_vcl_include_top' script. --- .../community/Nexcessnet/Turpentine/misc/version-2.vcl | 7 +++---- .../community/Nexcessnet/Turpentine/misc/version-3.vcl | 8 ++++---- .../community/Nexcessnet/Turpentine/misc/version-4.vcl | 8 ++++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 2ce648bef..2223bedbc 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -17,10 +17,6 @@ ## Nexcessnet_Turpentine Varnish v2 VCL Template -## Custom VCL Logic - Top - -{{custom_vcl_include_top}} - ## Custom C Code C{ @@ -28,6 +24,9 @@ C{ {{custom_c_code}} }C +## Custom VCL Logic - Top + +{{custom_vcl_include_top}} ## Backends diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 743cb9e21..06682eb30 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -17,10 +17,6 @@ ## Nexcessnet_Turpentine Varnish v3 VCL Template -## Custom VCL Logic - Top - -{{custom_vcl_include_top}} - ## Custom C Code C{ @@ -32,6 +28,10 @@ C{ import std; +## Custom VCL Logic - Top + +{{custom_vcl_include_top}} + ## Backends {{default_backend}} diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 505cdfccc..9504427b5 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -18,10 +18,6 @@ vcl 4.0; ## Nexcessnet_Turpentine Varnish v4 VCL Template -## Custom VCL Logic - Top - -{{custom_vcl_include_top}} - ## Custom C Code C{ @@ -34,6 +30,10 @@ C{ import std; import directors; +## Custom VCL Logic - Top + +{{custom_vcl_include_top}} + ## Backends {{default_backend}} From 7549ddea1b6a07a61375d6b22bd5e737e2767068 Mon Sep 17 00:00:00 2001 From: Carey Sizer Date: Wed, 10 Aug 2016 19:25:35 +1200 Subject: [PATCH 255/311] Fix issue with customer name not being removed from header when clearing persistent cookie The default Magento functionality provides a "Not ?" link to allow a customer to clear the persistent cookie on return to Magento. Clicking this link with Turpentine enabled doesn't cause the header to be purged. This fix adds the "persistent_session_expired" event to the default header's flush_events. This event is dispatched by Mage_Persistent_IndexController::_cleanup() --- app/design/frontend/base/default/layout/turpentine_esi.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index 9cd985aad..2734dfe11 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -44,7 +44,8 @@ - + + From 7558952db44bd5c42b45e559c092d716674d7e29 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Fri, 12 Aug 2016 17:19:00 +0200 Subject: [PATCH 256/311] Bugfix in "Normalize Encoding": When visitor accepts "*" he also accepts gzip. This is a performance fix for newer versions of Siege. They use "Accept-Encoding: *". --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7d1fb8c99..3549c1188 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -806,7 +806,7 @@ protected function _vcl_sub_normalize_user_agent() { protected function _vcl_sub_normalize_encoding() { $tpl = << Date: Fri, 12 Aug 2016 17:24:13 +0200 Subject: [PATCH 257/311] Fixed Crawler UserAgent regexp to match newer Siege versions. --- 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 6bc619ebd..66a07fa33 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -62,7 +62,7 @@ 300 21600 127.0.0.1 - + 1 From 3fd803524d2f03ab6451b94581aa17f6e9fae055 Mon Sep 17 00:00:00 2001 From: Andreas Emer Date: Thu, 18 Aug 2016 16:38:45 +0200 Subject: [PATCH 258/311] #963 Fix the Nginx 403 issue with urls which are starting with a dot --- app/code/community/Nexcessnet/Turpentine/Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php index a357b7a47..f91f1407d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Data.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Data.php @@ -130,7 +130,7 @@ public function getVersion() { public function urlBase64Encode($str) { return str_replace( array('/', '+'), - array('.', '-'), + array('_', '-'), base64_encode($str) ); } @@ -143,7 +143,7 @@ public function urlBase64Encode($str) { public function urlBase64Decode($str) { return base64_decode( str_replace( - array('.', '-'), + array('_', '-'), array('/', '+'), $str ) ); } From 7868ac48ffc4525cc1f1e9fab06ba68c6060ed8f Mon Sep 17 00:00:00 2001 From: Jan Gantzert Date: Sat, 20 Aug 2016 01:08:34 +0200 Subject: [PATCH 259/311] #878 Add onepage checkout progress review for varnish exclude in config --- app/design/frontend/base/default/layout/turpentine_esi.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index 9cd985aad..3277ebf20 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -269,6 +269,10 @@ + + + + From c55c70dedc3e325f96978b8576a6f8503137506e Mon Sep 17 00:00:00 2001 From: "Alex.Velykzhanin" Date: Tue, 30 Aug 2016 14:49:20 +0200 Subject: [PATCH 260/311] Improve condition to support safari browser Event --- .../frontend/base/default/template/turpentine/ajax.phtml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/design/frontend/base/default/template/turpentine/ajax.phtml b/app/design/frontend/base/default/template/turpentine/ajax.phtml index 4756c9f55..f67b3dac9 100644 --- a/app/design/frontend/base/default/template/turpentine/ajax.phtml +++ b/app/design/frontend/base/default/template/turpentine/ajax.phtml @@ -50,7 +50,9 @@ echo << (function() { var blockTag = {$this->helper('core')->jsonEncode($blockTag)}, esiUrl = {$this->helper('core')->jsonEncode($this->getEsiUrl())}; - if (typeof Ajax === 'object' && typeof Ajax.Updater === 'function' && typeof Event === 'function' ) { + if (typeof Ajax === 'object' && typeof Ajax.Updater === 'function' + && (typeof Event === 'function' || (typeof Event === 'object' && typeof Event.observe === 'function')) + ) { Event.observe( window, "load", function() { setTimeout( function() { new Ajax.Updater( blockTag, From c38b0b848d29566219b76df1fccfd1f5ee54eb6c Mon Sep 17 00:00:00 2001 From: Dmytro Vasylenko Date: Mon, 19 Sep 2016 15:39:50 +0300 Subject: [PATCH 261/311] Added one more format for configuration regexp --- .../Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php | 2 +- 1 file changed, 1 insertion(+), 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 3df98e393..c2e50f270 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -407,7 +407,7 @@ protected function _write($data) { $regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~'; if ($this->getVersion() === '4.0') { // Varnish4 supports "16k" style notation - $regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g]{1})?\s+\[bytes\]~'; + $regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g|b]{1})?\s+\[bytes\]~'; } if (preg_match($regexp, $cliBufferResponse['text'], $match)) { $realLimit = (int) $match[1]; From 796832e68b482fc8ef3fafcfd4a6d8381f9d5d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ho=C3=A0ng=20M=E1=BA=A1nh=20Ph=C3=BA?= Date: Thu, 29 Sep 2016 15:50:11 +0700 Subject: [PATCH 262/311] When using Varnish as front door listen on port 80 and Nginx/Apache listen on port 443 for HTTPS, the fix will keep the url parameters when redirect from HTTP to HTTPS. --- .../Model/Varnish/Configurator/Abstract.php | 22 +++++++++++++++++++ .../Nexcessnet/Turpentine/etc/system.xml | 12 +++++++++- .../Nexcessnet/Turpentine/misc/version-3.vcl | 10 +++++++++ .../Nexcessnet/Turpentine/misc/version-4.vcl | 10 +++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) 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 86805aea8..5220cd898 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -887,6 +887,24 @@ protected function _vcl_sub_maintenance_allowed_ips() { 'debug_ips' => Mage::getStoreConfig('dev/restrict/allow_ips') )); } + /** + * When using Varnish as front door listen on port 80 and Nginx/Apache listen on port 443 for HTTPS, the fix will keep the url parameters when redirect from HTTP to HTTPS. + * + * @return string + */ + protected function _vcl_sub_https_redirect_fix() { + $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); + $baseUrl = str_replace(array('http://','https://'), '', $baseUrl); + $baseUrl = rtrim($baseUrl,'/'); + + $tpl = <<_vcl_sub_synth(); } + + if (Mage::getStoreConfig('turpentine_varnish/general/https_redirect_fix')) { + $vars['https_redirect'] = $this->_vcl_sub_https_redirect_fix(); + } $customIncludeFile = $this->_getCustomIncludeFilename(); if (is_readable($customIncludeFile)) { diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index a5960bbd0..f4883321f 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -66,12 +66,22 @@ When Enable is selected, a VCL fix will be used to prevent formKey issues. If Disable is selected, an observer will be used. select - 28 + 26 adminhtml/system_config_source_enabledisable 1 1 1 + + + When using Varnish as front door listen on port 80 and Nginx/Apache listen on port 443 for HTTPS, the fix will keep the url parameters when redirect from HTTP to HTTPS. + select + 28 + adminhtml/system_config_source_enabledisable + 1 + 1 + 1 + It is a major security vulnerability, to leave this enabled on production sites diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index 05ac503d2..51cd426f5 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -92,9 +92,19 @@ sub generate_session_expires { {{generate_session_end}} ## Varnish Subroutines +sub vcl_synth { + if (resp.status == 750) { + set resp.status = 301; + set resp.http.Location = "https://" + req.http.host + req.url; + return(deliver); + } +} + sub vcl_recv { {{maintenance_allowed_ips}} + {{https_redirect}} + # this always needs to be done so it's up at the top if (req.restarts == 0) { if (req.http.X-Forwarded-For) { diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 757601a6f..58396ee22 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -97,9 +97,19 @@ sub generate_session_expires { {{generate_session_end}} ## Varnish Subroutines +sub vcl_synth { + if (resp.status == 750) { + set resp.status = 301; + set resp.http.Location = "https://" + req.http.host + req.url; + return(deliver); + } +} + sub vcl_recv { {{maintenance_allowed_ips}} + {{https_redirect}} + # this always needs to be done so it's up at the top if (req.restarts == 0) { if (req.http.X-Forwarded-For) { From 3582803b399b72c45eb34007fe7f7f17eecf4794 Mon Sep 17 00:00:00 2001 From: Dmytro Vasylenko Date: Sat, 1 Oct 2016 14:39:08 +0300 Subject: [PATCH 263/311] Fix possible issue with limit validation --- .../Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php | 2 +- 1 file changed, 1 insertion(+), 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 c2e50f270..7ae3ad6fa 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -412,7 +412,7 @@ protected function _write($data) { if (preg_match($regexp, $cliBufferResponse['text'], $match)) { $realLimit = (int) $match[1]; if (isset($match[2])) { - $factors = array('k'=>1, 'm'=>2, 'g'=>3); + $factors = array('b'=>0, 'k'=>1, 'm'=>2, 'g'=>3); $realLimit *= pow(1024, $factors[$match[2]]); } } else { From 397c6a9736c4a5a39a1c20f3661d6f3f43a42151 Mon Sep 17 00:00:00 2001 From: Nick Kravchuk Date: Wed, 19 Oct 2016 16:04:21 +0300 Subject: [PATCH 264/311] Removed unused code one more try ;) --- app/code/community/Nexcessnet/Turpentine/Block/Management.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Management.php b/app/code/community/Nexcessnet/Turpentine/Block/Management.php index ff66045b4..d7c22d80e 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Management.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Management.php @@ -24,7 +24,7 @@ class Nexcessnet_Turpentine_Block_Management public function __construct() { $this->_controller = 'varnish_management'; - // $this->setTemplate( 'turpentine/varnish_management.phtml' ); + parent::__construct(); } From 0b14a30968fb89b8343df3c2a3a8f10fc249604b Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Wed, 26 Oct 2016 12:08:05 +0200 Subject: [PATCH 265/311] Fix for picking the wrong block from the layout when multiple blocks found Some themes like Ultimo use `unsetChild` to remove default Magento blocks, and create the block again with the same name but other properties in another place. The `unsetChild` action does not remove a block from the XML, only from the object structure. When an ESI block is requested, the controller was only looking for the name of the block in the layout XML, so in some cases it picked the removed block. I added a check for setEsiOptions inside the block XML, with a fallback to the old behaviour. --- .../Nexcessnet/Turpentine/Helper/Esi.php | 26 +++++++++++++++++++ .../Turpentine/Model/Observer/Esi.php | 5 ++-- .../Turpentine/controllers/EsiController.php | 6 ++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index 00250a122..f7b263059 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -362,6 +362,32 @@ public function getFormKeyEsiUrl() { return $esiUrl; } + /** + * Grab a block node by name from the layout XML. + * + * Multiple blocks with the same name may exist in the layout, because some themes + * use 'unsetChild' to remove a block and create it with the same name somewhere + * else. For example Ultimo does this. + * + * @param Mage_Core_Model_Layout $layout + * @param string $blockName value of name= attribute in layout XML + * @return Mage_Core_Model_Layout_Element + */ + public function getEsiLayoutBlockNode($layout,$blockName) { + // first try very specific by checking for action setEsiOptions inside block + $blockNode = current($layout->getNode()->xpath( + sprintf('//block[@name=\'%s\'][action[@method=\'setEsiOptions\']]', + $blockName) + )); + // fallback: only match name + if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { + $blockNode = current($layout->getNode()->xpath( + sprintf('//block[@name=\'%s\']', $blockName) + )); + } + return $blockNode; + } + /** * Load the ESI cache clear events from the layout * diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 09d4a4c10..a79b7727d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -415,9 +415,8 @@ protected function _getBlockLayoutHandles($block) { $activeHandles = array(); // get the xml node representing the block we're working on (from the // default handle probably) - $blockNode = current($layout->getNode()->xpath(sprintf( - '//block[@name=\'%s\']', - $block->getNameInLayout() ))); + $blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode( + $layout, $block->getNameInLayout()); $childBlocks = Mage::helper('turpentine/data') ->getChildBlockNames($blockNode); foreach ($childBlocks as $blockName) { diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index c7c136cdf..061f913f6 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -212,10 +212,8 @@ protected function _getEsiBlock($esiData) { $turpentineHelper = Mage::helper('turpentine/data') ->setLayout($layout); - $blockNode = current($layout->getNode()->xpath( - sprintf('//block[@name=\'%s\']', $esiData->getNameInLayout()) - )); - + $blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode( + $layout, $esiData->getNameInLayout()); if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { Mage::helper('turpentine/debug')->logWarn( 'No block node found with @name="%s"', From 0107429c20d1f14c62d0797b8165b5d4eaf7f3f2 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 15 Nov 2016 09:54:32 -0300 Subject: [PATCH 266/311] Added changelog and bumped version to merge with master. --- CHANGELOG.md | 26 +++++++++++++++++-- .../Nexcessnet/Turpentine/etc/config.xml | 2 +- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f58411bb9..014215a95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -439,12 +439,34 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#1117] Fix #1100. (@GLips) * [#1155] Update TECHNICAL_NOTES.md. (@GLips) -### RELEASE-0.6.9 +### RELEASE-0.6.9 -> 0.7.0 * [#1162] Support PHP7. (@allardhoeve) * [#1173] Fix load balancing for Varnish 4. (@kleinmann) * [#1182] Update version-3.vcl normalisation. (@gewaechshaus) -### RELEASE-0.7.0 +### RELEASE-0.7.1 + + * [#1189] Custom Admin Path with Add Store Code to URLs (@miguelbalparda) + * [#1195] Fix for issue #1093 - poll still displaying when module output disabled (@aricwatson) + * [#1212] Allows Custom VCL template (@aricwatson) + * [#1214] Generate global blocks like formkey for ESI-Blocks (@possi) + * [#1216] Adds and implements an option to log all commands sent to Varnish (@aricwatson) + * [#1225] Enhanced block logging (@aricwatson) + * [#1226] Condensed the UA "buckets" down to just "mobile" and "other" (@aricwatson) + * [#1232] Adds better logging of hash_data calls in vcl_hash (@aricwatson) + * [#1243] Adds more flexibility/options to warm-cache.sh (@aricwatson) + * [#1254] Add customer_group caching to varnish 4 template feature (@jg-development) + * [#1258] Fix issue with customer name not being removed from header when clearing persistent cookie (@careysizer) + * [#1261] Fixed Crawler UserAgent regexp to match newer Siege versions. (@jeroenvermeulen) + * [#1262] Bugfix in "Normalize Encoding" for visitors who accept "*" (@jeroenvermeulen) + * [#1264] #963 Fix the Nginx 403 issue with urls which are starting with a dot (@andreasemer) + * [#1266] #878 Add onepage checkout progress review for varnish exclude in config (@jg-development) + * [#1271] #1270 Fix: Improve condition to support safari browser Event feature (@AlexanderPok) + * [#1282] Added one more format for configuration regexp bug (@odi-um) + * [#1289] Fix the issue when redirect HTTP to HTTPS feature (@hmphu) + * [#1298] Removed unused code (@nickua) + + diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 7a82afea0..7934d4e8e 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -20,7 +20,7 @@ - 0.7.0 + 0.7.1 From b1155b3bb34cd8d80b2127e95854da509f6eba22 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Wed, 16 Nov 2016 08:21:00 -0300 Subject: [PATCH 267/311] Resolving conflicts and fixing a bad merge. --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 88d4e177d..efef43060 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -313,15 +313,12 @@ sub vcl_hash { {{advanced_session_validation}} } -<<<<<<< HEAD - std.log("vcl_hash end return lookup"); -======= if (req.http.X-Varnish-Esi-Access == "customer_group" && req.http.Cookie ~ "customer_group=") { hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1")); } ->>>>>>> master + std.log("vcl_hash end return lookup"); return (lookup); } From 981952971914971aac37ea466bc9833fbe4b5d4e Mon Sep 17 00:00:00 2001 From: Phu Hoang Date: Thu, 17 Nov 2016 13:47:59 +0700 Subject: [PATCH 268/311] Keep params from original url --- .../community/Nexcessnet/Turpentine/Model/Observer/Esi.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index 09d4a4c10..2b1040c5a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -297,6 +297,11 @@ public function injectEsi($eventObject) { ); } + /** + * Keep params from original url + */ + $urlOptions['_query'] = Mage::app()->getRequest()->getParams(); + $esiUrl = Mage::getUrl('turpentine/esi/getBlock', $urlOptions); if ($esiOptions[$methodParam] == 'esi') { // setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS From 4c0e5674eb42c71dc74d1a7d1afb6c1668d64bee Mon Sep 17 00:00:00 2001 From: Phu Hoang Date: Thu, 17 Nov 2016 20:03:05 +0700 Subject: [PATCH 269/311] Correct varnish v3 template --- .../Model/Varnish/Configurator/Abstract.php | 13 ++++++++++++- .../Nexcessnet/Turpentine/misc/version-3.vcl | 8 ++++---- 2 files changed, 16 insertions(+), 5 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 77e4ec675..f83c1bfd4 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -910,11 +910,22 @@ protected function _vcl_sub_https_redirect_fix() { $baseUrl = str_replace(array('http://','https://'), '', $baseUrl); $baseUrl = rtrim($baseUrl,'/'); - $tpl = << Date: Thu, 17 Nov 2016 20:49:10 +0700 Subject: [PATCH 270/311] Migrate vcl_synth subroutine for Varnish v4 --- .../Model/Varnish/Configurator/Abstract.php | 37 +++++++++++++++++++ .../Nexcessnet/Turpentine/misc/version-4.vcl | 8 ---- 2 files changed, 37 insertions(+), 8 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 f83c1bfd4..f539e2b41 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -969,6 +969,40 @@ protected function _vcl_sub_synth() 'vcl_synth_content' => Mage::getStoreConfig('turpentine_vcl/maintenance/custom_vcl_synth'))); } + /** + * vcl_synth for fixing https + * + * @return string + */ + protected function _vcl_sub_synth_https_fix() + { + $tpl = $this->_vcl_sub_synth(); + + if(!$tpl){ + $tpl = <<_vcl_sub_https_redirect_fix(); + if(Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0'){ + $vars['vcl_synth'] = $this->_vcl_sub_synth_https_fix(); + } } foreach (array('','top') as $position) { diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index efef43060..5b5758b8d 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -102,14 +102,6 @@ sub generate_session_expires { {{generate_session_end}} ## Varnish Subroutines -sub vcl_synth { - if (resp.status == 750) { - set resp.status = 301; - set resp.http.Location = "https://" + req.http.host + req.url; - return(deliver); - } -} - sub vcl_init { {{directors}} } From e519dc81d071ddb100edaa84e538651c7a8bf732 Mon Sep 17 00:00:00 2001 From: bordeo Date: Wed, 14 Dec 2016 12:37:08 +0100 Subject: [PATCH 271/311] varnish 4.1 compatibility --- .../Nexcessnet/Turpentine/Model/Config/Select/Version.php | 1 + .../Nexcessnet/Turpentine/Model/Varnish/Admin.php | 2 +- .../Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php | 7 ++++--- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php index e88251213..0ce6b3f7b 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php @@ -26,6 +26,7 @@ public function toOptionArray() { array('value' => '2.1', 'label' => $helper->__('2.1.x')), array('value' => '3.0', 'label' => $helper->__('3.0.x')), array('value' => '4.0', 'label' => $helper->__('4.0.x')), + array('value' => '4.1', 'label' => $helper->__('4.1.x')), array('value' => 'auto', 'label' => $helper->__('Auto')), ); } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 6dbb2115d..096448da0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -138,7 +138,7 @@ protected function _testEsiSyntaxParam($socket) { $result = false; if ($helper->csrfFixupNeeded()) { - if ($socket->getVersion() === '4.0') { + if ($socket->getVersion() === '4.0' || $socket->getVersion() === '4.1' ) { $paramName = 'feature'; $value = $socket->param_show($paramName); $value = explode("\n", $value['text']); 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 7ae3ad6fa..fadcb2c38 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -82,7 +82,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { // varnish default, can only be changed at Varnish startup time // if data to write is over this limit the actual run-time limit is checked // and used - const CLI_CMD_LENGTH_LIMIT = 8192; + const CLI_CMD_LENGTH_LIMIT = 16384; /** * Regexp to detect the varnish version number @@ -93,7 +93,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { /** * VCL config versions, should match config select values */ - static protected $_VERSIONS = array('2.1', '3.0', '4.0'); + static protected $_VERSIONS = array('2.1', '3.0', '4.0', '4.1'); /** * Varnish socket connection @@ -405,7 +405,7 @@ protected function _write($data) { if ($dataLength >= self::CLI_CMD_LENGTH_LIMIT) { $cliBufferResponse = $this->param_show('cli_buffer'); $regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~'; - if ($this->getVersion() === '4.0') { + if ($this->getVersion() === '4.0' || $this->getVersion() === '4.1') { // Varnish4 supports "16k" style notation $regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g|b]{1})?\s+\[bytes\]~'; } @@ -518,6 +518,7 @@ protected function _translateCommandMethod($verb) { case '2.1': $command = str_replace('ban', 'purge', $command); break; + case '4.1': case '4.0': case '3.0': $command = str_replace('purge', 'ban', $command); 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 f539e2b41..a8c6149a7 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -40,6 +40,7 @@ static public function getFromSocket($socket) { } switch ($version) { case '4.0': + case '4.1': return Mage::getModel( 'turpentine/varnish_configurator_version4', array('socket' => $socket) ); @@ -868,6 +869,7 @@ protected function _vcl_sub_maintenance_allowed_ips() { switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) { case 4.0: + case 4.1: $tpl = <<_vcl_sub_https_redirect_fix(); - if(Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0'){ + if(Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0' || Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.1'){ $vars['vcl_synth'] = $this->_vcl_sub_synth_https_fix(); } } From 71573b16446c125cbb237b7a226d9bf98896cbec Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Thu, 15 Dec 2016 12:24:14 +0100 Subject: [PATCH 272/311] Small fix for notice when CM_REDISSESSION_LOCKING_ENABLED is already defined Example: 2016-12-15T11:01:56+00:00 ERR (3): Notice: Constant CM_REDISSESSION_LOCKING_ENABLED already defined in /path/to/httpdocs/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php on line 69 --- .../community/Nexcessnet/Turpentine/Model/Observer/Varnish.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index 7eb51c4e3..bfab14f7d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -65,7 +65,8 @@ public function addProductListToolbarRewrite($eventObject) { */ public function fixCmRedisSessionLocks($eventObject) { if (Mage::helper('core')->isModuleEnabled('Cm_RedisSession')) { - if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend']) { + if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend'] && + !defined('CM_REDISSESSION_LOCKING_ENABLED') ) { define('CM_REDISSESSION_LOCKING_ENABLED', false); } } From 3df3ec0b21cfa2247a811f882e02409be4195b8d Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 27 Dec 2016 10:46:16 -0300 Subject: [PATCH 273/311] Revert "use pass instead of pipe on non GET requests to improve performance" --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 5b5758b8d..470183f62 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -127,7 +127,7 @@ sub vcl_recv { if (!{{enable_caching}} || req.http.Authorization || req.method !~ "^(GET|HEAD|OPTIONS)$" || req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") { - return (pass); + return (pipe); } if({{send_unmodified_url}}) { From bcd58538bed76c35ec00e950847eb2ea3928ff68 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Tue, 27 Dec 2016 13:57:21 +0000 Subject: [PATCH 274/311] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- .../Turpentine/Block/Poll/ActivePoll.php | 30 +++++++++---------- .../Nexcessnet/Turpentine/Helper/Esi.php | 2 +- .../Turpentine/Model/Core/Session.php | 2 +- .../Turpentine/Model/Observer/Esi.php | 10 +++---- .../Turpentine/Model/Observer/Varnish.php | 2 +- .../Turpentine/Model/Varnish/Admin.php | 2 +- .../Turpentine/Model/Varnish/Admin/Socket.php | 2 +- .../Model/Varnish/Configurator/Abstract.php | 25 ++++++++-------- .../Model/Varnish/Configurator/Version3.php | 3 +- .../Model/Varnish/Configurator/Version4.php | 11 ++++--- .../Turpentine/controllers/EsiController.php | 6 ++-- contrib/tools/esi-decoder.php | 22 +++++++------- 12 files changed, 57 insertions(+), 60 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php index 56343127f..665af029b 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php @@ -21,19 +21,19 @@ class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll { - public function setTemplate($template) - { - if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) && - (!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll'))) - { - $this->_template = $template; - $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); - $this->setPollTemplate('turpentine/ajax.phtml', 'results'); - } - else - { - // Mage_Poll is disabled, so do nothing - } - return $this; - } + public function setTemplate($template) + { + if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) && + (!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll'))) + { + $this->_template = $template; + $this->setPollTemplate('turpentine/ajax.phtml', 'poll'); + $this->setPollTemplate('turpentine/ajax.phtml', 'results'); + } + else + { + // Mage_Poll is disabled, so do nothing + } + return $this; + } } diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index f7b263059..d9054c6fe 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -373,7 +373,7 @@ public function getFormKeyEsiUrl() { * @param string $blockName value of name= attribute in layout XML * @return Mage_Core_Model_Layout_Element */ - public function getEsiLayoutBlockNode($layout,$blockName) { + public function getEsiLayoutBlockNode($layout, $blockName) { // first try very specific by checking for action setEsiOptions inside block $blockNode = current($layout->getNode()->xpath( sprintf('//block[@name=\'%s\'][action[@method=\'setEsiOptions\']]', diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php index 4078fffb1..141c667b2 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php @@ -56,7 +56,7 @@ public function real_getFormKey() */ public function renewFormKey() { - $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); + $this->setData('_form_key', Mage::helper('core')->getRandomString(16)); } /** diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php index a79b7727d..bf06417a0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php @@ -227,9 +227,9 @@ public function injectEsi($eventObject) { 'Checking ESI block candidate: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() ); - $debugHelper->logInfo( "-- block testing: shouldResponseUseEsi = " . $esiHelper->shouldResponseUseEsi()); - $debugHelper->logInfo( "-- block testing: instanceof Mage_Core_Block_Template = " . $blockObject instanceof Mage_Core_Block_Template ); - $debugHelper->logInfo( "-- block testing: Esi Options = " . print_r($blockObject->getEsiOptions(), true) ); + $debugHelper->logInfo("-- block testing: shouldResponseUseEsi = ".$esiHelper->shouldResponseUseEsi()); + $debugHelper->logInfo("-- block testing: instanceof Mage_Core_Block_Template = ".$blockObject instanceof Mage_Core_Block_Template); + $debugHelper->logInfo("-- block testing: Esi Options = ".print_r($blockObject->getEsiOptions(), true)); } if ($esiHelper->shouldResponseUseEsi() && $blockObject instanceof Mage_Core_Block_Template && @@ -332,8 +332,8 @@ protected function _getEsiData($blockObject, $esiOptions) { $methodParam = $esiHelper->getEsiMethodParam(); $esiData = new Varien_Object(); $esiData->setStoreId(Mage::app()->getStore()->getId()); - $esiData->setDesignPackage( Mage::getDesign()->getPackageName() ); - $esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) ); + $esiData->setDesignPackage(Mage::getDesign()->getPackageName()); + $esiData->setDesignTheme(Mage::getDesign()->getTheme('layout')); $esiData->setNameInLayout($blockObject->getNameInLayout()); $esiData->setBlockType(get_class($blockObject)); $esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject)); diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index bfab14f7d..1fcadda7c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -66,7 +66,7 @@ public function addProductListToolbarRewrite($eventObject) { public function fixCmRedisSessionLocks($eventObject) { if (Mage::helper('core')->isModuleEnabled('Cm_RedisSession')) { if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend'] && - !defined('CM_REDISSESSION_LOCKING_ENABLED') ) { + ! defined('CM_REDISSESSION_LOCKING_ENABLED')) { define('CM_REDISSESSION_LOCKING_ENABLED', false); } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 096448da0..764f5dac5 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -138,7 +138,7 @@ protected function _testEsiSyntaxParam($socket) { $result = false; if ($helper->csrfFixupNeeded()) { - if ($socket->getVersion() === '4.0' || $socket->getVersion() === '4.1' ) { + if ($socket->getVersion() === '4.0' || $socket->getVersion() === '4.1') { $paramName = 'feature'; $value = $socket->param_show($paramName); $value = explode("\n", $value['text']); 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 fadcb2c38..ed4b92718 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -500,7 +500,7 @@ protected function _command($verb, $okCode = 200) { $response['code'], $response['text'] )); } else { if (Mage::getStoreConfig('turpentine_varnish/general/varnish_log_commands')) { - Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: ' . $data); + Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: '.$data); } return $response; } 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 a8c6149a7..d40efe3ea 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -111,8 +111,8 @@ public function save($generatedConfig) { * @return string */ protected function _getVclTemplateFilename($baseFilename) { - $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); - return sprintf('%s/misc/%s', $extensionDir, $baseFilename); + $extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine'); + return sprintf('%s/misc/%s', $extensionDir, $baseFilename); } /** @@ -131,7 +131,7 @@ protected function _getVclFilename() { * * @return string */ - protected function _getCustomIncludeFilename($position='') { + protected function _getCustomIncludeFilename($position = '') { $key = 'custom_include_file'; $key .= ($position) ? '_'.$position : ''; return $this->_formatTemplate( @@ -151,8 +151,7 @@ protected function _getCustomTemplateFilename() { Mage::getStoreConfig('turpentine_varnish/servers/custom_vcl_template'), array('root_dir' => Mage::getBaseDir()) ); - if (is_file($filePath)) { return $filePath; } - else { return null; } + if (is_file($filePath)) { return $filePath; } else { return null; } } @@ -193,8 +192,8 @@ protected function _vcl_call($subroutine) { */ protected function _getAdminFrontname() { if (Mage::getStoreConfig('admin/url/use_custom_path')) { - if(Mage::getStoreConfig('web/url/use_store')) { - return Mage::getModel('core/store')->load(0)->getCode() . "/" . Mage::getStoreConfig('admin/url/custom_path'); + if (Mage::getStoreConfig('web/url/use_store')) { + return Mage::getModel('core/store')->load(0)->getCode()."/".Mage::getStoreConfig('admin/url/custom_path'); } else { return Mage::getStoreConfig('admin/url/custom_path'); } @@ -909,8 +908,8 @@ protected function _vcl_sub_maintenance_allowed_ips() { */ protected function _vcl_sub_https_redirect_fix() { $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); - $baseUrl = str_replace(array('http://','https://'), '', $baseUrl); - $baseUrl = rtrim($baseUrl,'/'); + $baseUrl = str_replace(array('http://', 'https://'), '', $baseUrl); + $baseUrl = rtrim($baseUrl, '/'); switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) { case 4.0: @@ -982,7 +981,7 @@ protected function _vcl_sub_synth_https_fix() { $tpl = $this->_vcl_sub_synth(); - if(!$tpl){ + if ( ! $tpl) { $tpl = <<_vcl_sub_https_redirect_fix(); - if(Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0' || Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.1'){ + if (Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0' || Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.1') { $vars['vcl_synth'] = $this->_vcl_sub_synth_https_fix(); } } - foreach (array('','top') as $position) { + foreach (array('', 'top') as $position) { $customIncludeFile = $this->_getCustomIncludeFilename($position); if (is_readable($customIncludeFile)) { $key = 'custom_vcl_include'; diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php index 2247404b0..d025b737c 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php @@ -35,8 +35,7 @@ public function generate($doClean = true) { $customTemplate = $this->_getCustomTemplateFilename(); if ($customTemplate) { $tplFile = $customTemplate; - } - else { + } else { $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); } $vcl = $this->_formatTemplate(file_get_contents($tplFile), diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 72512cbcf..78c44c642 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -35,8 +35,7 @@ public function generate($doClean = true) { $customTemplate = $this->_getCustomTemplateFilename(); if ($customTemplate) { $tplFile = $customTemplate; - } - else { + } else { $tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE); } $vcl = $this->_formatTemplate(file_get_contents($tplFile), @@ -94,13 +93,13 @@ protected function _vcl_directors() $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); - for($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) { + for ($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) { $tpl .= <<_vcl_director_backend($host, $port, $prefix . $number, $probeUrl, $backendOptions); + $backends .= $this->_vcl_director_backend($host, $port, $prefix.$number, $probeUrl, $backendOptions); $number++; } diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php index 061f913f6..576e77c34 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php @@ -183,9 +183,9 @@ protected function _getEsiBlock($esiData) { } } $layout = Mage::getSingleton('core/layout'); - Mage::getSingleton( 'core/design_package' ) - ->setPackageName( $esiData->getDesignPackage() ) - ->setTheme( $esiData->getDesignTheme() ); + Mage::getSingleton('core/design_package') + ->setPackageName($esiData->getDesignPackage()) + ->setTheme($esiData->getDesignTheme()); // dispatch event for adding handles to layout update Mage::dispatchEvent( diff --git a/contrib/tools/esi-decoder.php b/contrib/tools/esi-decoder.php index cf2bb6685..553e3f2fa 100644 --- a/contrib/tools/esi-decoder.php +++ b/contrib/tools/esi-decoder.php @@ -1,16 +1,16 @@ Date: Thu, 16 Feb 2017 14:48:15 +0000 Subject: [PATCH 275/311] Apply the option `strip_vcl_whitespace` everywhere In some places the value of strip_vcl_whitespace was not being checked, e.g. The VCL saved to disk on config change was always being stripped. --- .../Turpentine/Model/Observer/Varnish.php | 13 +++++++------ .../controllers/Varnish/ManagementController.php | 9 ++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php index 1fcadda7c..29d03012a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php @@ -83,27 +83,28 @@ public function adminSystemConfigChangedSection($eventObject) { Mage::helper('turpentine/data')->getAutoApplyOnSave()) { $result = Mage::getModel('turpentine/varnish_admin')->applyConfig(); $session = Mage::getSingleton('core/session'); + $helper = Mage::helper('turpentine'); foreach ($result as $name => $value) { if ($value === true) { - $session->addSuccess(Mage::helper('turpentine/data') + $session->addSuccess($helper ->__('VCL successfully applied to: '.$name)); } else { - $session->addError(Mage::helper('turpentine/data') + $session->addError($helper ->__(sprintf('Failed to apply the VCL to %s: %s', $name, $value))); } } $cfgr = Mage::getModel('turpentine/varnish_admin')->getConfigurator(); if (is_null($cfgr)) { - $session->addError(Mage::helper('turpentine/data') + $session->addError($helper ->__('Failed to load configurator')); } else { - $result = $cfgr->save($cfgr->generate()); + $result = $cfgr->save($cfgr->generate($helper->shouldStripVclWhitespace('save'))); if ($result[0]) { - $session->addSuccess(Mage::helper('turpentine/data') + $session->addSuccess($helper ->__('The VCL file has been saved.')); } else { - $session->addError(Mage::helper('turpentine/data') + $session->addError($helper ->__('Failed to save the VCL file: '.$result[1]['message'])); } } diff --git a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php index 0472d4e62..92909451c 100644 --- a/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php +++ b/app/code/community/Nexcessnet/Turpentine/controllers/Varnish/ManagementController.php @@ -128,15 +128,18 @@ public function flushContentTypeAction() { */ public function applyConfigAction() { Mage::dispatchEvent('turpentine_varnish_apply_config'); - $result = Mage::getModel('turpentine/varnish_admin')->applyConfig(); + $helper = Mage::helper('turpentine'); + $result = Mage::getModel('turpentine/varnish_admin')->applyConfig($helper + ->shouldStripVclWhitespace('apply') + ); foreach ($result as $name => $value) { if ($value === true) { $this->_getSession() - ->addSuccess(Mage::helper('turpentine') + ->addSuccess($helper ->__('VCL successfully applied to '.$name)); } else { $this->_getSession() - ->addError(Mage::helper('turpentine') + ->addError($helper ->__(sprintf('Failed to apply the VCL to %s: %s', $name, $value))); } From 667149d0d3d6e2f96a5132e61465755ffe09a59d Mon Sep 17 00:00:00 2001 From: Richard Brown Date: Mon, 20 Feb 2017 14:44:33 +0000 Subject: [PATCH 276/311] Don't set X-Forwarded-For in vlc_recv for v4 According to https://varnish-cache.org/docs/5.0/whats-new/upgrading-4.0.html#x-forwarded-for-is-now-set-before-vcl-recv > In many cases, people unintentionally removed X-Forwarded-For when > implementing their own vcl_recv. Therefore it has been moved to before > vcl_recv, so if you don't want an IP added to it, you should remove it > in vcl_recv. Leaving the fragment in vcl_recv results in the proxy ip being inserted twice. --- .../community/Nexcessnet/Turpentine/misc/version-4.vcl | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 470183f62..81259865d 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -111,16 +111,6 @@ sub vcl_recv { {{https_redirect}} - # this always needs to be done so it's up at the top - if (req.restarts == 0) { - if (req.http.X-Forwarded-For) { - set req.http.X-Forwarded-For = - req.http.X-Forwarded-For + ", " + client.ip; - } else { - set req.http.X-Forwarded-For = client.ip; - } - } - # We only deal with GET and HEAD by default # we test this here instead of inside the url base regex section # so we can disable caching for the entire site if needed From b3dbe4e38737d992d2306a4e9f684dc59cff49e9 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 21 Feb 2017 08:18:33 -0600 Subject: [PATCH 277/311] 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 7934d4e8e..894453a34 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -20,7 +20,7 @@ - 0.7.1 + 0.7.2 From c382b852f540fae60ab602cb4af58d89fff295c5 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 21 Feb 2017 09:18:33 -0600 Subject: [PATCH 278/311] added CHANGELOG --- CHANGELOG.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 014215a95..450b74672 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -464,9 +464,14 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#1271] #1270 Fix: Improve condition to support safari browser Event feature (@AlexanderPok) * [#1282] Added one more format for configuration regexp bug (@odi-um) * [#1289] Fix the issue when redirect HTTP to HTTPS feature (@hmphu) - * [#1298] Removed unused code (@nickua) + * [#1298] Removed unused code (@nickua) - - - - +### RELEASE-0.7.1 +* [#885] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page @craigcarnell +* [#1132] use pass instead of pipe on non GET requests to improve performance @andrewkett +* [#1334] Small fix for notice when CM_REDISSESSION_LOCKING_ENABLED is already defined @jeroenvermeulen +* [#1301] Fix for picking the wrong block from the layout when multiple blocks found - v2 @jeroenvermeulen +* [#1332] varnish 4.1 compatibility @bordeo +* [#1335] Revert "use pass instead of pipe on non GET requests to improve performance" @miguelbalparda +* [#1336] Scrutinizer Auto-Fixes @miguelbalparda +* [#1313] Keep params from original url @hmphu \ No newline at end of file From 9b764d4a575ffc072ded4437ce4ce3923a252854 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Fri, 24 Feb 2017 13:58:35 -0600 Subject: [PATCH 279/311] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 450b74672..2ad484a92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -466,7 +466,7 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#1289] Fix the issue when redirect HTTP to HTTPS feature (@hmphu) * [#1298] Removed unused code (@nickua) -### RELEASE-0.7.1 +### RELEASE-0.7.2 * [#885] Add maintenance mode that will allow debug_ips through to visit the site, all other users get the landing page @craigcarnell * [#1132] use pass instead of pipe on non GET requests to improve performance @andrewkett * [#1334] Small fix for notice when CM_REDISSESSION_LOCKING_ENABLED is already defined @jeroenvermeulen @@ -474,4 +474,4 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#1332] varnish 4.1 compatibility @bordeo * [#1335] Revert "use pass instead of pipe on non GET requests to improve performance" @miguelbalparda * [#1336] Scrutinizer Auto-Fixes @miguelbalparda -* [#1313] Keep params from original url @hmphu \ No newline at end of file +* [#1313] Keep params from original url @hmphu From 0d9577a2c99f046ffeb94590ee3dba8ccb2ac64e Mon Sep 17 00:00:00 2001 From: Luke Evers Date: Fri, 17 Mar 2017 11:23:16 -0400 Subject: [PATCH 280/311] Add more options for Varnish probing --- .../Model/Varnish/Configurator/Abstract.php | 22 ++++++-- .../Nexcessnet/Turpentine/etc/config.xml | 4 ++ .../Nexcessnet/Turpentine/etc/system.xml | 52 ++++++++++++++++++- 3 files changed, 72 insertions(+), 6 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 d40efe3ea..b03d90cc6 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -734,6 +734,7 @@ protected function _vcl_director_backend($host, $port, $probeUrl = '', $options * Format a VCL probe declaration to put in backend which is in director * * @param string $probeUrl URL to check if backend is up + * * @return string */ protected function _vcl_get_probe($probeUrl) { @@ -744,17 +745,30 @@ protected function _vcl_get_probe($probeUrl) { } else { $tpl = <<_formatTemplate($tpl, [ 'probe_host' => $urlParts['host'], - 'probe_path' => $urlParts['path'] - ); - return $this->_formatTemplate($tpl, $vars); + 'probe_path' => $urlParts['path'], + 'timeout' => $timeout, + 'interval' => $interval, + 'window' => $window, + 'threshold' => $threshold, + ]); } } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 894453a34..155fe3c0a 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -58,6 +58,10 @@ 8080 127.0.0.1:8080 + 3s + 8s + 5 + 3 127.0.0.1:8080 300 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 575a425fd..6477684f4 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -359,10 +359,58 @@ yes|yes_admin + + + Maximum timeout for requests. If the request takes longer than the maximum timeout, it will be marked as a failed response. + text + 24 + 1 + 0 + 0 + + yes|yes_admin + + + + + How often to check a backend. + text + 25 + 1 + 0 + 0 + + yes|yes_admin + + + + + Total number of responses in a window of health. + text + 26 + 1 + 0 + 0 + + yes|yes_admin + + + + + Number of needed successful responses in the backend probe window. + text + 27 + 1 + 0 + 0 + + yes|yes_admin + + textarea - 25 + 28 1 0 0 @@ -373,7 +421,7 @@ text - 27 + 29 1 0 0 From de3657c21c2b465415f2f74fddd54c4d00d9f0fa Mon Sep 17 00:00:00 2001 From: Luke Evers Date: Fri, 17 Mar 2017 11:40:22 -0400 Subject: [PATCH 281/311] Use array definition to support PHP 5.3 --- .../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 b03d90cc6..2dd09ab25 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -761,14 +761,14 @@ protected function _vcl_get_probe($probeUrl) { $window = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_window'); $threshold = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_threshold'); - return $this->_formatTemplate($tpl, [ + return $this->_formatTemplate($tpl, array( 'probe_host' => $urlParts['host'], 'probe_path' => $urlParts['path'], 'timeout' => $timeout, 'interval' => $interval, 'window' => $window, 'threshold' => $threshold, - ]); + )); } } From 1c9c9a54673cc41f2662d930cd2a3082c9ab03f8 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Fri, 24 Mar 2017 12:12:38 +0000 Subject: [PATCH 282/311] Varnish v4: Moved configuration of directors to top of `sub vcl_recv` Reason: Also load-balance traffic which hits `return (pipe)` like POST requests, or traffic which is not part of Magento. --- .../Nexcessnet/Turpentine/misc/version-4.vcl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 470183f62..1d597bdbe 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -107,7 +107,13 @@ sub vcl_init { } sub vcl_recv { - {{maintenance_allowed_ips}} + if (req.url ~ "{{url_base_regex}}{{admin_frontname}}") { + set req.backend_hint = {{admin_backend_hint}}; + } else { + {{set_backend_hint}} + } + + {{maintenance_allowed_ips}} {{https_redirect}} @@ -148,10 +154,7 @@ sub vcl_recv { set req.http.X-Turpentine-Secret-Handshake = "{{secret_handshake}}"; # use the special admin backend and pipe if it's for the admin section if (req.url ~ "{{url_base_regex}}{{admin_frontname}}") { - set req.backend_hint = {{admin_backend_hint}}; return (pipe); - } else { - {{set_backend_hint}} } if (req.http.Cookie ~ "\bcurrency=") { set req.http.X-Varnish-Currency = regsub( From ac32e07b4cb50484ffb621d1d707636d6bbd0553 Mon Sep 17 00:00:00 2001 From: Jeroen Vermeulen Date: Fri, 24 Mar 2017 12:20:32 +0000 Subject: [PATCH 283/311] Some whitespace changes to improve layout of generated Varnish4 VCL --- .../Turpentine/Model/Varnish/Configurator/Version4.php | 3 +++ app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 78c44c642..770fabcb6 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -80,6 +80,7 @@ protected function _vcl_directors() $tpl = << Date: Tue, 25 Apr 2017 10:43:31 -0500 Subject: [PATCH 284/311] Update Admin.php --- .../community/Nexcessnet/Turpentine/Model/Varnish/Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php index 764f5dac5..18f8f9b85 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php @@ -104,7 +104,7 @@ public function applyConfig() { $result[$socketName] = 'Failed to load configurator'; } else { $vcl = $cfgr->generate($helper->shouldStripVclWhitespace('apply')); - $vclName = Mage::helper('turpentine/data') + $vclName = 'vcl_' . Mage::helper('turpentine/data') ->secureHash(microtime()); try { $this->_testEsiSyntaxParam($socket); From 3223b0553ffad39ffe043bbc56a7f8ef51102d58 Mon Sep 17 00:00:00 2001 From: Craig Carnell Date: Fri, 28 Apr 2017 12:14:07 +0100 Subject: [PATCH 285/311] When using hitch, we need to set http.X-Forwarded-Proto to HTTPS to prevent a re-direct loop --- .../Model/Varnish/Configurator/Abstract.php | 18 ++++++++++++++++++ .../Nexcessnet/Turpentine/etc/system.xml | 10 ++++++++++ .../Nexcessnet/Turpentine/misc/version-4.vcl | 1 + 3 files changed, 29 insertions(+) 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 d40efe3ea..bb9694279 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -901,6 +901,20 @@ protected function _vcl_sub_maintenance_allowed_ips() { 'debug_ips' => Mage::getStoreConfig('dev/restrict/allow_ips') )); } + /** + * When using Varnish on port 80 and Hitch listen on port 443 for HTTPS, the fix will set X-Forwarded-Proto to HTTPS to prevent redirect loop. + * + * @return string + */ + protected function _vcl_sub_https_proto_fix() { + $tpl = <<_vcl_sub_synth(); } + + if (Mage::getStoreConfig('turpentine_varnish/general/https_proto_fix')) { + $vars['https_proto_fix'] = $this->_vcl_sub_https_proto_fix(); + } if (Mage::getStoreConfig('turpentine_varnish/general/https_redirect_fix')) { $vars['https_redirect'] = $this->_vcl_sub_https_redirect_fix(); diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 575a425fd..3c206869f 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -72,6 +72,16 @@ 1 1 + + + When using Varnish on port 80 and hitch on port 443 for HTTPS, the fix will set X-Forwarded-Proto header to HTTPS to prevent a re-direct loop. + select + 27 + adminhtml/system_config_source_enabledisable + 1 + 1 + 1 + When using Varnish as front door listen on port 80 and Nginx/Apache listen on port 443 for HTTPS, the fix will keep the url parameters when redirect from HTTP to HTTPS. diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 470183f62..e0d3b7b64 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -109,6 +109,7 @@ sub vcl_init { sub vcl_recv { {{maintenance_allowed_ips}} + {{https_proto_fix}} {{https_redirect}} # this always needs to be done so it's up at the top From bcb22c520e4ae57ae1b978e5b47e466fd259465f Mon Sep 17 00:00:00 2001 From: "Jeroen Vermeulen - MageHost.pro" Date: Mon, 15 May 2017 22:28:37 +0200 Subject: [PATCH 286/311] Issue #1409 - Solved by keeping Cache-Control Keeping Cache-Control header by default, overriding when needed. --- app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl | 4 +++- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl | 4 +++- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl index 2223bedbc..4673e7b8e 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl @@ -329,7 +329,7 @@ sub vcl_fetch { remove beresp.http.Set-Cookie; } # we'll set our own cache headers if we need them - remove beresp.http.Cache-Control; + # we'll override the "Cache-Control" header if needed. remove beresp.http.Expires; remove beresp.http.Pragma; remove beresp.http.Cache; @@ -341,6 +341,7 @@ sub vcl_fetch { if (beresp.http.X-Turpentine-Cache == "0") { set beresp.cacheable = false; set beresp.ttl = {{grace_period}}s; + set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate"; return (pass); } else { set beresp.cacheable = true; @@ -360,6 +361,7 @@ sub vcl_fetch { } if (req.http.X-Varnish-Esi-Method == "ajax") { set beresp.ttl = {{grace_period}}s; + set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate"; return (pass); } else { set beresp.ttl = {{esi_private_ttl}}s; diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl index a391f2d8d..fdb8ce69d 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl @@ -335,7 +335,7 @@ sub vcl_fetch { unset beresp.http.Set-Cookie; } # we'll set our own cache headers if we need them - unset beresp.http.Cache-Control; + # we'll override the "Cache-Control" header if needed unset beresp.http.Expires; unset beresp.http.Pragma; unset beresp.http.Cache; @@ -346,6 +346,7 @@ sub vcl_fetch { } if (beresp.http.X-Turpentine-Cache == "0") { set beresp.ttl = {{grace_period}}s; + set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate"; return (hit_for_pass); } else { if ({{force_cache_static}} && @@ -374,6 +375,7 @@ sub vcl_fetch { # this is probably faster than bothering with 0 ttl # cache objects set beresp.ttl = {{grace_period}}s; + set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate"; return (hit_for_pass); } } else { diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 470183f62..19acba598 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -355,8 +355,9 @@ sub vcl_backend_response { set beresp.http.X-Varnish-Set-Cookie = beresp.http.Set-Cookie; unset beresp.http.Set-Cookie; } + # we'll set our own cache headers if we need them - unset beresp.http.Cache-Control; + # we'll override the "Cache-Control" header if needed unset beresp.http.Expires; unset beresp.http.Pragma; unset beresp.http.Cache; @@ -365,9 +366,11 @@ sub vcl_backend_response { if (beresp.http.X-Turpentine-Esi == "1") { set beresp.do_esi = true; } + if (beresp.http.X-Turpentine-Cache == "0") { set beresp.ttl = {{grace_period}}s; set beresp.uncacheable = true; + set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate"; return (deliver); } else { if ({{force_cache_static}} && @@ -397,6 +400,7 @@ sub vcl_backend_response { # cache objects set beresp.ttl = {{grace_period}}s; set beresp.uncacheable = true; + set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate"; return (deliver); } } else { From a2e37dedf8fe31a1c84c4ae4c284b1252e0ba752 Mon Sep 17 00:00:00 2001 From: "Jeroen Vermeulen - MageHost.pro" Date: Mon, 15 May 2017 22:31:50 +0200 Subject: [PATCH 287/311] Removed empty line to lower changes --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 19acba598..50d7ff4a6 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -366,7 +366,6 @@ sub vcl_backend_response { if (beresp.http.X-Turpentine-Esi == "1") { set beresp.do_esi = true; } - if (beresp.http.X-Turpentine-Cache == "0") { set beresp.ttl = {{grace_period}}s; set beresp.uncacheable = true; From dc5191894e6b19494ece2d4f0a563d262729a696 Mon Sep 17 00:00:00 2001 From: Alessandro Niciforo Date: Tue, 23 May 2017 13:15:29 +0200 Subject: [PATCH 288/311] Get last block found in the XML instead of the first, exactly how Magento would do it --- app/code/community/Nexcessnet/Turpentine/Helper/Esi.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index d9054c6fe..b0bca51b3 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -375,13 +375,13 @@ public function getFormKeyEsiUrl() { */ public function getEsiLayoutBlockNode($layout, $blockName) { // first try very specific by checking for action setEsiOptions inside block - $blockNode = current($layout->getNode()->xpath( + $blockNode = end($layout->getNode()->xpath( sprintf('//block[@name=\'%s\'][action[@method=\'setEsiOptions\']]', $blockName) )); // fallback: only match name if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { - $blockNode = current($layout->getNode()->xpath( + $blockNode = end($layout->getNode()->xpath( sprintf('//block[@name=\'%s\']', $blockName) )); } From eca4abb9856ba040ee160bdf47c91e46fcceac33 Mon Sep 17 00:00:00 2001 From: Luis Lorenzo Date: Tue, 13 Jun 2017 11:37:15 +0200 Subject: [PATCH 289/311] Fixed small typo --- app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 470183f62..8264d721d 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -300,7 +300,7 @@ sub vcl_hash { if (req.http.X-Varnish-Esi-Access == "private" && req.http.Cookie ~ "frontend=") { - std.log("hash_data - frontned cookie: " + regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1")); + std.log("hash_data - frontend cookie: " + regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1")); hash_data(regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1")); {{advanced_session_validation}} From d4f1eff917f61880ac1c9249297ecff3a35c297c Mon Sep 17 00:00:00 2001 From: Gianluca Strafella Date: Fri, 14 Jul 2017 14:02:22 +0200 Subject: [PATCH 290/311] default ttl based on session.gc_maxlifetime --- app/code/community/Nexcessnet/Turpentine/Helper/Esi.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index d9054c6fe..387abd4db 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php @@ -231,7 +231,11 @@ public function getCacheClearEvents() { * @return string */ public function getDefaultEsiTtl() { - return trim(Mage::getStoreConfig('web/cookie/cookie_lifetime')); + $defaultLifeTime = trim(Mage::getStoreConfig('web/cookie/cookie_lifetime')); + if ($defaultLifeTime < 60) { + $defaultLifeTime = ini_get('session.gc_maxlifetime'); + } + return $defaultLifeTime; } /** From 32d6065716e685d201b751d18177901ce463d0bb Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Mon, 24 Jul 2017 09:58:42 -0300 Subject: [PATCH 291/311] refs #1404 #1361 #1423 --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 bb9694279..6059fe236 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -684,7 +684,7 @@ protected function _vcl_director($name, $backendOptions) { $parts = explode(':', $backendNode, 2); $host = (empty($parts[0])) ? '127.0.0.1' : $parts[0]; $port = (empty($parts[1])) ? '80' : $parts[1]; - $backends .= $this->_vcl_director_backend($host, $port, $probeUrl, $backendOptions); + $backends .= $this->_vcl_director_backend($host, $port, $prefix.$number, $probeUrl, $backendOptions); } $vars = array( 'name' => $name, @@ -698,14 +698,15 @@ protected function _vcl_director($name, $backendOptions) { * * @param string $host backend host * @param string $port backend port + * @param string $descriptor backend descriptor * @param string $probeUrl URL to check if backend is up * @param array $options extra options for backend * @return string */ - protected function _vcl_director_backend($host, $port, $probeUrl = '', $options = array()) { + protected function _vcl_director_backend($host, $port, $descriptor = '', $probeUrl = '', $options = array()) { $tpl = << Date: Mon, 24 Jul 2017 10:07:03 -0300 Subject: [PATCH 292/311] Changelog and bump version --- CHANGELOG.md | 6 ++++++ app/code/community/Nexcessnet/Turpentine/etc/config.xml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad484a92..4a15f900b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -475,3 +475,9 @@ Magento CE 1.8+ or EE 1.13+, see [these instructions](https://github.com/nexcess * [#1335] Revert "use pass instead of pipe on non GET requests to improve performance" @miguelbalparda * [#1336] Scrutinizer Auto-Fixes @miguelbalparda * [#1313] Keep params from original url @hmphu + +### RELEASE-0.7.3 +* [#1400] Use vcl_ prefix in vcl name to avoid invalid character in name error @josh-palan +* [#1405] When using hitch, we need to set http.X-Forwarded-Proto to HTTPS @craigcarnell +* [#1410] Fix issue #1409: Solved by keeping Cache-Control header @jeroenvermeulen +* [#1423] Fixes for #1404 #1361 #1423 \ No newline at end of file diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 894453a34..4a18b6436 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/config.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/config.xml @@ -20,7 +20,7 @@ - 0.7.2 + 0.7.3 From 53ec1031c92f0a71ce055443d6602922eb799b93 Mon Sep 17 00:00:00 2001 From: Miguel Balparda Date: Tue, 25 Jul 2017 09:27:11 -0300 Subject: [PATCH 293/311] Adding undefined vars. --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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 6059fe236..2b1abb0d0 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -674,17 +674,25 @@ protected function _vcl_director($name, $backendOptions) { $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes_admin')); $probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url_admin'); + $prefix = 'admin'; } else { $backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL, Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes')); $probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url'); + if ('admin' == $name) { + $prefix = 'admin'; + } else { + $prefix = ''; + } } $backends = ''; + $number = 0; foreach ($backendNodes as $backendNode) { $parts = explode(':', $backendNode, 2); $host = (empty($parts[0])) ? '127.0.0.1' : $parts[0]; $port = (empty($parts[1])) ? '80' : $parts[1]; $backends .= $this->_vcl_director_backend($host, $port, $prefix.$number, $probeUrl, $backendOptions); + $number++; } $vars = array( 'name' => $name, From bf10b5872ddfe54e9ce7d958cdf280c67a0e3c0b Mon Sep 17 00:00:00 2001 From: Andrew Kett Date: Wed, 26 Jul 2017 12:06:41 +1200 Subject: [PATCH 294/311] Dispatch event in _getTemplateVars to allow other extensions to add custom vcl template variables --- .../Turpentine/Model/Varnish/Configurator/Version2.php | 9 +++++++++ .../Turpentine/Model/Varnish/Configurator/Version3.php | 9 +++++++++ .../Turpentine/Model/Varnish/Configurator/Version4.php | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php index 170153981..650d921bd 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version2.php @@ -23,6 +23,8 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version2 extends Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract { const VCL_TEMPLATE_FILE = 'version-2.vcl'; + const VCL_VERSION = '2'; + /** * Generate the Varnish 2.1-compatible VCL @@ -55,6 +57,13 @@ protected function _getTemplateVars() { $vars['esi_public_ttl'] = $this->_getDefaultTtl(); $vars['advanced_session_validation'] = $this->_getAdvancedSessionValidation(); + + //dispatch event to allow other extensions to add custom vcl template variables + Mage::dispatchEvent('turpentine_get_templatevars_after', array( + 'vars' => &$vars, + 'vcl_version'=> self::VCL_VERSION + )); + return $vars; } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php index d025b737c..25d20948a 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php @@ -23,6 +23,8 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version3 extends Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract { const VCL_TEMPLATE_FILE = 'version-3.vcl'; + const VCL_VERSION = '3'; + /** * Generate the Varnish 3.0-compatible VCL @@ -60,6 +62,13 @@ protected function _getTemplateVars() { $vars = parent::_getTemplateVars(); $vars['advanced_session_validation'] = $this->_getAdvancedSessionValidation(); + + //dispatch event to allow other extensions to add custom vcl template variables + Mage::dispatchEvent('turpentine_get_templatevars_after', array( + 'vars' => &$vars, + 'vcl_version'=> self::VCL_VERSION + )); + return $vars; } } diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 78c44c642..2ff5d248b 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -23,6 +23,8 @@ class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version4 extends Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract { const VCL_TEMPLATE_FILE = 'version-4.vcl'; + const VCL_VERSION = '4'; + /** * Generate the Varnish 4.0-compatible VCL @@ -72,6 +74,12 @@ protected function _getTemplateVars() { $vars['set_backend_hint'] = ''; } + //dispatch event to allow other extensions to add custom vcl template variables + Mage::dispatchEvent('turpentine_get_templatevars_after', array( + 'vars' => &$vars, + 'vcl_version'=> self::VCL_VERSION + )); + return $vars; } From e71f0fbb4b3655177081292bfd03152907cbc98e Mon Sep 17 00:00:00 2001 From: Andrew Kett Date: Wed, 26 Jul 2017 14:49:23 +1200 Subject: [PATCH 295/311] use 503 response for maintenance rather than 404 --- .../Turpentine/Model/Varnish/Configurator/Abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2b1abb0d0..436159b2d 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -971,7 +971,7 @@ protected function _vcl_sub_synth() $tpl = << Date: Thu, 27 Jul 2017 20:32:28 +1200 Subject: [PATCH 296/311] check for all hosts from all store views in http -> https redirect --- .../Model/Varnish/Configurator/Abstract.php | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 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 2b1abb0d0..af6c29d40 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -930,22 +930,25 @@ protected function _vcl_sub_https_proto_fix() { * @return string */ protected function _vcl_sub_https_redirect_fix() { - $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); - $baseUrl = str_replace(array('http://', 'https://'), '', $baseUrl); - $baseUrl = rtrim($baseUrl, '/'); - + + $hostRegex = array(); + foreach ($this->_getHostNames() as $host) { + $hostRegex[] = 'req.http.host ~ "^(?i)'.$host.'"'; + } + $hostRegex = implode(' || ', $hostRegex); + switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) { case 4.0: case 4.1: $tpl = <<_stripHost(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)); + $hosts = array( + $baseUrl => $baseUrl + ); + + foreach (Mage::app()->getWebsites() as $website) { + foreach ($website->getGroups() as $group) { + $stores = $group->getStores(); + foreach ($stores as $store) { + $baseUrl = $this->_stripHost(Mage::getStoreConfig('web/unsecure/base_url', $store->getId())); + $secureBaseUrl = $this->_stripHost(Mage::getStoreConfig('web/secure/base_url', $store->getId())); + + $hosts[$baseUrl] = $baseUrl; + $hosts[$secureBaseUrl] = $secureBaseUrl; + } + } + } + + return $hosts; + } + + protected function _stripHost ($baseUrl){ + return rtrim(str_replace(array('http://', 'https://'), '', $baseUrl), '/'); + } + /** * Get the allowed IPs when in maintenance mode * From 0cc851490a7b2d535857b24c86388e97c18f7674 Mon Sep 17 00:00:00 2001 From: Dovydas Altaravicius Date: Wed, 30 Aug 2017 11:57:10 +0300 Subject: [PATCH 297/311] Strict Notice: Version4 function _vcl_director_backend --- .../Turpentine/Model/Varnish/Configurator/Version4.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php index 78c44c642..e2d119fbb 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php @@ -165,7 +165,7 @@ protected function _vcl_director($name, $backendOptions) { * @param array $options extra options for backend * @return string */ - protected function _vcl_director_backend($host, $port, $descriptor, $probeUrl = '', $options = array()) { + protected function _vcl_director_backend($host, $port, $descriptor = '', $probeUrl = '', $options = array()) { $tpl = << Date: Wed, 20 Dec 2017 10:45:19 -0500 Subject: [PATCH 298/311] Fix travis build --- .travis.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 199d0e0f7..255ad8891 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,23 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 +# precise must be used for PHP 5.3 +# https://docs.travis-ci.com/user/reference/trusty#PHP-images +matrix: + include: + - php: 5.3 + dist: precise + addons: apt: packages: - python-markdown - libxml-xpath-perl - build-essential + - libxml2-utils script: - make all From db94e6b07b28735fa3ba14a804a6bedcff3caef4 Mon Sep 17 00:00:00 2001 From: Simon Sprankel Date: Tue, 2 Jan 2018 12:57:34 +0100 Subject: [PATCH 299/311] added ESI options for contact form, #116, #486 --- .../frontend/base/default/layout/turpentine_esi.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/design/frontend/base/default/layout/turpentine_esi.xml b/app/design/frontend/base/default/layout/turpentine_esi.xml index 40ebb8d0c..969502a06 100644 --- a/app/design/frontend/base/default/layout/turpentine_esi.xml +++ b/app/design/frontend/base/default/layout/turpentine_esi.xml @@ -455,6 +455,18 @@ + + + + + esi + private + 0 + + + + + +