Skip to content

Commit

Permalink
Merge pull request #1521 from nexcess/devel
Browse files Browse the repository at this point in the history
Release  0.7.5
  • Loading branch information
miguelbalparda committed Nov 21, 2018
2 parents 44d7b76 + 96bbdda commit c670a49
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

/**
* User: damian.pastorini@usestrategery.com
* Date: 08/01/14
* User: damian.pastorini@strategery.io
* Date: 2018-02-19
*/

class Nexcessnet_Turpentine_Block_Adminhtml_Cache_Grid extends Mage_Adminhtml_Block_Cache_Grid
Expand All @@ -17,23 +17,18 @@ protected function _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'))
{
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');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Nexcessnet/Turpentine/Helper/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 11 additions & 5 deletions app/code/community/Nexcessnet/Turpentine/Helper/Esi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<vmajor>\d)\.(?P<vminor>\d)\.(?P<vsub>\d) revision (?P<vhash>[0-9a-f]+)$/';
const REGEXP_VARNISH_VERSION = '/^varnish\-(?P<vmajor>\d+)\.(?P<vminor>\d+)\.(?P<vsub>\d+) revision (?P<vhash>[0-9a-f]+)$/';

/**
* VCL config versions, should match config select values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -753,17 +754,30 @@ protected function _vcl_get_probe($probeUrl) {
} else {
$tpl = <<<EOS
.probe = {
.timeout = {{timeout}};
.interval = {{interval}};
.window = {{window}};
.threshold = {{threshold}};
.request =
"GET {{probe_path}} HTTP/1.1"
"Host: {{probe_host}}"
"Connection: close";
}
EOS;
$vars = array(

$timeout = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_timeout');
$interval = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_interval');
$window = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_window');
$threshold = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_threshold');

return $this->_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,
));
}
}

Expand Down Expand Up @@ -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 = <<<EOS
if ( (req.http.host ~ "^(?i)www.$baseUrl" || req.http.host ~ "^(?i)$baseUrl") && req.http.X-Forwarded-Proto !~ "(?i)https") {
if ( ($hostRegex) && req.http.X-Forwarded-Proto !~ "(?i)https") {
return (synth(750, ""));
}
EOS;
break;
default:
$tpl = <<<EOS
if ( (req.http.host ~ "^(?i)www.$baseUrl" || req.http.host ~ "^(?i)$baseUrl") && req.http.X-Forwarded-Proto !~ "(?i)https") {
if ( ($hostRegex) && req.http.X-Forwarded-Proto !~ "(?i)https") {
error 750 "https://" + req.http.host + req.url;
}
EOS;
Expand All @@ -954,6 +971,34 @@ protected function _vcl_sub_https_redirect_fix() {
return $tpl;
}


protected function _getHostNames() {

$baseUrl = $this->_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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -80,6 +88,7 @@ protected function _vcl_directors()
$tpl = <<<EOS
new vdir = directors.round_robin();
new vdir_admin = directors.round_robin();
EOS;

if ('yes_admin' == Mage::getStoreConfig('turpentine_vcl/backend/load_balancing')) {
Expand All @@ -96,12 +105,14 @@ protected function _vcl_directors()
for ($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) {
$tpl .= <<<EOS
vdir.add_backend(web{$i});
EOS;
}

for ($i = 0, $iMax = count($adminBackendNodes); $i < $iMax; $i++) {
$tpl .= <<<EOS
vdir_admin.add_backend(webadmin{$i});
EOS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
8 changes: 6 additions & 2 deletions app/code/community/Nexcessnet/Turpentine/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<config>
<modules>
<Nexcessnet_Turpentine>
<version>0.7.4</version>
<version>0.7.5</version>
</Nexcessnet_Turpentine>
</modules>
<default>
Expand Down Expand Up @@ -58,12 +58,16 @@
<backend_port>8080</backend_port>
<backend_nodes>127.0.0.1:8080</backend_nodes>
<backend_probe_url/>
<backend_probe_timeout>3s</backend_probe_timeout>
<backend_probe_interval>8s</backend_probe_interval>
<backend_probe_window>5</backend_probe_window>
<backend_probe_threshold>3</backend_probe_threshold>
<backend_nodes_admin>127.0.0.1:8080</backend_nodes_admin>
<backend_probe_url_admin/>
<frontend_timeout>300</frontend_timeout>
<admin_timeout>21600</admin_timeout>
<crawlers>127.0.0.1</crawlers>
<crawler_user_agents><![CDATA[ApacheBench/.*,.*Googlebot.*,JoeDog/.*,.*Siege/.*,magespeedtest\.com,Nexcessnet_Turpentine/.*,.*PTST.*]]></crawler_user_agents>
<crawler_user_agents><![CDATA[ApacheBench/.*,.*Googlebot.*,.*APIs-Google.*,.*Mediapartners-Google.*,.*AdsBot-Google.*,JoeDog/.*,.*Siege/.*,magespeedtest\.com,Nexcessnet_Turpentine/.*,.*PTST.*,.*bingbot.*,.*msnbot.*,.*Baiduspider.*]]></crawler_user_agents>
</backend>
<normalization>
<encoding>1</encoding>
Expand Down
Loading

0 comments on commit c670a49

Please sign in to comment.