Skip to content

Commit

Permalink
Merge pull request #7 from bundan/master
Browse files Browse the repository at this point in the history
wordpress plugin updates
  • Loading branch information
i3149 committed Mar 20, 2012
2 parents 410165a + 1a0742c commit 67efba7
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cf-joomla/helper.php
Expand Up @@ -11,7 +11,7 @@
* other free or open source software licenses.
*/

define('CLOUDFLARE_VERSION', '0.1.4');
define('CLOUDFLARE_VERSION', '0.1.5');
require_once("ip_in_range.php");

class modCloudFlare {
Expand All @@ -27,7 +27,7 @@ function updateIP( $params ) {
global $is_cf;

$is_cf = FALSE;
$cf_ip_ranges = array("204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18", "108.162.192.0/18");
$cf_ip_ranges = array("204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18", "108.162.192.0/18"i,"190.93.240.0/20");
foreach ($cf_ip_ranges as $range) {
if (ip_in_range($_SERVER["REMOTE_ADDR"], $range)) {
if ($_SERVER["HTTP_CF_CONNECTING_IP"]) {
Expand Down
40 changes: 40 additions & 0 deletions cf-joomla/plgCloudFlare/cloudflare.php
@@ -0,0 +1,40 @@
<?php

defined( '_JEXEC' ) or die( 'Restricted access' );
define('CLOUDFLARE_VERSION', '0.1.5');
require_once("ip_in_range.php");

jimport( 'joomla.plugin.plugin' );

class PlgSystemCloudFlare extends JPlugin
{
public function __construct( &$subject, $config )
{
parent::__construct( $subject, $config );
}

function onAfterInitialise()
{
global $is_cf;

$is_cf = FALSE;
$cf_ip_ranges = array("204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18", "108.162.192.0/18","190.93.240.0/20");
foreach ($cf_ip_ranges as $range) {
if (ip_in_range($_SERVER["REMOTE_ADDR"], $range)) {
if ($_SERVER["HTTP_CF_CONNECTING_IP"]) {
$_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$is_cf = TRUE;
}
break;
}
}

// Let people know that the CF plugin is turned on.
if (!headers_sent())
{
header("X-CF-Powered-By: CF-Joomla " . CLOUDFLARE_VERSION);
}

}

}
21 changes: 21 additions & 0 deletions cf-joomla/plgCloudFlare/cloudflare.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<install version="2.5" type="plugin" group="system">
<name>CloudFlare Plugin</name>
<author>Jerome Chen</author>
<creationDate>March 2012</creationDate>
<authorEmail>jerome@cloudflare.com</authorEmail>
<authorUrl>http://cloudflare.com</authorUrl>
<version>1.0.0</version>
<description>Plugin for making Joomla sites work with CloudFlare</description>
<files>
<filename plugin="cloudflare">cloudflare.php</filename>
<filename>ip_in_range.php</filename>
</files>
<params>
<param name="cloudflare"
type="text"
default=""
label="CloudFlare"
/>
</params>
</install>
96 changes: 96 additions & 0 deletions cf-joomla/plgCloudFlare/ip_in_range.php
@@ -0,0 +1,96 @@
<?php

/*
* ip_in_range.php - Function to determine if an IP is located in a
* specific range as specified via several alternative
* formats.
*
* Network ranges can be specified as:
* 1. Wildcard format: 1.2.3.*
* 2. CIDR format: 1.2.3/24 OR 1.2.3.4/255.255.255.0
* 3. Start-End IP format: 1.2.3.0-1.2.3.255
*
* Return value BOOLEAN : ip_in_range($ip, $range);
*
* Copyright 2008: Paul Gregg <pgregg@pgregg.com>
* 10 January 2008
* Version: 1.2
*
* Source website: http://www.pgregg.com/projects/php/ip_in_range/
* Version 1.2
*
* This software is Donationware - if you feel you have benefited from
* the use of this tool then please consider a donation. The value of
* which is entirely left up to your discretion.
* http://www.pgregg.com/donate/
*
* Please do not remove this header, or source attibution from this file.
*/


// decbin32
// In order to simplify working with IP addresses (in binary) and their
// netmasks, it is easier to ensure that the binary strings are padded
// with zeros out to 32 characters - IP addresses are 32 bit numbers
function decbin32 ($dec) {
return str_pad(decbin($dec), 32, '0', STR_PAD_LEFT);
}

// ip_in_range
// This function takes 2 arguments, an IP address and a "range" in several
// different formats.
// Network ranges can be specified as:
// 1. Wildcard format: 1.2.3.*
// 2. CIDR format: 1.2.3/24 OR 1.2.3.4/255.255.255.0
// 3. Start-End IP format: 1.2.3.0-1.2.3.255
// The function will return true if the supplied IP is within the range.
// Note little validation is done on the range inputs - it expects you to
// use one of the above 3 formats.
function ip_in_range($ip, $range) {
if (strpos($range, '/') !== false) {
// $range is in IP/NETMASK format
list($range, $netmask) = explode('/', $range, 2);
if (strpos($netmask, '.') !== false) {
// $netmask is a 255.255.0.0 format
$netmask = str_replace('*', '0', $netmask);
$netmask_dec = ip2long($netmask);
return ( (ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec) );
} else {
// $netmask is a CIDR size block
// fix the range argument
$x = explode('.', $range);
while(count($x)<4) $x[] = '0';
list($a,$b,$c,$d) = $x;
$range = sprintf("%u.%u.%u.%u", empty($a)?'0':$a, empty($b)?'0':$b,empty($c)?'0':$c,empty($d)?'0':$d);
$range_dec = ip2long($range);
$ip_dec = ip2long($ip);

# Strategy 1 - Create the netmask with 'netmask' 1s and then fill it to 32 with 0s
#$netmask_dec = bindec(str_pad('', $netmask, '1') . str_pad('', 32-$netmask, '0'));

# Strategy 2 - Use math to create it
$wildcard_dec = pow(2, (32-$netmask)) - 1;
$netmask_dec = ~ $wildcard_dec;

return (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec));
}
} else {
// range might be 255.255.*.* or 1.2.3.0-1.2.3.255
if (strpos($range, '*') !==false) { // a.b.*.* format
// Just convert to A-B format by setting * to 0 for A and 255 for B
$lower = str_replace('*', '0', $range);
$upper = str_replace('*', '255', $range);
$range = "$lower-$upper";
}

if (strpos($range, '-')!==false) { // A-B format
list($lower, $upper) = explode('-', $range, 2);
$lower_dec = (float)sprintf("%u",ip2long($lower));
$upper_dec = (float)sprintf("%u",ip2long($upper));
$ip_dec = (float)sprintf("%u",ip2long($ip));
return ( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) );
}
return false;
}
}
?>
14 changes: 7 additions & 7 deletions cloudflare/cloudflare.php
Expand Up @@ -3,8 +3,8 @@
Plugin Name: CloudFlare
Plugin URI: http://www.cloudflare.com/wiki/CloudFlareWordPressPlugin
Description: CloudFlare integrates your blog with the CloudFlare platform.
Version: 1.2.0
Author: Ian Pye (CloudFlare Team)
Version: 1.2.3
Author: Ian Pye, Jerome Chen (CloudFlare Team)
License: GPLv2
*/

Expand All @@ -26,7 +26,7 @@
*/

define('CLOUDFLARE_VERSION', '1.2.0');
define('CLOUDFLARE_VERSION', '1.2.1');
require_once("ip_in_range.php");

// Make sure we don't expose any info if called directly
Expand All @@ -40,7 +40,7 @@ function cloudflare_init() {

$cf_api_host = "ssl://www.cloudflare.com";
$cf_api_port = 443;
$cf_ip_ranges = array("204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18", "108.162.192.0/18");
$cf_ip_ranges = array("204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18", "108.162.192.0/18","190.93.240.0/20");
$is_cf = ($_SERVER["HTTP_CF_CONNECTING_IP"])? TRUE: FALSE;

// Update the REMOTE_ADDR value if the current REMOTE_ADDR value is in the specified range.
Expand All @@ -60,7 +60,7 @@ function cloudflare_init() {
add_action('admin_menu', 'cloudflare_config_page');
cloudflare_admin_warnings();
}
add_action('init', 'cloudflare_init');
add_action('init', 'cloudflare_init',1);

function cloudflare_admin_init() {

Expand Down Expand Up @@ -134,7 +134,7 @@ function cloudflare_conf() {
&& check_admin_referer('cloudflare-db-opt','cloudflare-db-opt-nonce')) {

update_option('cloudflare_api_db_last_run', time());
if(current_user_can('edit_files')) {
if(current_user_can('administrator')) {
remove_action('admin_notices', 'cloudflare_warning');
$tables = $wpdb->get_col("SHOW TABLES");
foreach($tables as $table_name) {
Expand Down Expand Up @@ -321,4 +321,4 @@ function cloudflare_set_comment_status($id, $status) {

add_action('wp_set_comment_status', 'cloudflare_set_comment_status', 1, 2);

?>
?>
13 changes: 11 additions & 2 deletions cloudflare/readme.txt
@@ -1,9 +1,9 @@
=== CloudFlare ===
Contributors: i3149
Contributors: i3149, jchen329
Tags: cloudflare, comments, spam, cdn, free, website, performance, speed
Requires at least: 2.8
Tested up to: 3.3
Stable tag: 1.2.0
Stable tag: 1.2.2
License: GPLv2

The CloudFlare WordPress Plugin ensures your WordPress blog is running optimally on the CloudFlare platform.
Expand Down Expand Up @@ -42,6 +42,15 @@ You will also want to sign up your blog with CloudFlare.com

== Changelog ==

= 1.2.3 =
* Updated with new IP range

= 1.2.2 =
* Restricted database optimization to administrators

= 1.2.1 =
* Increased load priority to avoid conflicts with other plugins

= 1.2.0 =

* WP 3.3 compatibility.
Expand Down
6 changes: 3 additions & 3 deletions mod_cloudflare.c
Expand Up @@ -21,7 +21,7 @@
* CloudFlareIPHeader CF-Connecting-IP
* CloudFlareIPTrustedProxy 204.93.173.0/24
*
* Version 1.0.2
* Version 1.0.3
*/

#include "ap_config.h"
Expand All @@ -40,8 +40,8 @@
module AP_MODULE_DECLARE_DATA cloudflare_module;

#define CF_DEFAULT_IP_HEADER "CF-Connecting-IP"
#define CF_DEFAULT_TRUSTED_PROXY {"204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18","108.162.192.0/18"}
#define CF_DEFAULT_TRUSTED_PROXY_COUNT 7
#define CF_DEFAULT_TRUSTED_PROXY {"204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18","108.162.192.0/18","190.93.240.0/20"}
#define CF_DEFAULT_TRUSTED_PROXY_COUNT 8

typedef struct {
/** A proxy IP mask to match */
Expand Down
6 changes: 3 additions & 3 deletions mod_cloudflare_apache2_4.c
Expand Up @@ -40,8 +40,8 @@
module AP_MODULE_DECLARE_DATA cloudflare_module;

#define CF_DEFAULT_IP_HEADER "CF-Connecting-IP"
#define CF_DEFAULT_TRUSTED_PROXY {"204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18","108.162.192.0/18"}
#define CF_DEFAULT_TRUSTED_PROXY_COUNT 7
#define CF_DEFAULT_TRUSTED_PROXY {"204.93.240.0/24", "204.93.177.0/24", "199.27.128.0/21", "173.245.48.0/20", "103.22.200.0/22", "141.101.64.0/18","108.162.192.0/18","190.93.240.0/20"}
#define CF_DEFAULT_TRUSTED_PROXY_COUNT 8

typedef struct {
/** A proxy IP mask to match */
Expand Down Expand Up @@ -506,4 +506,4 @@ module AP_MODULE_DECLARE_DATA cloudflare_module = {
merge_cloudflare_server_config, /* merge per-server config structures */
cloudflare_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};
};

0 comments on commit 67efba7

Please sign in to comment.