Cloudflare - Version 1.3.3

Version Description

  • Bump stable version number.
Download this release

Release Info

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

Version 1.3.3

Files changed (5) hide show
  1. cloudflare.php +356 -0
  2. ip_in_range.php +96 -0
  3. ipv4_list.txt +0 -0
  4. ipv6_list.txt +0 -0
  5. readme.txt +125 -0
cloudflare.php ADDED
@@ -0,0 +1,356 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3
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.3');
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
+ $plugin_dir = plugin_dir_path(__FILE__);
44
+
45
+ // Let's get the IPs from the official cloudflare IPv4 list URL, which has the latest up to date list.
46
+ $request_file_refresh = FALSE;
47
+ $ipv4_file_data = @file_get_contents($plugin_dir . "ipv4_list.txt");
48
+ $last_modified = @filemtime($plugin_dir . "ipv4_list.txt");
49
+ if ($last_modified === FALSE) {
50
+ $request_file_refresh = TRUE;
51
+ } else {
52
+ $time_since_last_update = time() - $last_modified;
53
+ if ($time_since_last_update > 86400) {
54
+ $request_file_refresh = TRUE;
55
+ }
56
+ }
57
+
58
+ if ($ipv4_file_data === FALSE || trim($ipv4_file_data) == "" || $request_file_refresh === TRUE) {
59
+ $live_ips_v4_list = @file_get_contents("https://www.cloudflare.com/ips-v4");
60
+
61
+ if ($live_ips_v4_list !== FALSE && trim($live_ips_v4_list) != "") {
62
+ @file_put_contents($plugin_dir . "ipv4_list.txt", $live_ips_v4_list);
63
+ $cf_ip_ranges = explode("\n", $live_ips_v4_list);
64
+ } else {
65
+ // Use the default static list for now, until we are able to access the live updated list again.
66
+ $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");
67
+ }
68
+ } else {
69
+ $cf_ip_ranges = explode("\n", $ipv4_file_data);
70
+ }
71
+
72
+ foreach ($cf_ip_ranges as $key=>$val) {
73
+ $cf_ip_ranges[$key] = trim($val);
74
+ }
75
+
76
+ $is_cf = ($_SERVER["HTTP_CF_CONNECTING_IP"])? TRUE: FALSE;
77
+
78
+ // Update the REMOTE_ADDR value if the current REMOTE_ADDR value is in the specified range.
79
+ foreach ($cf_ip_ranges as $range) {
80
+ if (ip_in_range($_SERVER["REMOTE_ADDR"], $range)) {
81
+ if ($_SERVER["HTTP_CF_CONNECTING_IP"]) {
82
+ $_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_CF_CONNECTING_IP"];
83
+ }
84
+ break;
85
+ }
86
+ }
87
+
88
+ // Let people know that the CF WP plugin is turned on.
89
+ if (!headers_sent()) {
90
+ header("X-CF-Powered-By: WP " . CLOUDFLARE_VERSION);
91
+ }
92
+ add_action('admin_menu', 'cloudflare_config_page');
93
+ cloudflare_admin_warnings();
94
+ }
95
+ add_action('init', 'cloudflare_init',1);
96
+
97
+ function cloudflare_admin_init() {
98
+
99
+ }
100
+
101
+ add_action('admin_init', 'cloudflare_admin_init');
102
+
103
+ function cloudflare_config_page() {
104
+ if ( function_exists('add_submenu_page') ) {
105
+ add_submenu_page('plugins.php', __('CloudFlare Configuration'), __('CloudFlare'), 'manage_options', 'cloudflare', 'cloudflare_conf');
106
+ }
107
+ }
108
+
109
+ function load_cloudflare_keys () {
110
+ global $cloudflare_api_key, $cloudflare_api_email;
111
+ if (!$cloudflare_api_key) {
112
+ $cloudflare_api_key = get_option('cloudflare_api_key');
113
+ }
114
+ if (!$cloudflare_api_email) {
115
+ $cloudflare_api_email = get_option('cloudflare_api_email');
116
+ }
117
+ }
118
+
119
+ function cloudflare_conf() {
120
+ if ( function_exists('current_user_can') && !current_user_can('manage_options') )
121
+ die(__('Cheatin&#8217; uh?'));
122
+ global $cloudflare_api_key, $cloudflare_api_email, $is_cf;
123
+ global $wpdb;
124
+
125
+ $db_results = array();
126
+
127
+ if ( isset($_POST['submit'])
128
+ && !($_POST['optimize'])
129
+ && check_admin_referer('cloudflare-db-api','cloudflare-db-api-nonce') ) {
130
+
131
+ if ( function_exists('current_user_can') && !current_user_can('manage_options') ) {
132
+ die(__('Cheatin&#8217; uh?'));
133
+ }
134
+
135
+ $key = $_POST['key'];
136
+ $email = $_POST['email'];
137
+
138
+ if ( empty($key) ) {
139
+ $key_status = 'empty';
140
+ $ms[] = 'new_key_empty';
141
+ delete_option('cloudflare_api_key');
142
+ } else {
143
+ $ms[] = 'new_key_valid';
144
+ update_option('cloudflare_api_key', esc_sql($key));
145
+ update_option('cloudflare_api_key_set_once', "TRUE");
146
+ }
147
+
148
+ if ( empty($email) || !is_email($email) ) {
149
+ $email_status = 'empty';
150
+ $ms[] = 'new_email_empty';
151
+ delete_option('cloudflare_api_email');
152
+ } else {
153
+ $ms[] = 'new_email_valid';
154
+ update_option('cloudflare_api_email', esc_sql($email));
155
+ update_option('cloudflare_api_email_set_once', "TRUE");
156
+ }
157
+
158
+ $messages = array(
159
+ 'new_key_empty' => array('color' => 'aa0', 'text' => __('Your key has been cleared.')),
160
+ 'new_key_valid' => array('color' => '2d2', 'text' => __('Your key has been verified. Happy blogging!')),
161
+ 'new_email_empty' => array('color' => 'aa0', 'text' => __('Your email has been cleared.')),
162
+ 'new_email_valid' => array('color' => '2d2', 'text' => __('Your email has been verified. Happy blogging!')),
163
+ );
164
+ } else if ( isset($_POST['submit'])
165
+ && isset($_POST['optimize'])
166
+ && check_admin_referer('cloudflare-db-opt','cloudflare-db-opt-nonce')) {
167
+
168
+ update_option('cloudflare_api_db_last_run', time());
169
+ if(current_user_can('administrator')) {
170
+ remove_action('admin_notices', 'cloudflare_warning');
171
+ $tables = $wpdb->get_col("SHOW TABLES");
172
+ foreach($tables as $table_name) {
173
+ $optimize = $wpdb->query("OPTIMIZE TABLE `$table_name`");
174
+ $analyze = $wpdb->query("ANALYZE TABLE `$table_name`");
175
+ if (!$optimize || !$analyze) {
176
+ $db_results[] = "Error optimizing $table_name";
177
+ }
178
+ }
179
+ if (count($db_results) == 0) {
180
+ $db_results[] = "All tables optimized without error.";
181
+ }
182
+ } else {
183
+ $db_results[] = "The current user does not have the permission \"manage_database\". Please run the command again with an appropriate user.";
184
+ }
185
+ }
186
+
187
+ ?>
188
+ <?php if ( !empty($_POST['submit'] ) && !($_POST['optimize']) ) { ?>
189
+ <div id="message" class="updated fade"><p><strong><?php _e('Options saved.') ?></strong></p></div>
190
+ <?php } else if ( isset($_POST['submit']) && isset($_POST['optimize']) ) {
191
+ foreach ($db_results as $res) {
192
+ ?><div id="message" class="updated fade"><p><strong><?php _e($res) ?></strong></p></div><?php
193
+ }
194
+ }
195
+ ?>
196
+ <div class="wrap">
197
+
198
+ <?php if ($is_cf) { ?>
199
+ <h3>You are currently using CloudFlare!</h3>
200
+ <?php } ?>
201
+
202
+ <h4><?php _e('CLOUDFLARE WORDPRESS PLUGIN:'); ?></h4>
203
+ <?php // <div class="narrow"> ?>
204
+
205
+ CloudFlare has developed a plugin for WordPress. By using the CloudFlare WordPress Plugin, you receive:
206
+ <ol>
207
+ <li>Correct IP Address information for comments posted to your site</li>
208
+ <li>Better protection as spammers from your WordPress blog get reported to CloudFlare</li>
209
+ <li>Optimization of your server database (optional)</li>
210
+ </ol>
211
+
212
+ <h4>VERSION COMPATIBILITY:</h4>
213
+
214
+ The plugin is compatible with WordPress version 2.8.6 and later. The plugin will not install unless you have a compatible platform.
215
+
216
+ <h4>THINGS YOU NEED TO KNOW:</h4>
217
+
218
+ <ol>
219
+ <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>
220
+
221
+ <li>This plugin can also help to ensure your server database is running optimally. If you are going to run the Database Optimizer associated with this plugin, then run it at a low traffic time. While the Database Optimizer is running, your site will go into Read Only mode, which means that you or your visitors will not be allowed to post. The optimizer should run quickly. Once the optimizer is done running, you will be able to post to your site again. To run the Database Optimizer, click the icon below.</li>
222
+
223
+ <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>
224
+
225
+ <li>We recommend that any user on CloudFlare with WordPress use this plugin. </li>
226
+
227
+ <li>NOTE: This plugin is complementary to Akismet and W3 Total Cache. We recommend that you continue to use those services.</li>
228
+
229
+ </ol>
230
+
231
+ <h4>MORE INFORMATION ON CLOUDFLARE:</h4>
232
+
233
+ 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>.
234
+
235
+ <?php
236
+ // if ($is_cf) {
237
+ ?>
238
+
239
+ <hr />
240
+
241
+ <form action="" method="post" id="cloudflare-conf">
242
+ <?php wp_nonce_field('cloudflare-db-api','cloudflare-db-api-nonce'); ?>
243
+ <?php if (get_option('cloudflare_api_key') && get_option('cloudflare_api_email')) { ?>
244
+ <?php } else { ?>
245
+ <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>
246
+ <?php } ?>
247
+ <?php if ($ms) { foreach ( $ms as $m ) { ?>
248
+ <p style="padding: .5em; color: #<?php echo $messages[$m]['color']; ?>; font-weight: bold;"><?php echo $messages[$m]['text']; ?></p>
249
+ <?php } } ?>
250
+ <h3><label for="key"><?php _e('CloudFlare API Key'); ?></label></h3>
251
+ <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>
252
+ <h3><label for="email"><?php _e('CloudFlare API Email'); ?></label></h3>
253
+ <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>'); ?>)</p>
254
+
255
+ <p class="submit"><input type="submit" name="submit" value="<?php _e('Update options &raquo;'); ?>" /></p>
256
+ </form>
257
+
258
+ <?php
259
+ // }
260
+ ?>
261
+
262
+ <form action="" method="post" id="cloudflare-db">
263
+ <?php wp_nonce_field('cloudflare-db-opt','cloudflare-db-opt-nonce'); ?>
264
+ <input type="hidden" name="optimize" value="1" />
265
+
266
+ <h4><label for="optimize_db"><?php _e('DATABASE OPTIMIZER (optional): Make your site run even faster.'); ?></label>
267
+ <input type="submit" name="submit" value="<?php _e('Run the optimizer'); ?>" /> (<?php _e('<a href="http://www.cloudflare.com/wiki/WordPressDBOptimizer">What is this?</a>'); ?>)</h4>
268
+
269
+ </form>
270
+
271
+ <?php // </div> ?>
272
+ </div>
273
+ <?php
274
+ }
275
+
276
+ function cloudflare_admin_warnings() {
277
+
278
+ global $cloudflare_api_key, $cloudflare_api_email;
279
+ load_cloudflare_keys();
280
+
281
+ /**
282
+ if ( !get_option('cloudflare_api_key_set_once') && !$cloudflare_api_key && !isset($_POST['submit']) ) {
283
+ function cloudflare_warning() {
284
+ echo "
285
+ <div id='cloudflare-warning' class='updated fade'><p><strong>".__('CloudFlare is almost ready.')."</strong> ".sprintf(__('You must <a href="%1$s">enter your CloudFlare API key</a> for it to work.'), "plugins.php?page=cloudflare")."</p></div>
286
+ ";
287
+ }
288
+ add_action('admin_notices', 'cloudflare_warning');
289
+ return;
290
+ } else if ( !get_option('cloudflare_api_key_set_once') && !$cloudflare_api_email && !isset($_POST['submit']) ) {
291
+ function cloudflare_warning() {
292
+ echo "
293
+ <div id='cloudflare-warning' class='updated fade'><p><strong>".__('CloudFlare is almost ready.')."</strong> ".sprintf(__('You must <a href="%1$s">enter your CloudFlare API email</a> for it to work.'), "plugins.php?page=cloudflare")."</p></div>
294
+ ";
295
+ }
296
+ add_action('admin_notices', 'cloudflare_warning');
297
+ return;
298
+ }
299
+ */
300
+
301
+ // Check to see if they should optimized their DB
302
+ $last_run_time = (int)get_option('cloudflare_api_db_last_run');
303
+ if (!$last_run_time) {
304
+ $last_run_time = time();
305
+ }
306
+ if (time() - $last_run_time > 5259487) { // 2 Months (avg)
307
+ function cloudflare_warning() {
308
+ echo "
309
+ <div id='cloudflare-warning' class='updated fade'><p><strong>".__('Your Database is due to be optimized again.')."</strong> ".sprintf(__('We recommend that you <a href="%1$s">run the CloudFlare optimizer</a> every two months to keep your blog running quickly. It\'s time to run it again.'), "plugins.php?page=cloudflare")."</p></div>
310
+ ";
311
+ }
312
+ add_action('admin_notices', 'cloudflare_warning');
313
+ return;
314
+ }
315
+ }
316
+
317
+ // Now actually allow CF to see when a comment is approved/not-approved.
318
+ function cloudflare_set_comment_status($id, $status) {
319
+ global $cf_api_host, $cf_api_port, $cloudflare_api_key, $cloudflare_api_email;
320
+ if (!$cf_api_host || !$cf_api_port) {
321
+ return;
322
+ }
323
+ load_cloudflare_keys();
324
+ if (!$cloudflare_api_key || !$cloudflare_api_email) {
325
+ return;
326
+ }
327
+
328
+ // ajax/external-event.html?email=ian@cloudflare.com&t=94606855d7e42adf3b9e2fd004c7660b941b8e55aa42d&evnt_v={%22dd%22:%22d%22}&evnt_t=WP_SPAM
329
+ $comment = get_comment($id);
330
+ $value = array("a" => $comment->comment_author,
331
+ "am" => $comment->comment_author_email,
332
+ "ip" => $comment->comment_author_IP,
333
+ "con" => substr($comment->comment_content, 0, 100));
334
+ $url = "/ajax/external-event.html?evnt_v=" . urlencode(json_encode($value)) . "&u=$cloudflare_api_email&tkn=$cloudflare_api_key&evnt_t=";
335
+
336
+ // If spam, send this info over to CloudFlare.
337
+ if ($status == "spam") {
338
+ $url .= "WP_SPAM";
339
+ $fp = @fsockopen($cf_api_host, $cf_api_port, $errno, $errstr, 30);
340
+ if ($fp) {
341
+ $out = "GET $url HTTP/1.1\r\n";
342
+ $out .= "Host: www.cloudflare.com\r\n";
343
+ $out .= "Connection: Close\r\n\r\n";
344
+ fwrite($fp, $out);
345
+ $res = "";
346
+ while (!feof($fp)) {
347
+ $res .= fgets($fp, 128);
348
+ }
349
+ fclose($fp);
350
+ }
351
+ }
352
+ }
353
+
354
+ add_action('wp_set_comment_status', 'cloudflare_set_comment_status', 1, 2);
355
+
356
+ ?>
ip_in_range.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ // decbin32
32
+ // In order to simplify working with IP addresses (in binary) and their
33
+ // netmasks, it is easier to ensure that the binary strings are padded
34
+ // with zeros out to 32 characters - IP addresses are 32 bit numbers
35
+ function decbin32 ($dec) {
36
+ return str_pad(decbin($dec), 32, '0', STR_PAD_LEFT);
37
+ }
38
+
39
+ // ip_in_range
40
+ // This function takes 2 arguments, an IP address and a "range" in several
41
+ // different formats.
42
+ // Network ranges can be specified as:
43
+ // 1. Wildcard format: 1.2.3.*
44
+ // 2. CIDR format: 1.2.3/24 OR 1.2.3.4/255.255.255.0
45
+ // 3. Start-End IP format: 1.2.3.0-1.2.3.255
46
+ // The function will return true if the supplied IP is within the range.
47
+ // Note little validation is done on the range inputs - it expects you to
48
+ // use one of the above 3 formats.
49
+ function ip_in_range($ip, $range) {
50
+ if (strpos($range, '/') !== false) {
51
+ // $range is in IP/NETMASK format
52
+ list($range, $netmask) = explode('/', $range, 2);
53
+ if (strpos($netmask, '.') !== false) {
54
+ // $netmask is a 255.255.0.0 format
55
+ $netmask = str_replace('*', '0', $netmask);
56
+ $netmask_dec = ip2long($netmask);
57
+ return ( (ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec) );
58
+ } else {
59
+ // $netmask is a CIDR size block
60
+ // fix the range argument
61
+ $x = explode('.', $range);
62
+ while(count($x)<4) $x[] = '0';
63
+ list($a,$b,$c,$d) = $x;
64
+ $range = sprintf("%u.%u.%u.%u", empty($a)?'0':$a, empty($b)?'0':$b,empty($c)?'0':$c,empty($d)?'0':$d);
65
+ $range_dec = ip2long($range);
66
+ $ip_dec = ip2long($ip);
67
+
68
+ # Strategy 1 - Create the netmask with 'netmask' 1s and then fill it to 32 with 0s
69
+ #$netmask_dec = bindec(str_pad('', $netmask, '1') . str_pad('', 32-$netmask, '0'));
70
+
71
+ # Strategy 2 - Use math to create it
72
+ $wildcard_dec = pow(2, (32-$netmask)) - 1;
73
+ $netmask_dec = ~ $wildcard_dec;
74
+
75
+ return (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec));
76
+ }
77
+ } else {
78
+ // range might be 255.255.*.* or 1.2.3.0-1.2.3.255
79
+ if (strpos($range, '*') !==false) { // a.b.*.* format
80
+ // Just convert to A-B format by setting * to 0 for A and 255 for B
81
+ $lower = str_replace('*', '0', $range);
82
+ $upper = str_replace('*', '255', $range);
83
+ $range = "$lower-$upper";
84
+ }
85
+
86
+ if (strpos($range, '-')!==false) { // A-B format
87
+ list($lower, $upper) = explode('-', $range, 2);
88
+ $lower_dec = (float)sprintf("%u",ip2long($lower));
89
+ $upper_dec = (float)sprintf("%u",ip2long($upper));
90
+ $ip_dec = (float)sprintf("%u",ip2long($ip));
91
+ return ( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) );
92
+ }
93
+ return false;
94
+ }
95
+ }
96
+ ?>
ipv4_list.txt ADDED
File without changes
ipv6_list.txt ADDED
File without changes
readme.txt ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.3
6
+ Stable tag: 1.3.3
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
+ Try out our brand new Beta version, 1.3.2.Beta!
14
+ Included in this version:
15
+ 1) IPv6 support.
16
+ 2) Added Development Mode option to CloudFlare WordPress plugin settings page.
17
+ <a href="http://downloads.wordpress.org/plugin/cloudflare.1.3.2.Beta.zip" title="Download CloudFlare 1.3.2.Beta WordPress Plugin">Download the 1.3.2.Beta version here!</a>
18
+
19
+ CloudFlare has developed a plugin for WordPress. By using the CloudFlare WordPress Plugin, you receive:
20
+
21
+ * Correct IP Address information for comments posted to your site
22
+
23
+ * Optimization of your server database
24
+
25
+ * Better protection as spammers from your WordPress blog get reported to CloudFlare
26
+
27
+ THINGS YOU NEED TO KNOW:
28
+
29
+ * 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.
30
+
31
+ * This plugin can also help to ensure your server database is running optimally. If you are going to run the Database Optimizer associated with this plugin, then run it at a low traffic time. While the database optimizer is running, your site will go into Read Only mode, which means that you or your visitors will not be allowed to post. The optimizer should run quickly. Once the optimizer is done running, you will be able to post to your site again.
32
+
33
+ * 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.
34
+
35
+ * We recommend that any user on WordPress and CloudFlare should use this plugin.
36
+
37
+ MORE INFORMATION ON CLOUDFLARE:
38
+
39
+ 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).
40
+
41
+ == Installation ==
42
+
43
+ Upload the CloudFlare plugin to your blog, Activate it, and you're done!
44
+
45
+ You will also want to sign up your blog with CloudFlare.com
46
+
47
+ [Read more](http://blog.cloudflare.com/introducing-the-cloudflare-wordpress-plugin) on why we created this plugin.
48
+
49
+ == Changelog ==
50
+
51
+ = 1.3.3 =
52
+ * Bump stable version number.
53
+
54
+ = 1.3.2.Beta =
55
+ * BETA RELEASE: IPv6 support - Pull the IPv6 range from https://www.cloudflare.com/ips-v6. Added Development Mode option to wordpress plugin settings page.
56
+
57
+ = 1.2.4 =
58
+ * Pull the IP range from https://www.cloudflare.com/ips-v4. Modified to keep all files within cloudflare plugin directory.
59
+
60
+ = 1.2.3 =
61
+ * Updated with new IP range
62
+
63
+ = 1.2.2 =
64
+ * Restricted database optimization to administrators
65
+
66
+ = 1.2.1 =
67
+ * Increased load priority to avoid conflicts with other plugins
68
+
69
+ = 1.2.0 =
70
+
71
+ * WP 3.3 compatibility.
72
+
73
+ = 1.1.9 =
74
+
75
+ * Includes latest CloudFlare IP allocation -- 108.162.192.0/18.
76
+
77
+ = 1.1.8 =
78
+
79
+ * WP 3.2 compatibility.
80
+
81
+ = 1.1.7 =
82
+
83
+ * Implements several security updates.
84
+
85
+ = 1.1.6 =
86
+
87
+ * Includes latest CloudFlare IP allocation -- 141.101.64.0/18.
88
+
89
+ = 1.1.5 =
90
+
91
+ * Includes latest CloudFlare IP allocation -- 103.22.200.0/22.
92
+
93
+ = 1.1.4 =
94
+
95
+ * Updated messaging.
96
+
97
+ = 1.1.3 =
98
+
99
+ * Better permission checking for DB optimizer.
100
+ * Added CloudFlare's latest /20 to the list of CloudFlare IP ranges.
101
+
102
+ = 1.1.2 =
103
+
104
+ * Fixed several broken help links.
105
+ * Fixed confusing error message.
106
+
107
+ = 1.1.1 =
108
+
109
+ * Fix for Admin menus which are breaking when page variable contains '-'.
110
+
111
+ = 1.1.0 =
112
+
113
+ * Added a box to input CloudFlare API credentials.
114
+ * Added a call to CloudFlare's report spam API when a comment is marked as spam.
115
+
116
+ = 1.0.1 =
117
+
118
+ * Fix to check that it is OK to add a header before adding one.
119
+
120
+ = 1.0.0 =
121
+
122
+ * Initial feature set
123
+ * Set RemoteIP header correctly.
124
+ * On comment spam, send the offending IP to CloudFlare.
125
+ * Clean up DB on load.