Skip to content

Commit f89ae64

Browse files
Merge pull request #934 from nexcess/devel
Devel
2 parents c44ebcf + 08dbebe commit f89ae64

File tree

8 files changed

+88
-37
lines changed

8 files changed

+88
-37
lines changed

app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,14 @@ public function banCacheType( $eventObject ) {
299299
*/
300300
public function banProductReview( $eventObject ) {
301301
$patterns = array();
302+
/* @var $review \Mage_Review_Model_Review*/
302303
$review = $eventObject->getObject();
303-
$products = $review->getProductCollection()->getItems();
304+
305+
/* @var $productCollection \Mage_Review_Model_Resource_Review_Product_Collection*/
306+
$productCollection = $review->getProductCollection();
307+
308+
$products = $productCollection->addEntityFilter((int)$review->getEntityPkValue())->getItems();
309+
304310
$productIds = array_unique( array_map(
305311
create_function( '$p', 'return $p->getEntityId();' ),
306312
$products ) );

app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ protected function _connect() {
345345
$banner['text'] );
346346
}
347347

348-
$this->_version = $this->_determineVersion($banner['text']);
348+
if ($this->_version == null) { // If autodetecting
349+
$this->_version = $this->_determineVersion($banner['text']);
350+
}
349351

350352
return $this->isConnected();
351353
}

app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php

