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 d25bb7b78..087509d68 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php @@ -1,8 +1,8 @@ getCollection(); $turpentineEnabled = false; $fullPageEnabled = false; - foreach ($collection as $key=>$item) - { - if ($item->getStatus() == 1 && ($item->getId() == 'turpentine_pages' || $item->getId() == 'turpentine_esi_blocks')) - { + 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') - { + if ($item->getStatus() == 1 && $item->getId() == 'full_page') { $fullPageEnabled = true; } } - if ($turpentineEnabled) - { + if ($turpentineEnabled && !$fullPageEnabled) { $collection->removeItemByKey('full_page'); } - if ($fullPageEnabled) - { + if ($fullPageEnabled && !$turpentineEnabled) { $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 d330623e4..f33d0d784 100644 --- a/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php +++ b/app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php @@ -316,15 +316,7 @@ protected function _clearMessages() { */ protected function _real_toHtml() { if ( ! $this->_directCall) { - switch ($this->getNameInLayout()) { - case 'global_messages': - $this->_directCall = 'getHtml'; - break; - case 'messages': - default: - $this->_directCall = 'getGroupedHtml'; - break; - } + $this->_directCall = 'getGroupedHtml'; } switch ($this->_directCall) { case 'getHtml': diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php index 2b0449161..991b6a6a7 100644 --- a/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php +++ b/app/code/community/Nexcessnet/Turpentine/Helper/Cron.php @@ -192,7 +192,7 @@ public function getAllUrls() { } } $sitemap = (Mage::getConfig()->getNode('modules/MageWorx_XSitemap') !== FALSE) ? - 'xsitemap/cms_page' : 'sitemap/cms_page'; + 'mageworx_xsitemap/cms_page' : 'sitemap/cms_page'; foreach (Mage::getResourceModel($sitemap) ->getCollection($storeId) as $item) { $urls[] = $baseUrl.$item->getUrl(); diff --git a/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php b/app/code/community/Nexcessnet/Turpentine/Helper/Esi.php index b0bca51b3..8435c57ec 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; } /** @@ -375,15 +379,17 @@ public function getFormKeyEsiUrl() { */ public function getEsiLayoutBlockNode($layout, $blockName) { // first try very specific by checking for action setEsiOptions inside block - $blockNode = end($layout->getNode()->xpath( + $blockNodes = $layout->getNode()->xpath( sprintf('//block[@name=\'%s\'][action[@method=\'setEsiOptions\']]', $blockName) - )); + ); + $blockNode = end($blockNodes); // fallback: only match name if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) { - $blockNode = end($layout->getNode()->xpath( + $blockNodes = $layout->getNode()->xpath( sprintf('//block[@name=\'%s\']', $blockName) - )); + ); + $blockNode = end($blockNodes); } return $blockNode; } 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/Model/Varnish/Admin/Socket.php b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php index ed4b92718..e7feedee4 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php @@ -88,7 +88,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket { * 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]+)$/'; + const REGEXP_VARNISH_VERSION = '/^varnish\-(?P\d+)\.(?P\d+)\.(?P\d+) revision (?P[0-9a-f]+)$/'; /** * VCL config versions, should match config select values 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 436159b2d..ff007c489 100644 --- a/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +++ b/app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php @@ -743,6 +743,7 @@ protected function _vcl_director_backend($host, $port, $descriptor = '', $probeU * 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) { @@ -753,17 +754,30 @@ protected function _vcl_get_probe($probeUrl) { } else { $tpl = <<_formatTemplate($tpl, array( '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, + )); } } @@ -930,22 +944,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 * 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 e2d119fbb..13229ec8e 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; } @@ -80,6 +88,7 @@ protected function _vcl_directors() $tpl = <<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))); } diff --git a/app/code/community/Nexcessnet/Turpentine/etc/config.xml b/app/code/community/Nexcessnet/Turpentine/etc/config.xml index 55082bd31..1de6007f7 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.4 + 0.7.5 @@ -58,12 +58,16 @@ 8080 127.0.0.1:8080 + 3s + 8s + 5 + 3 127.0.0.1:8080 300 21600 127.0.0.1 - + 1 diff --git a/app/code/community/Nexcessnet/Turpentine/etc/system.xml b/app/code/community/Nexcessnet/Turpentine/etc/system.xml index 3c206869f..4ac2c8947 100644 --- a/app/code/community/Nexcessnet/Turpentine/etc/system.xml +++ b/app/code/community/Nexcessnet/Turpentine/etc/system.xml @@ -369,10 +369,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 @@ -383,7 +431,7 @@ text - 27 + 29 1 0 0 diff --git a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl index 15ff7ca06..eb1e76766 100644 --- a/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl +++ b/app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl @@ -103,25 +103,21 @@ sub generate_session_expires { ## Varnish Subroutines sub vcl_init { - {{directors}} +{{directors}} } 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_proto_fix}} {{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 @@ -149,10 +145,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( @@ -301,7 +294,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}} diff --git a/util/warm-cache.sh b/util/warm-cache.sh index 300559803..2c87ef08b 100755 --- a/util/warm-cache.sh +++ b/util/warm-cache.sh @@ -80,7 +80,7 @@ fi UA="" if [[ $AGENT =~ .. ]]; then UA="-A '$AGENT'" - echo "Warning with User-Agent '$AGENT'" + echo "Warming with User-Agent '$AGENT'" fi echo "Warming $(cat $TMP_URL_FILE | wc -l) URLs using $CONC concurrent users..."