Cloudflare - Version 1.3.10

Version Description

  • Added IP ranges.
Download this release

Release Info

Developer furkan811
Plugin Icon 128x128 Cloudflare
Version 1.3.10
Comparing to
See all releases

Version 1.3.10

Files changed (3) hide show
  1. cloudflare.php +396 -0
  2. ip_in_range.php +214 -0
  3. readme.txt +139 -0
cloudflare.php ADDED
@@ -0,0 +1,396 @@
1
+ <?php
2
+ /*
3
+ Plugin Name: CloudFlare
4
+ Plugin URI: http://www.cloudflare.com/wiki/CloudFlareWordPressPlugin
5
+ Description: CloudFlare integrates your blog with the CloudFlare platform.
6
+ Version: 1.3.10
7
+ Author: Ian Pye, Jerome Chen, James Greene (CloudFlare Team)
8
+ License: GPLv2
9
+ */
10
+
11
+ /*
12
+ This program is free software; you can redistribute it and/or modify
13
+ it under the terms of the GNU General Public License as published by
14
+ the Free Software Foundation; version 2 of the License.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
+
25
+ Plugin adapted from the Akismet WP plugin.
26
+
27
+ */
28
+
29
+ define('CLOUDFLARE_VERSION', '1.3.10');
30
+ require_once("ip_in_range.php");
31
+
32
+ // Make sure we don't expose any info if called directly
33
+ if ( !function_exists( 'add_action' ) ) {
34
+ echo "Hi there! I'm just a plugin, not much I can do when called directly.";
35
+ exit;
36
+ }
37
+
38
+ function cloudflare_init() {
39
+ global $cf_api_host, $cf_api_port, $is_cf;
40
+
41
+ $cf_api_host = "ssl://www.cloudflare.com";
42
+ $cf_api_port = 443;
43
+
44
+ $is_cf = ($_SERVER["HTTP_CF_CONNECTING_IP"])? TRUE: FALSE;
45
+
46
+ if (strpos($_SERVER["REMOTE_ADDR"], ":") === FALSE) {
47
+ $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.21.244.0/22","103.22.200.0/22","103.31.4.0/22","141.101.64.0/18","108.162.192.0/18","190.93.240.0/20","188.114.96.0/20","197.234.240.0/22","198.41.128.0/17","162.158.0.0/15");
48
+ // IPV4: Update the REMOTE_ADDR value if the current REMOTE_ADDR value is in the specified range.
49
+ foreach ($cf_ip_ranges as $range) {
50
+ if (ipv4_in_range($_SERVER["REMOTE_ADDR"], $range)) {
51
+ if ($_SERVER["HTTP_CF_CONNECTING_IP"]) {
52
+ $_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_CF_CONNECTING_IP"];
53
+ }
54
+ break;
55
+ }
56
+ }
57
+ }
58
+ else {
59
+ $cf_ip_ranges = array("2400:cb00::/32", "2606:4700::/32", "2803:f800::/32");
60
+ $ipv6 = get_ipv6_full($_SERVER["REMOTE_ADDR"]);
61
+ foreach ($cf_ip_ranges as $range) {
62
+ if (ipv6_in_range($ipv6, $range)) {
63
+ if ($_SERVER["HTTP_CF_CONNECTING_IP"]) {
64
+ $_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_CF_CONNECTING_IP"];
65
+ }
66
+ break;
67
+ }
68
+ }
69
+ }
70
+
71
+ // Let people know that the CF WP plugin is turned on.
72
+ if (!headers_sent()) {
73
+ header("X-CF-Powered-By: WP " . CLOUDFLARE_VERSION);
74
+ }
75
+ add_action('admin_menu', 'cloudflare_config_page');
76
+ cloudflare_admin_warnings();
77
+ }
78
+ add_action('init', 'cloudflare_init',1);
79
+
80
+ function cloudflare_admin_init() {
81
+
82
+ }
83
+
84
+ add_action('admin_init', 'cloudflare_admin_init');
85
+
86
+ function cloudflare_config_page() {
87
+ if ( function_exists('add_submenu_page') ) {
88
+ add_submenu_page('plugins.php', __('CloudFlare Configuration'), __('CloudFlare'), 'manage_options', 'cloudflare', 'cloudflare_conf');
89
+ }
90
+ }
91
+
92
+ function load_cloudflare_keys () {
93
+ global $cloudflare_api_key, $cloudflare_api_email;
94
+ if (!$cloudflare_api_key) {
95
+ $cloudflare_api_key = get_option('cloudflare_api_key');
96
+ }
97
+ if (!$cloudflare_api_email) {
98
+ $cloudflare_api_email = get_option('cloudflare_api_email');
99
+ }
100
+ }
101
+
102
+ function cloudflare_conf() {
103
+ if ( function_exists('current_user_can') && !current_user_can('manage_options') )
104
+ die(__('Cheatin&#8217; uh?'));
105
+ global $cloudflare_api_key, $cloudflare_api_email, $is_cf;
106
+ global $wpdb;
107
+
108
+ // get raw domain - may include www.
109
+ $urlparts = parse_url(site_url());
110
+ $raw_domain = $urlparts["host"];
111
+
112
+ $curl_installed = function_exists('curl_init');
113
+
114
+ if ($curl_installed) {
115
+ // Attempt to get the matching host from CF
116
+ $domain = get_domain($cloudflare_api_key, $cloudflare_api_email, $raw_domain);
117
+ // If not found, default to pulling the domain via client side.
118
+ if (!$domain) {
119
+ $domain = $raw_domain;
120
+ }
121
+ }
122
+ else {
123
+ $domain = $raw_domain;
124
+ }
125
+
126
+ define ("THIS_DOMAIN", $domain);
127
+
128
+ $db_results = array();
129
+
130
+ if ( isset($_POST['submit'])
131
+ && check_admin_referer('cloudflare-db-api','cloudflare-db-api-nonce') ) {
132
+
133
+ if ( function_exists('current_user_can') && !current_user_can('manage_options') ) {
134
+ die(__('Cheatin&#8217; uh?'));
135
+ }
136
+
137
+ $key = $_POST['key'];
138
+ $email = $_POST['email'];
139
+ $dev_mode = esc_sql($_POST["dev_mode"]);
140
+
141
+ if ( empty($key) ) {
142
+ $key_status = 'empty';
143
+ $ms[] = 'new_key_empty';
144
+ delete_option('cloudflare_api_key');
145
+ } else {
146
+ $ms[] = 'new_key_valid';
147
+ update_option('cloudflare_api_key', esc_sql($key));
148
+ update_option('cloudflare_api_key_set_once', "TRUE");
149
+ }
150
+
151
+ if ( empty($email) || !is_email($email) ) {
152
+ $email_status = 'empty';
153
+ $ms[] = 'new_email_empty';
154
+ delete_option('cloudflare_api_email');
155
+ } else {
156
+ $ms[] = 'new_email_valid';
157
+ update_option('cloudflare_api_email', esc_sql($email));
158
+ update_option('cloudflare_api_email_set_once', "TRUE");
159
+ }
160
+
161
+
162
+ $messages = array(
163
+ 'new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')),
164
+ 'new_key_valid' => array('color' => '2d2', 'text' => __('Your key has been verified. Happy blogging!')),
165
+ 'new_email_empty' => array('color' => 'aa0', 'text' => __('Your email has been cleared.')),
166
+ 'new_email_valid' => array('color' => '2d2', 'text' => __('Your email has been verified. Happy blogging!'))
167
+ );
168
+
169
+ if ($curl_installed) {
170
+ if ($key != "" && $email != "") {
171
+ set_dev_mode(esc_sql($key), esc_sql($email), THIS_DOMAIN, $dev_mode);
172
+ if ($dev_mode) {
173
+ $ms[] = 'dev_mode_on';
174
+ }
175
+ else {
176
+ $ms[] = 'dev_mode_off';
177
+ }
178
+ }
179
+
180
+ $messages['dev_mode_on'] = array('color' => '2d2', 'text' => __('Development mode is On. Happy blogging!'));
181
+ $messages['dev_mode_off'] = array('color' => 'aa0', 'text' => __('Development mode is Off. Happy blogging!'));
182
+ }
183
+ }
184
+ ?>
185
+ <?php if ( !empty($_POST['submit'] )) { ?>
186
+ <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
187
+ <?php } ?>
188
+ <div class="wrap">
189
+
190
+ <?php if ($is_cf) { ?>
191
+ <h3>You are currently using CloudFlare!</h3>
192
+ <?php } ?>
193
+
194
+ <h4><?php _e('CLOUDFLARE WORDPRESS PLUGIN:'); ?></h4>
195
+ <?php // <div class="narrow"> ?>
196
+
197
+ CloudFlare has developed a plugin for WordPress. By using the CloudFlare WordPress Plugin, you receive:
198
+ <ol>
199
+ <li>Correct IP Address information for comments posted to your site</li>
200
+ <li>Better protection as spammers from your WordPress blog get reported to CloudFlare</li>
201
+ </ol>
202
+
203
+ <h4>VERSION COMPATIBILITY:</h4>
204
+
205
+ The plugin is compatible with WordPress version 2.8.6 and later. The plugin will not install unless you have a compatible platform.
206
+
207
+ <h4>THINGS YOU NEED TO KNOW:</h4>
208
+
209
+ <ol>
210
+ <li>The main purpose of this plugin is to ensure you have no change to your originating IPs when using CloudFlare. Since CloudFlare acts a reverse proxy, connecting IPs now come from CloudFlare's range. This plugin will ensure you can continue to see the originating IP. Once you install the plugin, the IP benefit will be activated.</li>
211
+
212
+ <li>Every time you click the 'spam' button on your blog, this threat information is sent to CloudFlare to ensure you are constantly getting the best site protection.</li>
213
+
214
+ <li>We recommend that any user on CloudFlare with WordPress use this plugin. </li>
215
+
216
+ <li>NOTE: This plugin is complementary to Akismet and W3 Total Cache. We recommend that you continue to use those services.</li>
217
+
218
+ </ol>
219
+
220
+ <h4>MORE INFORMATION ON CLOUDFLARE:</h4>
221
+
222
+ CloudFlare is a service that makes websites load faster and protects sites from online spammers and hackers. Any website with a root domain (ie www.mydomain.com) can use CloudFlare. On average, it takes less than 5 minutes to sign up. You can learn more here: <a href="http://www.cloudflare.com/">CloudFlare.com</a>.
223
+
224
+ <?php
225
+ if ($curl_installed) {
226
+ $dev_mode = get_dev_mode_status($cloudflare_api_key, $cloudflare_api_email, THIS_DOMAIN);
227
+ }
228
+ ?>
229
+
230
+ <hr />
231
+
232
+ <form action="" method="post" id="cloudflare-conf">
233
+ <?php wp_nonce_field('cloudflare-db-api','cloudflare-db-api-nonce'); ?>
234
+ <?php if (get_option('cloudflare_api_key') && get_option('cloudflare_api_email')) { ?>
235
+ <?php } else { ?>
236
+ <p><?php printf(__('Input your API key from your CloudFlare Accounts Settings page here. To find your API key, log in to <a href="%1$s">CloudFlare</a> and go to \'Account\'.'), 'https://www.cloudflare.com/my-account.html'); ?></p>
237
+ <?php } ?>
238
+ <?php if ($ms) { foreach ( $ms as $m ) { ?>
239
+ <p style="padding: .5em; color: #<?php echo $messages[$m]['color']; ?>; font-weight: bold;"><?php echo $messages[$m]['text']; ?></p>
240
+ <?php } } ?>
241
+ <h3><label for="key"><?php _e('CloudFlare API Key'); ?></label></h3>
242
+ <p><input id="key" name="key" type="text" size="50" maxlength="48" value="<?php echo get_option('cloudflare_api_key'); ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /> (<?php _e('<a href="https://www.cloudflare.com/my-account.html">Get this?</a>'); ?>)</p>
243
+ <h3><label for="email"><?php _e('CloudFlare API Email'); ?></label></h3>
244
+ <p><input id="email" name="email" type="text" size="50" maxlength="48" value="<?php echo get_option('cloudflare_api_email'); ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /> (<?php _e('<a href="https://www.cloudflare.com/my-account.html">Get this?</a>'); ?>)
245
+ <h3><label for="dev_mode"><?php _e('Development Mode'); ?></label> <span style="font-size:9pt;">(<a href="https://support.cloudflare.com/entries/22280726-what-does-cloudflare-development-mode-mean" " target="_blank">What is this?</a>)</span></h3>
246
+
247
+ <?php if ($curl_installed) { ?>
248
+ <div style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;">
249
+ <input type="radio" name="dev_mode" value="0" <? if ($dev_mode == "off") echo "checked"; ?>> Off
250
+ <input type="radio" name="dev_mode" value="1" <? if ($dev_mode == "on") echo "checked"; ?>> On
251
+ </div>
252
+ <?php } else { ?>
253
+ You cannot toggle development mode because cURL is not installed for your domain. Please contact a server administrator for assistance with installing cURL.
254
+ <?php } ?>
255
+
256
+ </p>
257
+ <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options &raquo;'); ?>" /></p>
258
+ </form>
259
+
260
+ <?php // </div> ?>
261
+ </div>
262
+ <?php
263
+ }
264
+
265
+ function cloudflare_admin_warnings() {
266
+
267
+ global $cloudflare_api_key, $cloudflare_api_email;
268
+ load_cloudflare_keys();
269
+ }
270
+
271
+ // Now actually allow CF to see when a comment is approved/not-approved.
272
+ function cloudflare_set_comment_status($id, $status) {
273
+ global $cf_api_host, $cf_api_port, $cloudflare_api_key, $cloudflare_api_email;
274
+ if (!$cf_api_host || !$cf_api_port) {
275
+ return;
276
+ }
277
+ load_cloudflare_keys();
278
+ if (!$cloudflare_api_key || !$cloudflare_api_email) {
279
+ return;
280
+ }
281
+
282
+ // ajax/external-event.html?email=ian@cloudflare.com&t=94606855d7e42adf3b9e2fd004c7660b941b8e55aa42d&evnt_v={%22dd%22:%22d%22}&evnt_t=WP_SPAM
283
+ $comment = get_comment($id);
284
+ $value = array("a" => $comment->comment_author,
285
+ "am" => $comment->comment_author_email,
286
+ "ip" => $comment->comment_author_IP,
287
+ "con" => substr($comment->comment_content, 0, 100));
288
+ $url = "/ajax/external-event.html?evnt_v=" . urlencode(json_encode($value)) . "&u=$cloudflare_api_email&tkn=$cloudflare_api_key&evnt_t=";
289
+
290
+ // If spam, send this info over to CloudFlare.
291
+ if ($status == "spam") {
292
+ $url .= "WP_SPAM";
293
+ $fp = @fsockopen($cf_api_host, $cf_api_port, $errno, $errstr, 30);
294
+ if ($fp) {
295
+ $out = "GET $url HTTP/1.1\r\n";
296
+ $out .= "Host: www.cloudflare.com\r\n";
297
+ $out .= "Connection: Close\r\n\r\n";
298
+ fwrite($fp, $out);
299
+ $res = "";
300
+ while (!feof($fp)) {
301
+ $res .= fgets($fp, 128);
302
+ }
303
+ fclose($fp);
304
+ }
305
+ }
306
+ }
307
+
308
+ add_action('wp_set_comment_status', 'cloudflare_set_comment_status', 1, 2);
309
+
310
+ function get_dev_mode_status($token, $email, $zone) {
311
+ $url = 'https://www.cloudflare.com/api_json.html';
312
+ $fields = array(
313
+ 'a'=>"zone_load",
314
+ 'tkn'=>$token,
315
+ 'email'=>$email,
316
+ 'z'=>$zone
317
+ );
318
+
319
+ foreach($fields as $key=>$value) {
320
+ $fields_string .= $key.'='.$value.'&';
321
+ }
322
+ rtrim($fields_string,'&');
323
+ $ch = curl_init();
324
+ curl_setopt($ch,CURLOPT_URL,$url);
325
+ curl_setopt($ch,CURLOPT_POST,count($fields));
326
+ curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
327
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
328
+ $result = curl_exec($ch);
329
+ $result = json_decode($result);
330
+ curl_close($ch);
331
+
332
+ if ($result->response->zone->obj->zone_status_class == "status-dev-mode") {
333
+ return "on";
334
+ }
335
+
336
+ return "off";
337
+ }
338
+
339
+ function set_dev_mode($token, $email, $zone, $value)
340
+ {
341
+ $url = 'https://www.cloudflare.com/api_json.html';
342
+ $fields = array(
343
+ 'a'=>"devmode",
344
+ 'tkn'=>$token,
345
+ 'email'=>$email,
346
+ 'z'=>$zone,
347
+ 'v'=>$value
348
+ );
349
+ foreach($fields as $key=>$value) {
350
+ $fields_string .= $key.'='.$value.'&';
351
+ }
352
+ rtrim($fields_string,'&');
353
+ $ch = curl_init();
354
+ curl_setopt($ch,CURLOPT_URL,$url);
355
+ curl_setopt($ch,CURLOPT_POST,count($fields));
356
+ curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
357
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
358
+ $result = curl_exec($ch);
359
+ $result = json_decode($result);
360
+ curl_close($ch);
361
+ }
362
+
363
+ function get_domain($token, $email, $raw_domain) {
364
+ $url = 'https://www.cloudflare.com/api_json.html';
365
+ $fields = array(
366
+ 'a'=>"zone_load_multi",
367
+ 'tkn'=>$token,
368
+ 'email'=>$email
369
+ );
370
+
371
+ foreach($fields as $key=>$value) {
372
+ $fields_string .= $key.'='.$value.'&';
373
+ }
374
+ rtrim($fields_string,'&');
375
+ $ch = curl_init();
376
+ curl_setopt($ch,CURLOPT_URL,$url);
377
+ curl_setopt($ch,CURLOPT_POST,count($fields));
378
+ curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
379
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
380
+ $result = curl_exec($ch);
381
+ $result = json_decode($result);
382
+ curl_close($ch);
383
+
384
+ $zone_count = $result->response->zones->count;
385
+ if ($zone_count > 0) {
386
+ for ($i = 0; $i < $zone_count; $i++) {
387
+ $zone_name = $result->response->zones->objs[$i]->zone_name;
388
+ if (strpos($raw_domain, $zone_name) !== FALSE){
389
+ return $zone_name;
390
+ }
391
+ }
392
+ }
393
+
394
+ return null;
395
+ }
396
+ ?>
ip_in_range.php ADDED
@@ -0,0 +1,214 @@
1
+ <?php
2
+
3
+ /*
4
+ * ip_in_range.php - Function to determine if an IP is located in a
5
+ * specific range as specified via several alternative
6
+ * formats.
7
+ *
8
+ * Network ranges can be specified as:
9
+ * 1. Wildcard format: 1.2.3.*
10
+ * 2. CIDR format: 1.2.3/24 OR 1.2.3.4/255.255.255.0
11
+ * 3. Start-End IP format: 1.2.3.0-1.2.3.255
12
+ *
13
+ * Return value BOOLEAN : ip_in_range($ip, $range);
14
+ *
15
+ * Copyright 2008: Paul Gregg <pgregg@pgregg.com>
16
+ * 10 January 2008
17
+ * Version: 1.2
18
+ *
19
+ * Source website: http://www.pgregg.com/projects/php/ip_in_range/
20
+ * Version 1.2
21
+ *
22
+ * This software is Donationware - if you feel you have benefited from
23
+ * the use of this tool then please consider a donation. The value of
24
+ * which is entirely left up to your discretion.
25
+ * http://www.pgregg.com/donate/
26
+ *
27
+ * Please do not remove this header, or source attibution from this file.
28
+ */
29
+
30
+ /*
31
+ * Modified by James Greene <james@cloudflare.com> to include IPV6 support
32
+ * (original version only supported IPV4).
33
+ * 21 May 2012
34
+ */
35
+
36
+
37
+ // decbin32
38
+ // In order to simplify working with IP addresses (in binary) and their
39
+ // netmasks, it is easier to ensure that the binary strings are padded
40
+ // with zeros out to 32 characters - IP addresses are 32 bit numbers
41
+ function decbin32 ($dec) {
42
+ return str_pad(decbin($dec), 32, '0', STR_PAD_LEFT);
43
+ }
44
+
45
+ // ipv4_in_range
46
+ // This function takes 2 arguments, an IP address and a "range" in several
47
+ // different formats.
48
+ // Network ranges can be specified as:
49
+ // 1. Wildcard format: 1.2.3.*
50
+ // 2. CIDR format: 1.2.3/24 OR 1.2.3.4/255.255.255.0
51
+ // 3. Start-End IP format: 1.2.3.0-1.2.3.255
52
+ // The function will return true if the supplied IP is within the range.
53
+ // Note little validation is done on the range inputs - it expects you to
54
+ // use one of the above 3 formats.
55
+ function ipv4_in_range($ip, $range) {
56
+ if (strpos($range, '/') !== false) {
57
+ // $range is in IP/NETMASK format
58
+ list($range, $netmask) = explode('/', $range, 2);
59
+ if (strpos($netmask, '.') !== false) {
60
+ // $netmask is a 255.255.0.0 format
61
+ $netmask = str_replace('*', '0', $netmask);
62
+ $netmask_dec = ip2long($netmask);
63
+ return ( (ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec) );
64
+ } else {
65
+ // $netmask is a CIDR size block
66
+ // fix the range argument
67
+ $x = explode('.', $range);
68
+ while(count($x)<4) $x[] = '0';
69
+ list($a,$b,$c,$d) = $x;
70
+ $range = sprintf("%u.%u.%u.%u", empty($a)?'0':$a, empty($b)?'0':$b,empty($c)?'0':$c,empty($d)?'0':$d);
71
+ $range_dec = ip2long($range);
72
+ $ip_dec = ip2long($ip);
73
+
74
+ # Strategy 1 - Create the netmask with 'netmask' 1s and then fill it to 32 with 0s
75
+ #$netmask_dec = bindec(str_pad('', $netmask, '1') . str_pad('', 32-$netmask, '0'));
76
+
77
+ # Strategy 2 - Use math to create it
78
+ $wildcard_dec = pow(2, (32-$netmask)) - 1;
79
+ $netmask_dec = ~ $wildcard_dec;
80
+
81
+ return (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec));
82
+ }
83
+ } else {
84
+ // range might be 255.255.*.* or 1.2.3.0-1.2.3.255
85
+ if (strpos($range, '*') !==false) { // a.b.*.* format
86
+ // Just convert to A-B format by setting * to 0 for A and 255 for B
87
+ $lower = str_replace('*', '0', $range);
88
+ $upper = str_replace('*', '255', $range);
89
+ $range = "$lower-$upper";
90
+ }
91
+
92
+ if (strpos($range, '-')!==false) { // A-B format
93
+ list($lower, $upper) = explode('-', $range, 2);
94
+ $lower_dec = (float)sprintf("%u",ip2long($lower));
95
+ $upper_dec = (float)sprintf("%u",ip2long($upper));
96
+ $ip_dec = (float)sprintf("%u",ip2long($ip));
97
+ return ( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) );
98
+ }
99
+ return false;
100
+ }
101
+ }
102
+
103
+ function ip2long6($ip) {
104
+ if (substr_count($ip, '::')) {
105
+ $ip = str_replace('::', str_repeat(':0000', 8 - substr_count($ip, ':')) . ':', $ip);
106
+ }
107
+
108
+ $ip = explode(':', $ip);
109
+ $r_ip = '';
110
+ foreach ($ip as $v) {
111
+ $r_ip .= str_pad(base_convert($v, 16, 2), 16, 0, STR_PAD_LEFT);
112
+ }
113
+
114
+ return base_convert($r_ip, 2, 10);
115
+ }
116
+
117
+ // Get the ipv6 full format and return it as a decimal value.
118
+ function get_ipv6_full($ip)
119
+ {
120
+ $pieces = explode ("/", $ip, 2);
121
+ $left_piece = $pieces[0];
122
+ $right_piece = $pieces[1];
123
+
124
+ // Extract out the main IP pieces
125
+ $ip_pieces = explode("::", $left_piece, 2);
126
+ $main_ip_piece = $ip_pieces[0];
127
+ $last_ip_piece = $ip_pieces[1];
128
+
129
+ // Pad out the shorthand entries.
130
+ $main_ip_pieces = explode(":", $main_ip_piece);
131
+ foreach($main_ip_pieces as $key=>$val) {
132
+ $main_ip_pieces[$key] = str_pad($main_ip_pieces[$key], 4, "0", STR_PAD_LEFT);
133
+ }
134
+
135
+ // Check to see if the last IP block (part after ::) is set
136
+ $last_piece = "";
137
+ $size = count($main_ip_pieces);
138
+ if (trim($last_ip_piece) != "") {
139
+ $last_piece = str_pad($last_ip_piece, 4, "0", STR_PAD_LEFT);
140
+
141
+ // Build the full form of the IPV6 address considering the last IP block set
142
+ for ($i = $size; $i < 7; $i++) {
143
+ $main_ip_pieces[$i] = "0000";
144
+ }
145
+ $main_ip_pieces[7] = $last_piece;
146
+ }
147
+ else {
148
+ // Build the full form of the IPV6 address
149
+ for ($i = $size; $i < 8; $i++) {
150
+ $main_ip_pieces[$i] = "0000";
151
+ }
152
+ }
153
+
154
+ // Rebuild the final long form IPV6 address
155
+ $final_ip = implode(":", $main_ip_pieces);
156
+
157
+ return ip2long6($final_ip);
158
+ }
159
+
160
+
161
+ // Determine whether the IPV6 address is within range.
162
+ // $ip is the IPV6 address in decimal format to check if its within the IP range created by the cloudflare IPV6 address, $range_ip.
163
+ // $ip and $range_ip are converted to full IPV6 format.
164
+ // Returns true if the IPV6 address, $ip, is within the range from $range_ip. False otherwise.
165
+ function ipv6_in_range($ip, $range_ip)
166
+ {
167
+ $pieces = explode ("/", $range_ip, 2);
168
+ $left_piece = $pieces[0];
169
+ $right_piece = $pieces[1];
170
+
171
+ // Extract out the main IP pieces
172
+ $ip_pieces = explode("::", $left_piece, 2);
173
+ $main_ip_piece = $ip_pieces[0];
174
+ $last_ip_piece = $ip_pieces[1];
175
+
176
+ // Pad out the shorthand entries.
177
+ $main_ip_pieces = explode(":", $main_ip_piece);
178
+ foreach($main_ip_pieces as $key=>$val) {
179
+ $main_ip_pieces[$key] = str_pad($main_ip_pieces[$key], 4, "0", STR_PAD_LEFT);
180
+ }
181
+
182
+ // Create the first and last pieces that will denote the IPV6 range.
183
+ $first = $main_ip_pieces;
184
+ $last = $main_ip_pieces;
185
+
186
+ // Check to see if the last IP block (part after ::) is set
187
+ $last_piece = "";
188
+ $size = count($main_ip_pieces);
189
+ if (trim($last_ip_piece) != "") {
190
+ $last_piece = str_pad($last_ip_piece, 4, "0", STR_PAD_LEFT);
191
+
192
+ // Build the full form of the IPV6 address considering the last IP block set
193
+ for ($i = $size; $i < 7; $i++) {
194
+ $first[$i] = "0000";
195
+ $last[$i] = "ffff";
196
+ }
197
+ $main_ip_pieces[7] = $last_piece;
198
+ }
199
+ else {
200
+ // Build the full form of the IPV6 address
201
+ for ($i = $size; $i < 8; $i++) {
202
+ $first[$i] = "0000";
203
+ $last[$i] = "ffff";
204
+ }
205
+ }
206
+
207
+ // Rebuild the final long form IPV6 address
208
+ $first = ip2long6(implode(":", $first));
209
+ $last = ip2long6(implode(":", $last));
210
+ $in_range = ($ip >= $first && $ip <= $last);
211
+
212
+ return $in_range;
213
+ }
214
+ ?>
readme.txt ADDED
@@ -0,0 +1,139 @@
1
+ === CloudFlare ===
2
+ Contributors: i3149, jchen329, jamescf
3
+ Tags: cloudflare, comments, spam, cdn, free, website, performance, speed
4
+ Requires at least: 2.8
5
+ Tested up to: 3.5
6
+ Stable tag: 1.3.10
7
+ License: GPLv2
8
+
9
+ The CloudFlare WordPress Plugin ensures your WordPress blog is running optimally on the CloudFlare platform.
10
+
11
+ == Description ==
12
+
13
+ CloudFlare has developed a plugin for WordPress. By using the CloudFlare WordPress Plugin, you receive:
14
+
15
+ * Correct IP Address information for comments posted to your site
16
+
17
+ * Better protection as spammers from your WordPress blog get reported to CloudFlare
18
+
19
+ THINGS YOU NEED TO KNOW:
20
+
21
+ * The main purpose of this plugin is to ensure you have no change to your originating IPs when using CloudFlare. Since CloudFlare acts a reverse proxy, connecting IPs now come from CloudFlare's range. This plugin will ensure you can continue to see the originating IP.
22
+
23
+ * Every time you click the 'spam' button on your blog, this threat information is sent to CloudFlare to ensure you are constantly getting the best site protection.
24
+
25
+ * We recommend that any user on WordPress and CloudFlare should use this plugin.
26
+
27
+ MORE INFORMATION ON CLOUDFLARE:
28
+
29
+ CloudFlare is a service that makes websites load faster and protects sites from online spammers and hackers. Any website with a root domain (ie www.mydomain.com) can use CloudFlare. On average, it takes less than 5 minutes to sign up. You can learn more here: [CloudFlare.com](https://www.cloudflare.com/overview.html).
30
+
31
+ == Installation ==
32
+
33
+ Upload the CloudFlare plugin to your blog, Activate it, and you're done!
34
+
35
+ You will also want to sign up your blog with CloudFlare.com
36
+
37
+ [Read more](http://blog.cloudflare.com/introducing-the-cloudflare-wordpress-plugin) on why we created this plugin.
38
+
39
+ == Changelog ==
40
+
41
+ = 1.3.10 =
42
+
43
+ * Added IP ranges.
44
+
45
+ = 1.3.9 =
46
+ * Made adjustment to syntax surrounding cURL detection for PHP installations that do not have short_open_tag enabled.
47
+
48
+ = 1.3.8 =
49
+ * Fixed issue with invalid header.
50
+ * Updated IP ranges
51
+ * Fixed support link
52
+
53
+ = 1.3.7 =
54
+ * Remove Database Optimizer related text.
55
+
56
+ = 1.3.6 =
57
+ * Remove Database Optimizer.
58
+
59
+ = 1.3.5 =
60
+ * Disable Development Mode option if cURL not installed. Will Use JSONP in future release to allow domains without cURL to use Development Mode.
61
+
62
+ = 1.3.4 =
63
+ * Add in IPV6 support and Development Mode option to wordpress plugin settings page. Remove cached IP range text file.
64
+
65
+ = 1.3.3 =
66
+ * Bump stable version number.
67
+
68
+ = 1.3.2.Beta =
69
+ * BETA RELEASE: IPv6 support - Pull the IPv6 range from https://www.cloudflare.com/ips-v6. Added Development Mode option to wordpress plugin settings page.
70
+
71
+ = 1.2.4 =
72
+ * Pull the IP range from https://www.cloudflare.com/ips-v4. Modified to keep all files within cloudflare plugin directory.
73
+
74
+ = 1.2.3 =
75
+ * Updated with new IP range
76
+
77
+ = 1.2.2 =
78
+ * Restricted database optimization to administrators
79
+
80
+ = 1.2.1 =
81
+ * Increased load priority to avoid conflicts with other plugins
82
+
83
+ = 1.2.0 =
84
+
85
+ * WP 3.3 compatibility.
86
+
87
+ = 1.1.9 =
88
+
89
+ * Includes latest CloudFlare IP allocation -- 108.162.192.0/18.
90
+
91
+ = 1.1.8 =
92
+
93
+ * WP 3.2 compatibility.
94
+
95
+ = 1.1.7 =
96
+
97
+ * Implements several security updates.
98
+
99
+ = 1.1.6 =
100
+
101
+ * Includes latest CloudFlare IP allocation -- 141.101.64.0/18.
102
+
103
+ = 1.1.5 =
104
+
105
+ * Includes latest CloudFlare IP allocation -- 103.22.200.0/22.
106
+
107
+ = 1.1.4 =
108
+
109
+ * Updated messaging.
110
+
111
+ = 1.1.3 =
112
+
113
+ * Better permission checking for DB optimizer.
114
+ * Added CloudFlare's latest /20 to the list of CloudFlare IP ranges.
115
+
116
+ = 1.1.2 =
117
+
118
+ * Fixed several broken help links.
119
+ * Fixed confusing error message.
120
+
121
+ = 1.1.1 =
122
+
123
+ * Fix for Admin menus which are breaking when page variable contains '-'.
124
+
125
+ = 1.1.0 =
126
+
127
+ * Added a box to input CloudFlare API credentials.
128
+ * Added a call to CloudFlare's report spam API when a comment is marked as spam.
129
+
130
+ = 1.0.1 =
131
+
132
+ * Fix to check that it is OK to add a header before adding one.
133
+
134
+ = 1.0.0 =
135
+
136
+ * Initial feature set
137
+ * Set RemoteIP header correctly.
138
+ * On comment spam, send the offending IP to CloudFlare.
139
+ * Clean up DB on load.