WP-Ban - Version 1.63

Version Description

N/A

Download this release

Release Info

Developer GamerZ
Plugin Icon WP-Ban
Version 1.63
Comparing to
See all releases

Code changes from version 1.62 to 1.63

Files changed (7) hide show
  1. ban-options.php +516 -533
  2. readme.txt +9 -4
  3. screenshot-1.png +0 -0
  4. screenshot-2.png +0 -0
  5. screenshot-3.png +0 -0
  6. screenshot-4.png +0 -0
  7. wp-ban.php +280 -289
ban-options.php CHANGED
@@ -1,534 +1,517 @@
1
- <?php
2
- /*
3
- +----------------------------------------------------------------+
4
- | |
5
- | WordPress Plugin: WP-Ban |
6
- | Copyright (c) 2012 Lester "GaMerZ" Chan |
7
- | |
8
- | File Written By: |
9
- | - Lester "GaMerZ" Chan |
10
- | - http://lesterchan.net |
11
- | |
12
- | File Information: |
13
- | - WP-Ban Options |
14
- | - wp-content/plugins/wp-ban/ban-options.php |
15
- | |
16
- +----------------------------------------------------------------+
17
- */
18
-
19
-
20
- ### Check Whether User Can Manage Ban Options
21
- if(!current_user_can('manage_options')) {
22
- die('Access Denied');
23
- }
24
-
25
-
26
- ### Variables
27
- $base_name = plugin_basename('wp-ban/ban-options.php');
28
- $base_page = 'admin.php?page='.$base_name;
29
- $admin_login = trim($current_user->user_login);
30
- $mode = trim($_GET['mode']);
31
- $ban_settings = array('banned_ips', 'banned_hosts', 'banned_stats', 'banned_message', 'banned_referers', 'banned_exclude_ips', 'banned_ips_range', 'banned_user_agents');
32
-
33
-
34
- ### Form Processing
35
- // Update Options
36
- if(!empty($_POST['Submit'])) {
37
- check_admin_referer('wp-ban_templates');
38
- $text = '';
39
- $update_ban_queries = array();
40
- $update_ban_text = array();
41
- $banned_ips_post = explode("\n", trim($_POST['banned_ips']));
42
- $banned_ips_range_post = explode("\n", trim($_POST['banned_ips_range']));
43
- $banned_hosts_post = explode("\n", trim($_POST['banned_hosts']));
44
- $banned_referers_post = explode("\n", trim($_POST['banned_referers']));
45
- $banned_user_agents_post = explode("\n", trim($_POST['banned_user_agents']));
46
- $banned_exclude_ips_post = explode("\n", trim($_POST['banned_exclude_ips']));
47
- $banned_message = trim($_POST['banned_template_message']);
48
- if(!empty($banned_ips_post)) {
49
- $banned_ips = array();
50
- foreach($banned_ips_post as $banned_ip) {
51
- if($admin_login == 'admin' && ($banned_ip == get_IP() || is_admin_ip($banned_ip))) {
52
- $text .= '<font color="blue">'.sprintf(__('This IP \'%s\' Belongs To The Admin And Will Not Be Added To Ban List', 'wp-ban'),$banned_ip).'</font><br />';
53
- } else {
54
- $banned_ips[] = trim($banned_ip);
55
- }
56
- }
57
- }
58
- if(!empty($banned_ips_range_post)) {
59
- $banned_ips_range = array();
60
- foreach($banned_ips_range_post as $banned_ip_range) {
61
- $range = explode('-', $banned_ip_range);
62
- $range_start = trim($range[0]);
63
- $range_end = trim($range[1]);
64
- if($admin_login == 'admin' && (check_ip_within_range(get_IP(), $range_start, $range_end))) {
65
- $text .= '<font color="blue">'.sprintf(__('The Admin\'s IP \'%s\' Fall Within This Range (%s - %s) And Will Not Be Added To Ban List', 'wp-ban'), get_IP(), $range_start, $range_end).'</font><br />';
66
- } else {
67
- $banned_ips_range[] = trim($banned_ip_range);
68
- }
69
- }
70
- }
71
- if(!empty($banned_hosts_post)) {
72
- $banned_hosts = array();
73
- foreach($banned_hosts_post as $banned_host) {
74
- if($admin_login == 'admin' && ($banned_host == @gethostbyaddr(get_IP()) || is_admin_hostname($banned_host))) {
75
- $text .= '<font color="blue">'.sprintf(__('This Hostname \'%s\' Belongs To The Admin And Will Not Be Added To Ban List', 'wp-ban'), $banned_host).'</font><br />';
76
- } else {
77
- $banned_hosts[] = trim($banned_host);
78
- }
79
- }
80
- }
81
- if(!empty($banned_referers_post)) {
82
- $banned_referers = array();
83
- foreach($banned_referers_post as $banned_referer) {
84
- if(is_admin_referer($banned_referer)) {
85
- $text .= '<font color="blue">'.sprintf(__('This Referer \'%s\' Belongs To This Site And Will Not Be Added To Ban List', 'wp-ban'), $banned_referer).'</font><br />';
86
- } else {
87
- $banned_referers[] = trim($banned_referer);
88
- }
89
- }
90
- }
91
- if(!empty($banned_user_agents_post)) {
92
- $banned_user_agents = array();
93
- foreach($banned_user_agents_post as $banned_user_agent) {
94
- if(is_admin_user_agent($banned_user_agent)) {
95
- $text .= '<font color="blue">'.sprintf(__('This User Agent \'%s\' Is Used By The Current Admin And Will Not Be Added To Ban List', 'wp-ban'), $banned_user_agent).'</font><br />';
96
- } else {
97
- $banned_user_agents[] = trim($banned_user_agent);
98
- }
99
- }
100
- }
101
- if(!empty($banned_exclude_ips_post)) {
102
- $banned_exclude_ips = array();
103
- foreach($banned_exclude_ips_post as $banned_exclude_ip) {
104
- $banned_exclude_ips[] = trim($banned_exclude_ip);
105
- }
106
- }
107
- $update_ban_queries[] = update_option('banned_ips', $banned_ips);
108
- $update_ban_queries[] = update_option('banned_ips_range', $banned_ips_range);
109
- $update_ban_queries[] = update_option('banned_hosts', $banned_hosts);
110
- $update_ban_queries[] = update_option('banned_referers', $banned_referers);
111
- $update_ban_queries[] = update_option('banned_user_agents', $banned_user_agents);
112
- $update_ban_queries[] = update_option('banned_exclude_ips', $banned_exclude_ips);
113
- $update_ban_queries[] = update_option('banned_message', $banned_message);
114
- $update_ban_text[] = __('Banned IPs', 'wp-ban');
115
- $update_ban_text[] = __('Banned IP Range', 'wp-ban');
116
- $update_ban_text[] = __('Banned Host Names', 'wp-ban');
117
- $update_ban_text[] = __('Banned Referers', 'wp-ban');
118
- $update_ban_text[] = __('Banned User Agents', 'wp-ban');
119
- $update_ban_text[] = __('Banned Excluded IPs', 'wp-ban');
120
- $update_ban_text[] = __('Banned Message', 'wp-ban');
121
- $i=0;
122
- foreach($update_ban_queries as $update_ban_query) {
123
- if($update_ban_query) {
124
- $text .= '<font color="green">'.$update_ban_text[$i].' '.__('Updated', 'wp-ban').'</font><br />';
125
- }
126
- $i++;
127
- }
128
- if(empty($text)) {
129
- $text = '<font color="red">'.__('No Ban Option Updated', 'wp-ban').'</font>';
130
- }
131
- }
132
- if(!empty($_POST['do'])) {
133
- // Decide What To Do
134
- switch($_POST['do']) {
135
- // Credits To Joe (Ttech) - http://blog.fileville.net/
136
- case __('Reset Ban Stats', 'wp-ban'):
137
- check_admin_referer('wp-ban_stats');
138
- if($_POST['reset_ban_stats'] == 'yes') {
139
- $banned_stats = array('users' => array(), 'count' => 0);
140
- update_option('banned_stats', $banned_stats);
141
- $text = '<font color="green">'.__('All IP Ban Stats And Total Ban Stat Reseted', 'wp-ban').'</font>';
142
- } else {
143
- $banned_stats = get_option('banned_stats');
144
- $delete_ips = (array) $_POST['delete_ips'];
145
- foreach($delete_ips as $delete_ip) {
146
- unset($banned_stats['users'][$delete_ip]);
147
- }
148
- update_option('banned_stats', $banned_stats);
149
- $text = '<font color="green">'.__('Selected IP Ban Stats Reseted', 'wp-ban').'</font>';
150
- }
151
- break;
152
- // Uninstall WP-Ban
153
- case __('UNINSTALL WP-Ban', 'wp-ban') :
154
- check_admin_referer('wp-ban_uninstall');
155
- if(trim($_POST['uninstall_ban_yes']) == 'yes') {
156
- echo '<div id="message" class="updated fade">';
157
- echo '<p>';
158
- foreach($ban_settings as $setting) {
159
- $delete_setting = delete_option($setting);
160
- if($delete_setting) {
161
- echo '<font color="green">';
162
- printf(__('Setting Key \'%s\' has been deleted.', 'wp-ban'), "<strong><em>{$setting}</em></strong>");
163
- echo '</font><br />';
164
- } else {
165
- echo '<font color="red">';
166
- printf(__('Error deleting Setting Key \'%s\'.', 'wp-ban'), "<strong><em>{$setting}</em></strong>");
167
- echo '</font><br />';
168
- }
169
- }
170
- echo '</p>';
171
- echo '</div>';
172
- $mode = 'end-UNINSTALL';
173
- }
174
- break;
175
- }
176
- }
177
-
178
-
179
- ### Determines Which Mode It Is
180
- switch($mode) {
181
- // Deactivating WP-Ban
182
- case 'end-UNINSTALL':
183
- $deactivate_url = 'plugins.php?action=deactivate&amp;plugin=wp-ban/wp-ban.php';
184
- if(function_exists('wp_nonce_url')) {
185
- $deactivate_url = wp_nonce_url($deactivate_url, 'deactivate-plugin_wp-ban/wp-ban.php');
186
- }
187
- echo '<div class="wrap">';
188
- echo '<h2>'.__('Uninstall WP-Ban', 'wp-ban').'</h2>';
189
- echo '<p><strong>'.sprintf(__('<a href="%s">Click Here</a> To Finish The Uninstallation And WP-Ban Will Be Deactivated Automatically.', 'wp-ban'), $deactivate_url).'</strong></p>';
190
- echo '</div>';
191
- break;
192
- // Main Page
193
- default:
194
- $banned_ips = get_option('banned_ips');
195
- $banned_ips_range = get_option('banned_ips_range');
196
- $banned_hosts = get_option('banned_hosts');
197
- $banned_referers = get_option('banned_referers');
198
- $banned_user_agents = get_option('banned_user_agents');
199
- $banned_exclude_ips = get_option('banned_exclude_ips');
200
- $banned_ips_display = '';
201
- $banned_ips_range_display = '';
202
- $banned_hosts_display = '';
203
- $banned_referers_display = '';
204
- $banned_exclude_ips_display = '';
205
- if(!empty($banned_ips)) {
206
- foreach($banned_ips as $banned_ip) {
207
- $banned_ips_display .= $banned_ip."\n";
208
- }
209
- }
210
- if(!empty($banned_ips_range)) {
211
- foreach($banned_ips_range as $banned_ip_range) {
212
- $banned_ips_range_display .= $banned_ip_range."\n";
213
- }
214
- }
215
- if(!empty($banned_hosts)) {
216
- foreach($banned_hosts as $banned_host) {
217
- $banned_hosts_display .= $banned_host."\n";
218
- }
219
- }
220
- if(!empty($banned_referers)) {
221
- foreach($banned_referers as $banned_referer) {
222
- $banned_referers_display .= $banned_referer."\n";
223
- }
224
- }
225
- if(!empty($banned_user_agents)) {
226
- foreach($banned_user_agents as $banned_user_agent) {
227
- $banned_user_agents_display .= $banned_user_agent."\n";
228
- }
229
- }
230
- if(!empty($banned_exclude_ips)) {
231
- foreach($banned_exclude_ips as $banned_exclude_ip) {
232
- $banned_exclude_ips_display .= $banned_exclude_ip."\n";
233
- }
234
- }
235
- $banned_ips_display = trim($banned_ips_display);
236
- $banned_ips_range_display = trim($banned_ips_range_display);
237
- $banned_hosts_display = trim($banned_hosts_display);
238
- $banned_referers_display = trim($banned_referers_display);
239
- $banned_user_agents_display = trim($banned_user_agents_display);
240
- $banned_exclude_ips_display = trim($banned_exclude_ips_display);
241
- $banned_stats = get_option('banned_stats');
242
- ?>
243
- <script type="text/javascript">
244
- /* <![CDATA[*/
245
- var checked = 0;
246
- function banned_default_templates(template) {
247
- var default_template;
248
- switch(template) {
249
- case "message":
250
- default_template = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" <?php echo str_replace('"', '\"', get_language_attributes()); ?>>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=<?php echo get_option('blog_charset'); ?>\" />\n<title>%SITE_NAME% - %SITE_URL%</title>\n</head>\n<body>\n<div id=\"wp-ban-container\">\n<p style=\"text-align: center; font-weight: bold;\"><?php _e('You Are Banned.', 'wp-ban'); ?></p>\n</div>\n</body>\n</html>";
251
- break;
252
- }
253
- jQuery("#banned_template_" + template).val(default_template);
254
- }
255
- function toggle_checkbox() {
256
- for(i = 0; i < <?php echo sizeof($banned_stats['users']); ?>; i++) {
257
- if(checked == 0) {
258
- jQuery("#ban-" + i).attr("checked", "checked");
259
- } else {
260
- jQuery("#ban-" + i).removeAttr("checked");
261
- }
262
- }
263
- if(checked == 0) {
264
- checked = 1;
265
- } else {
266
- checked = 0;
267
- }
268
- }
269
- jQuery(document).ready(function() {
270
- jQuery('#show_button').click(function(event)
271
- {
272
- event.preventDefault();
273
- var banned_template_message_el = jQuery('#banned_template_message');
274
- if(jQuery(banned_template_message_el).is(':hidden'))
275
- {
276
- jQuery(this).val('<?php _e('Show Current Banned Message', 'wp-ban'); ?>');
277
- jQuery('#banned_preview_message').empty();
278
- jQuery(banned_template_message_el).fadeIn('fast');
279
- }
280
- else
281
- {
282
- jQuery(this).val('<?php _e('Show Banned Message Template', 'wp-ban'); ?>');
283
- jQuery.ajax({type: 'GET', url: '<?php echo admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')); ?>', data: 'action=ban-admin', cache: false, success: function(data) {
284
- var html_message = data;
285
- jQuery(banned_template_message_el).fadeOut('fast', function() {
286
- jQuery(html_message).filter('#wp-ban-container').appendTo('#banned_preview_message');
287
- });
288
- }});
289
- }
290
- });
291
- });
292
- /* ]]> */
293
- </script>
294
- <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
295
- <!-- Ban Options -->
296
- <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
297
- <?php wp_nonce_field('wp-ban_templates'); ?>
298
- <div class="wrap">
299
- <?php screen_icon(); ?>
300
- <h2><?php _e('Ban Options', 'wp-ban'); ?></h2>
301
- <table class="widefat">
302
- <thead>
303
- <tr>
304
- <th><?php _e('Your Details', 'wp-ban'); ?></th>
305
- <th><?php _e('Value', 'wp-ban'); ?></th>
306
- </tr>
307
- </thead>
308
- <tr>
309
- <td><?php _e('IP', 'wp-ban'); ?>:</td>
310
- <td><strong><?php echo get_IP(); ?></strong></td>
311
- </tr>
312
- <tr class="alternate">
313
- <td><?php _e('Host Name', 'wp-ban'); ?>:</td>
314
- <td><strong><?php echo @gethostbyaddr(get_IP()); ?></strong></td>
315
- </tr>
316
- <tr>
317
- <td><?php _e('User Agent', 'wp-ban'); ?>:</td>
318
- <td><strong><?php echo $_SERVER['HTTP_USER_AGENT']; ?></strong></td>
319
- </tr>
320
- <tr class="alternate">
321
- <td><?php _e('Site URL', 'wp-ban'); ?>:</td>
322
- <td><strong><?php echo get_option('home'); ?></strong></td>
323
- </tr>
324
- <tr>
325
- <td valign="top" colspan="2" align="center">
326
- <?php _e('Please <strong>DO NOT</strong> ban yourself.', 'wp-ban'); ?>
327
- </td>
328
- </tr>
329
- </table>
330
- <p>&nbsp;</p>
331
- <table class="form-table">
332
- <tr>
333
- <td valign="top">
334
- <strong><?php _e('Banned IPs', 'wp-ban'); ?>:</strong><br />
335
- <?php _e('Use <strong>*</strong> for wildcards.', 'wp-ban'); ?><br />
336
- <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
337
- <?php _e('Examples:', 'wp-ban'); ?>
338
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">192.168.1.100</span></p>
339
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">192.168.1.*</span></p>
340
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">192.168.*.*</span></p>
341
- </td>
342
- <td>
343
- <textarea cols="40" rows="10" name="banned_ips" dir="ltr"><?php echo $banned_ips_display; ?></textarea>
344
- </td>
345
- </tr>
346
- <tr>
347
- <td valign="top">
348
- <strong><?php _e('Banned IP Range', 'wp-ban'); ?>:</strong><br />
349
- <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
350
- <?php _e('Examples:', 'wp-ban'); ?><br />
351
- <strong>&raquo;</strong> <span dir="ltr">192.168.1.1-192.168.1.255</span><br /><br />
352
- <?php _e('Notes:', 'wp-ban'); ?><br />
353
- <strong>&raquo;</strong> <?php _e('No Wildcards Allowed.', 'wp-ban'); ?><br />
354
- </td>
355
- <td>
356
- <textarea cols="40" rows="10" name="banned_ips_range" dir="ltr"><?php echo $banned_ips_range_display; ?></textarea>
357
- </td>
358
- </tr>
359
- <tr>
360
- <td valign="top">
361
- <strong><?php _e('Banned Host Names', 'wp-ban'); ?>:</strong><br />
362
- <?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
363
- <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
364
- <?php _e('Examples:', 'wp-ban'); ?>
365
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">*.sg</span></p>
366
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">*.cn</span></p>
367
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">*.th</span></p>
368
- </td>
369
- <td>
370
- <textarea cols="40" rows="10" name="banned_hosts" dir="ltr"><?php echo $banned_hosts_display; ?></textarea>
371
- </td>
372
- </tr>
373
- <tr>
374
- <td valign="top">
375
- <strong><?php _e('Banned Referers', 'wp-ban'); ?>:</strong><br />
376
- <?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
377
- <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
378
- <?php _e('Examples:', 'wp-ban'); ?><br />
379
- <strong>&raquo;</strong> <span dir="ltr">http://*.blogspot.com</span><br /><br />
380
- <?php _e('Notes:', 'wp-ban'); ?><br />
381
- <strong>&raquo;</strong> <?php _e('There are ways to bypass this method of banning.', 'wp-ban'); ?>
382
- </td>
383
- <td>
384
- <textarea cols="40" rows="10" name="banned_referers" dir="ltr"><?php echo $banned_referers_display; ?></textarea>
385
- </td>
386
- </tr>
387
- <tr>
388
- <td valign="top">
389
- <strong><?php _e('Banned User Agents', 'wp-ban'); ?>:</strong><br />
390
- <?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
391
- <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
392
- <?php _e('Examples:', 'wp-ban'); ?>
393
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">EmailSiphon*</span></p>
394
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">LMQueueBot*</span></p>
395
- <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">ContactBot*</span></p>
396
- <?php _e('Suggestions:', 'wp-ban'); ?><br />
397
- <strong>&raquo;</strong> <?php _e('See <a href="http://www.user-agents.org/">http://www.user-agents.org/</a>', 'wp-ban'); ?>
398
- </td>
399
- <td>
400
- <textarea cols="40" rows="10" name="banned_user_agents" dir="ltr"><?php echo $banned_user_agents_display; ?></textarea>
401
- </td>
402
- </tr>
403
- <tr>
404
- <td valign="top">
405
- <strong><?php _e('Banned Exclude IPs', 'wp-ban'); ?>:</strong><br />
406
- <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
407
- <?php _e('Examples:', 'wp-ban'); ?><br />
408
- <strong>&raquo;</strong> <span dir="ltr">192.168.1.100</span><br /><br />
409
- <?php _e('Notes:', 'wp-ban'); ?><br />
410
- <strong>&raquo;</strong> <?php _e('No Wildcards Allowed.', 'wp-ban'); ?><br />
411
- <strong>&raquo;</strong> <?php _e('These Users Will Not Get Banned.', 'wp-ban'); ?>
412
- </td>
413
- <td>
414
- <textarea cols="40" rows="10" name="banned_exclude_ips" dir="ltr"><?php echo $banned_exclude_ips_display; ?></textarea>
415
- </td>
416
- </tr>
417
- <tr>
418
- <td valign="top">
419
- <strong><?php _e('Banned Message', 'wp-ban'); ?>:</strong><br /><br /><br />
420
- <?php _e('Allowed Variables:', 'wp-ban'); ?>
421
- <p style="margin: 2px 0">- %SITE_NAME%</p>
422
- <p style="margin: 2px 0">- %SITE_URL%</p>
423
- <p style="margin: 2px 0">- %USER_ATTEMPTS_COUNT%</p>
424
- <p style="margin: 2px 0">- %USER_IP%</p>
425
- <p style="margin: 2px 0">- %USER_HOSTNAME%</p>
426
- <p style="margin: 2px 0">- %TOTAL_ATTEMPTS_COUNT%</p><br />
427
- <p><?php printf(__('Note: Your message must be within %s', 'wp-ban'), htmlspecialchars('<div id="wp-ban-container"></div>')); ?></p><br />
428
- <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-ban'); ?>" onclick="banned_default_templates('message');" class="button" /><br /><br />
429
- <input type="button" id="show_button" value="<?php _e('Show Current Banned Message', 'wp-ban'); ?>" class="button" /><br />
430
- </td>
431
- <td>
432
- <textarea cols="100" style="width: 100%;" rows="20" id="banned_template_message" name="banned_template_message"><?php echo stripslashes(get_option('banned_message')); ?></textarea>
433
- <div id="banned_preview_message"></div>
434
- </td>
435
- </tr>
436
- </table>
437
- <p style="text-align: center;">
438
- <input type="submit" name="Submit" class="button" value="<?php _e('Save Changes', 'wp-ban'); ?>" />
439
- </p>
440
- </div>
441
- </form>
442
- <p>&nbsp;</p>
443
-
444
- <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
445
- <?php wp_nonce_field('wp-ban_stats'); ?>
446
- <div class="wrap">
447
- <h3><?php _e('Ban Stats', 'wp-ban'); ?></h3>
448
- <br style="clear" />
449
- <table class="widefat">
450
- <thead>
451
- <tr>
452
- <th width="40%" style="text-align: center;"><?php _e('IPs', 'wp-ban'); ?></th>
453
- <th width="30%" style="text-align: center;"><?php _e('Attempts', 'wp-ban'); ?></th>
454
- <th width="30%"><input type="checkbox" id="toogle_checkbox" name="toogle_checkbox" value="1" onclick="toggle_checkbox();" />&nbsp;<label for="toogle_checkbox"><?php _e('Action', 'wp-ban'); ?></label></th>
455
- </tr>
456
- </thead>
457
- <?php
458
- // Credits To Joe (Ttech) - http://blog.fileville.net/
459
- if(!empty($banned_stats['users'])) {
460
- $i = 0;
461
- ksort($banned_stats['users']);
462
- foreach($banned_stats['users'] as $key => $value) {
463
- if($i%2 == 0) {
464
- $style = '';
465
- } else {
466
- $style = ' class="alternate"';
467
- }
468
- echo "<tr$style>\n";
469
- echo "<td style=\"text-align: center;\">$key</td>\n";
470
- echo "<td style=\"text-align: center;\">".number_format_i18n(intval($value))."</td>\n";
471
- echo "<td><input type=\"checkbox\" id=\"ban-$i\" name=\"delete_ips[]\" value=\"$key\" />&nbsp;<label for=\"ban-$i\">".__('Reset this IP ban stat?', 'wp-ban')."</label></td>\n";
472
- echo '</tr>'."\n";
473
- $i++;
474
- }
475
- } else {
476
- echo "<tr>\n";
477
- echo '<td colspan="3" align="center">'.__('No Attempts', 'wp-ban').'</td>'."\n";
478
- echo '</tr>'."\n";
479
- }
480
- ?>
481
- <tr class="thead">
482
- <td style="text-align: center;"><strong><?php _e('Total Attempts:', 'wp-ban'); ?></strong></td>
483
- <td style="text-align: center;"><strong><?php echo number_format_i18n(intval($banned_stats['count'])); ?></strong></td>
484
- <td><input type="checkbox" id="reset_ban_stats" name="reset_ban_stats" value="yes" />&nbsp;<label for="reset_ban_stats"><?php _e('Reset all IP ban stats and total ban stat?', 'wp-ban'); ?></label></td>
485
- </tr>
486
- </table>
487
- <p style="text-align: center;"><input type="submit" name="do" value="<?php _e('Reset Ban Stats', 'wp-ban'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Reset Ban Stats.', 'wp-ban'); ?>\n\n<?php _e('This Action Is Not Reversible. Are you sure?', 'wp-ban'); ?>')" /></p>
488
- </div>
489
- </form>
490
- <p>&nbsp;</p>
491
-
492
- <!-- Uninstall WP-Ban -->
493
- <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
494
- <?php wp_nonce_field('wp-ban_uninstall'); ?>
495
- <div class="wrap">
496
- <h3><?php _e('Uninstall WP-Ban', 'wp-ban'); ?></h3>
497
- <p>
498
- <?php _e('Deactivating WP-Ban plugin does not remove any data that may have been created, such as the ban options. To completely remove this plugin, you can uninstall it here.', 'wp-ban'); ?>
499
- </p>
500
- <p style="color: red">
501
- <strong><?php _e('WARNING:', 'wp-ban'); ?></strong><br />
502
- <?php _e('Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to back up all the data first.', 'wp-ban'); ?>
503
- </p>
504
- <p style="color: red">
505
- <strong><?php _e('The following WordPress Options will be DELETED:', 'wp-ban'); ?></strong><br />
506
- </p>
507
- <table class="widefat">
508
- <thead>
509
- <tr>
510
- <th><?php _e('WordPress Options', 'wp-ban'); ?></th>
511
- </tr>
512
- </thead>
513
- <tr>
514
- <td valign="top">
515
- <ol>
516
- <?php
517
- foreach($ban_settings as $settings) {
518
- echo '<li>'.$settings.'</li>'."\n";
519
- }
520
- ?>
521
- </ol>
522
- </td>
523
- </tr>
524
- </table>
525
- <p>&nbsp;</p>
526
- <p style="text-align: center;">
527
- <input type="checkbox" name="uninstall_ban_yes" value="yes" />&nbsp;<?php _e('Yes', 'wp-ban'); ?><br /><br />
528
- <input type="submit" name="do" value="<?php _e('UNINSTALL WP-Ban', 'wp-ban'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Uninstall WP-Ban From WordPress.\nThis Action Is Not Reversible.\n\n Choose [Cancel] To Stop, [OK] To Uninstall.', 'wp-ban'); ?>')" />
529
- </p>
530
- </div>
531
- </form>
532
- <?php
533
- } // End switch($mode)
534
  ?>