+38-17
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ static public function getFromSocket( $socket ) {
3939
return null;
4040
}
4141
switch( $version ) {
42-
case '4.0':
43-
return Mage::getModel(
44-
'turpentine/varnish_configurator_version4',
45-
array( 'socket' => $socket ) );
42+
case '4.0':
43+
return Mage::getModel(
44+
'turpentine/varnish_configurator_version4',
45+
array( 'socket' => $socket ) );
4646

4747
case '3.0':
4848
return Mage::getModel(
@@ -209,17 +209,33 @@ protected function _getNormalizeHostTarget() {
209209
* @return string
210210
*/
211211
public function getAllowedHostsRegex() {
212-
$hosts = array();
213-
foreach( Mage::app()->getStores() as $store ) {
214-
$hosts[] = parse_url( $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB , false ), PHP_URL_HOST );
215-
}
216-
217-
$hosts = array_values(array_unique( $hosts ));
218-
212+
$hosts = array();
213+
foreach( Mage::app()->getStores() as $store ) {
214+
$hosts[] = parse_url( $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB , false ), PHP_URL_HOST );
215+
}
216+
217+
$hosts = array_values(array_unique( $hosts ));
218+
219219
$pattern = '('.implode('|', array_map("preg_quote", $hosts)).')';
220-
return $pattern;
220+
return $pattern;
221221
}
222-
222+
223+
/**
224+
* Get the Host normalization sub routine
225+
*
226+
* @return string
227+
*/
228+
protected function _vcl_sub_allowed_hosts_regex() {
229+
$tpl = <<<EOS
230+
# if host is not allowed in magento pass to backend
231+
if (req.http.host !~ "{{allowed_hosts_regex}}") {
232+
return (pass);
233+
}
234+
EOS;
235+
return $this->_formatTemplate( $tpl, array(
236+
'allowed_hosts_regex' => $this->getAllowedHostsRegex() ) );
237+
}
238+
223239
/**
224240
* Get the base url path regex
225241
*
@@ -292,7 +308,7 @@ protected function _getDefaultBackend() {
292308
'first_byte_timeout' => $timeout . 's',
293309
'between_bytes_timeout' => $timeout . 's',
294310
);
295-
if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) ) {
311+
if ( Mage::getStoreConfig( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) {
296312
return $this->_vcl_director( 'default', $default_options );
297313
} else {
298314
return $this->_vcl_backend( 'default',
@@ -313,7 +329,7 @@ protected function _getAdminBackend() {
313329
'first_byte_timeout' => $timeout . 's',
314330
'between_bytes_timeout' => $timeout . 's',
315331
);
316-
if ( Mage::getStoreConfigFlag( 'turpentine_vcl/backend/load_balancing' ) ) {
332+
if ( Mage::getStoreConfig( 'turpentine_vcl/backend/load_balancing' ) != 'no' ) {
317333
return $this->_vcl_director( 'admin', $admin_options );
318334
} else {
319335
return $this->_vcl_backend( 'admin',
@@ -821,7 +837,7 @@ protected function _getTemplateVars() {
821837
'admin_frontname' => $this->_getAdminFrontname(),
822838
'normalize_host_target' => $this->_getNormalizeHostTarget(),
823839
'url_base_regex' => $this->getBaseUrlPathRegex(),
824-
'allowed_hosts_regex' => $this->getAllowedHostsRegex(),
840+
'allowed_hosts_regex' => $this->getAllowedHostsRegex(),
825841
'url_excludes' => $this->_getUrlExcludes(),
826842
'get_param_excludes' => $this->_getGetParamExcludes(),
827843
'get_param_ignored' => $this->_getIgnoreGetParameters(),
@@ -857,6 +873,11 @@ protected function _getTemplateVars() {
857873
'esi_private_ttl' => Mage::helper( 'turpentine/esi' )
858874
->getDefaultEsiTtl(),
859875
);
876+
877+
if( (bool)Mage::getStoreConfig( 'turpentine_vcl/urls/bypass_cache_store_url') ) {
878+
$vars['allowed_hosts'] = $this->_vcl_sub_allowed_hosts_regex();
879+
}
880+
860881
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/encoding' ) ) {
861882
$vars['normalize_encoding'] = $this->_vcl_sub_normalize_encoding();
862883
}
@@ -872,7 +893,7 @@ protected function _getTemplateVars() {
872893
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_target' ) ) {
873894
$vars['normalize_cookie_target'] = $this->_getNormalizeCookieTarget();
874895
}
875-
896+
876897
$customIncludeFile = $this->_getCustomIncludeFilename();
877898
if( is_readable( $customIncludeFile ) ) {
878899
$vars['custom_vcl_include'] = file_get_contents( $customIncludeFile );

app/code/community/Nexcessnet/Turpentine/etc/config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<config>
2121
<modules>
2222
<Nexcessnet_Turpentine>
23-
<version>0.6.5</version>
23+
<version>0.6.6</version>
2424
</Nexcessnet_Turpentine>
2525
</modules>
2626
<default>

app/code/community/Nexcessnet/Turpentine/etc/system.xml

+10
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,16 @@
503503
<show_in_website>0</show_in_website>
504504
<show_in_store>0</show_in_store>
505505
</url_blacklist>
506+
<bypass_cache_store_url translate="label" module="turpentine">
507+
<label>Bypass Varnish if base URL is not found within a store?</label>
508+
<comment>If enabled any URL in the client that does not start with a store URL will bypass the cache</comment>
509+
<frontend_type>select</frontend_type>
510+
<source_model>turpentine/config_select_toggle</source_model>
511+
<sort_order>11</sort_order>
512+
<show_in_default>1</show_in_default>
513+
<show_in_website>0</show_in_website>
514+
<show_in_store>0</show_in_store>
515+
</bypass_cache_store_url>
506516
</fields>
507517
</urls>
508518
<params translate="label" module="turpentine">

app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl

+1-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ sub vcl_recv {
161161
error 403 "External ESI requests are not allowed";
162162
}
163163
}
164-
# if host is not allowed in magento pass to backend
165-
if (req.http.host !~ "{{allowed_hosts_regex}}") {
166-
return (pass);
167-
}
164+
{{allowed_hosts}}
168165
# no frontend cookie was sent to us AND this is not an ESI or AJAX call
169166
if (req.http.Cookie !~ "frontend=" && !req.http.X-Varnish-Esi-Method) {
170167
if (client.ip ~ crawler_acl ||

app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl

+1-4
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,7 @@ sub vcl_recv {
159159
return (synth(403, "External ESI requests are not allowed"));
160160
}
161161
}
162-
# if host is not allowed in magento pass to backend
163-
if (req.http.host !~ "{{allowed_hosts_regex}}") {
164-
return (pass);
165-
}
162+
{{allowed_hosts}}
166163
# no frontend cookie was sent to us AND this is not an ESI or AJAX call
167164
if (req.http.Cookie !~ "frontend=" && !req.http.X-Varnish-Esi-Method) {
168165
if (client.ip ~ crawler_acl ||

contrib/tools/esi-decoder.php

+27-9
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@
77
*
88
* Make sure you place this utility on a protected spot on your web server where only authorized users can use it.
99
*
10-
* If the URLs you see in "varnishlog" or "varnishncsa", read this FAQ item:
10+
* If the URLs you see in "varnishlog" or "varnishncsa" are not working because they are cut off, read this FAQ item:
1111
* 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
1212
*
1313
*/
1414

15-
// You might need to fix the path to your app/Mage.php on the line below.
16-
require_once dirname(__FILE__).'/../../app/Mage.php';
15+
$tries = 5;
16+
$dir = dirname(__FILE__);
17+
while( $tries-- && ! file_exists( $dir . '/app/Mage.php' ) ) {
18+
$dir = dirname($dir); // go one dir up
19+
}
20+
if ( file_exists( $dir . '/app/Mage.php' ) ) {
21+
require_once $dir . '/app/Mage.php';
22+
} else {
23+
die( "Could not find 'app/Mage.php'. Please edit esi-decoder.php and 'require' it manually." );
24+
}
1725

1826
Mage::app();
1927
$data = ( empty($_REQUEST['data']) ) ? '' : $_REQUEST['data'];
@@ -69,7 +77,12 @@
6977
}
7078
$dataHelper = Mage::helper( 'turpentine/data' );
7179
$esiDataArray = $dataHelper->thaw( $processData );
72-
?>
80+
$showContentUrl = Mage::getUrl( 'turpentine/esi/getBlock',
81+
array( 'method' => 'esi',
82+
'ttl' => 0,
83+
'hmac' => $dataHelper->getHmac( $processData ),
84+
'data' => $processData ) );
85+
?>
7386
<div class="center">=&nbsp; DATA &nbsp;=</div>
7487
<div class="result">
7588
<pre><?php echo htmlentities( var_export( $esiDataArray, 1 ) ); ?></pre>
@@ -78,14 +91,19 @@
7891
$refPreg = preg_quote( $esiHelper->getEsiReferrerParam(), '|' );
7992
if ( preg_match('|'.$refPreg.'/([\w\.\-]+),*|', $data, $matches) ):
8093
$processData = $matches[1];
94+
?>
95+
<div class="center">=&nbsp; REFERRER &nbsp;=</div>
96+
<div class="result">
97+
<pre><?php echo htmlentities( $dataHelper->urlBase64Decode( $processData ) ); ?></pre>
98+
</div>
99+
<?php
100+
endif; // if preg_match referrer
81101
?>
82-
<div class="center">=&nbsp; REFERRER &nbsp;=</div>
83-
<div class="result">
84-
<pre><?php echo htmlentities( $dataHelper->urlBase64Decode( $processData ) ); ?></pre>
102+
<div class="center">
103+
<input type="button" value="SHOW CONTENT" onclick='window.open(<?php echo json_encode($showContentUrl); ?>,"_blank");' />
85104
</div>
86105
<?php
87-
endif;
88-
endif;
106+
endif; // if $data
89107
?>
90108
</body>
91109
</html>

0 commit comments

Comments
 (0)