Version Notes
Supports Magento v1.6 and later
Download this release
Release Info
Developer | Chris Wells |
Extension | Nexcessnet_Turpentine |
Version | 0.6.3 |
Comparing to | |
See all releases |
Code changes from version 0.6.1 to 0.6.3
- app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php +44 -0
- app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php +4 -0
- app/{design/frontend/base/default/template/turpentine/esi.phtml → code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php} +8 -15
- app/code/community/Nexcessnet/Turpentine/Helper/Data.php +10 -0
- app/code/community/Nexcessnet/Turpentine/Helper/Debug.php +137 -33
- app/code/community/Nexcessnet/Turpentine/Helper/Esi.php +1 -1
- app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php +53 -0
- app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php +4 -1
- app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php +28 -0
- app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php +64 -6
- app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php +2 -5
- app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php +109 -5
- app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php~ +769 -0
- app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php +43 -0
- app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php +1 -1
- app/code/community/Nexcessnet/Turpentine/etc/config.xml +85 -1
- app/code/community/Nexcessnet/Turpentine/etc/system.xml +69 -1
- app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl +19 -8
- app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl +46 -16
- app/code/local/Mage/Core/Model/Session.php +0 -69
- app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml +0 -119
- app/design/frontend/base/default/layout/turpentine_esi.xml +34 -0
- app/design/frontend/base/default/template/turpentine/ajax.phtml +0 -81
- app/design/frontend/base/default/template/turpentine/notices.phtml +0 -36
- package.xml +1 -1
app/code/community/Nexcessnet/Turpentine/Block/Adminhtml/Cache/Grid.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* User: damian.pastorini@usestrategery.com
|
5 |
+
* Date: 08/01/14
|
6 |
+
*/
|
7 |
+
|
8 |
+
class Nexcessnet_Turpentine_Block_Adminhtml_Cache_Grid extends Mage_Adminhtml_Block_Cache_Grid
|
9 |
+
{
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Prepare grid collection
|
13 |
+
*/
|
14 |
+
protected function _prepareCollection()
|
15 |
+
{
|
16 |
+
parent::_prepareCollection();
|
17 |
+
$collection = $this->getCollection();
|
18 |
+
$turpentineEnabled = false;
|
19 |
+
$fullPageEnabled = false;
|
20 |
+
foreach ($collection as $key=>$item)
|
21 |
+
{
|
22 |
+
if($item->getStatus()==1 && ($item->getId()=='turpentine_pages' || $item->getId()=='turpentine_esi_blocks'))
|
23 |
+
{
|
24 |
+
$turpentineEnabled = true;
|
25 |
+
}
|
26 |
+
if($item->getStatus()==1 && $item->getId()=='full_page')
|
27 |
+
{
|
28 |
+
$fullPageEnabled = true;
|
29 |
+
}
|
30 |
+
}
|
31 |
+
if($turpentineEnabled)
|
32 |
+
{
|
33 |
+
$collection->removeItemByKey('full_page');
|
34 |
+
}
|
35 |
+
if($fullPageEnabled)
|
36 |
+
{
|
37 |
+
$collection->removeItemByKey('turpentine_pages');
|
38 |
+
$collection->removeItemByKey('turpentine_esi_blocks');
|
39 |
+
}
|
40 |
+
$this->setCollection($collection);
|
41 |
+
return $this;
|
42 |
+
}
|
43 |
+
|
44 |
+
}
|
app/code/community/Nexcessnet/Turpentine/Block/Core/Messages.php
CHANGED
@@ -204,6 +204,10 @@ class Nexcessnet_Turpentine_Block_Core_Messages extends Mage_Core_Block_Messages
|
|
204 |
$html = $this->_real_toHtml();
|
205 |
}
|
206 |
$this->_directCall = false;
|
|
|
|
|
|
|
|
|
207 |
return $html;
|
208 |
}
|
209 |
|
204 |
$html = $this->_real_toHtml();
|
205 |
}
|
206 |
$this->_directCall = false;
|
207 |
+
|
208 |
+
if (count($this->getMessages()) == 0) {
|
209 |
+
return '';
|
210 |
+
}
|
211 |
return $html;
|
212 |
}
|
213 |
|
app/{design/frontend/base/default/template/turpentine/esi.phtml → code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php}
RENAMED
@@ -19,20 +19,13 @@
|
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
}
|
31 |
-
echo sprintf( '<esi:remove>ESI processing not enabled</esi:remove>
|
32 |
-
<!--esi <esi:include src="%s" /> -->',
|
33 |
-
$this->getEsiUrl() ) . PHP_EOL;
|
34 |
-
if( $debugEnabled ) {
|
35 |
-
echo sprintf( '<!-- ESI END [%s] -->', $this->getNameInLayout() ) . PHP_EOL;
|
36 |
-
} else {
|
37 |
-
echo '<!-- ESI END DUMMY COMMENT [] -->' . PHP_EOL;
|
38 |
}
|
19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
*/
|
21 |
|
22 |
+
class Nexcessnet_Turpentine_Block_Poll_Activepoll extends Mage_Poll_Block_ActivePoll {
|
23 |
|
24 |
+
public function setTemplate($template)
|
25 |
+
{
|
26 |
+
$this->_template = $template;
|
27 |
+
$this->setPollTemplate('turpentine/ajax.phtml', 'poll' );
|
28 |
+
$this->setPollTemplate('turpentine/ajax.phtml', 'results' );
|
29 |
+
return $this;
|
30 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
app/code/community/Nexcessnet/Turpentine/Helper/Data.php
CHANGED
@@ -270,6 +270,16 @@ class Nexcessnet_Turpentine_Helper_Data extends Mage_Core_Helper_Abstract {
|
|
270 |
'turpentine_varnish/general/auto_apply_on_save' );
|
271 |
}
|
272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
/**
|
274 |
* Get config value specifying when to strip VCL whitespaces
|
275 |
*
|
270 |
'turpentine_varnish/general/auto_apply_on_save' );
|
271 |
}
|
272 |
|
273 |
+
/**
|
274 |
+
* Get config value specifying when to strip VCL whitespaces
|
275 |
+
*
|
276 |
+
* @return string
|
277 |
+
*/
|
278 |
+
public function getVclFix() {
|
279 |
+
return Mage::getStoreConfig(
|
280 |
+
'turpentine_varnish/general/vcl_fix' );
|
281 |
+
}
|
282 |
+
|
283 |
/**
|
284 |
* Get config value specifying when to strip VCL whitespaces
|
285 |
*
|
app/code/community/Nexcessnet/Turpentine/Helper/Debug.php
CHANGED
@@ -21,41 +21,116 @@
|
|
21 |
|
22 |
class Nexcessnet_Turpentine_Helper_Debug extends Mage_Core_Helper_Abstract {
|
23 |
/**
|
24 |
-
*
|
25 |
*
|
26 |
-
* @param
|
27 |
-
* @
|
28 |
-
* @return mixed
|
29 |
*/
|
30 |
-
public function
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
} catch( Exception $e ) {
|
35 |
-
return parent::__call( $name, $args );
|
36 |
-
}
|
37 |
-
switch( substr( $name, 3 ) ) {
|
38 |
-
case 'Error':
|
39 |
-
return $this->_log( Zend_Log::ERR, $message );
|
40 |
-
case 'Warn':
|
41 |
-
return $this->_log( Zend_Log::WARN, $message );
|
42 |
-
case 'Notice':
|
43 |
-
return $this->_log( Zend_Log::NOTICE, $message );
|
44 |
-
case 'Info':
|
45 |
-
return $this->_log( Zend_Log::INFO, $message );
|
46 |
-
case 'Debug':
|
47 |
-
if( Mage::helper( 'turpentine/varnish' )
|
48 |
-
->getVarnishDebugEnabled() ) {
|
49 |
-
return $this->_log( Zend_Log::DEBUG, $message );
|
50 |
-
} else {
|
51 |
-
return;
|
52 |
-
}
|
53 |
-
default:
|
54 |
-
break;
|
55 |
-
}
|
56 |
}
|
57 |
-
|
58 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
|
61 |
/**
|
@@ -135,10 +210,39 @@ class Nexcessnet_Turpentine_Helper_Debug extends Mage_Core_Helper_Abstract {
|
|
135 |
*/
|
136 |
protected function _log( $level, $message ) {
|
137 |
$message = 'TURPENTINE: ' . $message;
|
138 |
-
Mage::log( $message, $level );
|
139 |
return $message;
|
140 |
}
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
/**
|
143 |
* Format a list of function arguments for the backtrace
|
144 |
*
|
21 |
|
22 |
class Nexcessnet_Turpentine_Helper_Debug extends Mage_Core_Helper_Abstract {
|
23 |
/**
|
24 |
+
* Logs errors
|
25 |
*
|
26 |
+
* @param $message
|
27 |
+
* @return string
|
|
|
28 |
*/
|
29 |
+
public function logError( $message )
|
30 |
+
{
|
31 |
+
if ( func_num_args() > 1 ) {
|
32 |
+
$message = $this->_prepareLogMessage( func_get_args() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
34 |
+
|
35 |
+
return $this->_log( Zend_Log::ERR, $message );
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Logs warnings
|
40 |
+
*
|
41 |
+
* @param $message
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
public function logWarn( $message )
|
45 |
+
{
|
46 |
+
if ( func_num_args() > 1 ) {
|
47 |
+
$message = $this->_prepareLogMessage( func_get_args() );
|
48 |
+
}
|
49 |
+
|
50 |
+
return $this->_log( Zend_Log::WARN, $message );
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Logs notices
|
55 |
+
*
|
56 |
+
* @param $message
|
57 |
+
* @return string
|
58 |
+
*/
|
59 |
+
public function logNotice( $message )
|
60 |
+
{
|
61 |
+
if ( func_num_args() > 1 ) {
|
62 |
+
$message = $this->_prepareLogMessage( func_get_args() );
|
63 |
+
}
|
64 |
+
|
65 |
+
return $this->_log( Zend_Log::NOTICE, $message );
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Logs info.
|
70 |
+
*
|
71 |
+
* @param $message
|
72 |
+
* @return string
|
73 |
+
*/
|
74 |
+
public function logInfo( $message )
|
75 |
+
{
|
76 |
+
if ( func_num_args() > 1 ) {
|
77 |
+
$message = $this->_prepareLogMessage( func_get_args() );
|
78 |
+
}
|
79 |
+
|
80 |
+
return $this->_log( Zend_Log::INFO, $message );
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Logs debug.
|
85 |
+
*
|
86 |
+
* @param $message
|
87 |
+
* @return string
|
88 |
+
*/
|
89 |
+
public function logDebug( $message )
|
90 |
+
{
|
91 |
+
if( ! Mage::helper( 'turpentine/varnish' )->getVarnishDebugEnabled() ) {
|
92 |
+
return;
|
93 |
+
}
|
94 |
+
|
95 |
+
if ( func_num_args() > 1 ) {
|
96 |
+
$message = $this->_prepareLogMessage( func_get_args() );
|
97 |
+
}
|
98 |
+
|
99 |
+
return $this->_log( Zend_Log::DEBUG, $message );
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Prepares advanced log message.
|
104 |
+
*
|
105 |
+
* @param array $args
|
106 |
+
* @return string
|
107 |
+
*/
|
108 |
+
protected function _prepareLogMessage( array $args )
|
109 |
+
{
|
110 |
+
$pattern = $args[0];
|
111 |
+
$substitutes = array_slice( $args, 1 );
|
112 |
+
|
113 |
+
if ( ! $this->_validatePattern( $pattern, $substitutes ) ) {
|
114 |
+
return $pattern;
|
115 |
+
}
|
116 |
+
|
117 |
+
return vsprintf( $pattern, $substitutes );
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Validates string and attributes for substitution as per sprintf function.
|
122 |
+
*
|
123 |
+
* NOTE: this could be implemented as shown at
|
124 |
+
* http://stackoverflow.com/questions/2053664/how-to-check-that-vsprintf-has-the-correct-number-of-arguments-before-running
|
125 |
+
* although IMHO it's too time consuming to validate the patterns.
|
126 |
+
*
|
127 |
+
* @param string $pattern
|
128 |
+
* @param array $arguments
|
129 |
+
* @return bool
|
130 |
+
*/
|
131 |
+
protected function _validatePattern( $pattern, $arguments )
|
132 |
+
{
|
133 |
+
return true;
|
134 |
}
|
135 |
|
136 |
/**
|
210 |
*/
|
211 |
protected function _log( $level, $message ) {
|
212 |
$message = 'TURPENTINE: ' . $message;
|
213 |
+
Mage::log( $message, $level, $this->_getLogFileName() );
|
214 |
return $message;
|
215 |
}
|
216 |
|
217 |
+
/**
|
218 |
+
* Get the name of the log file to use
|
219 |
+
* @return string
|
220 |
+
*/
|
221 |
+
protected function _getLogFileName() {
|
222 |
+
if ( $this->useCustomLogFile() ) {
|
223 |
+
return $this->getCustomLogFileName();
|
224 |
+
}
|
225 |
+
return '';
|
226 |
+
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* Check if custom log file should be used
|
230 |
+
* @return bool
|
231 |
+
*/
|
232 |
+
public function useCustomLogFile() {
|
233 |
+
return Mage::getStoreConfigFlag(
|
234 |
+
'turpentine_varnish/logging/use_custom_log_file' );
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Get custom log file name
|
239 |
+
* @return string
|
240 |
+
*/
|
241 |
+
public function getCustomLogFileName() {
|
242 |
+
return (string)Mage::getStoreConfig(
|
243 |
+
'turpentine_varnish/logging/custom_log_file_name' );
|
244 |
+
}
|
245 |
+
|
246 |
/**
|
247 |
* Format a list of function arguments for the backtrace
|
248 |
*
|
app/code/community/Nexcessnet/Turpentine/Helper/Esi.php
CHANGED
@@ -181,7 +181,7 @@ class Nexcessnet_Turpentine_Helper_Esi extends Mage_Core_Helper_Abstract {
|
|
181 |
if( $url === null ) {
|
182 |
$url = $this->getDummyUrl();
|
183 |
}
|
184 |
-
$request =
|
185 |
$request->fakeRouterDispatch();
|
186 |
return $request;
|
187 |
}
|
181 |
if( $url === null ) {
|
182 |
$url = $this->getDummyUrl();
|
183 |
}
|
184 |
+
$request = Mage::getModel('turpentine/dummy_request', $url);
|
185 |
$request->fakeRouterDispatch();
|
186 |
return $request;
|
187 |
}
|
app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Nexcess.net Turpentine Extension for Magento
|
5 |
+
* Copyright (C) 2012 Nexcess.net L.L.C.
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or modify
|
8 |
+
* it under the terms of the GNU General Public License as published by
|
9 |
+
* the Free Software Foundation; either version 2 of the License, or
|
10 |
+
* (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License along
|
18 |
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
19 |
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
+
*/
|
21 |
+
class Nexcessnet_Turpentine_Model_Core_Session extends Mage_Core_Model_Session
|
22 |
+
{
|
23 |
+
public function __construct($data=array())
|
24 |
+
{
|
25 |
+
$name = isset($data['name']) ? $data['name'] : null;
|
26 |
+
$this->init('core', $name);
|
27 |
+
}
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Retrieve Session Form Key
|
31 |
+
*
|
32 |
+
* @return string A 16 bit unique key for forms
|
33 |
+
*/
|
34 |
+
public function getFormKey()
|
35 |
+
{
|
36 |
+
if (Mage::registry('replace_form_key') &&
|
37 |
+
!Mage::app()->getRequest()->getParam('form_key', false)) {
|
38 |
+
// flag request for ESI processing
|
39 |
+
Mage::register('turpentine_esi_flag', true, true);
|
40 |
+
return '{{form_key_esi_placeholder}}';
|
41 |
+
} else {
|
42 |
+
return parent::getFormKey();
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
public function real_getFormKey()
|
47 |
+
{
|
48 |
+
if (!$this->getData('_form_key')) {
|
49 |
+
$this->setData('_form_key', Mage::helper('core')->getRandomString(16));
|
50 |
+
}
|
51 |
+
return $this->getData('_form_key');
|
52 |
+
}
|
53 |
+
}
|
app/code/community/Nexcessnet/Turpentine/Model/Dummy/Request.php
CHANGED
@@ -526,9 +526,12 @@ class Nexcessnet_Turpentine_Model_Dummy_Request extends
|
|
526 |
* @return null
|
527 |
*/
|
528 |
protected function _fixupFakeSuperGlobals( $uri ) {
|
|
|
529 |
$parsedUrl = parse_url( $uri );
|
530 |
|
531 |
-
|
|
|
|
|
532 |
if( isset( $parsedUrl['query'] ) && $parsedUrl['query'] ) {
|
533 |
$this->SERVER['QUERY_STRING'] = $parsedUrl['query'];
|
534 |
$this->SERVER['REQUEST_URI'] .= '?' . $this->SERVER['QUERY_STRING'];
|
526 |
* @return null
|
527 |
*/
|
528 |
protected function _fixupFakeSuperGlobals( $uri ) {
|
529 |
+
$uri = str_replace('|', urlencode('|'), $uri);
|
530 |
$parsedUrl = parse_url( $uri );
|
531 |
|
532 |
+
if ( isset($parsedUrl['path']) ) {
|
533 |
+
$this->SERVER['REQUEST_URI'] = $parsedUrl['path'];
|
534 |
+
}
|
535 |
if( isset( $parsedUrl['query'] ) && $parsedUrl['query'] ) {
|
536 |
$this->SERVER['QUERY_STRING'] = $parsedUrl['query'];
|
537 |
$this->SERVER['REQUEST_URI'] .= '?' . $this->SERVER['QUERY_STRING'];
|
app/code/community/Nexcessnet/Turpentine/Model/Observer/Ban.php
CHANGED
@@ -217,6 +217,34 @@ class Nexcessnet_Turpentine_Model_Observer_Ban extends Varien_Event_Observer {
|
|
217 |
}
|
218 |
}
|
219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
/**
|
221 |
* Do a full cache flush, corresponds to "Flush Magento Cache" and
|
222 |
* "Flush Cache Storage" buttons in admin > cache management
|
217 |
}
|
218 |
}
|
219 |
|
220 |
+
/**
|
221 |
+
* Ban a specific CMS page revision from cache after edit (enterprise edition only)
|
222 |
+
* Events:
|
223 |
+
* enterprise_cms_revision_save_commit_after
|
224 |
+
*
|
225 |
+
* @param Varien_Object $eventObject
|
226 |
+
* @return null
|
227 |
+
*/
|
228 |
+
public function banCmsPageRevisionCache($eventObject) {
|
229 |
+
if ( Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ) {
|
230 |
+
$pageId = $eventObject->getDataObject()->getPageId();
|
231 |
+
$page = Mage::getModel( 'cms/page' )->load( $pageId );
|
232 |
+
|
233 |
+
// Don't do anything if the page isn't found.
|
234 |
+
if( !$page ) {
|
235 |
+
return;
|
236 |
+
}
|
237 |
+
$pageIdentifier = $page->getIdentifier();
|
238 |
+
$result = $this->_getVarnishAdmin()->flushUrl( $pageIdentifier . '(?:\.html?)?$' );
|
239 |
+
Mage::dispatchEvent( 'turpentine_ban_cms_page_cache', $result );
|
240 |
+
$cronHelper = Mage::helper( 'turpentine/cron' );
|
241 |
+
if( $this->_checkResult( $result ) &&
|
242 |
+
$cronHelper->getCrawlerEnabled() ) {
|
243 |
+
$cronHelper->addCmsPageToCrawlerQueue( $pageIdentifier );
|
244 |
+
}
|
245 |
+
}
|
246 |
+
}
|
247 |
+
|
248 |
/**
|
249 |
* Do a full cache flush, corresponds to "Flush Magento Cache" and
|
250 |
* "Flush Cache Storage" buttons in admin > cache management
|
app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php
CHANGED
@@ -20,6 +20,35 @@
|
|
20 |
*/
|
21 |
|
22 |
class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
/**
|
25 |
* Check the ESI flag and set the ESI header if needed
|
@@ -196,7 +225,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
196 |
if( $esiHelper->getEsiBlockLogEnabled() ) {
|
197 |
$debugHelper->logInfo(
|
198 |
'Checking ESI block candidate: %s',
|
199 |
-
$blockObject->getNameInLayout() );
|
200 |
}
|
201 |
if( $esiHelper->shouldResponseUseEsi() &&
|
202 |
$blockObject instanceof Mage_Core_Block_Template &&
|
@@ -205,11 +234,11 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
205 |
// admin blocks are not allowed to be cached for now
|
206 |
$debugHelper->logWarn(
|
207 |
'Ignoring attempt to inject adminhtml block: %s',
|
208 |
-
$blockObject->getNameInLayout() );
|
209 |
return;
|
210 |
} elseif( $esiHelper->getEsiBlockLogEnabled() ) {
|
211 |
$debugHelper->logInfo( 'Block check passed, injecting block: %s',
|
212 |
-
$blockObject->getNameInLayout() );
|
213 |
}
|
214 |
Varien_Profiler::start( 'turpentine::observer::esi::injectEsi' );
|
215 |
$ttlParam = $esiHelper->getEsiTtlParam();
|
@@ -293,7 +322,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
293 |
$esiData->setBlockType( get_class( $blockObject ) );
|
294 |
$esiData->setLayoutHandles( $this->_getBlockLayoutHandles( $blockObject ) );
|
295 |
$esiData->setEsiMethod( $esiOptions[$methodParam] );
|
296 |
-
if( $esiOptions[$cacheTypeParam] == 'private' ) {
|
297 |
if( is_array( @$esiOptions['flush_events'] ) ) {
|
298 |
$esiData->setFlushEvents( array_merge(
|
299 |
$esiHelper->getDefaultCacheClearEvents(),
|
@@ -307,7 +336,11 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
307 |
$esiData->setParentUrl( Mage::app()->getRequest()->getRequestString() );
|
308 |
}
|
309 |
if( is_array( $esiOptions['dummy_blocks'] ) ) {
|
310 |
-
$
|
|
|
|
|
|
|
|
|
311 |
} else {
|
312 |
Mage::helper( 'turpentine/debug' )->logWarn(
|
313 |
'Invalid dummy_blocks for block: %s',
|
@@ -411,7 +444,7 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
411 |
|
412 |
// set the default TTL
|
413 |
if( !isset( $options[$ttlParam] ) ) {
|
414 |
-
if( $options[$cacheTypeParam] == 'private' ) {
|
415 |
switch( $options[$methodParam] ) {
|
416 |
case 'ajax':
|
417 |
$options[$ttlParam] = '0';
|
@@ -487,4 +520,29 @@ class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
|
487 |
protected function _checkIsEsiUrl( $url ) {
|
488 |
return !$this->_checkIsNotEsiUrl( $url );
|
489 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
490 |
}
|
20 |
*/
|
21 |
|
22 |
class Nexcessnet_Turpentine_Model_Observer_Esi extends Varien_Event_Observer {
|
23 |
+
/**
|
24 |
+
* Set a cookie with the customer group id when customer logs in
|
25 |
+
*
|
26 |
+
* Events: customer_login
|
27 |
+
*
|
28 |
+
* @param Varien_Object $eventObject
|
29 |
+
* @return null
|
30 |
+
*/
|
31 |
+
public function setCustomerGroupCookie( $eventObject ) {
|
32 |
+
$customer = $eventObject->getCustomer();
|
33 |
+
$cookie = Mage::getSingleton('core/cookie');
|
34 |
+
if (Mage::getStoreConfig('persistent/options/enabled')) {
|
35 |
+
$cookie->set('customer_group', $customer->getGroupId(), Mage::getStoreConfig('persistent/options/lifetime'));
|
36 |
+
} else {
|
37 |
+
$cookie->set('customer_group', $customer->getGroupId());
|
38 |
+
}
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Destroy the cookie with the customer group when customer logs out
|
43 |
+
*
|
44 |
+
* Events: customer_logout
|
45 |
+
*
|
46 |
+
* @param Varien_Object $eventObject
|
47 |
+
* @return null
|
48 |
+
*/
|
49 |
+
public function removeCustomerGroupCookie( $eventObject ) {
|
50 |
+
Mage::getSingleton('core/cookie')->delete('customer_group');
|
51 |
+
}
|
52 |
|
53 |
/**
|
54 |
* Check the ESI flag and set the ESI header if needed
|
225 |
if( $esiHelper->getEsiBlockLogEnabled() ) {
|
226 |
$debugHelper->logInfo(
|
227 |
'Checking ESI block candidate: %s',
|
228 |
+
$blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );
|
229 |
}
|
230 |
if( $esiHelper->shouldResponseUseEsi() &&
|
231 |
$blockObject instanceof Mage_Core_Block_Template &&
|
234 |
// admin blocks are not allowed to be cached for now
|
235 |
$debugHelper->logWarn(
|
236 |
'Ignoring attempt to inject adminhtml block: %s',
|
237 |
+
$blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );
|
238 |
return;
|
239 |
} elseif( $esiHelper->getEsiBlockLogEnabled() ) {
|
240 |
$debugHelper->logInfo( 'Block check passed, injecting block: %s',
|
241 |
+
$blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );
|
242 |
}
|
243 |
Varien_Profiler::start( 'turpentine::observer::esi::injectEsi' );
|
244 |
$ttlParam = $esiHelper->getEsiTtlParam();
|
322 |
$esiData->setBlockType( get_class( $blockObject ) );
|
323 |
$esiData->setLayoutHandles( $this->_getBlockLayoutHandles( $blockObject ) );
|
324 |
$esiData->setEsiMethod( $esiOptions[$methodParam] );
|
325 |
+
if( $esiOptions[$cacheTypeParam] == 'private' || $esiOptions[$cacheTypeParam] == 'customer_group' ) {
|
326 |
if( is_array( @$esiOptions['flush_events'] ) ) {
|
327 |
$esiData->setFlushEvents( array_merge(
|
328 |
$esiHelper->getDefaultCacheClearEvents(),
|
336 |
$esiData->setParentUrl( Mage::app()->getRequest()->getRequestString() );
|
337 |
}
|
338 |
if( is_array( $esiOptions['dummy_blocks'] ) ) {
|
339 |
+
$dummyBlocks = array();
|
340 |
+
foreach( $esiOptions['dummy_blocks'] as $key => $value ) {
|
341 |
+
$dummyBlocks[] = ( empty($value) && !is_numeric($key) ) ? $key : $value;
|
342 |
+
}
|
343 |
+
$esiData->setDummyBlocks( $dummyBlocks );
|
344 |
} else {
|
345 |
Mage::helper( 'turpentine/debug' )->logWarn(
|
346 |
'Invalid dummy_blocks for block: %s',
|
444 |
|
445 |
// set the default TTL
|
446 |
if( !isset( $options[$ttlParam] ) ) {
|
447 |
+
if( $options[$cacheTypeParam] == 'private' || $options[$cacheTypeParam] == 'customer_group' ) {
|
448 |
switch( $options[$methodParam] ) {
|
449 |
case 'ajax':
|
450 |
$options[$ttlParam] = '0';
|
520 |
protected function _checkIsEsiUrl( $url ) {
|
521 |
return !$this->_checkIsNotEsiUrl( $url );
|
522 |
}
|
523 |
+
|
524 |
+
public function hookToControllerActionPreDispatch($observer) {
|
525 |
+
if(Mage::helper( 'turpentine/data')->getVclFix() == 0 && $observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') {
|
526 |
+
Mage::dispatchEvent("add_to_cart_before", array('request' => $observer->getControllerAction()->getRequest()));
|
527 |
+
}
|
528 |
+
}
|
529 |
+
|
530 |
+
public function hookToControllerActionPostDispatch($observer) {
|
531 |
+
if($observer->getEvent()->getControllerAction()->getFullActionName() == 'checkout_cart_add') {
|
532 |
+
Mage::dispatchEvent("add_to_cart_after", array('request' => $observer->getControllerAction()->getRequest()));
|
533 |
+
}
|
534 |
+
}
|
535 |
+
|
536 |
+
public function hookToAddToCartBefore($observer) {
|
537 |
+
//Mage::log("hookToAddToCartBefore-antes ".print_r($observer->getEvent()->getRequest()->getParams(),true)." will be added to cart.", null, 'carrinho.log', true);
|
538 |
+
$key = Mage::getSingleton('core/session')->getFormKey();
|
539 |
+
$observer->getEvent()->getRequest()->setParam('form_key', $key);
|
540 |
+
$request = $observer->getEvent()->getRequest()->getParams();
|
541 |
+
//Mage::log("hookToAddToCartBefore ".print_r($request,true)." will be added to cart.", null, 'carrinho.log', true);
|
542 |
+
}
|
543 |
+
|
544 |
+
public function hookToAddToCartAfter($observer) {
|
545 |
+
$request = $observer->getEvent()->getRequest()->getParams();
|
546 |
+
//Mage::log("hookToAddToCartAfter ".print_r($request,true)." is added to cart.", null, 'carrinho.log', true);
|
547 |
+
}
|
548 |
}
|
app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php
CHANGED
@@ -27,7 +27,6 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin {
|
|
27 |
/**
|
28 |
* Flush all Magento URLs in Varnish cache
|
29 |
*
|
30 |
-
* @param Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract $cfgr
|
31 |
* @return bool
|
32 |
*/
|
33 |
public function flushAll() {
|
@@ -37,8 +36,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin {
|
|
37 |
/**
|
38 |
* Flush all Magento URLs matching the given (relative) regex
|
39 |
*
|
40 |
-
* @param
|
41 |
-
* @param string $pattern regex to match against URLs
|
42 |
* @return bool
|
43 |
*/
|
44 |
public function flushUrl( $subPattern ) {
|
@@ -94,7 +92,6 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin {
|
|
94 |
/**
|
95 |
* Generate and apply the config to the Varnish instances
|
96 |
*
|
97 |
-
* @param Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract $cfgr
|
98 |
* @return bool
|
99 |
*/
|
100 |
public function applyConfig() {
|
@@ -155,7 +152,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin {
|
|
155 |
}
|
156 |
} else {
|
157 |
// error
|
158 |
-
Mage::helper( 'turpentine/debug' )->
|
159 |
'Failed to parse param.show output to check esi_syntax value' );
|
160 |
$result = true;
|
161 |
}
|
27 |
/**
|
28 |
* Flush all Magento URLs in Varnish cache
|
29 |
*
|
|
|
30 |
* @return bool
|
31 |
*/
|
32 |
public function flushAll() {
|
36 |
/**
|
37 |
* Flush all Magento URLs matching the given (relative) regex
|
38 |
*
|
39 |
+
* @param string $subPattern regex to match against URLs
|
|
|
40 |
* @return bool
|
41 |
*/
|
42 |
public function flushUrl( $subPattern ) {
|
92 |
/**
|
93 |
* Generate and apply the config to the Varnish instances
|
94 |
*
|
|
|
95 |
* @return bool
|
96 |
*/
|
97 |
public function applyConfig() {
|
152 |
}
|
153 |
} else {
|
154 |
// error
|
155 |
+
Mage::helper( 'turpentine/debug' )->logWarn(
|
156 |
'Failed to parse param.show output to check esi_syntax value' );
|
157 |
$result = true;
|
158 |
}
|
app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php
CHANGED
@@ -195,6 +195,26 @@ abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract {
|
|
195 |
}
|
196 |
}
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
/**
|
199 |
* Get the base url path regex
|
200 |
*
|
@@ -322,6 +342,56 @@ abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract {
|
|
322 |
Mage::getStoreConfig( 'turpentine_vcl/params/get_params' ) ) );
|
323 |
}
|
324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
/**
|
326 |
* Get the Force Static Caching option
|
327 |
*
|
@@ -491,9 +561,10 @@ abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract {
|
|
491 |
/**
|
492 |
* Format a VCL backend declaration
|
493 |
*
|
494 |
-
* @param string $name
|
495 |
-
* @param string $host
|
496 |
-
* @param string $port
|
|
|
497 |
* @return string
|
498 |
*/
|
499 |
protected function _vcl_backend( $name, $host, $port, $options=array() ) {
|
@@ -581,7 +652,7 @@ if (req.http.Accept-Encoding) {
|
|
581 |
} else if (req.http.Accept-Encoding ~ "deflate") {
|
582 |
set req.http.Accept-Encoding = "deflate";
|
583 |
} else {
|
584 |
-
#
|
585 |
unset req.http.Accept-Encoding;
|
586 |
}
|
587 |
}
|
@@ -604,6 +675,26 @@ EOS;
|
|
604 |
'normalize_host_target' => $this->_getNormalizeHostTarget() ) );
|
605 |
}
|
606 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
607 |
/**
|
608 |
* Build the list of template variables to apply to the VCL template
|
609 |
*
|
@@ -616,13 +707,20 @@ EOS;
|
|
616 |
'admin_frontname' => $this->_getAdminFrontname(),
|
617 |
'normalize_host_target' => $this->_getNormalizeHostTarget(),
|
618 |
'url_base_regex' => $this->getBaseUrlPathRegex(),
|
|
|
619 |
'url_excludes' => $this->_getUrlExcludes(),
|
620 |
'get_param_excludes' => $this->_getGetParamExcludes(),
|
|
|
621 |
'default_ttl' => $this->_getDefaultTtl(),
|
622 |
'enable_get_excludes' => ($this->_getGetParamExcludes() ? 'true' : 'false'),
|
|
|
623 |
'debug_headers' => $this->_getEnableDebugHeaders(),
|
624 |
'grace_period' => $this->_getGracePeriod(),
|
625 |
'force_cache_static' => $this->_getForceCacheStatic(),
|
|
|
|
|
|
|
|
|
626 |
'static_extensions' => $this->_getStaticExtensions(),
|
627 |
'static_ttl' => $this->_getStaticTtl(),
|
628 |
'url_ttls' => $this->_getUrlTtls(),
|
@@ -654,7 +752,13 @@ EOS;
|
|
654 |
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/host' ) ) {
|
655 |
$vars['normalize_host'] = $this->_vcl_sub_normalize_host();
|
656 |
}
|
657 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
658 |
$customIncludeFile = $this->_getCustomIncludeFilename();
|
659 |
if( is_readable( $customIncludeFile ) ) {
|
660 |
$vars['custom_vcl_include'] = file_get_contents( $customIncludeFile );
|
195 |
}
|
196 |
}
|
197 |
|
198 |
+
/**
|
199 |
+
* Get hosts as regex
|
200 |
+
*
|
201 |
+
* ex: base_url: example.com
|
202 |
+
* path_regex: (example.com|example.net)
|
203 |
+
*
|
204 |
+
* @return string
|
205 |
+
*/
|
206 |
+
public function getAllowedHostsRegex() {
|
207 |
+
$hosts = array();
|
208 |
+
foreach( Mage::app()->getStores() as $store ) {
|
209 |
+
$hosts[] = parse_url( $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB , false ), PHP_URL_HOST );
|
210 |
+
}
|
211 |
+
|
212 |
+
$hosts = array_values(array_unique( $hosts ));
|
213 |
+
|
214 |
+
$pattern = '('.implode('|', array_map("preg_quote", $hosts)).')';
|
215 |
+
return $pattern;
|
216 |
+
}
|
217 |
+
|
218 |
/**
|
219 |
* Get the base url path regex
|
220 |
*
|
342 |
Mage::getStoreConfig( 'turpentine_vcl/params/get_params' ) ) );
|
343 |
}
|
344 |
|
345 |
+
protected function _getIgnoreGetParameters()
|
346 |
+
{
|
347 |
+
/** @var Nexcessnet_Turpentine_Helper_Data $helper */
|
348 |
+
$helper = Mage::helper('turpentine');
|
349 |
+
$ignoredParameters = $helper->cleanExplode(',', Mage::getStoreConfig( 'turpentine_vcl/params/ignore_get_params'));
|
350 |
+
return implode( '|', $ignoredParameters);
|
351 |
+
}
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Get the Generate Session
|
355 |
+
*
|
356 |
+
* @return string
|
357 |
+
*/
|
358 |
+
protected function _getGenerateSessionStart() {
|
359 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
|
360 |
+
? '/* -- REMOVED' : '';
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Get the Generate Session
|
365 |
+
*
|
366 |
+
* @return string
|
367 |
+
*/
|
368 |
+
protected function _getGenerateSessionEnd() {
|
369 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
|
370 |
+
? '-- */' : '';
|
371 |
+
}
|
372 |
+
|
373 |
+
|
374 |
+
/**
|
375 |
+
* Get the Generate Session
|
376 |
+
*
|
377 |
+
* @return string
|
378 |
+
*/
|
379 |
+
protected function _getGenerateSession() {
|
380 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
|
381 |
+
? '# call generate_session' : 'call generate_session;';
|
382 |
+
}
|
383 |
+
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Get the Generate Session Expires
|
387 |
+
*
|
388 |
+
* @return string
|
389 |
+
*/
|
390 |
+
protected function _getGenerateSessionExpires() {
|
391 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
|
392 |
+
? '# call generate_session_expires' : 'call generate_session_expires;';
|
393 |
+
}
|
394 |
+
|
395 |
/**
|
396 |
* Get the Force Static Caching option
|
397 |
*
|
561 |
/**
|
562 |
* Format a VCL backend declaration
|
563 |
*
|
564 |
+
* @param string $name name of the backend
|
565 |
+
* @param string $host backend host
|
566 |
+
* @param string $port backend port
|
567 |
+
* @param array $options options
|
568 |
* @return string
|
569 |
*/
|
570 |
protected function _vcl_backend( $name, $host, $port, $options=array() ) {
|
652 |
} else if (req.http.Accept-Encoding ~ "deflate") {
|
653 |
set req.http.Accept-Encoding = "deflate";
|
654 |
} else {
|
655 |
+
# unknown algorithm
|
656 |
unset req.http.Accept-Encoding;
|
657 |
}
|
658 |
}
|
675 |
'normalize_host_target' => $this->_getNormalizeHostTarget() ) );
|
676 |
}
|
677 |
|
678 |
+
/**
|
679 |
+
* Get the hostname for cookie normalization
|
680 |
+
*
|
681 |
+
* @return string
|
682 |
+
*/
|
683 |
+
protected function _getNormalizeCookieTarget() {
|
684 |
+
return trim( Mage::getStoreConfig(
|
685 |
+
'turpentine_vcl/normalization/cookie_target' ) );
|
686 |
+
}
|
687 |
+
|
688 |
+
/**
|
689 |
+
* Get the regex for cookie normalization
|
690 |
+
*
|
691 |
+
* @return string
|
692 |
+
*/
|
693 |
+
protected function _getNormalizeCookieRegex() {
|
694 |
+
return trim( Mage::getStoreConfig(
|
695 |
+
'turpentine_vcl/normalization/cookie_regex' ) );
|
696 |
+
}
|
697 |
+
|
698 |
/**
|
699 |
* Build the list of template variables to apply to the VCL template
|
700 |
*
|
707 |
'admin_frontname' => $this->_getAdminFrontname(),
|
708 |
'normalize_host_target' => $this->_getNormalizeHostTarget(),
|
709 |
'url_base_regex' => $this->getBaseUrlPathRegex(),
|
710 |
+
'allowed_hosts_regex' => $this->getAllowedHostsRegex(),
|
711 |
'url_excludes' => $this->_getUrlExcludes(),
|
712 |
'get_param_excludes' => $this->_getGetParamExcludes(),
|
713 |
+
'get_param_ignored' => $this->_getIgnoreGetParameters(),
|
714 |
'default_ttl' => $this->_getDefaultTtl(),
|
715 |
'enable_get_excludes' => ($this->_getGetParamExcludes() ? 'true' : 'false'),
|
716 |
+
'enable_get_ignored' => ($this->_getIgnoreGetParameters() ? 'true' : 'false'),
|
717 |
'debug_headers' => $this->_getEnableDebugHeaders(),
|
718 |
'grace_period' => $this->_getGracePeriod(),
|
719 |
'force_cache_static' => $this->_getForceCacheStatic(),
|
720 |
+
'generate_session_expires' => $this->_getGenerateSessionExpires(),
|
721 |
+
'generate_session' => $this->_getGenerateSession(),
|
722 |
+
'generate_session_start' => $this->_getGenerateSessionStart(),
|
723 |
+
'generate_session_end' => $this->_getGenerateSessionEnd(),
|
724 |
'static_extensions' => $this->_getStaticExtensions(),
|
725 |
'static_ttl' => $this->_getStaticTtl(),
|
726 |
'url_ttls' => $this->_getUrlTtls(),
|
752 |
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/host' ) ) {
|
753 |
$vars['normalize_host'] = $this->_vcl_sub_normalize_host();
|
754 |
}
|
755 |
+
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_regex' ) ) {
|
756 |
+
$vars['normalize_cookie_regex'] = $this->_getNormalizeCookieRegex();
|
757 |
+
}
|
758 |
+
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_target' ) ) {
|
759 |
+
$vars['normalize_cookie_target'] = $this->_getNormalizeCookieTarget();
|
760 |
+
}
|
761 |
+
|
762 |
$customIncludeFile = $this->_getCustomIncludeFilename();
|
763 |
if( is_readable( $customIncludeFile ) ) {
|
764 |
$vars['custom_vcl_include'] = file_get_contents( $customIncludeFile );
|
app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php~
ADDED
@@ -0,0 +1,769 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Nexcess.net Turpentine Extension for Magento
|
5 |
+
* Copyright (C) 2012 Nexcess.net L.L.C.
|
6 |
+
*
|
7 |
+
* This program is free software; you can redistribute it and/or modify
|
8 |
+
* it under the terms of the GNU General Public License as published by
|
9 |
+
* the Free Software Foundation; either version 2 of the License, or
|
10 |
+
* (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License along
|
18 |
+
* with this program; if not, write to the Free Software Foundation, Inc.,
|
19 |
+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
+
*/
|
21 |
+
|
22 |
+
abstract class Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract {
|
23 |
+
|
24 |
+
const VCL_CUSTOM_C_CODE_FILE = 'uuid.c';
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Get the correct version of a configurator from a socket
|
28 |
+
*
|
29 |
+
* @param Nexcessnet_Turpentine_Model_Varnish_Admin_Socket $socket
|
30 |
+
* @return Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract
|
31 |
+
*/
|
32 |
+
static public function getFromSocket( $socket ) {
|
33 |
+
try {
|
34 |
+
$version = $socket->getVersion();
|
35 |
+
} catch( Mage_Core_Exception $e ) {
|
36 |
+
Mage::getSingleton( 'core/session' )
|
37 |
+
->addError( 'Error determining Varnish version: ' .
|
38 |
+
$e->getMessage() );
|
39 |
+
return null;
|
40 |
+
}
|
41 |
+
switch( $version ) {
|
42 |
+
case '3.0':
|
43 |
+
return Mage::getModel(
|
44 |
+
'turpentine/varnish_configurator_version3',
|
45 |
+
array( 'socket' => $socket ) );
|
46 |
+
case '2.1':
|
47 |
+
return Mage::getModel(
|
48 |
+
'turpentine/varnish_configurator_version2',
|
49 |
+
array( 'socket' => $socket ) );
|
50 |
+
default:
|
51 |
+
Mage::throwException( 'Unsupported Varnish version' );
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* The socket this configurator is based on
|
57 |
+
*
|
58 |
+
* @var Nexcessnet_Turpentine_Model_Varnish_Admin_Socket
|
59 |
+
*/
|
60 |
+
protected $_socket = null;
|
61 |
+
/**
|
62 |
+
* options array
|
63 |
+
*
|
64 |
+
* @var array
|
65 |
+
*/
|
66 |
+
protected $_options = array(
|
67 |
+
'vcl_template' => null,
|
68 |
+
);
|
69 |
+
|
70 |
+
public function __construct( $options=array() ) {
|
71 |
+
$this->_options = array_merge( $this->_options, $options );
|
72 |
+
}
|
73 |
+
|
74 |
+
abstract public function generate($doClean=true);
|
75 |
+
// abstract protected function _getTemplateVars();
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Save the generated config to the file specified in Magento config
|
79 |
+
*
|
80 |
+
* @param string $generatedConfig config generated by @generate
|
81 |
+
* @return null
|
82 |
+
*/
|
83 |
+
public function save( $generatedConfig ) {
|
84 |
+
$filename = $this->_getVclFilename();
|
85 |
+
$dir = dirname( $filename );
|
86 |
+
if( !is_dir( $dir ) ) {
|
87 |
+
// this umask is probably redundant, but just in case...
|
88 |
+
if( !mkdir( $dir, 0777 & ~umask(), true ) ) {
|
89 |
+
$err = error_get_last();
|
90 |
+
return array( false, $err );
|
91 |
+
}
|
92 |
+
}
|
93 |
+
if( strlen( $generatedConfig ) !==
|
94 |
+
file_put_contents( $filename, $generatedConfig ) ) {
|
95 |
+
$err = error_get_last();
|
96 |
+
return array( false, $err );
|
97 |
+
}
|
98 |
+
return array( true, null );
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Get the full path for a given template filename
|
103 |
+
*
|
104 |
+
* @param string $baseFilename
|
105 |
+
* @return string
|
106 |
+
*/
|
107 |
+
protected function _getVclTemplateFilename( $baseFilename ) {
|
108 |
+
$extensionDir = Mage::getModuleDir( '', 'Nexcessnet_Turpentine' );
|
109 |
+
return sprintf( '%s/misc/%s', $extensionDir, $baseFilename );
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Get the name of the file to save the VCL to
|
114 |
+
*
|
115 |
+
* @return string
|
116 |
+
*/
|
117 |
+
protected function _getVclFilename() {
|
118 |
+
return $this->_formatTemplate(
|
119 |
+
Mage::getStoreConfig( 'turpentine_varnish/servers/config_file' ),
|
120 |
+
array( 'root_dir' => Mage::getBaseDir() ) );
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Get the name of the custom include VCL file
|
125 |
+
*
|
126 |
+
* @return string
|
127 |
+
*/
|
128 |
+
protected function _getCustomIncludeFilename() {
|
129 |
+
return $this->_formatTemplate(
|
130 |
+
Mage::getStoreConfig( 'turpentine_varnish/servers/custom_include_file' ),
|
131 |
+
array( 'root_dir' => Mage::getBaseDir() ) );
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Format a template string, replacing {{keys}} with the appropriate values
|
136 |
+
* and remove unspecified keys
|
137 |
+
*
|
138 |
+
* @param string $template template string to operate on
|
139 |
+
* @param array $vars array of key => value replacements
|
140 |
+
* @return string
|
141 |
+
*/
|
142 |
+
protected function _formatTemplate( $template, array $vars ) {
|
143 |
+
$needles = array_map( create_function( '$k', 'return "{{".$k."}}";' ),
|
144 |
+
array_keys( $vars ) );
|
145 |
+
$replacements = array_values( $vars );
|
146 |
+
// do replacements, then delete unused template vars
|
147 |
+
return preg_replace( '~{{[^}]+}}~', '',
|
148 |
+
str_replace( $needles, $replacements, $template ) );
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Format a VCL subroutine call
|
153 |
+
*
|
154 |
+
* @param string $subroutine subroutine name
|
155 |
+
* @return string
|
156 |
+
*/
|
157 |
+
protected function _vcl_call( $subroutine ) {
|
158 |
+
return sprintf( 'call %s;', $subroutine );
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Get the Magento admin frontname
|
163 |
+
*
|
164 |
+
* This is just the plain string, not in URL format. ex:
|
165 |
+
* http://example.com/magento/admin -> admin
|
166 |
+
*
|
167 |
+
* @return string
|
168 |
+
*/
|
169 |
+
protected function _getAdminFrontname() {
|
170 |
+
if( Mage::getStoreConfig( 'admin/url/use_custom_path' ) ) {
|
171 |
+
return Mage::getStoreConfig( 'admin/url/custom_path' );
|
172 |
+
} else {
|
173 |
+
return (string)Mage::getConfig()->getNode(
|
174 |
+
'admin/routers/adminhtml/args/frontName' );
|
175 |
+
}
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Get the hostname for host normalization from Magento's base URL
|
180 |
+
*
|
181 |
+
* @return string
|
182 |
+
*/
|
183 |
+
protected function _getNormalizeHostTarget() {
|
184 |
+
$configHost = trim( Mage::getStoreConfig(
|
185 |
+
'turpentine_vcl/normalization/host_target' ) );
|
186 |
+
if( $configHost ) {
|
187 |
+
return $configHost;
|
188 |
+
} else {
|
189 |
+
$baseUrl = parse_url( Mage::getBaseUrl() );
|
190 |
+
if( isset( $baseUrl['port'] ) ) {
|
191 |
+
return sprintf( '%s:%d', $baseUrl['host'], $baseUrl['port'] );
|
192 |
+
} else {
|
193 |
+
return $baseUrl['host'];
|
194 |
+
}
|
195 |
+
}
|
196 |
+
}
|
197 |
+
|
198 |
+
/**
|
199 |
+
* Get hosts as regex
|
200 |
+
*
|
201 |
+
* ex: base_url: example.com
|
202 |
+
* path_regex: (example.com|example.net)
|
203 |
+
*
|
204 |
+
* @return string
|
205 |
+
*/
|
206 |
+
public function getAllowedHostsRegex() {
|
207 |
+
$hosts = array();
|
208 |
+
foreach( Mage::app()->getStores() as $store ) {
|
209 |
+
$hosts[] = parse_url( $store->getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB , false ), PHP_URL_HOST );
|
210 |
+
}
|
211 |
+
|
212 |
+
$hosts = array_values(array_unique( $hosts ));
|
213 |
+
|
214 |
+
$pattern = '('.implode('|', array_map("preg_quote", $hosts)).')';
|
215 |
+
return $pattern;
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Get the base url path regex
|
220 |
+
*
|
221 |
+
* ex: base_url: http://example.com/magento/
|
222 |
+
* path_regex: /magento/(?:(?:index|litespeed)\.php/)?
|
223 |
+
*
|
224 |
+
* @return string
|
225 |
+
*/
|
226 |
+
public function getBaseUrlPathRegex() {
|
227 |
+
$pattern = '^(%s)(?:(?:index|litespeed)\\.php/)?';
|
228 |
+
return sprintf( $pattern, implode( '|',
|
229 |
+
array_map( create_function( '$x', 'return preg_quote($x,"|");' ),
|
230 |
+
$this->_getBaseUrlPaths() ) ) );
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Get the path part of each store's base URL and static file URLs
|
235 |
+
*
|
236 |
+
* @return array
|
237 |
+
*/
|
238 |
+
protected function _getBaseUrlPaths() {
|
239 |
+
$paths = array();
|
240 |
+
$linkTypes = array( Mage_Core_Model_Store::URL_TYPE_LINK,
|
241 |
+
Mage_Core_Model_Store::URL_TYPE_JS,
|
242 |
+
Mage_Core_Model_Store::URL_TYPE_SKIN,
|
243 |
+
Mage_Core_Model_Store::URL_TYPE_MEDIA );
|
244 |
+
foreach( Mage::app()->getStores() as $store ) {
|
245 |
+
foreach( $linkTypes as $linkType ) {
|
246 |
+
$paths[] = parse_url( $store->getBaseUrl( $linkType , false ),
|
247 |
+
PHP_URL_PATH );
|
248 |
+
$paths[] = parse_url( $store->getBaseUrl( $linkType , true ),
|
249 |
+
PHP_URL_PATH );
|
250 |
+
}
|
251 |
+
}
|
252 |
+
$paths = array_unique( $paths );
|
253 |
+
usort( $paths, create_function( '$a, $b',
|
254 |
+
'return strlen( $b ) - strlen( $a );' ) );
|
255 |
+
return array_values( $paths );
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Format the URL exclusions for insertion in a regex. Admin frontname and
|
260 |
+
* API are automatically added.
|
261 |
+
*
|
262 |
+
* @return string
|
263 |
+
*/
|
264 |
+
protected function _getUrlExcludes() {
|
265 |
+
$urls = Mage::getStoreConfig( 'turpentine_vcl/urls/url_blacklist' );
|
266 |
+
return implode( '|', array_merge( array( $this->_getAdminFrontname(), 'api' ),
|
267 |
+
Mage::helper( 'turpentine/data' )->cleanExplode( PHP_EOL, $urls ) ) );
|
268 |
+
}
|
269 |
+
|
270 |
+
/**
|
271 |
+
* Get the default cache TTL from Magento config
|
272 |
+
*
|
273 |
+
* @return string
|
274 |
+
*/
|
275 |
+
protected function _getDefaultTtl() {
|
276 |
+
return Mage::helper( 'turpentine/varnish' )->getDefaultTtl();
|
277 |
+
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* Get the default backend configuration string
|
281 |
+
*
|
282 |
+
* @return string
|
283 |
+
*/
|
284 |
+
protected function _getDefaultBackend() {
|
285 |
+
$timeout = Mage::getStoreConfig( 'turpentine_vcl/backend/frontend_timeout' );
|
286 |
+
$default_options = array(
|
287 |
+
'first_byte_timeout' => $timeout . 's',
|
288 |
+
'between_bytes_timeout' => $timeout . 's',
|
289 |
+
);
|
290 |
+
return $this->_vcl_backend( 'default',
|
291 |
+
Mage::getStoreConfig( 'turpentine_vcl/backend/backend_host' ),
|
292 |
+
Mage::getStoreConfig( 'turpentine_vcl/backend/backend_port' ),
|
293 |
+
$default_options );
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Get the admin backend configuration string
|
298 |
+
*
|
299 |
+
* @return string
|
300 |
+
*/
|
301 |
+
protected function _getAdminBackend() {
|
302 |
+
$timeout = Mage::getStoreConfig( 'turpentine_vcl/backend/admin_timeout' );
|
303 |
+
$admin_options = array(
|
304 |
+
'first_byte_timeout' => $timeout . 's',
|
305 |
+
'between_bytes_timeout' => $timeout . 's',
|
306 |
+
);
|
307 |
+
return $this->_vcl_backend( 'admin',
|
308 |
+
Mage::getStoreConfig( 'turpentine_vcl/backend/backend_host' ),
|
309 |
+
Mage::getStoreConfig( 'turpentine_vcl/backend/backend_port' ),
|
310 |
+
$admin_options );
|
311 |
+
}
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Get the grace period for vcl_fetch
|
315 |
+
*
|
316 |
+
* This is curently hardcoded to 15 seconds, will be configurable at some
|
317 |
+
* point
|
318 |
+
*
|
319 |
+
* @return string
|
320 |
+
*/
|
321 |
+
protected function _getGracePeriod() {
|
322 |
+
return Mage::getStoreConfig( 'turpentine_vcl/ttls/grace_period' );
|
323 |
+
}
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Get whether debug headers should be enabled or not
|
327 |
+
*
|
328 |
+
* @return string
|
329 |
+
*/
|
330 |
+
protected function _getEnableDebugHeaders() {
|
331 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/varnish_debug' )
|
332 |
+
? 'true' : 'false';
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Format the GET variable excludes for insertion in a regex
|
337 |
+
*
|
338 |
+
* @return string
|
339 |
+
*/
|
340 |
+
protected function _getGetParamExcludes() {
|
341 |
+
return implode( '|', Mage::helper( 'turpentine/data' )->cleanExplode( ',',
|
342 |
+
Mage::getStoreConfig( 'turpentine_vcl/params/get_params' ) ) );
|
343 |
+
}
|
344 |
+
|
345 |
+
protected function _getIgnoreGetParameters()
|
346 |
+
{
|
347 |
+
/** @var Nexcessnet_Turpentine_Helper_Data $helper */
|
348 |
+
$helper = Mage::helper('turpentine');
|
349 |
+
$ignoredParameters = $helper->cleanExplode(',', Mage::getStoreConfig( 'turpentine_vcl/params/ignore_get_params'));
|
350 |
+
return implode( '|', $ignoredParameters);
|
351 |
+
}
|
352 |
+
|
353 |
+
/**
|
354 |
+
* Get the Generate Session
|
355 |
+
*
|
356 |
+
* @return string
|
357 |
+
*/
|
358 |
+
protected function _getGenerateSessionStart() {
|
359 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
|
360 |
+
? '/* -- REMOVED' : '';
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Get the Generate Session
|
365 |
+
*
|
366 |
+
* @return string
|
367 |
+
*/
|
368 |
+
protected function _getGenerateSessionEnd() {
|
369 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
|
370 |
+
? '-- */' : '';
|
371 |
+
}
|
372 |
+
|
373 |
+
|
374 |
+
/**
|
375 |
+
* Get the Generate Session
|
376 |
+
*
|
377 |
+
* @return string
|
378 |
+
*/
|
379 |
+
protected function _getGenerateSession() {
|
380 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
|
381 |
+
? '# call generate_session' : 'call generate_session;';
|
382 |
+
}
|
383 |
+
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Get the Generate Session Expires
|
387 |
+
*
|
388 |
+
* @return string
|
389 |
+
*/
|
390 |
+
protected function _getGenerateSessionExpires() {
|
391 |
+
return Mage::getStoreConfig( 'turpentine_varnish/general/vcl_fix' )
|
392 |
+
? '# call generate_session_expires' : 'call generate_session_expires;';
|
393 |
+
}
|
394 |
+
|
395 |
+
/**
|
396 |
+
* Get the Force Static Caching option
|
397 |
+
*
|
398 |
+
* @return string
|
399 |
+
*/
|
400 |
+
protected function _getForceCacheStatic() {
|
401 |
+
return Mage::getStoreConfig( 'turpentine_vcl/static/force_static' )
|
402 |
+
? 'true' : 'false';
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Format the list of static cache extensions
|
407 |
+
*
|
408 |
+
* @return string
|
409 |
+
*/
|
410 |
+
protected function _getStaticExtensions() {
|
411 |
+
return implode( '|', Mage::helper( 'turpentine/data' )->cleanExplode( ',',
|
412 |
+
Mage::getStoreConfig( 'turpentine_vcl/static/exts' ) ) );
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Get the static caching TTL
|
417 |
+
*
|
418 |
+
* @return string
|
419 |
+
*/
|
420 |
+
protected function _getStaticTtl() {
|
421 |
+
return Mage::getStoreConfig( 'turpentine_vcl/ttls/static_ttl' );
|
422 |
+
}
|
423 |
+
|
424 |
+
/**
|
425 |
+
* Format the by-url TTL value list
|
426 |
+
*
|
427 |
+
* @return string
|
428 |
+
*/
|
429 |
+
protected function _getUrlTtls() {
|
430 |
+
$str = array();
|
431 |
+
$configTtls = Mage::helper( 'turpentine/data' )->cleanExplode( PHP_EOL,
|
432 |
+
Mage::getStoreConfig( 'turpentine_vcl/ttls/url_ttls' ) );
|
433 |
+
$ttls = array();
|
434 |
+
foreach( $configTtls as $line ) {
|
435 |
+
$ttls[] = explode( ',', trim( $line ) );
|
436 |
+
}
|
437 |
+
foreach( $ttls as $ttl ) {
|
438 |
+
$str[] = sprintf( 'if (bereq.url ~ "%s%s") { set beresp.ttl = %ds; }',
|
439 |
+
$this->getBaseUrlPathRegex(), $ttl[0], $ttl[1] );
|
440 |
+
}
|
441 |
+
$str = implode( ' else ', $str );
|
442 |
+
if( $str ) {
|
443 |
+
$str .= sprintf( ' else { set beresp.ttl = %ds; }',
|
444 |
+
$this->_getDefaultTtl() );
|
445 |
+
} else {
|
446 |
+
$str = sprintf( 'set beresp.ttl = %ds;', $this->_getDefaultTtl() );
|
447 |
+
}
|
448 |
+
return $str;
|
449 |
+
}
|
450 |
+
|
451 |
+
/**
|
452 |
+
* Get the Enable Caching value
|
453 |
+
*
|
454 |
+
* @return string
|
455 |
+
*/
|
456 |
+
protected function _getEnableCaching() {
|
457 |
+
return Mage::helper( 'turpentine/varnish' )->getVarnishEnabled() ?
|
458 |
+
'true' : 'false';
|
459 |
+
}
|
460 |
+
|
461 |
+
/**
|
462 |
+
* Get the list of allowed debug IPs
|
463 |
+
*
|
464 |
+
* @return array
|
465 |
+
*/
|
466 |
+
protected function _getDebugIps() {
|
467 |
+
return Mage::helper( 'turpentine/data' )->cleanExplode( ',',
|
468 |
+
Mage::getStoreConfig( 'dev/restrict/allow_ips' ) );
|
469 |
+
}
|
470 |
+
|
471 |
+
/**
|
472 |
+
* Get the list of crawler IPs
|
473 |
+
*
|
474 |
+
* @return array
|
475 |
+
*/
|
476 |
+
protected function _getCrawlerIps() {
|
477 |
+
return Mage::helper( 'turpentine/data' )->cleanExplode( ',',
|
478 |
+
Mage::getStoreConfig( 'turpentine_vcl/backend/crawlers' ) );
|
479 |
+
}
|
480 |
+
|
481 |
+
/**
|
482 |
+
* Get the regex formatted list of crawler user agents
|
483 |
+
*
|
484 |
+
* @return string
|
485 |
+
*/
|
486 |
+
protected function _getCrawlerUserAgents() {
|
487 |
+
return implode( '|', Mage::helper( 'turpentine/data' )
|
488 |
+
->cleanExplode( ',',
|
489 |
+
Mage::getStoreConfig(
|
490 |
+
'turpentine_vcl/backend/crawler_user_agents' ) ) );
|
491 |
+
}
|
492 |
+
|
493 |
+
/**
|
494 |
+
* Get the time to increase a cached objects TTL on cache hit (in seconds).
|
495 |
+
*
|
496 |
+
* This should be set very low since it gets added to every hit.
|
497 |
+
*
|
498 |
+
* @return string
|
499 |
+
*/
|
500 |
+
protected function _getLruFactor() {
|
501 |
+
return Mage::getStoreConfig( 'turpentine_vcl/ttls/lru_factor' );
|
502 |
+
}
|
503 |
+
|
504 |
+
/**
|
505 |
+
* Get the advanced session validation restrictions
|
506 |
+
*
|
507 |
+
* Note that if User-Agent Normalization is on then the normalized user-agent
|
508 |
+
* is used for user-agent validation instead of the full user-agent
|
509 |
+
*
|
510 |
+
* @return string
|
511 |
+
*/
|
512 |
+
protected function _getAdvancedSessionValidationTargets() {
|
513 |
+
$validation = array();
|
514 |
+
if( Mage::getStoreConfig( 'web/session/use_remote_addr' ) ) {
|
515 |
+
$validation[] = 'client.ip';
|
516 |
+
}
|
517 |
+
if( Mage::getStoreConfig( 'web/session/use_http_via' ) ) {
|
518 |
+
$validation[] = 'req.http.Via';
|
519 |
+
}
|
520 |
+
if( Mage::getStoreConfig( 'web/session/use_http_x_forwarded_for' ) ) {
|
521 |
+
$validation[] = 'req.http.X-Forwarded-For';
|
522 |
+
}
|
523 |
+
if( Mage::getStoreConfig(
|
524 |
+
'web/session/use_http_user_agent' ) &&
|
525 |
+
!Mage::getStoreConfig(
|
526 |
+
'turpentine_vcl/normalization/user_agent' ) ) {
|
527 |
+
$validation[] = 'req.http.User-Agent';
|
528 |
+
}
|
529 |
+
return $validation;
|
530 |
+
}
|
531 |
+
|
532 |
+
/**
|
533 |
+
* Remove empty and commented out lines from the generated VCL
|
534 |
+
*
|
535 |
+
* @param string $dirtyVcl generated vcl
|
536 |
+
* @return string
|
537 |
+
*/
|
538 |
+
protected function _cleanVcl( $dirtyVcl ) {
|
539 |
+
return implode( PHP_EOL,
|
540 |
+
array_filter(
|
541 |
+
Mage::helper( 'turpentine/data' )
|
542 |
+
->cleanExplode( PHP_EOL, $dirtyVcl ),
|
543 |
+
array( $this, '_cleanVclHelper' )
|
544 |
+
)
|
545 |
+
);
|
546 |
+
}
|
547 |
+
|
548 |
+
/**
|
549 |
+
* Helper to filter out blank/commented lines for VCL cleaning
|
550 |
+
*
|
551 |
+
* @param string $line
|
552 |
+
* @return bool
|
553 |
+
*/
|
554 |
+
protected function _cleanVclHelper( $line ) {
|
555 |
+
return $line &&
|
556 |
+
( ( substr( $line, 0, 1 ) != '#' &&
|
557 |
+
substr( $line, 0, 2 ) != '//' ) ||
|
558 |
+
substr( $line, 0, 8 ) == '#include' );
|
559 |
+
}
|
560 |
+
|
561 |
+
/**
|
562 |
+
* Format a VCL backend declaration
|
563 |
+
*
|
564 |
+
* @param string $name name of the backend
|
565 |
+
* @param string $host backend host
|
566 |
+
* @param string $port backend port
|
567 |
+
* @param array $options options
|
568 |
+
* @return string
|
569 |
+
*/
|
570 |
+
protected function _vcl_backend( $name, $host, $port, $options=array() ) {
|
571 |
+
$tpl = <<<EOS
|
572 |
+
backend {{name}} {
|
573 |
+
.host = "{{host}}";
|
574 |
+
.port = "{{port}}";
|
575 |
+
|
576 |
+
EOS;
|
577 |
+
$vars = array(
|
578 |
+
'host' => $host,
|
579 |
+
'port' => $port,
|
580 |
+
'name' => $name,
|
581 |
+
);
|
582 |
+
$str = $this->_formatTemplate( $tpl, $vars );
|
583 |
+
foreach( $options as $key => $value ) {
|
584 |
+
$str .= sprintf( ' .%s = %s;', $key, $value ) . PHP_EOL;
|
585 |
+
}
|
586 |
+
$str .= '}' . PHP_EOL;
|
587 |
+
return $str;
|
588 |
+
}
|
589 |
+
|
590 |
+
/**
|
591 |
+
* Format a VCL ACL declaration
|
592 |
+
*
|
593 |
+
* @param string $name ACL name
|
594 |
+
* @param array $hosts list of hosts to add to the ACL
|
595 |
+
* @return string
|
596 |
+
*/
|
597 |
+
protected function _vcl_acl( $name, array $hosts ) {
|
598 |
+
$tpl = <<<EOS
|
599 |
+
acl {{name}} {
|
600 |
+
{{hosts}}
|
601 |
+
}
|
602 |
+
EOS;
|
603 |
+
$fmtHost = create_function( '$h', 'return sprintf(\'"%s";\',$h);' );
|
604 |
+
$vars = array(
|
605 |
+
'name' => $name,
|
606 |
+
'hosts' => implode( "\n ", array_map( $fmtHost, $hosts ) ),
|
607 |
+
);
|
608 |
+
return $this->_formatTemplate( $tpl, $vars );
|
609 |
+
}
|
610 |
+
|
611 |
+
/**
|
612 |
+
* Get the User-Agent normalization sub routine
|
613 |
+
*
|
614 |
+
* @return string
|
615 |
+
*/
|
616 |
+
protected function _vcl_sub_normalize_user_agent() {
|
617 |
+
/**
|
618 |
+
* Mobile regex from
|
619 |
+
* @link http://magebase.com/magento-tutorials/magento-design-exceptions-explained/
|
620 |
+
*/
|
621 |
+
$tpl = <<<EOS
|
622 |
+
if (req.http.User-Agent ~ "iP(?:hone|ad|od)|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera (?:Mini|Mobi)") {
|
623 |
+
set req.http.X-Normalized-User-Agent = "mobile";
|
624 |
+
} else if (req.http.User-Agent ~ "MSIE") {
|
625 |
+
set req.http.X-Normalized-User-Agent = "msie";
|
626 |
+
} else if (req.http.User-Agent ~ "Firefox") {
|
627 |
+
set req.http.X-Normalized-User-Agent = "firefox";
|
628 |
+
} else if (req.http.User-Agent ~ "Chrome") {
|
629 |
+
set req.http.X-Normalized-User-Agent = "chrome";
|
630 |
+
} else if (req.http.User-Agent ~ "Safari") {
|
631 |
+
set req.http.X-Normalized-User-Agent = "safari";
|
632 |
+
} else if (req.http.User-Agent ~ "Opera") {
|
633 |
+
set req.http.X-Normalized-User-Agent = "opera";
|
634 |
+
} else {
|
635 |
+
set req.http.X-Normalized-User-Agent = "other";
|
636 |
+
}
|
637 |
+
|
638 |
+
EOS;
|
639 |
+
return $tpl;
|
640 |
+
}
|
641 |
+
|
642 |
+
/**
|
643 |
+
* Get the Accept-Encoding normalization sub routine
|
644 |
+
*
|
645 |
+
* @return string
|
646 |
+
*/
|
647 |
+
protected function _vcl_sub_normalize_encoding() {
|
648 |
+
$tpl = <<<EOS
|
649 |
+
if (req.http.Accept-Encoding) {
|
650 |
+
if (req.http.Accept-Encoding ~ "gzip") {
|
651 |
+
set req.http.Accept-Encoding = "gzip";
|
652 |
+
} else if (req.http.Accept-Encoding ~ "deflate") {
|
653 |
+
set req.http.Accept-Encoding = "deflate";
|
654 |
+
} else {
|
655 |
+
# unknown algorithm
|
656 |
+
unset req.http.Accept-Encoding;
|
657 |
+
}
|
658 |
+
}
|
659 |
+
|
660 |
+
EOS;
|
661 |
+
return $tpl;
|
662 |
+
}
|
663 |
+
|
664 |
+
/**
|
665 |
+
* Get the Host normalization sub routine
|
666 |
+
*
|
667 |
+
* @return string
|
668 |
+
*/
|
669 |
+
protected function _vcl_sub_normalize_host() {
|
670 |
+
$tpl = <<<EOS
|
671 |
+
set req.http.Host = "{{normalize_host_target}}";
|
672 |
+
|
673 |
+
EOS;
|
674 |
+
return $this->_formatTemplate( $tpl, array(
|
675 |
+
'normalize_host_target' => $this->_getNormalizeHostTarget() ) );
|
676 |
+
}
|
677 |
+
|
678 |
+
/**
|
679 |
+
* Get the hostname for cookie normalization
|
680 |
+
*
|
681 |
+
* @return string
|
682 |
+
*/
|
683 |
+
protected function _getNormalizeCookieTarget() {
|
684 |
+
return trim( Mage::getStoreConfig(
|
685 |
+
'turpentine_vcl/normalization/cookie_target' ) );
|
686 |
+
}
|
687 |
+
|
688 |
+
/**
|
689 |
+
* Get the regex for cookie normalization
|
690 |
+
*
|
691 |
+
* @return string
|
692 |
+
*/
|
693 |
+
protected function _getNormalizeCookieRegex() {
|
694 |
+
return trim( Mage::getStoreConfig(
|
695 |
+
'turpentine_vcl/normalization/cookie_regex' ) );
|
696 |
+
}
|
697 |
+
|
698 |
+
/**
|
699 |
+
* Build the list of template variables to apply to the VCL template
|
700 |
+
*
|
701 |
+
* @return array
|
702 |
+
*/
|
703 |
+
protected function _getTemplateVars() {
|
704 |
+
$vars = array(
|
705 |
+
'default_backend' => $this->_getDefaultBackend(),
|
706 |
+
'admin_backend' => $this->_getAdminBackend(),
|
707 |
+
'admin_frontname' => $this->_getAdminFrontname(),
|
708 |
+
'normalize_host_target' => $this->_getNormalizeHostTarget(),
|
709 |
+
'url_base_regex' => $this->getBaseUrlPathRegex(),
|
710 |
+
'allowed_hosts_regex' => $this->getAllowedHostsRegex(),
|
711 |
+
'url_excludes' => $this->_getUrlExcludes(),
|
712 |
+
'get_param_excludes' => $this->_getGetParamExcludes(),
|
713 |
+
'get_param_ignored' => $this->_getIgnoreGetParameters(),
|
714 |
+
'default_ttl' => $this->_getDefaultTtl(),
|
715 |
+
'enable_get_excludes' => ($this->_getGetParamExcludes() ? 'true' : 'false'),
|
716 |
+
'enable_get_ignored' => ($this->_getIgnoreGetParameters()) ? 'true' : 'false',
|
717 |
+
'debug_headers' => $this->_getEnableDebugHeaders(),
|
718 |
+
'grace_period' => $this->_getGracePeriod(),
|
719 |
+
'force_cache_static' => $this->_getForceCacheStatic(),
|
720 |
+
'generate_session_expires' => $this->_getGenerateSessionExpires(),
|
721 |
+
'generate_session' => $this->_getGenerateSession(),
|
722 |
+
'generate_session_start' => $this->_getGenerateSessionStart(),
|
723 |
+
'generate_session_end' => $this->_getGenerateSessionEnd(),
|
724 |
+
'static_extensions' => $this->_getStaticExtensions(),
|
725 |
+
'static_ttl' => $this->_getStaticTtl(),
|
726 |
+
'url_ttls' => $this->_getUrlTtls(),
|
727 |
+
'enable_caching' => $this->_getEnableCaching(),
|
728 |
+
'crawler_acl' => $this->_vcl_acl( 'crawler_acl',
|
729 |
+
$this->_getCrawlerIps() ),
|
730 |
+
'esi_cache_type_param' =>
|
731 |
+
Mage::helper( 'turpentine/esi' )->getEsiCacheTypeParam(),
|
732 |
+
'esi_method_param' =>
|
733 |
+
Mage::helper( 'turpentine/esi' )->getEsiMethodParam(),
|
734 |
+
'esi_ttl_param' => Mage::helper( 'turpentine/esi' )->getEsiTtlParam(),
|
735 |
+
'secret_handshake' => Mage::helper( 'turpentine/varnish' )
|
736 |
+
->getSecretHandshake(),
|
737 |
+
'crawler_user_agent_regex' => $this->_getCrawlerUserAgents(),
|
738 |
+
// 'lru_factor' => $this->_getLruFactor(),
|
739 |
+
'debug_acl' => $this->_vcl_acl( 'debug_acl',
|
740 |
+
$this->_getDebugIps() ),
|
741 |
+
'custom_c_code' => file_get_contents(
|
742 |
+
$this->_getVclTemplateFilename( self::VCL_CUSTOM_C_CODE_FILE ) ),
|
743 |
+
'esi_private_ttl' => Mage::helper( 'turpentine/esi' )
|
744 |
+
->getDefaultEsiTtl(),
|
745 |
+
);
|
746 |
+
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/encoding' ) ) {
|
747 |
+
$vars['normalize_encoding'] = $this->_vcl_sub_normalize_encoding();
|
748 |
+
}
|
749 |
+
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/user_agent' ) ) {
|
750 |
+
$vars['normalize_user_agent'] = $this->_vcl_sub_normalize_user_agent();
|
751 |
+
}
|
752 |
+
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/host' ) ) {
|
753 |
+
$vars['normalize_host'] = $this->_vcl_sub_normalize_host();
|
754 |
+
}
|
755 |
+
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_regex' ) ) {
|
756 |
+
$vars['normalize_cookie_regex'] = $this->_getNormalizeCookieRegex();
|
757 |
+
}
|
758 |
+
if( Mage::getStoreConfig( 'turpentine_vcl/normalization/cookie_target' ) ) {
|
759 |
+
$vars['normalize_cookie_target'] = $this->_getNormalizeCookieTarget();
|
760 |
+
}
|
761 |
+
|
762 |
+
$customIncludeFile = $this->_getCustomIncludeFilename();
|
763 |
+
if( is_readable( $customIncludeFile ) ) {
|
764 |
+
$vars['custom_vcl_include'] = file_get_contents( $customIncludeFile );
|
765 |
+
}
|
766 |
+
|
767 |
+
return $vars;
|
768 |
+
}
|
769 |
+
}
|
app/code/community/Nexcessnet/Turpentine/controllers/Adminhtml/CacheController.php
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* User: damian.pastorini@usestrategery.com
|
4 |
+
* Date: 08/01/14
|
5 |
+
*/
|
6 |
+
|
7 |
+
require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS.'CacheController.php';
|
8 |
+
|
9 |
+
class Nexcessnet_Turpentine_Adminhtml_CacheController extends Mage_Adminhtml_CacheController
|
10 |
+
{
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Mass action for cache enabeling
|
14 |
+
*/
|
15 |
+
public function massEnableAction()
|
16 |
+
{
|
17 |
+
$types = $this->getRequest()->getParam('types');
|
18 |
+
$allTypes = Mage::app()->useCache();
|
19 |
+
|
20 |
+
$updatedTypes = 0;
|
21 |
+
foreach ($types as $code) {
|
22 |
+
if (empty($allTypes[$code])) {
|
23 |
+
$allTypes[$code] = 1;
|
24 |
+
$updatedTypes++;
|
25 |
+
}
|
26 |
+
}
|
27 |
+
if ($updatedTypes > 0) {
|
28 |
+
// disable FPC when Varnish cache is enabled:
|
29 |
+
if($allTypes['turpentine_pages']==1 || $allTypes['turpentine_esi_blocks']==1)
|
30 |
+
{
|
31 |
+
$allTypes['full_page'] = 0;
|
32 |
+
Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Full page cache has been disabled since Varnish cache is enabled."));
|
33 |
+
} else if ($allTypes['full_page']==1) {
|
34 |
+
Mage::getSingleton('core/session')->addSuccess(Mage::helper('adminhtml')->__("Turpentine cache has been disabled since Full Page cache is enabled."));
|
35 |
+
}
|
36 |
+
// disable FPC when Varnish cache is enabled.
|
37 |
+
Mage::app()->saveUseCache($allTypes);
|
38 |
+
$this->_getSession()->addSuccess(Mage::helper('adminhtml')->__("%s cache type(s) enabled.", $updatedTypes));
|
39 |
+
}
|
40 |
+
$this->_redirect('*/*');
|
41 |
+
}
|
42 |
+
|
43 |
+
}
|
app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php
CHANGED
@@ -66,7 +66,7 @@ class Nexcessnet_Turpentine_EsiController extends Mage_Core_Controller_Front_Act
|
|
66 |
$esiDataHmac = $req->getParam( $esiHelper->getEsiHmacParam() );
|
67 |
$esiDataParamValue = $req->getParam( $esiHelper->getEsiDataParam() );
|
68 |
if( $esiDataHmac !== ( $hmac = $dataHelper->getHmac( $esiDataParamValue ) ) ) {
|
69 |
-
$debugHelper->logWarn( 'ESI data HMAC mismatch, expected (%s) but
|
70 |
$hmac, $esiDataHmac );
|
71 |
$resp->setHttpResponseCode( 500 );
|
72 |
$resp->setBody( 'ESI data is not valid' );
|
66 |
$esiDataHmac = $req->getParam( $esiHelper->getEsiHmacParam() );
|
67 |
$esiDataParamValue = $req->getParam( $esiHelper->getEsiDataParam() );
|
68 |
if( $esiDataHmac !== ( $hmac = $dataHelper->getHmac( $esiDataParamValue ) ) ) {
|
69 |
+
$debugHelper->logWarn( 'ESI data HMAC mismatch, expected (%s) but received (%s)',
|
70 |
$hmac, $esiDataHmac );
|
71 |
$resp->setHttpResponseCode( 500 );
|
72 |
$resp->setBody( 'ESI data is not valid' );
|
app/code/community/Nexcessnet/Turpentine/etc/config.xml
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
<config>
|
21 |
<modules>
|
22 |
<Nexcessnet_Turpentine>
|
23 |
-
<version>0.6.
|
24 |
</Nexcessnet_Turpentine>
|
25 |
</modules>
|
26 |
<default>
|
@@ -29,12 +29,17 @@
|
|
29 |
<auto_apply_on_save>1</auto_apply_on_save>
|
30 |
<strip_vcl_whitespace>always</strip_vcl_whitespace>
|
31 |
<varnish_debug>0</varnish_debug>
|
|
|
32 |
<block_debug>0</block_debug>
|
33 |
<ajax_messages>1</ajax_messages>
|
34 |
<fix_product_toolbar>0</fix_product_toolbar>
|
35 |
<crawler_enable>0</crawler_enable>
|
36 |
<crawler_debug>0</crawler_debug>
|
37 |
</general>
|
|
|
|
|
|
|
|
|
38 |
<servers>
|
39 |
<version>auto</version>
|
40 |
<server_list>127.0.0.1:6082</server_list>
|
@@ -69,6 +74,7 @@
|
|
69 |
</urls>
|
70 |
<params>
|
71 |
<get_params>__SID,XDEBUG_PROFILE</get_params>
|
|
|
72 |
</params>
|
73 |
<static>
|
74 |
<force_static>1</force_static>
|
@@ -116,6 +122,20 @@
|
|
116 |
</rewrite>
|
117 |
</core>
|
118 |
-->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
</blocks>
|
120 |
<helpers>
|
121 |
<turpentine>
|
@@ -126,6 +146,11 @@
|
|
126 |
<turpentine>
|
127 |
<class>Nexcessnet_Turpentine_Model</class>
|
128 |
</turpentine>
|
|
|
|
|
|
|
|
|
|
|
129 |
</models>
|
130 |
<cache>
|
131 |
<types>
|
@@ -210,6 +235,22 @@
|
|
210 |
</turpentine_esi_controller_action_layout_generate_blocks_after>
|
211 |
</observers>
|
212 |
</controller_action_layout_generate_blocks_after>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
<!--
|
214 |
Magento sometimes sees the last URL as being the
|
215 |
turpentine/esi/getBlock url, and then redirects to it which is not
|
@@ -311,6 +352,15 @@
|
|
311 |
</turpentine_varnish_cms_page_save_commit_after>
|
312 |
</observers>
|
313 |
</cms_page_save_commit_after>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
<adminhtml_cache_flush_system>
|
315 |
<observers>
|
316 |
<turpentine_varnish_adminhtml_cache_flush_system>
|
@@ -367,6 +417,40 @@
|
|
367 |
</turpentine_esi>
|
368 |
</updates>
|
369 |
</layout>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
</frontend>
|
371 |
<admin>
|
372 |
<routers>
|
20 |
<config>
|
21 |
<modules>
|
22 |
<Nexcessnet_Turpentine>
|
23 |
+
<version>0.6.3</version>
|
24 |
</Nexcessnet_Turpentine>
|
25 |
</modules>
|
26 |
<default>
|
29 |
<auto_apply_on_save>1</auto_apply_on_save>
|
30 |
<strip_vcl_whitespace>always</strip_vcl_whitespace>
|
31 |
<varnish_debug>0</varnish_debug>
|
32 |
+
<vcl_fix>1</vcl_fix>
|
33 |
<block_debug>0</block_debug>
|
34 |
<ajax_messages>1</ajax_messages>
|
35 |
<fix_product_toolbar>0</fix_product_toolbar>
|
36 |
<crawler_enable>0</crawler_enable>
|
37 |
<crawler_debug>0</crawler_debug>
|
38 |
</general>
|
39 |
+
<logging>
|
40 |
+
<use_custom_log_file>0</use_custom_log_file>
|
41 |
+
<custom_log_file_name>turpentine.log</custom_log_file_name>
|
42 |
+
</logging>
|
43 |
<servers>
|
44 |
<version>auto</version>
|
45 |
<server_list>127.0.0.1:6082</server_list>
|
74 |
</urls>
|
75 |
<params>
|
76 |
<get_params>__SID,XDEBUG_PROFILE</get_params>
|
77 |
+
<ignore_get_params>utm_source,utm_medium,utm_campaign,utm_content,utm_term,gclid,cx,ie,cof,siteurl</ignore_get_params>
|
78 |
</params>
|
79 |
<static>
|
80 |
<force_static>1</force_static>
|
122 |
</rewrite>
|
123 |
</core>
|
124 |
-->
|
125 |
+
<!--
|
126 |
+
Rewrite the poll ActivePoll block, as it uses its own custom
|
127 |
+
template setting methods.
|
128 |
+
-->
|
129 |
+
<poll>
|
130 |
+
<rewrite>
|
131 |
+
<activePoll>Nexcessnet_Turpentine_Block_Poll_ActivePoll</activePoll>
|
132 |
+
</rewrite>
|
133 |
+
</poll>
|
134 |
+
<adminhtml>
|
135 |
+
<rewrite>
|
136 |
+
<cache_grid>Nexcessnet_Turpentine_Block_Adminhtml_Cache_Grid</cache_grid>
|
137 |
+
</rewrite>
|
138 |
+
</adminhtml>
|
139 |
</blocks>
|
140 |
<helpers>
|
141 |
<turpentine>
|
146 |
<turpentine>
|
147 |
<class>Nexcessnet_Turpentine_Model</class>
|
148 |
</turpentine>
|
149 |
+
<core>
|
150 |
+
<rewrite>
|
151 |
+
<session>Nexcessnet_Turpentine_Model_Core_Session</session>
|
152 |
+
</rewrite>
|
153 |
+
</core>
|
154 |
</models>
|
155 |
<cache>
|
156 |
<types>
|
235 |
</turpentine_esi_controller_action_layout_generate_blocks_after>
|
236 |
</observers>
|
237 |
</controller_action_layout_generate_blocks_after>
|
238 |
+
<customer_login>
|
239 |
+
<observers>
|
240 |
+
<turpentine_customer_login_cookie>
|
241 |
+
<class>turpentine/observer_esi</class>
|
242 |
+
<method>setCustomerGroupCookie</method>
|
243 |
+
</turpentine_customer_login_cookie>
|
244 |
+
</observers>
|
245 |
+
</customer_login>
|
246 |
+
<customer_logout>
|
247 |
+
<observers>
|
248 |
+
<turpentine_customer_logout_remove_cookie>
|
249 |
+
<class>turpentine/observer_esi</class>
|
250 |
+
<method>removeCustomerGroupCookie</method>
|
251 |
+
</turpentine_customer_logout_remove_cookie>
|
252 |
+
</observers>
|
253 |
+
</customer_logout>
|
254 |
<!--
|
255 |
Magento sometimes sees the last URL as being the
|
256 |
turpentine/esi/getBlock url, and then redirects to it which is not
|
352 |
</turpentine_varnish_cms_page_save_commit_after>
|
353 |
</observers>
|
354 |
</cms_page_save_commit_after>
|
355 |
+
<enterprise_cms_revision_save_commit_after>
|
356 |
+
<observers>
|
357 |
+
<turpentine_varnish_enterprise_cms_revision_save_commit_after>
|
358 |
+
<class>turpentine/observer_ban</class>
|
359 |
+
<method>banCmsPageRevisionCache</method>
|
360 |
+
<type>singleton</type>
|
361 |
+
</turpentine_varnish_enterprise_cms_revision_save_commit_after>
|
362 |
+
</observers>
|
363 |
+
</enterprise_cms_revision_save_commit_after>
|
364 |
<adminhtml_cache_flush_system>
|
365 |
<observers>
|
366 |
<turpentine_varnish_adminhtml_cache_flush_system>
|
417 |
</turpentine_esi>
|
418 |
</updates>
|
419 |
</layout>
|
420 |
+
<events>
|
421 |
+
<controller_action_predispatch>
|
422 |
+
<observers>
|
423 |
+
<controller_action_before>
|
424 |
+
<class>turpentine/observer_esi</class>
|
425 |
+
<method>hookToControllerActionPreDispatch</method>
|
426 |
+
</controller_action_before>
|
427 |
+
</observers>
|
428 |
+
</controller_action_predispatch>
|
429 |
+
<!--controller_action_postdispatch>
|
430 |
+
<observers>
|
431 |
+
<controller_action_after>
|
432 |
+
<class>turpentine/observer_esi</class>
|
433 |
+
<method>hookToControllerActionPostDispatch</method>
|
434 |
+
</controller_action_after>
|
435 |
+
</observers>
|
436 |
+
</controller_action_postdispatch-->
|
437 |
+
<add_to_cart_before>
|
438 |
+
<observers>
|
439 |
+
<add_to_cart_before>
|
440 |
+
<class>turpentine/observer_esi</class>
|
441 |
+
<method>hookToAddToCartBefore</method>
|
442 |
+
</add_to_cart_before>
|
443 |
+
</observers>
|
444 |
+
</add_to_cart_before>
|
445 |
+
<!--add_to_cart_after>
|
446 |
+
<observers>
|
447 |
+
<add_to_cart_after>
|
448 |
+
<class>turpentine/observer_esi</class>
|
449 |
+
<method>hookToAddToCartAfter</method>
|
450 |
+
</add_to_cart_after>
|
451 |
+
</observers>
|
452 |
+
</add_to_cart_after-->
|
453 |
+
</events>
|
454 |
</frontend>
|
455 |
<admin>
|
456 |
<routers>
|
app/code/community/Nexcessnet/Turpentine/etc/system.xml
CHANGED
@@ -62,6 +62,16 @@
|
|
62 |
<show_in_website>0</show_in_website>
|
63 |
<show_in_store>0</show_in_store>
|
64 |
</strip_vcl_whitespace>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
<varnish_debug translate="label" module="turpentine">
|
66 |
<label>Enable Debug Info</label>
|
67 |
<comment>It is a major security vulnerability, to leave this enabled on production sites</comment>
|
@@ -124,6 +134,37 @@
|
|
124 |
</crawler_debug>
|
125 |
</fields>
|
126 |
</general>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
<servers translate="label" module="turpentine">
|
128 |
<label>Servers</label>
|
129 |
<frontend_type>text</frontend_type>
|
@@ -305,6 +346,24 @@
|
|
305 |
<show_in_website>0</show_in_website>
|
306 |
<show_in_store>0</show_in_store>
|
307 |
</host_target>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
</fields>
|
309 |
</normalization>
|
310 |
<ttls translate="label" module="turpentine">
|
@@ -400,8 +459,17 @@
|
|
400 |
<sort_order>10</sort_order>
|
401 |
<show_in_default>1</show_in_default>
|
402 |
<show_in_website>0</show_in_website>
|
403 |
-
<show_in_store>0</show_in_store>
|
404 |
</get_params>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
</fields>
|
406 |
</params>
|
407 |
<static translate="label" module="turpentine">
|
62 |
<show_in_website>0</show_in_website>
|
63 |
<show_in_store>0</show_in_store>
|
64 |
</strip_vcl_whitespace>
|
65 |
+
<vcl_fix translate="label comment">
|
66 |
+
<label>Use VCL fix</label>
|
67 |
+
<comment>When Enable is selected, a VCL fix will be used to prevent formKey issues. If Disable is selected, an observer will be used.</comment>
|
68 |
+
<frontend_type>select</frontend_type>
|
69 |
+
<sort_order>28</sort_order>
|
70 |
+
<source_model>adminhtml/system_config_source_enabledisable</source_model>
|
71 |
+
<show_in_default>1</show_in_default>
|
72 |
+
<show_in_website>1</show_in_website>
|
73 |
+
<show_in_store>1</show_in_store>
|
74 |
+
</vcl_fix>
|
75 |
<varnish_debug translate="label" module="turpentine">
|
76 |
<label>Enable Debug Info</label>
|
77 |
<comment>It is a major security vulnerability, to leave this enabled on production sites</comment>
|
134 |
</crawler_debug>
|
135 |
</fields>
|
136 |
</general>
|
137 |
+
<logging translate="label" module="turpentine">
|
138 |
+
<label>Logging</label>
|
139 |
+
<sort_order>15</sort_order>
|
140 |
+
<show_in_default>1</show_in_default>
|
141 |
+
<show_in_website>0</show_in_website>
|
142 |
+
<show_in_store>0</show_in_store>
|
143 |
+
<fields>
|
144 |
+
<use_custom_log_file translate="label,comment" module="turpentine">
|
145 |
+
<label>Use custom log file</label>
|
146 |
+
<comment>Log to custom log file rather than system.log</comment>
|
147 |
+
<frontend_type>select</frontend_type>
|
148 |
+
<source_model>turpentine/config_select_toggle</source_model>
|
149 |
+
<sort_order>10</sort_order>
|
150 |
+
<show_in_default>1</show_in_default>
|
151 |
+
<show_in_website>0</show_in_website>
|
152 |
+
<show_in_store>0</show_in_store>
|
153 |
+
</use_custom_log_file>
|
154 |
+
<custom_log_file_name translate="label,comment" module="turpentine">
|
155 |
+
<label>Custom log file name</label>
|
156 |
+
<frontend_type>text</frontend_type>
|
157 |
+
<sort_order>20</sort_order>
|
158 |
+
<comment>Only enter a file name, no paths.</comment>
|
159 |
+
<show_in_default>1</show_in_default>
|
160 |
+
<show_in_website>0</show_in_website>
|
161 |
+
<show_in_store>0</show_in_store>
|
162 |
+
<depends>
|
163 |
+
<use_custom_log_file>1</use_custom_log_file>
|
164 |
+
</depends>
|
165 |
+
</custom_log_file_name>
|
166 |
+
</fields>
|
167 |
+
</logging>
|
168 |
<servers translate="label" module="turpentine">
|
169 |
<label>Servers</label>
|
170 |
<frontend_type>text</frontend_type>
|
346 |
<show_in_website>0</show_in_website>
|
347 |
<show_in_store>0</show_in_store>
|
348 |
</host_target>
|
349 |
+
<cookie_regex translate="label" module="turpentine">
|
350 |
+
<label>Normalize Cookie Regex</label>
|
351 |
+
<comment>Cookie regex to match to override initial cookie domain</comment>
|
352 |
+
<frontend_type>text</frontend_type>
|
353 |
+
<sort_order>50</sort_order>
|
354 |
+
<show_in_default>1</show_in_default>
|
355 |
+
<show_in_website>0</show_in_website>
|
356 |
+
<show_in_store>0</show_in_store>
|
357 |
+
</cookie_regex>
|
358 |
+
<cookie_target translate="label" module="turpentine">
|
359 |
+
<label>Normalized Cookie Target</label>
|
360 |
+
<comment>Domain to force cookies to which the regex matches</comment>
|
361 |
+
<frontend_type>text</frontend_type>
|
362 |
+
<sort_order>60</sort_order>
|
363 |
+
<show_in_default>1</show_in_default>
|
364 |
+
<show_in_website>0</show_in_website>
|
365 |
+
<show_in_store>0</show_in_store>
|
366 |
+
</cookie_target>
|
367 |
</fields>
|
368 |
</normalization>
|
369 |
<ttls translate="label" module="turpentine">
|
459 |
<sort_order>10</sort_order>
|
460 |
<show_in_default>1</show_in_default>
|
461 |
<show_in_website>0</show_in_website>
|
462 |
+
<show_in_store>0</show_in_store>
|
463 |
</get_params>
|
464 |
+
<ignore_get_params translate="label" module="turpentine">
|
465 |
+
<label>Ignore GET Parameters</label>
|
466 |
+
<comment>Comma-separated list of GET variables that will be ignored for caching</comment>
|
467 |
+
<frontend_type>textarea</frontend_type>
|
468 |
+
<sort_order>20</sort_order>
|
469 |
+
<show_in_default>1</show_in_default>
|
470 |
+
<show_in_website>0</show_in_website>
|
471 |
+
<show_in_store>0</show_in_store>
|
472 |
+
</ignore_get_params>
|
473 |
</fields>
|
474 |
</params>
|
475 |
<static translate="label" module="turpentine">
|
app/code/community/Nexcessnet/Turpentine/misc/version-2.vcl
CHANGED
@@ -105,11 +105,19 @@ sub vcl_recv {
|
|
105 |
set req.http.X-Opt-Force-Static-Caching = "{{force_cache_static}}";
|
106 |
set req.http.X-Opt-Enable-Get-Excludes = "{{enable_get_excludes}}";
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
# We only deal with GET and HEAD by default
|
109 |
# we test this here instead of inside the url base regex section
|
110 |
# so we can disable caching for the entire site if needed
|
111 |
if (req.http.X-Opt-Enable-Caching != "true" || req.http.Authorization ||
|
112 |
-
!(req.request ~ "^(GET|HEAD)$") ||
|
113 |
req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") {
|
114 |
return (pipe);
|
115 |
}
|
@@ -117,10 +125,6 @@ sub vcl_recv {
|
|
117 |
# remove double slashes from the URL, for higher cache hit rate
|
118 |
set req.url = regsuball(req.url, "(.*)//+(.*)", "\1/\2");
|
119 |
|
120 |
-
{{normalize_encoding}}
|
121 |
-
{{normalize_user_agent}}
|
122 |
-
{{normalize_host}}
|
123 |
-
|
124 |
# check if the request is for part of magento
|
125 |
if (req.url ~ "{{url_base_regex}}") {
|
126 |
# set this so Turpentine can see the request passed through Varnish
|
@@ -188,11 +192,12 @@ sub vcl_recv {
|
|
188 |
req.url ~ "(?:[?&](?:{{get_param_excludes}})(?=[&=]|$))") {
|
189 |
return (pass);
|
190 |
}
|
191 |
-
if (req.url ~ "[?&](
|
192 |
-
# Strip out
|
193 |
-
set req.url = regsuball(req.url, "(?:(\?)?|&)(?:
|
194 |
set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1");
|
195 |
}
|
|
|
196 |
|
197 |
return (lookup);
|
198 |
}
|
@@ -240,6 +245,12 @@ sub vcl_hash {
|
|
240 |
set req.hash += regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1");
|
241 |
{{advanced_session_validation}}
|
242 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
return (hash);
|
244 |
}
|
245 |
|
105 |
set req.http.X-Opt-Force-Static-Caching = "{{force_cache_static}}";
|
106 |
set req.http.X-Opt-Enable-Get-Excludes = "{{enable_get_excludes}}";
|
107 |
|
108 |
+
# Normalize request data before potentially sending things off to the
|
109 |
+
# backend. This ensures all request types get the same information, most
|
110 |
+
# notably POST requests getting a normalized user agent string to empower
|
111 |
+
# adaptive designs.
|
112 |
+
{{normalize_encoding}}
|
113 |
+
{{normalize_user_agent}}
|
114 |
+
{{normalize_host}}
|
115 |
+
|
116 |
# We only deal with GET and HEAD by default
|
117 |
# we test this here instead of inside the url base regex section
|
118 |
# so we can disable caching for the entire site if needed
|
119 |
if (req.http.X-Opt-Enable-Caching != "true" || req.http.Authorization ||
|
120 |
+
!(req.request ~ "^(GET|HEAD|OPTIONS)$") ||
|
121 |
req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") {
|
122 |
return (pipe);
|
123 |
}
|
125 |
# remove double slashes from the URL, for higher cache hit rate
|
126 |
set req.url = regsuball(req.url, "(.*)//+(.*)", "\1/\2");
|
127 |
|
|
|
|
|
|
|
|
|
128 |
# check if the request is for part of magento
|
129 |
if (req.url ~ "{{url_base_regex}}") {
|
130 |
# set this so Turpentine can see the request passed through Varnish
|
192 |
req.url ~ "(?:[?&](?:{{get_param_excludes}})(?=[&=]|$))") {
|
193 |
return (pass);
|
194 |
}
|
195 |
+
if ({{enable_get_ignored}} && req.url ~ "[?&]({{get_param_ignored}})=") {
|
196 |
+
# Strip out ignored GET related parameters
|
197 |
+
set req.url = regsuball(req.url, "(?:(\?)?|&)(?:{{get_param_ignored}})=[^&]+", "\1");
|
198 |
set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1");
|
199 |
}
|
200 |
+
|
201 |
|
202 |
return (lookup);
|
203 |
}
|
245 |
set req.hash += regsub(req.http.Cookie, "^.*?frontend=([^;]*);*.*$", "\1");
|
246 |
{{advanced_session_validation}}
|
247 |
}
|
248 |
+
|
249 |
+
if (req.http.X-Varnish-Esi-Access == "customer_group" &&
|
250 |
+
req.http.Cookie ~ "customer_group=") {
|
251 |
+
set req.hash += regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1");
|
252 |
+
}
|
253 |
+
|
254 |
return (hash);
|
255 |
}
|
256 |
|
app/code/community/Nexcessnet/Turpentine/misc/version-3.vcl
CHANGED
@@ -46,6 +46,7 @@ import std;
|
|
46 |
|
47 |
## Custom Subroutines
|
48 |
|
|
|
49 |
sub generate_session {
|
50 |
# generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID
|
51 |
# from SID URL param
|
@@ -72,7 +73,7 @@ sub generate_session {
|
|
72 |
} else {
|
73 |
set req.http.Cookie = req.http.X-Varnish-Faked-Session;
|
74 |
}
|
75 |
-
}
|
76 |
|
77 |
sub generate_session_expires {
|
78 |
# sets X-Varnish-Cookie-Expires to now + esi_private_ttl in format:
|
@@ -92,7 +93,7 @@ sub generate_session_expires {
|
|
92 |
);
|
93 |
}C
|
94 |
}
|
95 |
-
|
96 |
## Varnish Subroutines
|
97 |
|
98 |
sub vcl_recv {
|
@@ -106,21 +107,25 @@ sub vcl_recv {
|
|
106 |
}
|
107 |
}
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# We only deal with GET and HEAD by default
|
110 |
# we test this here instead of inside the url base regex section
|
111 |
# so we can disable caching for the entire site if needed
|
112 |
if (!{{enable_caching}} || req.http.Authorization ||
|
113 |
-
req.request !~ "^(GET|HEAD)$" ||
|
114 |
req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") {
|
115 |
return (pipe);
|
116 |
}
|
117 |
|
118 |
# remove double slashes from the URL, for higher cache hit rate
|
119 |
-
set req.url = regsuball(req.url, "(
|
120 |
-
|
121 |
-
{{normalize_encoding}}
|
122 |
-
{{normalize_user_agent}}
|
123 |
-
{{normalize_host}}
|
124 |
|
125 |
# check if the request is for part of magento
|
126 |
if (req.url ~ "{{url_base_regex}}") {
|
@@ -153,15 +158,20 @@ sub vcl_recv {
|
|
153 |
error 403 "External ESI requests are not allowed";
|
154 |
}
|
155 |
}
|
156 |
-
#
|
157 |
-
if (req.http.
|
|
|
|
|
|
|
|
|
158 |
if (client.ip ~ crawler_acl ||
|
159 |
req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") {
|
160 |
# it's a crawler, give it a fake cookie
|
161 |
set req.http.Cookie = "frontend=crawler-session";
|
162 |
} else {
|
163 |
# it's a real user, make up a new session for them
|
164 |
-
call generate_session;
|
|
|
165 |
}
|
166 |
}
|
167 |
if ({{force_cache_static}} &&
|
@@ -186,12 +196,13 @@ sub vcl_recv {
|
|
186 |
# TODO: should this be pass or pipe?
|
187 |
return (pass);
|
188 |
}
|
189 |
-
if (req.url ~ "[?&](
|
190 |
-
# Strip out
|
191 |
-
set req.url = regsuball(req.url, "(?:(\?)?|&)(?:
|
192 |
set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1");
|
193 |
}
|
194 |
|
|
|
195 |
# everything else checks out, try and pull from the cache
|
196 |
return (lookup);
|
197 |
}
|
@@ -237,6 +248,12 @@ sub vcl_hash {
|
|
237 |
{{advanced_session_validation}}
|
238 |
|
239 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
return (hash);
|
241 |
}
|
242 |
|
@@ -336,12 +353,25 @@ sub vcl_fetch {
|
|
336 |
sub vcl_deliver {
|
337 |
if (req.http.X-Varnish-Faked-Session) {
|
338 |
# need to set the set-cookie header since we just made it out of thin air
|
339 |
-
call generate_session_expires;
|
|
|
340 |
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
|
341 |
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
|
342 |
if (req.http.Host) {
|
343 |
-
|
|
|
|
|
344 |
"; domain=" + regsub(req.http.Host, ":\d+$", "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
}
|
346 |
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
|
347 |
unset resp.http.X-Varnish-Cookie-Expires;
|
46 |
|
47 |
## Custom Subroutines
|
48 |
|
49 |
+
{{generate_session_start}}
|
50 |
sub generate_session {
|
51 |
# generate a UUID and add `frontend=$UUID` to the Cookie header, or use SID
|
52 |
# from SID URL param
|
73 |
} else {
|
74 |
set req.http.Cookie = req.http.X-Varnish-Faked-Session;
|
75 |
}
|
76 |
+
}
|
77 |
|
78 |
sub generate_session_expires {
|
79 |
# sets X-Varnish-Cookie-Expires to now + esi_private_ttl in format:
|
93 |
);
|
94 |
}C
|
95 |
}
|
96 |
+
{{generate_session_end}}
|
97 |
## Varnish Subroutines
|
98 |
|
99 |
sub vcl_recv {
|
107 |
}
|
108 |
}
|
109 |
|
110 |
+
# Normalize request data before potentially sending things off to the
|
111 |
+
# backend. This ensures all request types get the same information, most
|
112 |
+
# notably POST requests getting a normalized user agent string to empower
|
113 |
+
# adaptive designs.
|
114 |
+
{{normalize_encoding}}
|
115 |
+
{{normalize_user_agent}}
|
116 |
+
{{normalize_host}}
|
117 |
+
|
118 |
# We only deal with GET and HEAD by default
|
119 |
# we test this here instead of inside the url base regex section
|
120 |
# so we can disable caching for the entire site if needed
|
121 |
if (!{{enable_caching}} || req.http.Authorization ||
|
122 |
+
req.request !~ "^(GET|HEAD|OPTIONS)$" ||
|
123 |
req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") {
|
124 |
return (pipe);
|
125 |
}
|
126 |
|
127 |
# remove double slashes from the URL, for higher cache hit rate
|
128 |
+
set req.url = regsuball(req.url, "([^:])//+", "\1/");
|
|
|
|
|
|
|
|
|
129 |
|
130 |
# check if the request is for part of magento
|
131 |
if (req.url ~ "{{url_base_regex}}") {
|
158 |
error 403 "External ESI requests are not allowed";
|
159 |
}
|
160 |
}
|
161 |
+
# if host is not allowed in magento pass to backend
|
162 |
+
if (req.http.host !~ "{{allowed_hosts_regex}}") {
|
163 |
+
return (pass);
|
164 |
+
}
|
165 |
+
# no frontend cookie was sent to us AND this is not an ESI or AJAX call
|
166 |
+
if (req.http.Cookie !~ "frontend=" && !req.http.X-Varnish-Esi-Method) {
|
167 |
if (client.ip ~ crawler_acl ||
|
168 |
req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") {
|
169 |
# it's a crawler, give it a fake cookie
|
170 |
set req.http.Cookie = "frontend=crawler-session";
|
171 |
} else {
|
172 |
# it's a real user, make up a new session for them
|
173 |
+
{{generate_session}}# call generate_session;
|
174 |
+
return (pipe);
|
175 |
}
|
176 |
}
|
177 |
if ({{force_cache_static}} &&
|
196 |
# TODO: should this be pass or pipe?
|
197 |
return (pass);
|
198 |
}
|
199 |
+
if ({{enable_get_ignored}} && req.url ~ "[?&]({{get_param_ignored}})=") {
|
200 |
+
# Strip out Ignored GET parameters
|
201 |
+
set req.url = regsuball(req.url, "(?:(\?)?|&)(?:{{get_param_ignored}})=[^&]+", "\1");
|
202 |
set req.url = regsuball(req.url, "(?:(\?)&|\?$)", "\1");
|
203 |
}
|
204 |
|
205 |
+
|
206 |
# everything else checks out, try and pull from the cache
|
207 |
return (lookup);
|
208 |
}
|
248 |
{{advanced_session_validation}}
|
249 |
|
250 |
}
|
251 |
+
|
252 |
+
if (req.http.X-Varnish-Esi-Access == "customer_group" &&
|
253 |
+
req.http.Cookie ~ "customer_group=") {
|
254 |
+
hash_data(regsub(req.http.Cookie, "^.*?customer_group=([^;]*);*.*$", "\1"));
|
255 |
+
}
|
256 |
+
|
257 |
return (hash);
|
258 |
}
|
259 |
|
353 |
sub vcl_deliver {
|
354 |
if (req.http.X-Varnish-Faked-Session) {
|
355 |
# need to set the set-cookie header since we just made it out of thin air
|
356 |
+
# call generate_session_expires;
|
357 |
+
{{generate_session_expires}}
|
358 |
set resp.http.Set-Cookie = req.http.X-Varnish-Faked-Session +
|
359 |
"; expires=" + resp.http.X-Varnish-Cookie-Expires + "; path=/";
|
360 |
if (req.http.Host) {
|
361 |
+
if (req.http.User-Agent ~ "^(?:{{crawler_user_agent_regex}})$") {
|
362 |
+
# it's a crawler, no need to share cookies
|
363 |
+
set resp.http.Set-Cookie = resp.http.Set-Cookie +
|
364 |
"; domain=" + regsub(req.http.Host, ":\d+$", "");
|
365 |
+
} else {
|
366 |
+
# it's a real user, allow sharing of cookies between stores
|
367 |
+
if(req.http.Host ~ "{{normalize_cookie_regex}}") {
|
368 |
+
set resp.http.Set-Cookie = resp.http.Set-Cookie +
|
369 |
+
"; domain={{normalize_cookie_target}}";
|
370 |
+
} else {
|
371 |
+
set resp.http.Set-Cookie = resp.http.Set-Cookie +
|
372 |
+
"; domain=" + regsub(req.http.Host, ":\d+$", "");
|
373 |
+
}
|
374 |
+
}
|
375 |
}
|
376 |
set resp.http.Set-Cookie = resp.http.Set-Cookie + "; httponly";
|
377 |
unset resp.http.X-Varnish-Cookie-Expires;
|
app/code/local/Mage/Core/Model/Session.php
DELETED
@@ -1,69 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Magento
|
4 |
-
*
|
5 |
-
* NOTICE OF LICENSE
|
6 |
-
*
|
7 |
-
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
-
* that is bundled with this package in the file LICENSE.txt.
|
9 |
-
* It is also available through the world-wide-web at this URL:
|
10 |
-
* http://opensource.org/licenses/osl-3.0.php
|
11 |
-
* If you did not receive a copy of the license and are unable to
|
12 |
-
* obtain it through the world-wide-web, please send an email
|
13 |
-
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
-
*
|
15 |
-
* DISCLAIMER
|
16 |
-
*
|
17 |
-
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
-
* versions in the future. If you wish to customize Magento for your
|
19 |
-
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
-
*
|
21 |
-
* @category Mage
|
22 |
-
* @package Mage_Core
|
23 |
-
* @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
|
24 |
-
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
-
*/
|
26 |
-
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Core session model
|
30 |
-
*
|
31 |
-
* @todo extend from Mage_Core_Model_Session_Abstract
|
32 |
-
*
|
33 |
-
* @method null|bool getCookieShouldBeReceived()
|
34 |
-
* @method Mage_Core_Model_Session setCookieShouldBeReceived(bool $flag)
|
35 |
-
* @method Mage_Core_Model_Session unsCookieShouldBeReceived()
|
36 |
-
*/
|
37 |
-
class Mage_Core_Model_Session extends Mage_Core_Model_Session_Abstract
|
38 |
-
{
|
39 |
-
public function __construct($data=array())
|
40 |
-
{
|
41 |
-
$name = isset($data['name']) ? $data['name'] : null;
|
42 |
-
$this->init('core', $name);
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Retrieve Session Form Key
|
47 |
-
*
|
48 |
-
* @return string A 16 bit unique key for forms
|
49 |
-
*/
|
50 |
-
public function getFormKey()
|
51 |
-
{
|
52 |
-
if (Mage::registry('replace_form_key') &&
|
53 |
-
!Mage::app()->getRequest()->getParam('form_key', false)) {
|
54 |
-
// flag request for ESI processing
|
55 |
-
Mage::register('turpentine_esi_flag', true, true);
|
56 |
-
return '{{form_key_esi_placeholder}}';
|
57 |
-
} else {
|
58 |
-
return $this->real_getFormKey();
|
59 |
-
}
|
60 |
-
}
|
61 |
-
|
62 |
-
public function real_getFormKey()
|
63 |
-
{
|
64 |
-
if (!$this->getData('_form_key')) {
|
65 |
-
$this->setData('_form_key', Mage::helper('core')->getRandomString(16));
|
66 |
-
}
|
67 |
-
return $this->getData('_form_key');
|
68 |
-
}
|
69 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/design/adminhtml/default/default/template/turpentine/varnish_management.phtml
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Nexcess.net Turpentine Extension for Magento
|
5 |
-
* Copyright (C) 2012 Nexcess.net L.L.C.
|
6 |
-
*
|
7 |
-
* This program is free software; you can redistribute it and/or modify
|
8 |
-
* it under the terms of the GNU General Public License as published by
|
9 |
-
* the Free Software Foundation; either version 2 of the License, or
|
10 |
-
* (at your option) any later version.
|
11 |
-
*
|
12 |
-
* This program is distributed in the hope that it will be useful,
|
13 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
-
* GNU General Public License for more details.
|
16 |
-
*
|
17 |
-
* You should have received a copy of the GNU General Public License along
|
18 |
-
* with this program; if not, write to the Free Software Foundation, Inc.,
|
19 |
-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
-
*/
|
21 |
-
|
22 |
-
?>
|
23 |
-
<br />
|
24 |
-
<div class="content-header">
|
25 |
-
<table cellspacing="0">
|
26 |
-
<tr>
|
27 |
-
<td>
|
28 |
-
<h3><?php echo Mage::helper( 'turpentine/data' )
|
29 |
-
->__('Varnish Management') ?></h3>
|
30 |
-
</td>
|
31 |
-
<td class="form-buttons"></td>
|
32 |
-
</tr>
|
33 |
-
</table>
|
34 |
-
</div>
|
35 |
-
<table class="form-list varnish-management">
|
36 |
-
<tr>
|
37 |
-
<td class="scope-label">
|
38 |
-
<button
|
39 |
-
onclick="setLocation('<?php echo $this->getApplyConfigUrl()?>')"
|
40 |
-
type="button"
|
41 |
-
class="scalable save">
|
42 |
-
<span><?php echo Mage::helper( 'turpentine/data' )
|
43 |
-
->__('Apply Varnish Config') ?></span>
|
44 |
-
</button>
|
45 |
-
</td>
|
46 |
-
<td class="scope-label">
|
47 |
-
<?php echo Mage::helper( 'turpentine/data' )
|
48 |
-
->__('Update the VCL configuration on the running Varnish instances')?>
|
49 |
-
</td>
|
50 |
-
</tr>
|
51 |
-
<tr>
|
52 |
-
<td class="scope-label">
|
53 |
-
<button
|
54 |
-
onclick="setLocation('<?php echo $this->getSaveConfigUrl()?>')"
|
55 |
-
type="button"
|
56 |
-
class="scalable save">
|
57 |
-
<span><?php echo Mage::helper( 'turpentine/data' )
|
58 |
-
->__('Save Varnish Config') ?></span>
|
59 |
-
</button>
|
60 |
-
</td>
|
61 |
-
<td class="scope-label">
|
62 |
-
<?php echo Mage::helper( 'turpentine/data' )
|
63 |
-
->__('Save the configuration to a VCL file.')?>
|
64 |
-
</td>
|
65 |
-
</tr>
|
66 |
-
<tr>
|
67 |
-
<td class="scope-label">
|
68 |
-
<button
|
69 |
-
onclick="setLocation('<?php echo $this->getGetConfigUrl()?>')"
|
70 |
-
type="button"
|
71 |
-
class="scalable">
|
72 |
-
<span><?php echo Mage::helper( 'turpentine/data' )
|
73 |
-
->__('Download Varnish Config') ?></span>
|
74 |
-
</button>
|
75 |
-
</td>
|
76 |
-
<td class="scope-label">
|
77 |
-
<?php echo Mage::helper( 'turpentine/data' )
|
78 |
-
->__('Download the generated VCL file.')?>
|
79 |
-
</td>
|
80 |
-
</tr>
|
81 |
-
<tr>
|
82 |
-
<?php if( Mage::helper( 'turpentine/varnish' )->isBypassEnabled() ): ?>
|
83 |
-
<td class="scope-label">
|
84 |
-
<button
|
85 |
-
onclick="setLocation('<?php echo $this->getSwitchNavigationUrl( 'varnish' ); ?>')"
|
86 |
-
type="button"
|
87 |
-
class="scalable back">
|
88 |
-
<span><?php echo Mage::helper( 'turpentine/data' )
|
89 |
-
->__('Deactivate Varnish Bypass') ?></span>
|
90 |
-
</button>
|
91 |
-
</td>
|
92 |
-
<td class="scope-label">
|
93 |
-
<?php echo Mage::helper( 'turpentine/data' )
|
94 |
-
->__('Remove the bypass cookie and use again Varnish.')?>
|
95 |
-
</td>
|
96 |
-
<?php else: ?>
|
97 |
-
<td class="scope-label">
|
98 |
-
<button
|
99 |
-
onclick="setLocation('<?php echo $this->getSwitchNavigationUrl( 'default' ); ?>')"
|
100 |
-
type="button"
|
101 |
-
class="scalable delete">
|
102 |
-
<span><?php echo Mage::helper( 'turpentine/data' )
|
103 |
-
->__('Activate Varnish Bypass') ?></span>
|
104 |
-
</button>
|
105 |
-
</td>
|
106 |
-
<td class="scope-label">
|
107 |
-
<?php echo Mage::helper( 'turpentine/data' )
|
108 |
-
->__('Create a cookie to bypass Varnish only for your session.')?>
|
109 |
-
</td>
|
110 |
-
<?php endif; ?>
|
111 |
-
</tr>
|
112 |
-
</table>
|
113 |
-
<?php echo $this->getChildHtml(); ?>
|
114 |
-
|
115 |
-
<style>
|
116 |
-
.varnish-management button {
|
117 |
-
width: 190px;
|
118 |
-
}
|
119 |
-
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/design/frontend/base/default/layout/turpentine_esi.xml
CHANGED
@@ -96,6 +96,7 @@
|
|
96 |
<action method="setEsiOptions">
|
97 |
<params>
|
98 |
<access>private</access>
|
|
|
99 |
<flush_events>
|
100 |
<poll_vote_add/>
|
101 |
</flush_events>
|
@@ -177,6 +178,39 @@
|
|
177 |
-->
|
178 |
</catalog_product_compare_index>
|
179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
<!-- Checkout -->
|
182 |
|
96 |
<action method="setEsiOptions">
|
97 |
<params>
|
98 |
<access>private</access>
|
99 |
+
<method>ajax</method>
|
100 |
<flush_events>
|
101 |
<poll_vote_add/>
|
102 |
</flush_events>
|
178 |
-->
|
179 |
</catalog_product_compare_index>
|
180 |
|
181 |
+
<!-- Catalog Search -->
|
182 |
+
|
183 |
+
<!--
|
184 |
+
If the search input box is inside the header, it needs to contain the current search string after searching.
|
185 |
+
The block below overrules the ESI Options for the header on the search results page.
|
186 |
+
We change the scope of the header to "page", so the current URL is passed to the ESI request.
|
187 |
+
We set the TTL to 0, because the same user is probably not going to search for the same string again.
|
188 |
+
-->
|
189 |
+
<catalogsearch_result_index>
|
190 |
+
<reference name="header">
|
191 |
+
<action method="setEsiOptions">
|
192 |
+
<params>
|
193 |
+
<access>private</access>
|
194 |
+
<scope>page</scope>
|
195 |
+
<ttl>0</ttl>
|
196 |
+
</params>
|
197 |
+
</action>
|
198 |
+
</reference>
|
199 |
+
</catalogsearch_result_index>
|
200 |
+
|
201 |
+
<!-- fixes issues with 'recently viewed products' in CE 1.9's RWD theme -->
|
202 |
+
<catalog_category_layered_nochildren>
|
203 |
+
<reference name="left.reports.product.viewed">
|
204 |
+
<action method="setEsiOptions">
|
205 |
+
<params>
|
206 |
+
<access>private</access>
|
207 |
+
<flush_events>
|
208 |
+
<catalog_controller_product_view/>
|
209 |
+
</flush_events>
|
210 |
+
</params>
|
211 |
+
</action>
|
212 |
+
</reference>
|
213 |
+
</catalog_category_layered_nochildren>
|
214 |
|
215 |
<!-- Checkout -->
|
216 |
|
app/design/frontend/base/default/template/turpentine/ajax.phtml
DELETED
@@ -1,81 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Nexcess.net Turpentine Extension for Magento
|
5 |
-
* Copyright (C) 2012 Nexcess.net L.L.C.
|
6 |
-
*
|
7 |
-
* This program is free software; you can redistribute it and/or modify
|
8 |
-
* it under the terms of the GNU General Public License as published by
|
9 |
-
* the Free Software Foundation; either version 2 of the License, or
|
10 |
-
* (at your option) any later version.
|
11 |
-
*
|
12 |
-
* This program is distributed in the hope that it will be useful,
|
13 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
-
* GNU General Public License for more details.
|
16 |
-
*
|
17 |
-
* You should have received a copy of the GNU General Public License along
|
18 |
-
* with this program; if not, write to the Free Software Foundation, Inc.,
|
19 |
-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 |
-
*/
|
21 |
-
|
22 |
-
$debugEnabled = (bool)Mage::helper( 'turpentine/esi' )->getEsiDebugEnabled();
|
23 |
-
$blockTag = sprintf( 'turpentine-esi-block-%s',
|
24 |
-
Mage::helper( 'turpentine/data' )->secureHash( $this->getNameInLayout() ) );
|
25 |
-
|
26 |
-
if( $debugEnabled ) {
|
27 |
-
echo sprintf( '<!-- AJAX START [%s] -->', $this->getNameInLayout() ) . PHP_EOL;
|
28 |
-
}
|
29 |
-
/**
|
30 |
-
* Note that the new content will be inside the "turpentine-esi-block" div
|
31 |
-
* which could possible alter how things are displayed. If this turns out to
|
32 |
-
* be an issue we'll have to go back to using Ajax.Request so the container
|
33 |
-
* block is completely replaced which means no nice appear effect.
|
34 |
-
*
|
35 |
-
* @link http://prototypejs.org/doc/latest/ajax/index.html
|
36 |
-
* @link http://prototypejs.org/doc/latest/ajax/Ajax/Request/index.html
|
37 |
-
* @link http://prototypejs.org/doc/latest/dom/Element/replace/index.html
|
38 |
-
* @link http://madrobby.github.com/scriptaculous/effect-appear/
|
39 |
-
*
|
40 |
-
* @link http://api.jquery.com/jQuery.ajax/
|
41 |
-
* @link http://api.jquery.com/fadeIn/
|
42 |
-
*/
|
43 |
-
$_prototypeFunction = $debugEnabled ? 'onComplete' : 'onSuccess';
|
44 |
-
$_jQueryFunction = $debugEnabled ? 'always' : 'done';
|
45 |
-
echo <<<HTML
|
46 |
-
<div id="$blockTag" style="display: none">
|
47 |
-
<script type="text/javascript">
|
48 |
-
(function() {
|
49 |
-
var blockTag = {$this->helper('core')->jsonEncode($blockTag)}, esiUrl = {$this->helper('core')->jsonEncode($this->getEsiUrl())};
|
50 |
-
if (typeof Ajax === 'object' && typeof Ajax.Updater === 'function') {
|
51 |
-
new Ajax.Updater(
|
52 |
-
blockTag,
|
53 |
-
esiUrl,
|
54 |
-
{
|
55 |
-
method: "get",
|
56 |
-
evalScripts: true,
|
57 |
-
{$_prototypeFunction}: function() {
|
58 |
-
$(blockTag).appear({
|
59 |
-
duration: 0.3
|
60 |
-
});
|
61 |
-
}
|
62 |
-
}
|
63 |
-
);
|
64 |
-
} else if (typeof jQuery === 'function') {
|
65 |
-
jQuery.ajax(
|
66 |
-
{
|
67 |
-
url: esiUrl,
|
68 |
-
type: "get",
|
69 |
-
dataType: "html"
|
70 |
-
}
|
71 |
-
).{$_jQueryFunction}(function() {
|
72 |
-
$(blockTag).fadeIn(300);
|
73 |
-
});
|
74 |
-
}
|
75 |
-
})();
|
76 |
-
</script>
|
77 |
-
</div>
|
78 |
-
HTML;
|
79 |
-
if( $debugEnabled ) {
|
80 |
-
echo sprintf( '<!-- AJAX END [%s] -->', $this->getNameInLayout() ) . PHP_EOL;
|
81 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/design/frontend/base/default/template/turpentine/notices.phtml
DELETED
@@ -1,36 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Nexcess.net Turpentine Extension for Magento
|
4 |
-
* Copyright (C) 2012 Nexcess.net L.L.C.
|
5 |
-
*
|
6 |
-
* This program is free software; you can redistribute it and/or modify
|
7 |
-
* it under the terms of the GNU General Public License as published by
|
8 |
-
* the Free Software Foundation; either version 2 of the License, or
|
9 |
-
* (at your option) any later version.
|
10 |
-
*
|
11 |
-
* This program is distributed in the hope that it will be useful,
|
12 |
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
-
* GNU General Public License for more details.
|
15 |
-
*
|
16 |
-
* You should have received a copy of the GNU General Public License along
|
17 |
-
* with this program; if not, write to the Free Software Foundation, Inc.,
|
18 |
-
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
19 |
-
*/
|
20 |
-
?>
|
21 |
-
|
22 |
-
<?php if($this->helper( 'turpentine/varnish' )->shouldDisplayNotice()): ?>
|
23 |
-
<div class="varnish-global-notice">
|
24 |
-
<div class="notice-inner">
|
25 |
-
<p>
|
26 |
-
<strong><?php echo $this->__('The cookie that allows bypassing Varnish is present in your browser.'); ?></strong><br />
|
27 |
-
<?php echo $this->__('Remember that this navigation mode should be only activated for testing. You will suffer a decline in overall performance until you delete this cookie.'); ?>
|
28 |
-
</p>
|
29 |
-
</div>
|
30 |
-
</div>
|
31 |
-
<style>
|
32 |
-
.varnish-global-notice { border:1px solid #cfcfcf; border-width:0 0 1px; background:#ffff90; font-size:12px; line-height:1.25; text-align:center; color:#2f2f2f; }
|
33 |
-
.varnish-global-notice .notice-inner { width:860px; margin:0 auto; padding:12px 0 12px 0px; text-align:left; }
|
34 |
-
.varnish-global-notice .notice-inner p { margin:0; padding:10px; }
|
35 |
-
</style>
|
36 |
-
<?php endif; ?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package.xml
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
<?xml version='1.0' encoding='utf-8'?>
|
2 |
-
<package><name>Nexcessnet_Turpentine</name><license uri="http://opensource.org/licenses/GPL-2.0">GPLv2</license><notes>Supports Magento v1.6 and later</notes><time>
|
1 |
<?xml version='1.0' encoding='utf-8'?>
|
2 |
+
<package><name>Nexcessnet_Turpentine</name><license uri="http://opensource.org/licenses/GPL-2.0">GPLv2</license><notes>Supports Magento v1.6 and later</notes><time>11:56:08</time><__packager>build_package.py v0.0.3</__packager><summary>Improves Magento support for Varnish caching and generates 2.1 and 3.0 compatible VCLs.</summary><stability>stable</stability><__commit_hash>42cd7044e41e01bd7ebce968d6b05001838afd3a</__commit_hash><version>0.6.3</version><extends /><contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file hash="a0bd4a5632b369b058c0ec5262e0cc49" name="turpentine.xml" /></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file hash="7b6eab8bd2e7528eafb647c3e2ba8634" name="turpentine_esi.xml" /></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file hash="58848d4d90973bfd63b466ea181352a5" name="Nexcessnet_Turpentine.xml" /></dir></target><target name="magecommunity"><dir name="Nexcessnet"><dir name="Turpentine"><dir name="Helper"><file hash="a7d1c51e24f9d35373fc8533871120a3" name="Esi.php" /><file hash="802e269b0c80131efbb070309fdc610f" name="Varnish.php" /><file hash="913d0762f9df7696f1217f82791f1b78" name="Cron.php" /><file hash="0ee525f0fba5236f05ad2289fe2f2292" name="Data.php" /><file hash="6b637be4eac4c924fc1f02b2d49699c3" name="Ban.php" /><file hash="4a448ad2fe5b5a253a37d3f4aa3dd1bb" name="Debug.php" /></dir><dir name="misc"><file hash="7c24835522ec526d212ea98add1ceb2a" name="version-3.vcl" /><file hash="ba5d5c7263cd90eea3785953e3549041" name="uuid.c" /><file hash="6298eb180a1ae61a79b0cf929be61144" name="version-2.vcl" /></dir><dir name="etc"><file hash="6dd44a194829f6e28daa977efe324f22" name="system.xml" /><file hash="3b608fbcca3d307833d10604dff23966" name="cache.xml" /><file hash="1194d7176973fa7bcd8f6ad4c7d9b346" name="config.xml" /></dir><dir name="controllers"><file hash="3446129075986c4143e9d74d5154cf64" name="EsiController.php" /><dir name="Adminhtml"><file hash="fb44492ff908e0dd28a4fa62e382bd3e" name="CacheController.php" /></dir><dir name="Varnish"><file hash="625118bfe342139b7fd9464c05d1b0a6" name="ManagementController.php" /></dir></dir><dir name="Model"><file hash="c2cb79001524617febbfddf099d09f37" name="Session.php" /><dir name="Shim"><dir name="Mage"><dir name="Core"><file hash="9e5d87f0aa84c9fb1541db83aba69abd" name="Config.php" /><file hash="821bff6c2fb372e3ffb39abf6453b3f8" name="Layout.php" /><file hash="4a1aa246373520936f0e4b5b3a3baf25" name="App.php" /></dir></dir></dir><dir name="PageCache"><dir name="Container"><file hash="139e8a9bfa209316036e798fff654a8a" name="Notices.php" /></dir></dir><dir name="Dummy"><file hash="f6611808da53ffa00561a8f76b26016e" name="Request.php" /></dir><dir name="Varnish"><file hash="6c1a8e5e3f412bff082c6df136e5db1a" name="Admin.php" /><dir name="Admin"><file hash="c3d44d59ece358553d2cfa8f92964d39" name="Socket.php" /></dir><dir name="Configurator"><file hash="b831b872fcb05d9c723149159db0eed1" name="Version2.php" /><file hash="82d0abe0123272e59e6c319dfdd4e9dc" name="Version3.php" /><file hash="fd99025d6f79c2a2dfe5a910099b6ac6" name="Abstract.php~" /><file hash="d63b4714180cb963d81d32a3fa31e95e" name="Abstract.php" /></dir></dir><dir name="Observer"><file hash="4d97c660f6ad74162f842d5d2bfa53d7" name="Esi.php" /><file hash="7244a8ce600e980d612409595b9b6b9b" name="Varnish.php" /><file hash="a34e79218e8ca1fefad303b9399bda9d" name="Cron.php" /><file hash="5b6c57ab373444fcac7a42262f8178d5" name="Ban.php" /><file hash="9d57fad69ff42b71c66ca26bc3372317" name="Debug.php" /></dir><dir name="Core"><file hash="d4f63abc6d34c923c6e64a522b6fc36e" name="Session.php" /></dir><dir name="Config"><dir name="Select"><file hash="2e01b14592189b3f6a8a05be5ef4c69c" name="StripWhitespace.php" /><file hash="dc472f34c25b1688cfa9fa206958c536" name="Version.php" /><file hash="9348c5e58037fd97d89b84ccab4ef2d0" name="Toggle.php" /></dir></dir></dir><dir name="Block"><file hash="e9b03d651a8da9b1d32c4fd2f4781792" name="Management.php" /><file hash="390cf75d04b1b098cad562229b649c2d" name="Notices.php" /><dir name="Adminhtml"><dir name="Cache"><file hash="798cf7afa80e0a06be2b8c6cb2bef02b" name="Grid.php" /></dir></dir><dir name="Catalog"><dir name="Product"><dir name="List"><file hash="ce9fca4c273987759f284fe31c1597f5" name="Toolbar.php" /></dir></dir></dir><dir name="Core"><file hash="f9b035bb701943aa12755abdb029fa8f" name="Messages.php" /></dir><dir name="Poll"><file hash="bf9ca23a445776435e38e6c8be9976ea" name="ActivePoll.php" /></dir></dir></dir></dir></target></contents><dependencies><required><php><min>5.2.13</min><max>6.0.0</max></php></required></dependencies><authors><author><name>Chris Wells</name><user>nexcess_net</user><email>clwells@nexcess.net</email></author><author><name>Alex Headley</name><user>aheadley_nex</user><email>aheadley@nexcess.net</email></author></authors><date>2015-07-28</date><compatibile /><channel>community</channel><description>Turpentine is a Magento extension to improve Magento's compatibility with Varnish, a very-fast caching reverse-proxy. By default, Varnish doesn't cache requests with cookies and Magento sends the frontend cookie with every request causing a (near) zero hit-rate for Varnish's cache. Turpentine provides Varnish configuration files (VCLs) to work with Magento and modifies Magento's behaviour to significantly improve the cache hit rate.</description></package>
|