1
+ <?php
2
+ ### Check Whether User Can Manage Ban Options
3
+ if(!current_user_can('manage_options')) {
4
+ die('Access Denied');
5
+ }
6
+
7
+
8
+ ### Variables
9
+ $base_name = plugin_basename('wp-ban/ban-options.php');
10
+ $base_page = 'admin.php?page='.$base_name;
11
+ $admin_login = trim($current_user->user_login);
12
+ $mode = (isset($_GET['mode']) ? trim($_GET['mode']) : '');
13
+ $ban_settings = array('banned_ips', 'banned_hosts', 'banned_stats', 'banned_message', 'banned_referers', 'banned_exclude_ips', 'banned_ips_range', 'banned_user_agents');
14
+
15
+
16
+ ### Form Processing
17
+ // Update Options
18
+ if(!empty($_POST['Submit'])) {
19
+ check_admin_referer('wp-ban_templates');
20
+ $text = '';
21
+ $update_ban_queries = array();
22
+ $update_ban_text = array();
23
+ $banned_ips_post = explode("\n", trim($_POST['banned_ips']));
24
+ $banned_ips_range_post = explode("\n", trim($_POST['banned_ips_range']));
25
+ $banned_hosts_post = explode("\n", trim($_POST['banned_hosts']));
26
+ $banned_referers_post = explode("\n", trim($_POST['banned_referers']));
27
+ $banned_user_agents_post = explode("\n", trim($_POST['banned_user_agents']));
28
+ $banned_exclude_ips_post = explode("\n", trim($_POST['banned_exclude_ips']));
29
+ $banned_message = trim($_POST['banned_template_message']);
30
+ if(!empty($banned_ips_post)) {
31
+ $banned_ips = array();
32
+ foreach($banned_ips_post as $banned_ip) {
33
+ if($admin_login == 'admin' && ($banned_ip == get_IP() || is_admin_ip($banned_ip))) {
34
+ $text .= '<font color="blue">'.sprintf(__('This IP \'%s\' Belongs To The Admin And Will Not Be Added To Ban List', 'wp-ban'),$banned_ip).'</font><br />';
35
+ } else {
36
+ $banned_ips[] = trim($banned_ip);
37
+ }
38
+ }
39
+ }
40
+ if(!empty($banned_ips_range_post)) {
41
+ $banned_ips_range = array();
42
+ foreach($banned_ips_range_post as $banned_ip_range) {
43
+ $range = explode('-', $banned_ip_range);
44
+ $range_start = trim($range[0]);
45
+ $range_end = trim($range[1]);
46
+ if($admin_login == 'admin' && (check_ip_within_range(get_IP(), $range_start, $range_end))) {
47
+ $text .= '<font color="blue">'.sprintf(__('The Admin\'s IP \'%s\' Fall Within This Range (%s - %s) And Will Not Be Added To Ban List', 'wp-ban'), get_IP(), $range_start, $range_end).'</font><br />';
48
+ } else {
49
+ $banned_ips_range[] = trim($banned_ip_range);
50
+ }
51
+ }
52
+ }
53
+ if(!empty($banned_hosts_post)) {
54
+ $banned_hosts = array();
55
+ foreach($banned_hosts_post as $banned_host) {
56
+ if($admin_login == 'admin' && ($banned_host == @gethostbyaddr(get_IP()) || is_admin_hostname($banned_host))) {
57
+ $text .= '<font color="blue">'.sprintf(__('This Hostname \'%s\' Belongs To The Admin And Will Not Be Added To Ban List', 'wp-ban'), $banned_host).'</font><br />';
58
+ } else {
59
+ $banned_hosts[] = trim($banned_host);
60
+ }
61
+ }
62
+ }
63
+ if(!empty($banned_referers_post)) {
64
+ $banned_referers = array();
65
+ foreach($banned_referers_post as $banned_referer) {
66
+ if(is_admin_referer($banned_referer)) {
67
+ $text .= '<font color="blue">'.sprintf(__('This Referer \'%s\' Belongs To This Site And Will Not Be Added To Ban List', 'wp-ban'), $banned_referer).'</font><br />';
68
+ } else {
69
+ $banned_referers[] = trim($banned_referer);
70
+ }
71
+ }
72
+ }
73
+ if(!empty($banned_user_agents_post)) {
74
+ $banned_user_agents = array();
75
+ foreach($banned_user_agents_post as $banned_user_agent) {
76
+ if(is_admin_user_agent($banned_user_agent)) {
77
+ $text .= '<font color="blue">'.sprintf(__('This User Agent \'%s\' Is Used By The Current Admin And Will Not Be Added To Ban List', 'wp-ban'), $banned_user_agent).'</font><br />';
78
+ } else {
79
+ $banned_user_agents[] = trim($banned_user_agent);
80
+ }
81
+ }
82
+ }
83
+ if(!empty($banned_exclude_ips_post)) {
84
+ $banned_exclude_ips = array();
85
+ foreach($banned_exclude_ips_post as $banned_exclude_ip) {
86
+ $banned_exclude_ips[] = trim($banned_exclude_ip);
87
+ }
88
+ }
89
+ $update_ban_queries[] = update_option('banned_ips', $banned_ips);
90
+ $update_ban_queries[] = update_option('banned_ips_range', $banned_ips_range);
91
+ $update_ban_queries[] = update_option('banned_hosts', $banned_hosts);
92
+ $update_ban_queries[] = update_option('banned_referers', $banned_referers);
93
+ $update_ban_queries[] = update_option('banned_user_agents', $banned_user_agents);
94
+ $update_ban_queries[] = update_option('banned_exclude_ips', $banned_exclude_ips);
95
+ $update_ban_queries[] = update_option('banned_message', $banned_message);
96
+ $update_ban_text[] = __('Banned IPs', 'wp-ban');
97
+ $update_ban_text[] = __('Banned IP Range', 'wp-ban');
98
+ $update_ban_text[] = __('Banned Host Names', 'wp-ban');
99
+ $update_ban_text[] = __('Banned Referers', 'wp-ban');
100
+ $update_ban_text[] = __('Banned User Agents', 'wp-ban');
101
+ $update_ban_text[] = __('Banned Excluded IPs', 'wp-ban');
102
+ $update_ban_text[] = __('Banned Message', 'wp-ban');
103
+ $i=0;
104
+ foreach($update_ban_queries as $update_ban_query) {
105
+ if($update_ban_query) {
106
+ $text .= '<font color="green">'.$update_ban_text[$i].' '.__('Updated', 'wp-ban').'</font><br />';
107
+ }
108
+ $i++;
109
+ }
110
+ if(empty($text)) {
111
+ $text = '<font color="red">'.__('No Ban Option Updated', 'wp-ban').'</font>';
112
+ }
113
+ }
114
+ if(!empty($_POST['do'])) {
115
+ // Decide What To Do
116
+ switch($_POST['do']) {
117
+ // Credits To Joe (Ttech) - http://blog.fileville.net/
118
+ case __('Reset Ban Stats', 'wp-ban'):
119
+ check_admin_referer('wp-ban_stats');
120
+ if($_POST['reset_ban_stats'] == 'yes') {
121
+ $banned_stats = array('users' => array(), 'count' => 0);
122
+ update_option('banned_stats', $banned_stats);
123
+ $text = '<font color="green">'.__('All IP Ban Stats And Total Ban Stat Reseted', 'wp-ban').'</font>';
124
+ } else {
125
+ $banned_stats = get_option('banned_stats');
126
+ $delete_ips = (array) $_POST['delete_ips'];
127
+ foreach($delete_ips as $delete_ip) {
128
+ unset($banned_stats['users'][$delete_ip]);
129
+ }
130
+ update_option('banned_stats', $banned_stats);
131
+ $text = '<font color="green">'.__('Selected IP Ban Stats Reseted', 'wp-ban').'</font>';
132
+ }
133
+ break;
134
+ // Uninstall WP-Ban
135
+ case __('UNINSTALL WP-Ban', 'wp-ban') :
136
+ check_admin_referer('wp-ban_uninstall');
137
+ if(trim($_POST['uninstall_ban_yes']) == 'yes') {
138
+ echo '<div id="message" class="updated fade">';
139
+ echo '<p>';
140
+ foreach($ban_settings as $setting) {
141
+ $delete_setting = delete_option($setting);
142
+ if($delete_setting) {
143
+ echo '<font color="green">';
144
+ printf(__('Setting Key \'%s\' has been deleted.', 'wp-ban'), "<strong><em>{$setting}</em></strong>");
145
+ echo '</font><br />';
146
+ } else {
147
+ echo '<font color="red">';
148
+ printf(__('Error deleting Setting Key \'%s\'.', 'wp-ban'), "<strong><em>{$setting}</em></strong>");
149
+ echo '</font><br />';
150
+ }
151
+ }
152
+ echo '</p>';
153
+ echo '</div>';
154
+ $mode = 'end-UNINSTALL';
155
+ }
156
+ break;
157
+ }
158
+ }
159
+
160
+
161
+ ### Determines Which Mode It Is
162
+ switch($mode) {
163
+ // Deactivating WP-Ban
164
+ case 'end-UNINSTALL':
165
+ $deactivate_url = 'plugins.php?action=deactivate&amp;plugin=wp-ban/wp-ban.php';
166
+ if(function_exists('wp_nonce_url')) {
167
+ $deactivate_url = wp_nonce_url($deactivate_url, 'deactivate-plugin_wp-ban/wp-ban.php');
168
+ }
169
+ echo '<div class="wrap">';
170
+ echo '<h2>'.__('Uninstall WP-Ban', 'wp-ban').'</h2>';
171
+ echo '<p><strong>'.sprintf(__('<a href="%s">Click Here</a> To Finish The Uninstallation And WP-Ban Will Be Deactivated Automatically.', 'wp-ban'), $deactivate_url).'</strong></p>';
172
+ echo '</div>';
173
+ break;
174
+ // Main Page
175
+ default:
176
+ $banned_ips = get_option('banned_ips');
177
+ $banned_ips_range = get_option('banned_ips_range');
178
+ $banned_hosts = get_option('banned_hosts');
179
+ $banned_referers = get_option('banned_referers');
180
+ $banned_user_agents = get_option('banned_user_agents');
181
+ $banned_exclude_ips = get_option('banned_exclude_ips');
182
+ $banned_ips_display = '';
183
+ $banned_ips_range_display = '';
184
+ $banned_hosts_display = '';
185
+ $banned_referers_display = '';
186
+ $banned_user_agents_display = '';
187
+ $banned_exclude_ips_display = '';
188
+ if(!empty($banned_ips)) {
189
+ foreach($banned_ips as $banned_ip) {
190
+ $banned_ips_display .= $banned_ip."\n";
191
+ }
192
+ }
193
+ if(!empty($banned_ips_range)) {
194
+ foreach($banned_ips_range as $banned_ip_range) {
195
+ $banned_ips_range_display .= $banned_ip_range."\n";
196
+ }
197
+ }
198
+ if(!empty($banned_hosts)) {
199
+ foreach($banned_hosts as $banned_host) {
200
+ $banned_hosts_display .= $banned_host."\n";
201
+ }
202
+ }
203
+ if(!empty($banned_referers)) {
204
+ foreach($banned_referers as $banned_referer) {
205
+ $banned_referers_display .= $banned_referer."\n";
206
+ }
207
+ }
208
+ if(!empty($banned_user_agents)) {
209
+ foreach($banned_user_agents as $banned_user_agent) {
210
+ $banned_user_agents_display .= $banned_user_agent."\n";
211
+ }
212
+ }
213
+ if(!empty($banned_exclude_ips)) {
214
+ foreach($banned_exclude_ips as $banned_exclude_ip) {
215
+ $banned_exclude_ips_display .= $banned_exclude_ip."\n";
216
+ }
217
+ }
218
+ $banned_ips_display = trim($banned_ips_display);
219
+ $banned_ips_range_display = trim($banned_ips_range_display);
220
+ $banned_hosts_display = trim($banned_hosts_display);
221
+ $banned_referers_display = trim($banned_referers_display);
222
+ $banned_user_agents_display = trim($banned_user_agents_display);
223
+ $banned_exclude_ips_display = trim($banned_exclude_ips_display);
224
+ $banned_stats = get_option('banned_stats');
225
+ ?>
226
+ <script type="text/javascript">
227
+ /* <![CDATA[*/
228
+ var checked = 0;
229
+ function banned_default_templates(template) {
230
+ var default_template;
231
+ switch(template) {
232
+ case "message":
233
+ default_template = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" <?php echo str_replace('"', '\"', get_language_attributes()); ?>>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=<?php echo get_option('blog_charset'); ?>\" />\n<title>%SITE_NAME% - %SITE_URL%</title>\n</head>\n<body>\n<div id=\"wp-ban-container\">\n<p style=\"text-align: center; font-weight: bold;\"><?php _e('You Are Banned.', 'wp-ban'); ?></p>\n</div>\n</body>\n</html>";
234
+ break;
235
+ }
236
+ jQuery("#banned_template_" + template).val(default_template);
237
+ }
238
+ function toggle_checkbox() {
239
+ for(i = 0; i < <?php echo sizeof($banned_stats['users']); ?>; i++) {
240
+ if(checked == 0) {
241
+ jQuery("#ban-" + i).attr("checked", "checked");
242
+ } else {
243
+ jQuery("#ban-" + i).removeAttr("checked");
244
+ }
245
+ }
246
+ if(checked == 0) {
247
+ checked = 1;
248
+ } else {
249
+ checked = 0;
250
+ }
251
+ }
252
+ jQuery(document).ready(function() {
253
+ jQuery('#show_button').click(function(event)
254
+ {
255
+ event.preventDefault();
256
+ var banned_template_message_el = jQuery('#banned_template_message');
257
+ if(jQuery(banned_template_message_el).is(':hidden'))
258
+ {
259
+ jQuery(this).val('<?php _e('Show Current Banned Message', 'wp-ban'); ?>');
260
+ jQuery('#banned_preview_message').empty();
261
+ jQuery(banned_template_message_el).fadeIn('fast');
262
+ }
263
+ else
264
+ {
265
+ jQuery(this).val('<?php _e('Show Banned Message Template', 'wp-ban'); ?>');
266
+ jQuery.ajax({type: 'GET', url: '<?php echo admin_url('admin-ajax.php'); ?>', data: 'action=ban-admin', cache: false, success: function(data) {
267
+ var html_message = data;
268
+ jQuery(banned_template_message_el).fadeOut('fast', function() {
269
+ jQuery(html_message).filter('#wp-ban-container').appendTo('#banned_preview_message');
270
+ });
271
+ }});
272
+ }
273
+ });
274
+ });
275
+ /* ]]> */
276
+ </script>
277
+ <?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
278
+ <!-- Ban Options -->
279
+ <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
280
+ <?php wp_nonce_field('wp-ban_templates'); ?>
281
+ <div class="wrap">
282
+ <?php screen_icon(); ?>
283
+ <h2><?php _e('Ban Options', 'wp-ban'); ?></h2>
284
+ <table class="widefat">
285
+ <thead>
286
+ <tr>
287
+ <th><?php _e('Your Details', 'wp-ban'); ?></th>
288
+ <th><?php _e('Value', 'wp-ban'); ?></th>
289
+ </tr>
290
+ </thead>
291
+ <tr>
292
+ <td><?php _e('IP', 'wp-ban'); ?>:</td>
293
+ <td><strong><?php echo get_IP(); ?></strong></td>
294
+ </tr>
295
+ <tr class="alternate">
296
+ <td><?php _e('Host Name', 'wp-ban'); ?>:</td>
297
+ <td><strong><?php echo @gethostbyaddr(get_IP()); ?></strong></td>
298
+ </tr>
299
+ <tr>
300
+ <td><?php _e('User Agent', 'wp-ban'); ?>:</td>
301
+ <td><strong><?php echo $_SERVER['HTTP_USER_AGENT']; ?></strong></td>
302
+ </tr>
303
+ <tr class="alternate">
304
+ <td><?php _e('Site URL', 'wp-ban'); ?>:</td>
305
+ <td><strong><?php echo get_option('home'); ?></strong></td>
306
+ </tr>
307
+ <tr>
308
+ <td valign="top" colspan="2" align="center">
309
+ <?php _e('Please <strong>DO NOT</strong> ban yourself.', 'wp-ban'); ?>
310
+ </td>
311
+ </tr>
312
+ </table>
313
+ <p>&nbsp;</p>
314
+ <table class="form-table">
315
+ <tr>
316
+ <td valign="top">
317
+ <strong><?php _e('Banned IPs', 'wp-ban'); ?>:</strong><br />
318
+ <?php _e('Use <strong>*</strong> for wildcards.', 'wp-ban'); ?><br />
319
+ <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
320
+ <?php _e('Examples:', 'wp-ban'); ?>
321
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">192.168.1.100</span></p>
322
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">192.168.1.*</span></p>
323
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">192.168.*.*</span></p>
324
+ </td>
325
+ <td>
326
+ <textarea cols="40" rows="10" name="banned_ips" dir="ltr"><?php echo $banned_ips_display; ?></textarea>
327
+ </td>
328
+ </tr>
329
+ <tr>
330
+ <td valign="top">
331
+ <strong><?php _e('Banned IP Range', 'wp-ban'); ?>:</strong><br />
332
+ <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
333
+ <?php _e('Examples:', 'wp-ban'); ?><br />
334
+ <strong>&raquo;</strong> <span dir="ltr">192.168.1.1-192.168.1.255</span><br /><br />
335
+ <?php _e('Notes:', 'wp-ban'); ?><br />
336
+ <strong>&raquo;</strong> <?php _e('No Wildcards Allowed.', 'wp-ban'); ?><br />
337
+ </td>
338
+ <td>
339
+ <textarea cols="40" rows="10" name="banned_ips_range" dir="ltr"><?php echo $banned_ips_range_display; ?></textarea>
340
+ </td>
341
+ </tr>
342
+ <tr>
343
+ <td valign="top">
344
+ <strong><?php _e('Banned Host Names', 'wp-ban'); ?>:</strong><br />
345
+ <?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
346
+ <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
347
+ <?php _e('Examples:', 'wp-ban'); ?>
348
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">*.sg</span></p>
349
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">*.cn</span></p>
350
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">*.th</span></p>
351
+ </td>
352
+ <td>
353
+ <textarea cols="40" rows="10" name="banned_hosts" dir="ltr"><?php echo $banned_hosts_display; ?></textarea>
354
+ </td>
355
+ </tr>
356
+ <tr>
357
+ <td valign="top">
358
+ <strong><?php _e('Banned Referers', 'wp-ban'); ?>:</strong><br />
359
+ <?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
360
+ <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
361
+ <?php _e('Examples:', 'wp-ban'); ?><br />
362
+ <strong>&raquo;</strong> <span dir="ltr">http://*.blogspot.com</span><br /><br />
363
+ <?php _e('Notes:', 'wp-ban'); ?><br />
364
+ <strong>&raquo;</strong> <?php _e('There are ways to bypass this method of banning.', 'wp-ban'); ?>
365
+ </td>
366
+ <td>
367
+ <textarea cols="40" rows="10" name="banned_referers" dir="ltr"><?php echo $banned_referers_display; ?></textarea>
368
+ </td>
369
+ </tr>
370
+ <tr>
371
+ <td valign="top">
372
+ <strong><?php _e('Banned User Agents', 'wp-ban'); ?>:</strong><br />
373
+ <?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
374
+ <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
375
+ <?php _e('Examples:', 'wp-ban'); ?>
376
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">EmailSiphon*</span></p>
377
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">LMQueueBot*</span></p>
378
+ <p style="margin: 2px 0"><strong>&raquo;</strong> <span dir="ltr">ContactBot*</span></p>
379
+ <?php _e('Suggestions:', 'wp-ban'); ?><br />
380
+ <strong>&raquo;</strong> <?php _e('See <a href="http://www.user-agents.org/">http://www.user-agents.org/</a>', 'wp-ban'); ?>
381
+ </td>
382
+ <td>
383
+ <textarea cols="40" rows="10" name="banned_user_agents" dir="ltr"><?php echo $banned_user_agents_display; ?></textarea>
384
+ </td>
385
+ </tr>
386
+ <tr>
387
+ <td valign="top">
388
+ <strong><?php _e('Banned Exclude IPs', 'wp-ban'); ?>:</strong><br />
389
+ <?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
390
+ <?php _e('Examples:', 'wp-ban'); ?><br />
391
+ <strong>&raquo;</strong> <span dir="ltr">192.168.1.100</span><br /><br />
392
+ <?php _e('Notes:', 'wp-ban'); ?><br />
393
+ <strong>&raquo;</strong> <?php _e('No Wildcards Allowed.', 'wp-ban'); ?><br />
394
+ <strong>&raquo;</strong> <?php _e('These Users Will Not Get Banned.', 'wp-ban'); ?>
395
+ </td>
396
+ <td>
397
+ <textarea cols="40" rows="10" name="banned_exclude_ips" dir="ltr"><?php echo $banned_exclude_ips_display; ?></textarea>
398
+ </td>
399
+ </tr>
400
+ <tr>
401
+ <td valign="top">
402
+ <strong><?php _e('Banned Message', 'wp-ban'); ?>:</strong><br /><br /><br />
403
+ <?php _e('Allowed Variables:', 'wp-ban'); ?>
404
+ <p style="margin: 2px 0">- %SITE_NAME%</p>
405
+ <p style="margin: 2px 0">- %SITE_URL%</p>
406
+ <p style="margin: 2px 0">- %USER_ATTEMPTS_COUNT%</p>
407
+ <p style="margin: 2px 0">- %USER_IP%</p>
408
+ <p style="margin: 2px 0">- %USER_HOSTNAME%</p>
409
+ <p style="margin: 2px 0">- %TOTAL_ATTEMPTS_COUNT%</p><br />
410
+ <p><?php printf(__('Note: Your message must be within %s', 'wp-ban'), htmlspecialchars('<div id="wp-ban-container"></div>')); ?></p><br />
411
+ <input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-ban'); ?>" onclick="banned_default_templates('message');" class="button" /><br /><br />
412
+ <input type="button" id="show_button" value="<?php _e('Show Current Banned Message', 'wp-ban'); ?>" class="button" /><br />
413
+ </td>
414
+ <td>
415
+ <textarea cols="100" style="width: 100%;" rows="20" id="banned_template_message" name="banned_template_message"><?php echo stripslashes(get_option('banned_message')); ?></textarea>
416
+ <div id="banned_preview_message"></div>
417
+ </td>
418
+ </tr>
419
+ </table>
420
+ <p style="text-align: center;">
421
+ <input type="submit" name="Submit" class="button" value="<?php _e('Save Changes', 'wp-ban'); ?>" />
422
+ </p>
423
+ </div>
424
+ </form>
425
+ <p>&nbsp;</p>
426
+
427
+ <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
428
+ <?php wp_nonce_field('wp-ban_stats'); ?>
429
+ <div class="wrap">
430
+ <h3><?php _e('Ban Stats', 'wp-ban'); ?></h3>
431
+ <br style="clear" />
432
+ <table class="widefat">
433
+ <thead>
434
+ <tr>
435
+ <th width="40%" style="text-align: center;"><?php _e('IPs', 'wp-ban'); ?></th>
436
+ <th width="30%" style="text-align: center;"><?php _e('Attempts', 'wp-ban'); ?></th>
437
+ <th width="30%"><input type="checkbox" id="toogle_checkbox" name="toogle_checkbox" value="1" onclick="toggle_checkbox();" />&nbsp;<label for="toogle_checkbox"><?php _e('Action', 'wp-ban'); ?></label></th>
438
+ </tr>
439
+ </thead>
440
+ <?php
441
+ // Credits To Joe (Ttech) - http://blog.fileville.net/
442
+ if(!empty($banned_stats['users'])) {
443
+ $i = 0;
444
+ ksort($banned_stats['users']);
445
+ foreach($banned_stats['users'] as $key => $value) {
446
+ if($i%2 == 0) {
447
+ $style = '';
448
+ } else {
449
+ $style = ' class="alternate"';
450
+ }
451
+ echo "<tr$style>\n";
452
+ echo "<td style=\"text-align: center;\">$key</td>\n";
453
+ echo "<td style=\"text-align: center;\">".number_format_i18n(intval($value))."</td>\n";
454
+ echo "<td><input type=\"checkbox\" id=\"ban-$i\" name=\"delete_ips[]\" value=\"$key\" />&nbsp;<label for=\"ban-$i\">".__('Reset this IP ban stat?', 'wp-ban')."</label></td>\n";
455
+ echo '</tr>'."\n";
456
+ $i++;
457
+ }
458
+ } else {
459
+ echo "<tr>\n";
460
+ echo '<td colspan="3" align="center">'.__('No Attempts', 'wp-ban').'</td>'."\n";
461
+ echo '</tr>'."\n";
462
+ }
463
+ ?>
464
+ <tr class="thead">
465
+ <td style="text-align: center;"><strong><?php _e('Total Attempts:', 'wp-ban'); ?></strong></td>
466
+ <td style="text-align: center;"><strong><?php echo number_format_i18n(intval($banned_stats['count'])); ?></strong></td>
467
+ <td><input type="checkbox" id="reset_ban_stats" name="reset_ban_stats" value="yes" />&nbsp;<label for="reset_ban_stats"><?php _e('Reset all IP ban stats and total ban stat?', 'wp-ban'); ?></label></td>
468
+ </tr>
469
+ </table>
470
+ <p style="text-align: center;"><input type="submit" name="do" value="<?php _e('Reset Ban Stats', 'wp-ban'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Reset Ban Stats.', 'wp-ban'); ?>\n\n<?php _e('This Action Is Not Reversible. Are you sure?', 'wp-ban'); ?>')" /></p>
471
+ </div>
472
+ </form>
473
+ <p>&nbsp;</p>
474
+
475
+ <!-- Uninstall WP-Ban -->
476
+ <form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
477
+ <?php wp_nonce_field('wp-ban_uninstall'); ?>
478
+ <div class="wrap">
479
+ <h3><?php _e('Uninstall WP-Ban', 'wp-ban'); ?></h3>
480
+ <p>
481
+ <?php _e('Deactivating WP-Ban plugin does not remove any data that may have been created, such as the ban options. To completely remove this plugin, you can uninstall it here.', 'wp-ban'); ?>
482
+ </p>
483
+ <p style="color: red">
484
+ <strong><?php _e('WARNING:', 'wp-ban'); ?></strong><br />
485
+ <?php _e('Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to back up all the data first.', 'wp-ban'); ?>
486
+ </p>
487
+ <p style="color: red">
488
+ <strong><?php _e('The following WordPress Options will be DELETED:', 'wp-ban'); ?></strong><br />
489
+ </p>
490
+ <table class="widefat">
491
+ <thead>
492
+ <tr>
493
+ <th><?php _e('WordPress Options', 'wp-ban'); ?></th>
494
+ </tr>
495
+ </thead>
496
+ <tr>
497
+ <td valign="top">
498
+ <ol>
499
+ <?php
500
+ foreach($ban_settings as $settings) {
501
+ echo '<li>'.$settings.'</li>'."\n";
502
+ }
503
+ ?>
504
+ </ol>
505
+ </td>
506
+ </tr>
507
+ </table>
508
+ <p>&nbsp;</p>
509
+ <p style="text-align: center;">
510
+ <input type="checkbox" name="uninstall_ban_yes" value="yes" />&nbsp;<?php _e('Yes', 'wp-ban'); ?><br /><br />
511
+ <input type="submit" name="do" value="<?php _e('UNINSTALL WP-Ban', 'wp-ban'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Uninstall WP-Ban From WordPress.\nThis Action Is Not Reversible.\n\n Choose [Cancel] To Stop, [OK] To Uninstall.', 'wp-ban'); ?>')" />
512
+ </p>
513
+ </div>
514
+ </form>
515
+ <?php
516
+ } // End switch($mode)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
517
  ?>
