From 23ee5f0109e2e68e4d875ba889fb80672619f5e2 Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Mon, 17 Jun 2013 12:28:49 +0100 Subject: [PATCH] key scheme change added --- readme.txt | 1 + wp-common | 2 +- wp-ffpc-acache.php | 2 +- wp-ffpc-backend.php | 22 ++++++++------ wp-ffpc-class.php | 60 ++++++++++++++++++++++++++++----------- wp-ffpc-nginx-sample.conf | 2 +- wp-ffpc.php | 3 +- 7 files changed, 63 insertions(+), 29 deletions(-) diff --git a/readme.txt b/readme.txt index 8f56bce..8e720c5 100644 --- a/readme.txt +++ b/readme.txt @@ -93,6 +93,7 @@ What's new: * additional cookie patterns to exclude visitors from cache * syslog dropped; using standard PHP log instead, combined with WP_DEBUG to change to info/notice level * possibility to start pre-cache from wp-cron +* changeable key scheme ( was fixed previously ) What's fixed: diff --git a/wp-common b/wp-common index c862af5..fe3a3c9 160000 --- a/wp-common +++ b/wp-common @@ -1 +1 @@ -Subproject commit c862af55f464e366dd6f44d20dcf709d0b5bbe51 +Subproject commit fe3a3c9c52091f21924de59d379442201e8a059a diff --git a/wp-ffpc-acache.php b/wp-ffpc-acache.php index 010a577..f094b49 100644 --- a/wp-ffpc-acache.php +++ b/wp-ffpc-acache.php @@ -69,8 +69,8 @@ if ( isset($wp_ffpc_config['nocache_cookies']) && !empty($wp_ffpc_config['nocach /* canonical redirect storage */ $wp_ffpc_redirect = null; - /* fires up the backend storage array with current config */ +include_once ('wp-ffpc-backend.php'); $wp_ffpc_backend = new WP_FFPC_Backend( $wp_ffpc_config ); /* no cache for for logged in users unless it's set diff --git a/wp-ffpc-backend.php b/wp-ffpc-backend.php index 8975286..d453fff 100644 --- a/wp-ffpc-backend.php +++ b/wp-ffpc-backend.php @@ -44,6 +44,7 @@ if (!class_exists('WP_FFPC_Backend')) { private $options = array(); private $status = array(); public $cookies = array(); + private $urimap = array(); private $utilities; /** @@ -59,7 +60,14 @@ if (!class_exists('WP_FFPC_Backend')) { $this->cookies = array ( 'comment_author_' , 'wordpressuser_' , 'wp-postpass_', 'wordpress_logged_in_' ); - $this->utilities = WP_Plugins_Utilities::Utility(); + $this->utilities = WP_Plugins_Utilities_v1::Utility(); + + $this->urimap = array( + '$scheme' => str_replace ( '://', '', $this->utilities->replace_if_ssl ( 'http://' ) ), + '$host' => $_SERVER['HTTP_HOST'], + '$request_uri' => $_SERVER['REQUEST_URI'], + '$remote_user' => $_SERVER['REMOTE_USER'], + ); /* no config, nothing is going to work */ if ( empty ( $this->options ) ) { @@ -85,14 +93,12 @@ if (!class_exists('WP_FFPC_Backend')) { * */ public function key ( &$prefix ) { - /* use the full accessed URL string as key, same will be generated by nginx as well - we need a data and a meta key: data is string only with content, meta is not used in nginx */ - if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) - $_SERVER['HTTPS'] = 'on'; + /* data is string only with content, meta is not used in nginx */ + $key = str_replace ( array_keys( $this->urimap ), $this->urimap, $this->options['key'] ); + $this->log ( __translate__('original key configuration: ', $this->plugin_constant ) . $this->options['key'] ); + $this->log ( __translate__('setting key to: ', $this->plugin_constant ) . $key ); - $protocol = ( isset($_SERVER['HTTPS']) && ( ( strtolower($_SERVER['HTTPS']) == 'on' ) || ( $_SERVER['HTTPS'] == '1' ) ) ) ? 'https://' : 'http://'; - - return $prefix . $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + return $key; } diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index ad62ca4..a395c23 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -10,7 +10,6 @@ */ if ( ! class_exists( 'WP_FFPC' ) ) { - /* get the plugin abstract class*/ include_once ( 'wp-common/wp-plugin-abstract.php' ); /* get the common functions class*/ @@ -29,7 +28,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { * @var array $select_invalidation_method Invalidation methods string array * */ - class WP_FFPC extends WP_Plugins_Abstract { + class WP_FFPC extends WP_Plugins_Abstract_v2 { const host_separator = ','; const port_separator = ':'; const donation_id_key = 'hosted_button_id='; @@ -63,7 +62,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { protected $select_invalidation_method = array (); protected $select_schedules = array(); protected $valid_cache_type = array (); - + protected $list_uri_vars = array(); private $shell_function = false; private $shell_possibilities = array (); private $backend = NULL; @@ -130,6 +129,17 @@ if ( ! class_exists( 'WP_FFPC' ) ) { 2 => __( 'modified post and all taxonomies' , $this->plugin_constant ), ); + $this->list_uri_vars = array ( + '$scheme' => __('The HTTP scheme (i.e. http, https).', $this->plugin_constant ), + '$host' => __('Host in the header of request or name of the server processing the request if the Host header is not available.', $this->plugin_constant ), + '$request_uri' => __('The *original* request URI as received from the client including the args', $this->plugin_constant ), + '$remote_user' => __('Name of user, authenticated by the Auth Basic Module', $this->plugin_constant ), + //'$cookie_COOKnginy IE' => __('Value of COOKIE', $this->plugin_constant ), + //'$http_HEADER' => __('Value of HTTP request header HEADER ( lowercase, dashes converted to underscore )', $this->plugin_constant ), + //'$query_string' => __('Full request URI after rewrites', $this->plugin_constant ), + //'' => __('', $this->plugin_constant ), + ); + $wp_schedules = wp_get_schedules(); $schedules['null'] = __( 'do not use timed precache' ); foreach ( $wp_schedules as $interval=>$details ) { @@ -217,14 +227,16 @@ if ( ! class_exists( 'WP_FFPC' ) ) { /* save parameter updates, if there are any */ if ( isset( $_POST[ $this->button_flush ] ) ) { - update_option( self::precache_log , '' ); - update_option( self::precache_timestamp , '' ); + $this->_delete_option( self::precache_log ); + $this->_delete_option( self::precache_timestamp ); - if ( @file_exists ( $this->precache_logfile ) ) - unlink ( $this->precache_logfile ); + if ( @file_exists ( $this->precache_logfile ) ) { + unlink ( $this->precache_logfile ); + } - if ( @file_exists ( $this->precache_phpfile ) ) - unlink ( $this->precache_phpfile ); + if ( @file_exists ( $this->precache_phpfile ) ) { + unlink ( $this->precache_phpfile ); + } $this->backend->clear( false, true ); $this->status = 3; @@ -439,6 +451,20 @@ if ( ! class_exists( 'WP_FFPC' ) ) { plugin_constant); ?> + +
+ +
+
+ + use the guide below to change it. Changing this requires changes in the nginx configuration and restarting nginx, if nginx memcached is in use.', $this->plugin_constant); ?> +
list_uri_vars as $uri => $desc ) { + echo '
'. $uri .'
'. $desc .'
'; + } + ?>
+
+ @@ -450,7 +476,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
options['log'],true); ?> /> - plugin_constant); ?> + WP_DEBUG is enabled, notices and info level is displayed as well, otherwie only ERRORS are logged.', $this->plugin_constant); ?>
@@ -602,7 +628,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { } else { ?>

- +
@@ -618,7 +644,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { -
+ @@ -798,7 +824,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { /* add the required includes and generate the needed code */ $string[] = "global_config, true ) . ';' ; - $string[] = "include_once ('" . $this->acache_backend . "');"; + //$string[] = "include_once ('" . $this->acache_backend . "');"; $string[] = "include_once ('" . $this->acache_worker . "');"; $string[] = "?>"; @@ -818,7 +844,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { /* replace the data prefix with the configured one */ $to_replace = array ( 'DATAPREFIX' , 'SERVERROOT', 'SERVERLOG' ); - $replace_with = array ( $this->options['prefix_data'], ABSPATH, $_SERVER['SERVER_NAME'] ); + $replace_with = array ( $this->options['prefix_data'] . $this->options['key'] , ABSPATH, $_SERVER['SERVER_NAME'] ); $nginx = str_replace ( $to_replace , $replace_with , $nginx ); /* set upstream servers from configured servers, best to get from the actual backend */ @@ -909,12 +935,12 @@ if ( ! class_exists( 'WP_FFPC' ) ) { $starttime = $starttime[1] + $starttime[0]; $page = file_get_contents( $permalink ); - $size = round ( ( strlen ( $page ) / 1024 ), 3 ); + $size = round ( ( strlen ( $page ) / 1024 ), 2 ); $endtime = explode ( " ", microtime() ); - $endtime = ( $endtime[1] + $endtime[0] ) - $starttime; + $endtime = round( ( $endtime[1] + $endtime[0] ) - $starttime, 2 ); - echo $permalink . "\t" . $endtime . "\t" . $size . "\n"; + echo $permalink . "\t" . $endtime . "\t" . $size . "\n"; unset ( $page, $size, $starttime, $endtime ); sleep( 1 ); } diff --git a/wp-ffpc-nginx-sample.conf b/wp-ffpc-nginx-sample.conf index 253e2d9..487de73 100644 --- a/wp-ffpc-nginx-sample.conf +++ b/wp-ffpc-nginx-sample.conf @@ -79,7 +79,7 @@ MEMCACHED_SERVERS # try to get result from memcached location @memcached { default_type text/html; - set $memcached_key DATAPREFIX$scheme://$host$request_uri; + set $memcached_key DATAPREFIX; set $memcached_request 1; # exceptions diff --git a/wp-ffpc.php b/wp-ffpc.php index 64a84a3..3d1ea9e 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -47,7 +47,8 @@ $wp_ffpc_defaults = array ( 'persistent' => false, 'response_header' => false, 'generate_time' => false, - 'precache_schedule' => 'null' + 'precache_schedule' => 'null', + 'key' => '$scheme://$host$request_uri', ); $wp_ffpc = new WP_FFPC ( 'wp-ffpc', '1.2', 'WP-FFPC', $wp_ffpc_defaults, 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC' );