readme.txt CHANGED
@@ -3,15 +3,17 @@ Contributors: GamerZ
3
  Donate link: http://lesterchan.net/site/donation/
4
  Tags: banned, ban, deny, denied, permission, ip, hostname, host, spam, bots, bot, exclude, referrer, url, referral, range
5
  Requires at least: 2.8
6
- Tested up to: 3.9
7
- Stable tag: trunk
8
 
9
  Ban users by IP, IP Range, host name, user agent and referrer url from visiting your WordPress's blog.
10
 
11
  == Description ==
12
-
13
  It will display a custom ban message when the banned IP, IP range, host name or referrer url that tries to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recorded on how many times they attempt to visit your blog. It allows wildcard matching too.
14
 
 
 
 
15
  = Development =
16
  * [https://github.com/lesterchan/wp-ban](https://github.com/lesterchan/wp-ban "https://github.com/lesterchan/wp-ban")
17
 
@@ -19,13 +21,16 @@ It will display a custom ban message when the banned IP, IP range, host name or
19
  * [http://dev.wp-plugins.org/browser/wp-ban/i18n/](http://dev.wp-plugins.org/browser/wp-ban/i18n/ "http://dev.wp-plugins.org/browser/wp-ban/i18n/")
20
 
21
  = Credits =
22
- * Right To Left Language Support by [Kambiz R. Khojasteh](http://persian-programming.com/ "Kambiz R. Khojasteh")
23
 
24
  = Donations =
25
  * I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
26
 
27
  == Changelog ==
28
 
 
 
 
29
  = Version 1.62 (12-03-2013) =
30
  * FIXED: Use a different modifier for preg_match() and use preg_quote() to escape regex
31
 
3
  Donate link: http://lesterchan.net/site/donation/
4
  Tags: banned, ban, deny, denied, permission, ip, hostname, host, spam, bots, bot, exclude, referrer, url, referral, range
5
  Requires at least: 2.8
6
+ Tested up to: 4.0
7
+ Stable tag: 1.63
8
 
9
  Ban users by IP, IP Range, host name, user agent and referrer url from visiting your WordPress's blog.
10
 
11
  == Description ==
 
12
  It will display a custom ban message when the banned IP, IP range, host name or referrer url that tries to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recorded on how many times they attempt to visit your blog. It allows wildcard matching too.
13
 
14
+ = Build Status =
15
+ [![Build Status](https://travis-ci.org/lesterchan/wp-ban.svg?branch=master)](https://travis-ci.org/lesterchan/wp-ban)
16
+
17
  = Development =
18
  * [https://github.com/lesterchan/wp-ban](https://github.com/lesterchan/wp-ban "https://github.com/lesterchan/wp-ban")
19
 
21
  * [http://dev.wp-plugins.org/browser/wp-ban/i18n/](http://dev.wp-plugins.org/browser/wp-ban/i18n/ "http://dev.wp-plugins.org/browser/wp-ban/i18n/")
22
 
23
  = Credits =
24
+ * Plugin icon by [Dave Gandy](http://fontawesome.io) from [Flaticon](http://www.flaticon.com)
25
 
26
  = Donations =
27
  * I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.
28
 
29
  == Changelog ==
30
 
31
+ = Version 1.63 =
32
+ * FIXED: Notices
33
+
34
  = Version 1.62 (12-03-2013) =
35
  * FIXED: Use a different modifier for preg_match() and use preg_quote() to escape regex
36
 
screenshot-1.png DELETED
Binary file
screenshot-2.png DELETED
Binary file
screenshot-3.png DELETED
Binary file
screenshot-4.png DELETED
Binary file
wp-ban.php CHANGED
@@ -1,290 +1,281 @@
1
- <?php
2
- /*
3
- Plugin Name: WP-Ban
4
- Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
- Description: Ban users by IP, IP Range, host name, user agent and referer url from visiting your WordPress's blog. It will display a custom ban message when the banned IP, IP range, host name, user agent or referer url tries to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recordered on how many times they attemp to visit your blog. It allows wildcard matching too.
6
- Version: 1.62
7
- Author: Lester 'GaMerZ' Chan
8
- Author URI: http://lesterchan.net
9
- Text Domain: wp-ban
10
- */
11
-
12
-
13
- /*
14
- Copyright 2013 Lester Chan (email : lesterchan@gmail.com)
15
-
16
- This program is free software; you can redistribute it and/or modify
17
- it under the terms of the GNU General Public License as published by
18
- the Free Software Foundation; either version 2 of the License, or
19
- (at your option) any later version.
20
-
21
- This program is distributed in the hope that it will be useful,
22
- but WITHOUT ANY WARRANTY; without even the implied warranty of
23
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
- GNU General Public License for more details.
25
-
26
- You should have received a copy of the GNU General Public License
27
- along with this program; if not, write to the Free Software
28
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
- */
30
-
31
-
32
- ### Create Text Domain For Translation
33
- add_action('init', 'ban_textdomain');
34
- function ban_textdomain() {
35
- load_plugin_textdomain('wp-ban', false, 'wp-ban');
36
- }
37
-
38
-
39
- ### Function: Ban Menu
40
- add_action('admin_menu', 'ban_menu');
41
- function ban_menu() {
42
- if (function_exists('add_management_page')) {
43
- add_options_page(__('Ban', 'wp-ban'), __('Ban', 'wp-ban'), 'manage_options', 'wp-ban/ban-options.php');
44
- }
45
- }
46
-
47
-
48
- ### Function: Get IP Address
49
- if(!function_exists('get_IP')) {
50
- function get_IP() {
51
- if(!empty($_SERVER['HTTP_CLIENT_IP'])) {
52
- $ip_address = $_SERVER['HTTP_CLIENT_IP'];
53
- } else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
54
- $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
55
- } else if(!empty($_SERVER['REMOTE_ADDR'])) {
56
- $ip_address = $_SERVER['REMOTE_ADDR'];
57
- } else {
58
- $ip_address = '';
59
- }
60
- if(strpos($ip_address, ',') !== false) {
61
- $ip_address = explode(',', $ip_address);
62
- $ip_address = $ip_address[0];
63
- }
64
- return esc_attr($ip_address);
65
- }
66
- }
67
-
68
-
69
- ### Function: Preview Banned Message
70
- add_action('wp_ajax_ban-admin', 'preview_banned_message');
71
- function preview_banned_message()
72
- {
73
- $banned_stats = get_option('banned_stats');
74
- $banned_message = stripslashes(get_option('banned_message'));
75
- $banned_message = str_replace("%SITE_NAME%", get_option('blogname'), $banned_message);
76
- $banned_message = str_replace("%SITE_URL%", get_option('siteurl'), $banned_message);
77
- $banned_message = str_replace("%USER_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['users'][get_IP()]), $banned_message);
78
- $banned_message = str_replace("%USER_IP%", get_IP(), $banned_message);
79
- $banned_message = str_replace("%USER_HOSTNAME%", @gethostbyaddr(get_IP()), $banned_message);
80
- $banned_message = str_replace("%TOTAL_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['count']), $banned_message);
81
- echo $banned_message;
82
- exit();
83
- }
84
-
85
-
86
- ### Function: Print Out Banned Message
87
- function print_banned_message() {
88
- // Credits To Joe (Ttech) - http://blog.fileville.net/
89
- $banned_stats = get_option('banned_stats');
90
- $banned_stats['count'] = intval($banned_stats['count']) + 1;
91
- $banned_stats['users'][get_IP()] = intval($banned_stats['users'][get_IP()]) + 1;
92
- update_option('banned_stats', $banned_stats);
93
- $banned_message = stripslashes(get_option('banned_message'));
94
- $banned_message = str_replace("%SITE_NAME%", get_option('blogname'), $banned_message);
95
- $banned_message = str_replace("%SITE_URL%", get_option('siteurl'), $banned_message);
96
- $banned_message = str_replace("%USER_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['users'][get_IP()]), $banned_message);
97
- $banned_message = str_replace("%USER_IP%", get_IP(), $banned_message);
98
- $banned_message = str_replace("%USER_HOSTNAME%", @gethostbyaddr(get_IP()), $banned_message);
99
- $banned_message = str_replace("%TOTAL_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['count']), $banned_message);
100
- echo $banned_message;
101
- exit();
102
- }
103
-
104
-
105
- ### Function: Process Banning
106
- function process_ban($banarray, $against) {
107
- if(!empty($banarray) && !empty($against)) {
108
- foreach($banarray as $cban) {
109
- if(preg_match_wildcard($cban, $against)) {
110
- print_banned_message();
111
- }
112
- }
113
- }
114
- return;
115
- }
116
-
117
-
118
- ### Function: Process Banned IP Range
119
- function process_ban_ip_range($banned_ips_range) {
120
- if(!empty($banned_ips_range)) {
121
- foreach($banned_ips_range as $banned_ip_range) {
122
- $range = explode('-', $banned_ip_range);
123
- $range_start = trim($range[0]);
124
- $range_end = trim($range[1]);
125
- if(check_ip_within_range(get_IP(), $range_start, $range_end)) {
126
- print_banned_message();
127
- break;
128
- }
129
- }
130
- }
131
- }
132
-
133
-
134
- ### Function: Banned
135
- add_action('init', 'banned');
136
- function banned() {
137
- $ip = get_IP();
138
- if($ip == 'unknown') {
139
- return;
140
- }
141
- $banned_ips = get_option('banned_ips');
142
- if(is_array($banned_ips))
143
- $banned_ips = array_filter($banned_ips);
144
-
145
- $banned_ips_range = get_option('banned_ips_range');
146
- if(is_array($banned_ips_range))
147
- $banned_ips_range = array_filter($banned_ips_range);
148
-
149
- $banned_hosts = get_option('banned_hosts');
150
- if(is_array($banned_hosts))
151
- $banned_hosts = array_filter($banned_hosts);
152
-
153
- $banned_referers = get_option('banned_referers');
154
- if(is_array($banned_referers))
155
- $banned_referers = array_filter($banned_referers);
156
-
157
- $banned_user_agents = get_option('banned_user_agents');
158
- if(is_array($banned_user_agents))
159
- $banned_user_agents = array_filter($banned_user_agents);
160
-
161
- $banned_exclude_ips = get_option('banned_exclude_ips');
162
- if(is_array($banned_exclude_ips))
163
- $banned_exclude_ips = array_filter($banned_exclude_ips);
164
-
165
- $is_excluded = false;
166
- if(!empty($banned_exclude_ips)) {
167
- foreach($banned_exclude_ips as $banned_exclude_ip) {
168
- if($ip == $banned_exclude_ip) {
169
- $is_excluded = true;
170
- break;
171
- }
172
- }
173
- }
174
-
175
- if(!$is_excluded) {
176
- if(!empty($banned_ips))
177
- process_ban($banned_ips, $ip);
178
- if(!empty($banned_ips_range))
179
- process_ban_ip_range($banned_ips_range);
180
- if(!empty($banned_hosts))
181
- process_ban($banned_hosts, @gethostbyaddr($ip));
182
- if(!empty($banned_referers))
183
- process_ban($banned_referers, $_SERVER['HTTP_REFERER']);
184
- if(!empty($banned_user_agents))
185
- process_ban($banned_user_agents, $_SERVER['HTTP_USER_AGENT']);
186
- }
187
- }
188
-
189
-
190
- ### Function: Check Whether Or Not The IP Address Belongs To Admin
191
- function is_admin_ip($check) {
192
- return preg_match_wildcard($check, get_IP());
193
- }
194
-
195
-
196
- ### Function: Check Whether IP Within A Given IP Range
197
- function check_ip_within_range($ip, $range_start, $range_end) {
198
- $range_start = ip2long($range_start);
199
- $range_end = ip2long($range_end);
200
- $ip = ip2long($ip);
201
- if($ip !== false && $ip >= $range_start && $ip <= $range_end) {
202
- return true;
203
- }
204
- return false;
205
- }
206
-
207
-
208
- ### Function: Check Whether Or Not The Hostname Belongs To Admin
209
- function is_admin_hostname($check) {
210
- return preg_match_wildcard($check, @gethostbyaddr(get_IP()));
211
- }
212
-
213
-
214
- ### Function: Check Whether Or Not The Referer Belongs To This Site
215
- function is_admin_referer($check) {
216
- $url_patterns = array(get_option('siteurl'), get_option('home'), get_option('siteurl').'/', get_option('home').'/', get_option('siteurl').'/ ', get_option('home').'/ ', $_SERVER['HTTP_REFERER']);
217
- foreach($url_patterns as $url) {
218
- if(preg_match_wildcard($check, $url)) {
219
- return true;
220
- }
221
- }
222
- return false;
223
- }
224
-
225
-
226
- ### Function: Check Whether Or Not The User Agent Is Used by Admin
227
- function is_admin_user_agent($check) {
228
- return preg_match_wildcard($check, $_SERVER['HTTP_USER_AGENT']);
229
- }
230
-
231
-
232
- ### Function: Returns page's language attributes depends on WordPress language
233
- function get_language_attributes($doctype = 'html') {
234
- ob_start();
235
- language_attributes();
236
- $language_attributes = ob_get_contents();
237
- ob_end_clean();
238
- return $language_attributes;
239
- }
240
-
241
-
242
- ### Function: Wildcard Check
243
- function preg_match_wildcard($regex, $subject) {
244
- $regex = preg_quote($regex, '#');
245
- $regex = str_replace('\*', '.*', $regex);
246
- if(preg_match("#^$regex$#", $subject))
247
- {
248
- return true;
249
- }
250
- else
251
- {
252
- return false;
253
- }
254
- }
255
-
256
-
257
- ### Function: Create Ban Options
258
- add_action('activate_wp-ban/wp-ban.php', 'ban_init');
259
- function ban_init() {
260
- global $wpdb;
261
- ban_textdomain();
262
- $banned_ips = array();
263
- $banned_ips_range = array();
264
- $banned_hosts = array();
265
- $banned_referers = array();
266
- $banned_exclude_ips = array();
267
- $banned_stats = array('users' => array(), 'count' => 0);
268
- add_option('banned_ips', $banned_ips, 'Banned IPs');
269
- add_option('banned_hosts', $banned_hosts, 'Banned Hosts');
270
- add_option('banned_stats', $banned_stats, 'WP-Ban Stats');
271
- add_option('banned_message', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
272
- '<html xmlns="http://www.w3.org/1999/xhtml" '.get_language_attributes().'>'."\n".
273
- '<head>'."\n".
274
- '<meta http-equiv="Content-Type" content="text/html; charset='.get_option('blog_charset').'" />'."\n".
275
- '<title>%SITE_NAME% - %SITE_URL%</title>'."\n".
276
- '</head>'."\n".
277
- '<body>'."\n".
278
- '<div id="wp-ban-container">'."\n".
279
- '<p style="text-align: center; font-weight: bold;">'.__('You Are Banned.', 'wp-ban').'</p>'."\n".
280
- '</div>'."\n".
281
- '</body>'."\n".
282
- '</html>', 'Banned Message');
283
- // Database Upgrade For WP-Ban 1.11
284
- add_option('banned_referers', $banned_referers, 'Banned Referers');
285
- add_option('banned_exclude_ips', $banned_exclude_ips, 'Banned Exclude IP');
286
- add_option('banned_ips_range', $banned_ips_range, 'Banned IP Range');
287
- // Database Upgrade For WP-Ban 1.30
288
- add_option('banned_user_agents', $banned_user_agents, 'Banned User Agents');
289
- }
290
  ?>
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-Ban
4
+ Plugin URI: http://lesterchan.net/portfolio/programming/php/
5
+ Description: Ban users by IP, IP Range, host name, user agent and referer url from visiting your WordPress's blog. It will display a custom ban message when the banned IP, IP range, host name, user agent or referer url tries to visit you blog. You can also exclude certain IPs from being banned. There will be statistics recordered on how many times they attemp to visit your blog. It allows wildcard matching too.
6
+ Version: 1.63
7
+ Author: Lester 'GaMerZ' Chan
8
+ Author URI: http://lesterchan.net
9
+ Text Domain: wp-ban
10
+ */
11
+
12
+
13
+ /*
14
+ Copyright 2014 Lester Chan (email : lesterchan@gmail.com)
15
+
16
+ This program is free software; you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation; either version 2 of the License, or
19
+ (at your option) any later version.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program; if not, write to the Free Software
28
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
+ */
30
+
31
+
32
+ ### Create Text Domain For Translation
33
+ add_action( 'plugins_loaded', 'ban_textdomain' );
34
+ function ban_textdomain() {
35
+ load_plugin_textdomain( 'wp-ban', false, dirname( plugin_basename( __FILE__ ) ) );
36
+ }
37
+
38
+
39
+ ### Function: Ban Menu
40
+ add_action('admin_menu', 'ban_menu');
41
+ function ban_menu() {
42
+ add_options_page(__('Ban', 'wp-ban'), __('Ban', 'wp-ban'), 'manage_options', 'wp-ban/ban-options.php');
43
+ }
44
+
45
+
46
+ ### Function: Get IP Address
47
+ if(!function_exists('get_IP')) {
48
+ function get_IP() {
49
+ if(!empty($_SERVER['HTTP_CLIENT_IP'])) {
50
+ $ip_address = $_SERVER['HTTP_CLIENT_IP'];
51
+ } else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
52
+ $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
53
+ } else if(!empty($_SERVER['REMOTE_ADDR'])) {
54
+ $ip_address = $_SERVER['REMOTE_ADDR'];
55
+ } else {
56
+ $ip_address = '';
57
+ }
58
+ if(strpos($ip_address, ',') !== false) {
59
+ $ip_address = explode(',', $ip_address);
60
+ $ip_address = $ip_address[0];
61
+ }
62
+ return esc_attr($ip_address);
63
+ }
64
+ }
65
+
66
+
67
+ ### Function: Preview Banned Message
68
+ add_action('wp_ajax_ban-admin', 'preview_banned_message');
69
+ function preview_banned_message()
70
+ {
71
+ $banned_stats = get_option('banned_stats');
72
+ $banned_message = stripslashes(get_option('banned_message'));
73
+ $banned_message = str_replace("%SITE_NAME%", get_option('blogname'), $banned_message);
74
+ $banned_message = str_replace("%SITE_URL%", get_option('siteurl'), $banned_message);
75
+ $banned_message = str_replace("%USER_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['users'][get_IP()]), $banned_message);
76
+ $banned_message = str_replace("%USER_IP%", get_IP(), $banned_message);
77
+ $banned_message = str_replace("%USER_HOSTNAME%", @gethostbyaddr(get_IP()), $banned_message);
78
+ $banned_message = str_replace("%TOTAL_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['count']), $banned_message);
79
+ echo $banned_message;
80
+ exit();
81
+ }
82
+
83
+
84
+ ### Function: Print Out Banned Message
85
+ function print_banned_message() {
86
+ // Credits To Joe (Ttech) - http://blog.fileville.net/
87
+ $banned_stats = get_option('banned_stats');
88
+ $banned_stats['count'] = intval($banned_stats['count']) + 1;
89
+ $banned_stats['users'][get_IP()] = intval($banned_stats['users'][get_IP()]) + 1;
90
+ update_option('banned_stats', $banned_stats);
91
+ $banned_message = stripslashes(get_option('banned_message'));
92
+ $banned_message = str_replace("%SITE_NAME%", get_option('blogname'), $banned_message);
93
+ $banned_message = str_replace("%SITE_URL%", get_option('siteurl'), $banned_message);
94
+ $banned_message = str_replace("%USER_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['users'][get_IP()]), $banned_message);
95
+ $banned_message = str_replace("%USER_IP%", get_IP(), $banned_message);
96
+ $banned_message = str_replace("%USER_HOSTNAME%", @gethostbyaddr(get_IP()), $banned_message);
97
+ $banned_message = str_replace("%TOTAL_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['count']), $banned_message);
98
+ echo $banned_message;
99
+ exit();
100
+ }
101
+
102
+
103
+ ### Function: Process Banning
104
+ function process_ban($banarray, $against) {
105
+ if(!empty($banarray) && !empty($against)) {
106
+ foreach($banarray as $cban) {
107
+ if(preg_match_wildcard($cban, $against)) {
108
+ print_banned_message();
109
+ }
110
+ }
111
+ }
112
+ return;
113
+ }
114
+
115
+
116
+ ### Function: Process Banned IP Range
117
+ function process_ban_ip_range($banned_ips_range) {
118
+ if(!empty($banned_ips_range)) {
119
+ foreach($banned_ips_range as $banned_ip_range) {
120
+ $range = explode('-', $banned_ip_range);
121
+ $range_start = trim($range[0]);
122
+ $range_end = trim($range[1]);
123
+ if(check_ip_within_range(get_IP(), $range_start, $range_end)) {
124
+ print_banned_message();
125
+ break;
126
+ }
127
+ }
128
+ }
129
+ }
130
+
131
+
132
+ ### Function: Banned
133
+ add_action('init', 'banned');
134
+ function banned() {
135
+ $ip = get_IP();
136
+ if($ip == 'unknown') {
137
+ return;
138
+ }
139
+ $banned_ips = get_option('banned_ips');
140
+ if(is_array($banned_ips))
141
+ $banned_ips = array_filter($banned_ips);
142
+
143
+ $banned_ips_range = get_option('banned_ips_range');
144
+ if(is_array($banned_ips_range))
145
+ $banned_ips_range = array_filter($banned_ips_range);
146
+
147
+ $banned_hosts = get_option('banned_hosts');
148
+ if(is_array($banned_hosts))
149
+ $banned_hosts = array_filter($banned_hosts);
150
+
151
+ $banned_referers = get_option('banned_referers');
152
+ if(is_array($banned_referers))
153
+ $banned_referers = array_filter($banned_referers);
154
+
155
+ $banned_user_agents = get_option('banned_user_agents');
156
+ if(is_array($banned_user_agents))
157
+ $banned_user_agents = array_filter($banned_user_agents);
158
+
159
+ $banned_exclude_ips = get_option('banned_exclude_ips');
160
+ if(is_array($banned_exclude_ips))
161
+ $banned_exclude_ips = array_filter($banned_exclude_ips);
162
+
163
+ $is_excluded = false;
164
+ if(!empty($banned_exclude_ips)) {
165
+ foreach($banned_exclude_ips as $banned_exclude_ip) {
166
+ if($ip == $banned_exclude_ip) {
167
+ $is_excluded = true;
168
+ break;
169
+ }
170
+ }
171
+ }
172
+
173
+ if(!$is_excluded) {
174
+ if(!empty($banned_ips))
175
+ process_ban($banned_ips, $ip);
176
+ if(!empty($banned_ips_range))
177
+ process_ban_ip_range($banned_ips_range);
178
+ if(!empty($banned_hosts))
179
+ process_ban($banned_hosts, @gethostbyaddr($ip));
180
+ if(!empty($banned_referers))
181
+ process_ban($banned_referers, $_SERVER['HTTP_REFERER']);
182
+ if(!empty($banned_user_agents))
183
+ process_ban($banned_user_agents, $_SERVER['HTTP_USER_AGENT']);
184
+ }
185
+ }
186
+
187
+
188
+ ### Function: Check Whether Or Not The IP Address Belongs To Admin
189
+ function is_admin_ip($check) {
190
+ return preg_match_wildcard($check, get_IP());
191
+ }
192
+
193
+
194
+ ### Function: Check Whether IP Within A Given IP Range
195
+ function check_ip_within_range($ip, $range_start, $range_end) {
196
+ $range_start = ip2long($range_start);
197
+ $range_end = ip2long($range_end);
198
+ $ip = ip2long($ip);
199
+ if($ip !== false && $ip >= $range_start && $ip <= $range_end) {
200
+ return true;
201
+ }
202
+ return false;
203
+ }
204
+
205
+
206
+ ### Function: Check Whether Or Not The Hostname Belongs To Admin
207
+ function is_admin_hostname($check) {
208
+ return preg_match_wildcard($check, @gethostbyaddr(get_IP()));
209
+ }
210
+
211
+
212
+ ### Function: Check Whether Or Not The Referer Belongs To This Site
213
+ function is_admin_referer($check) {
214
+ $url_patterns = array(get_option('siteurl'), get_option('home'), get_option('siteurl').'/', get_option('home').'/', get_option('siteurl').'/ ', get_option('home').'/ ', $_SERVER['HTTP_REFERER']);
215
+ foreach($url_patterns as $url) {
216
+ if(preg_match_wildcard($check, $url)) {
217
+ return true;
218
+ }
219
+ }
220
+ return false;
221
+ }
222
+
223
+
224
+ ### Function: Check Whether Or Not The User Agent Is Used by Admin
225
+ function is_admin_user_agent($check) {
226
+ return preg_match_wildcard($check, $_SERVER['HTTP_USER_AGENT']);
227
+ }
228
+
229
+
230
+ ### Function: Returns page's language attributes depends on WordPress language
231
+ function get_language_attributes($doctype = 'html') {
232
+ ob_start();
233
+ language_attributes();
234
+ $language_attributes = ob_get_contents();
235
+ ob_end_clean();
236
+ return $language_attributes;
237
+ }
238
+
239
+
240
+ ### Function: Wildcard Check
241
+ function preg_match_wildcard($regex, $subject) {
242
+ $regex = preg_quote($regex, '#');
243
+ $regex = str_replace('\*', '.*', $regex);
244
+ if(preg_match("#^$regex$#", $subject))
245
+ {
246
+ return true;
247
+ }
248
+ else
249
+ {
250
+ return false;
251
+ }
252
+ }
253
+
254
+
255
+ ### Function: Create Ban Options
256
+ add_action('activate_wp-ban/wp-ban.php', 'ban_init');
257
+ function ban_init() {
258
+ ban_textdomain();
259
+ add_option('banned_ips', array());
260
+ add_option('banned_hosts',array());
261
+ add_option('banned_stats', array('users' => array(), 'count' => 0));
262
+ add_option('banned_message', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
263
+ '<html xmlns="http://www.w3.org/1999/xhtml" '.get_language_attributes().'>'."\n".
264
+ '<head>'."\n".
265
+ '<meta http-equiv="Content-Type" content="text/html; charset='.get_option('blog_charset').'" />'."\n".
266
+ '<title>%SITE_NAME% - %SITE_URL%</title>'."\n".
267
+ '</head>'."\n".
268
+ '<body>'."\n".
269
+ '<div id="wp-ban-container">'."\n".
270
+ '<p style="text-align: center; font-weight: bold;">'.__('You Are Banned.', 'wp-ban').'</p>'."\n".
271
+ '</div>'."\n".
272
+ '</body>'."\n".
273
+ '</html>', 'Banned Message');
274
+ // Database Upgrade For WP-Ban 1.11
275
+ add_option('banned_referers', array());
276
+ add_option('banned_exclude_ips', array());
277
+ add_option('banned_ips_range', array());
278
+ // Database Upgrade For WP-Ban 1.30
279
+ add_option('banned_user_agents', array());
280
+ }
 
 
 
 
 
 
 
 
 
281
  ?>