Version Description
N/A
Download this release
Release Info
Developer | GamerZ |
Plugin | WP-Ban |
Version | 1.67 |
Comparing to | |
See all releases |
Code changes from version 1.66 to 1.67
- ban-options.php +386 -386
- readme.txt +5 -2
- wp-ban.php +192 -196
ban-options.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
### Check Whether User Can Manage Ban Options
|
3 |
if(!current_user_can('manage_options')) {
|
4 |
-
|
5 |
}
|
6 |
|
7 |
### Variables
|
@@ -11,132 +11,132 @@ $admin_login = trim($current_user->user_login);
|
|
11 |
|
12 |
### Form Processing
|
13 |
// Update Options
|
14 |
-
if(!empty($_POST['Submit'])) {
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
}
|
119 |
-
if(!empty($_POST['do'])) {
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
}
|
141 |
|
142 |
$banned_ips = get_option('banned_ips');
|
@@ -152,34 +152,34 @@ $banned_referers_display = '';
|
|
152 |
$banned_user_agents_display = '';
|
153 |
$banned_exclude_ips_display = '';
|
154 |
if(!empty($banned_ips)) {
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
}
|
159 |
if(!empty($banned_ips_range)) {
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
}
|
164 |
if(!empty($banned_hosts)) {
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
}
|
169 |
if(!empty($banned_referers)) {
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
}
|
174 |
if(!empty($banned_user_agents)) {
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
}
|
179 |
if(!empty($banned_exclude_ips)) {
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
}
|
184 |
$banned_ips_display = trim($banned_ips_display);
|
185 |
$banned_ips_range_display = trim($banned_ips_range_display);
|
@@ -192,53 +192,53 @@ $banned_options = get_option( 'banned_options' );
|
|
192 |
?>
|
193 |
<script type="text/javascript">
|
194 |
/* <![CDATA[*/
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
/* ]]> */
|
243 |
</script>
|
244 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
|
@@ -246,162 +246,162 @@ $banned_options = get_option( 'banned_options' );
|
|
246 |
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
|
247 |
<?php wp_nonce_field('wp-ban_templates'); ?>
|
248 |
<div class="wrap">
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
</div>
|
406 |
</form>
|
407 |
<p> </p>
|
@@ -409,47 +409,47 @@ $banned_options = get_option( 'banned_options' );
|
|
409 |
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
|
410 |
<?php wp_nonce_field('wp-ban_stats'); ?>
|
411 |
<div class="wrap">
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
</div>
|
454 |
</form>
|
455 |
-
<p> </p>
|
1 |
<?php
|
2 |
### Check Whether User Can Manage Ban Options
|
3 |
if(!current_user_can('manage_options')) {
|
4 |
+
die('Access Denied');
|
5 |
}
|
6 |
|
7 |
### Variables
|
11 |
|
12 |
### Form Processing
|
13 |
// Update Options
|
14 |
+
if( ! empty( $_POST['Submit'] ) ) {
|
15 |
+
check_admin_referer('wp-ban_templates');
|
16 |
+
$text = '';
|
17 |
|
18 |
+
$banned_options = array();
|
19 |
+
$banned_options['reverse_proxy'] = isset( $_POST['banned_option_reverse_proxy'] ) ? intval( $_POST['banned_option_reverse_proxy'] ) : 0;
|
20 |
|
21 |
+
$banned_ips_post = ! empty( $_POST['banned_ips'] ) ? explode( "\n", trim( $_POST['banned_ips'] ) ) : array();
|
22 |
+
$banned_ips_range_post = ! empty( $_POST['banned_ips_range'] ) ? explode( "\n", trim( $_POST['banned_ips_range'] ) ) : array();
|
23 |
+
$banned_hosts_post = ! empty( $_POST['banned_hosts'] ) ? explode( "\n", trim($_POST['banned_hosts'] ) ) : array();
|
24 |
+
$banned_referers_post = ! empty( $_POST['banned_referers'] ) ? explode( "\n", trim($_POST['banned_referers'] ) ) : array();
|
25 |
+
$banned_user_agents_post = ! empty( $_POST['banned_user_agents'] ) ? explode( "\n", trim($_POST['banned_user_agents'] ) ) : array();
|
26 |
+
$banned_exclude_ips_post = ! empty( $_POST['banned_exclude_ips'] ) ? explode( "\n", trim( $_POST['banned_exclude_ips'] ) ) : array();
|
27 |
+
$banned_message = ! empty( $_POST['banned_template_message'] ) ? trim( $_POST['banned_template_message'] ) : '';
|
28 |
|
29 |
+
if(!empty($banned_ips_post)) {
|
30 |
+
$banned_ips = array();
|
31 |
+
foreach($banned_ips_post as $banned_ip) {
|
32 |
+
if($admin_login == 'admin' && ($banned_ip == ban_get_ip() || is_admin_ip($banned_ip))) {
|
33 |
+
$text .= '<p style="color: blue;">'.sprintf(__('This IP \'%s\' Belongs To The Admin And Will Not Be Added To Ban List', 'wp-ban'),$banned_ip).'</p>';
|
34 |
+
} else {
|
35 |
+
$banned_ips[] = trim($banned_ip);
|
36 |
+
}
|
37 |
+
}
|
38 |
+
}
|
39 |
+
if( ! empty( $banned_ips_range_post ) ) {
|
40 |
+
$banned_ips_range = array();
|
41 |
+
foreach( $banned_ips_range_post as $banned_ip_range ) {
|
42 |
+
$range = explode( '-', $banned_ip_range );
|
43 |
+
if( sizeof( $range ) === 2 ) {
|
44 |
+
$range_start = trim( $range[0] );
|
45 |
+
$range_end = trim( $range[1] );
|
46 |
+
if( $admin_login === 'admin' && ( check_ip_within_range( ban_get_ip(), $range_start, $range_end ) ) ) {
|
47 |
+
$text .= '<p style="color: blue;">'.sprintf( __( 'The Admin\'s IP \'%s\' Fall Within This Range (%s - %s) And Will Not Be Added To Ban List', 'wp-ban' ), ban_get_ip(), $range_start, $range_end ).'</p>';
|
48 |
+
} else {
|
49 |
+
$banned_ips_range[] = trim( $banned_ip_range );
|
50 |
+
}
|
51 |
+
}
|
52 |
+
}
|
53 |
+
}
|
54 |
+
if(!empty($banned_hosts_post)) {
|
55 |
+
$banned_hosts = array();
|
56 |
+
foreach($banned_hosts_post as $banned_host) {
|
57 |
+
if($admin_login == 'admin' && ($banned_host == @gethostbyaddr(ban_get_ip()) || is_admin_hostname($banned_host))) {
|
58 |
+
$text .= '<p style="color: blue;">'.sprintf(__('This Hostname \'%s\' Belongs To The Admin And Will Not Be Added To Ban List', 'wp-ban'), $banned_host).'</p>';
|
59 |
+
} else {
|
60 |
+
$banned_hosts[] = trim($banned_host);
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
if(!empty($banned_referers_post)) {
|
65 |
+
$banned_referers = array();
|
66 |
+
foreach($banned_referers_post as $banned_referer) {
|
67 |
+
if(is_admin_referer($banned_referer)) {
|
68 |
+
$text .= '<p style="color: blue;">'.sprintf(__('This Referer \'%s\' Belongs To This Site And Will Not Be Added To Ban List', 'wp-ban'), $banned_referer).'</p>';
|
69 |
+
} else {
|
70 |
+
$banned_referers[] = trim($banned_referer);
|
71 |
+
}
|
72 |
+
}
|
73 |
+
}
|
74 |
+
if(!empty($banned_user_agents_post)) {
|
75 |
+
$banned_user_agents = array();
|
76 |
+
foreach($banned_user_agents_post as $banned_user_agent) {
|
77 |
+
if(is_admin_user_agent($banned_user_agent)) {
|
78 |
+
$text .= '<p style="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).'</p>';
|
79 |
+
} else {
|
80 |
+
$banned_user_agents[] = trim($banned_user_agent);
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
+
if(!empty($banned_exclude_ips_post)) {
|
85 |
+
$banned_exclude_ips = array();
|
86 |
+
foreach($banned_exclude_ips_post as $banned_exclude_ip) {
|
87 |
+
$banned_exclude_ips[] = trim($banned_exclude_ip);
|
88 |
+
}
|
89 |
+
}
|
90 |
+
$update_ban_queries = array();
|
91 |
+
$update_ban_queries[] = update_option( 'banned_options', $banned_options );
|
92 |
+
$update_ban_queries[] = update_option('banned_ips', $banned_ips);
|
93 |
+
$update_ban_queries[] = update_option('banned_ips_range', $banned_ips_range);
|
94 |
+
$update_ban_queries[] = update_option('banned_hosts', $banned_hosts);
|
95 |
+
$update_ban_queries[] = update_option('banned_referers', $banned_referers);
|
96 |
+
$update_ban_queries[] = update_option('banned_user_agents', $banned_user_agents);
|
97 |
+
$update_ban_queries[] = update_option('banned_exclude_ips', $banned_exclude_ips);
|
98 |
+
$update_ban_queries[] = update_option('banned_message', $banned_message);
|
99 |
+
$update_ban_text = array();
|
100 |
+
$update_ban_text[] = __( 'Banned Options', 'wp-ban' );
|
101 |
+
$update_ban_text[] = __('Banned IPs', 'wp-ban');
|
102 |
+
$update_ban_text[] = __('Banned IP Range', 'wp-ban');
|
103 |
+
$update_ban_text[] = __('Banned Host Names', 'wp-ban');
|
104 |
+
$update_ban_text[] = __('Banned Referers', 'wp-ban');
|
105 |
+
$update_ban_text[] = __('Banned User Agents', 'wp-ban');
|
106 |
+
$update_ban_text[] = __('Banned Excluded IPs', 'wp-ban');
|
107 |
+
$update_ban_text[] = __('Banned Message', 'wp-ban');
|
108 |
+
$i=0;
|
109 |
+
foreach($update_ban_queries as $update_ban_query) {
|
110 |
+
if($update_ban_query) {
|
111 |
+
$text .= '<p style="color: green;">'.$update_ban_text[$i].' '.__('Updated', 'wp-ban').'</p>';
|
112 |
+
}
|
113 |
+
$i++;
|
114 |
+
}
|
115 |
+
if(empty($text)) {
|
116 |
+
$text = '<p style="color: red;">'.__('No Ban Option Updated', 'wp-ban').'</p>';
|
117 |
+
}
|
118 |
}
|
119 |
+
if( ! empty( $_POST['do'] ) ) {
|
120 |
+
// Decide What To Do
|
121 |
+
switch( $_POST['do'] ) {
|
122 |
+
// Credits To Joe (Ttech) - http://blog.fileville.net/
|
123 |
+
case __('Reset Ban Stats', 'wp-ban'):
|
124 |
+
check_admin_referer('wp-ban_stats');
|
125 |
+
if( ! empty( $_POST['reset_ban_stats'] ) &&$_POST['reset_ban_stats'] === 'yes' ) {
|
126 |
+
$banned_stats = array('users' => array(), 'count' => 0);
|
127 |
+
update_option('banned_stats', $banned_stats);
|
128 |
+
$text = '<p style="color: green;">'.__('All IP Ban Stats And Total Ban Stat Reseted', 'wp-ban').'</p>';
|
129 |
+
} else {
|
130 |
+
$banned_stats = get_option('banned_stats');
|
131 |
+
$delete_ips = (array) $_POST['delete_ips'];
|
132 |
+
foreach($delete_ips as $delete_ip) {
|
133 |
+
unset($banned_stats['users'][$delete_ip]);
|
134 |
+
}
|
135 |
+
update_option('banned_stats', $banned_stats);
|
136 |
+
$text = '<p style="color: green;">'.__('Selected IP Ban Stats Reseted', 'wp-ban').'</p>';
|
137 |
+
}
|
138 |
+
break;
|
139 |
+
}
|
140 |
}
|
141 |
|
142 |
$banned_ips = get_option('banned_ips');
|
152 |
$banned_user_agents_display = '';
|
153 |
$banned_exclude_ips_display = '';
|
154 |
if(!empty($banned_ips)) {
|
155 |
+
foreach($banned_ips as $banned_ip) {
|
156 |
+
$banned_ips_display .= $banned_ip."\n";
|
157 |
+
}
|
158 |
}
|
159 |
if(!empty($banned_ips_range)) {
|
160 |
+
foreach($banned_ips_range as $banned_ip_range) {
|
161 |
+
$banned_ips_range_display .= $banned_ip_range."\n";
|
162 |
+
}
|
163 |
}
|
164 |
if(!empty($banned_hosts)) {
|
165 |
+
foreach($banned_hosts as $banned_host) {
|
166 |
+
$banned_hosts_display .= $banned_host."\n";
|
167 |
+
}
|
168 |
}
|
169 |
if(!empty($banned_referers)) {
|
170 |
+
foreach($banned_referers as $banned_referer) {
|
171 |
+
$banned_referers_display .= $banned_referer."\n";
|
172 |
+
}
|
173 |
}
|
174 |
if(!empty($banned_user_agents)) {
|
175 |
+
foreach($banned_user_agents as $banned_user_agent) {
|
176 |
+
$banned_user_agents_display .= $banned_user_agent."\n";
|
177 |
+
}
|
178 |
}
|
179 |
if(!empty($banned_exclude_ips)) {
|
180 |
+
foreach($banned_exclude_ips as $banned_exclude_ip) {
|
181 |
+
$banned_exclude_ips_display .= $banned_exclude_ip."\n";
|
182 |
+
}
|
183 |
}
|
184 |
$banned_ips_display = trim($banned_ips_display);
|
185 |
$banned_ips_range_display = trim($banned_ips_range_display);
|
192 |
?>
|
193 |
<script type="text/javascript">
|
194 |
/* <![CDATA[*/
|
195 |
+
var checked = 0;
|
196 |
+
function banned_default_templates(template) {
|
197 |
+
var default_template;
|
198 |
+
switch(template) {
|
199 |
+
case "message":
|
200 |
+
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>";
|
201 |
+
break;
|
202 |
+
}
|
203 |
+
jQuery("#banned_template_" + template).val(default_template);
|
204 |
+
}
|
205 |
+
function toggle_checkbox() {
|
206 |
+
for(i = 0; i < <?php echo sizeof($banned_stats['users']); ?>; i++) {
|
207 |
+
if(checked == 0) {
|
208 |
+
jQuery("#ban-" + i).attr("checked", "checked");
|
209 |
+
} else {
|
210 |
+
jQuery("#ban-" + i).removeAttr("checked");
|
211 |
+
}
|
212 |
+
}
|
213 |
+
if(checked == 0) {
|
214 |
+
checked = 1;
|
215 |
+
} else {
|
216 |
+
checked = 0;
|
217 |
+
}
|
218 |
+
}
|
219 |
+
jQuery(document).ready(function() {
|
220 |
+
jQuery('#show_button').click(function(event)
|
221 |
+
{
|
222 |
+
event.preventDefault();
|
223 |
+
var banned_template_message_el = jQuery('#banned_template_message');
|
224 |
+
if(jQuery(banned_template_message_el).is(':hidden'))
|
225 |
+
{
|
226 |
+
jQuery(this).val('<?php _e('Show Current Banned Message', 'wp-ban'); ?>');
|
227 |
+
jQuery('#banned_preview_message').empty();
|
228 |
+
jQuery(banned_template_message_el).fadeIn('fast');
|
229 |
+
}
|
230 |
+
else
|
231 |
+
{
|
232 |
+
jQuery(this).val('<?php _e('Show Banned Message Template', 'wp-ban'); ?>');
|
233 |
+
jQuery.ajax({type: 'GET', url: '<?php echo admin_url('admin-ajax.php'); ?>', data: 'action=ban-admin', cache: false, success: function(data) {
|
234 |
+
var html_message = data;
|
235 |
+
jQuery(banned_template_message_el).fadeOut('fast', function() {
|
236 |
+
jQuery(html_message).filter('#wp-ban-container').appendTo('#banned_preview_message');
|
237 |
+
});
|
238 |
+
}});
|
239 |
+
}
|
240 |
+
});
|
241 |
+
});
|
242 |
/* ]]> */
|
243 |
</script>
|
244 |
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
|
246 |
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
|
247 |
<?php wp_nonce_field('wp-ban_templates'); ?>
|
248 |
<div class="wrap">
|
249 |
+
<?php screen_icon(); ?>
|
250 |
+
<h2><?php _e('Ban Options', 'wp-ban'); ?></h2>
|
251 |
+
<table class="widefat">
|
252 |
+
<thead>
|
253 |
+
<tr>
|
254 |
+
<th><?php _e('Your Details', 'wp-ban'); ?></th>
|
255 |
+
<th><?php _e('Value', 'wp-ban'); ?></th>
|
256 |
+
</tr>
|
257 |
+
</thead>
|
258 |
+
<tr>
|
259 |
+
<td><?php _e('IP', 'wp-ban'); ?>:</td>
|
260 |
+
<td><strong><?php echo ban_get_ip(); ?></strong></td>
|
261 |
+
</tr>
|
262 |
+
<tr class="alternate">
|
263 |
+
<td><?php _e('Host Name', 'wp-ban'); ?>:</td>
|
264 |
+
<td><strong><?php echo @gethostbyaddr(ban_get_ip()); ?></strong></td>
|
265 |
+
</tr>
|
266 |
+
<tr>
|
267 |
+
<td><?php _e('User Agent', 'wp-ban'); ?>:</td>
|
268 |
+
<td><strong><?php echo $_SERVER['HTTP_USER_AGENT']; ?></strong></td>
|
269 |
+
</tr>
|
270 |
+
<tr class="alternate">
|
271 |
+
<td><?php _e('Site URL', 'wp-ban'); ?>:</td>
|
272 |
+
<td><strong><?php echo get_option('home'); ?></strong></td>
|
273 |
+
</tr>
|
274 |
+
<tr>
|
275 |
+
<td valign="top" colspan="2" align="center">
|
276 |
+
<?php _e('Please <strong>DO NOT</strong> ban yourself.', 'wp-ban'); ?>
|
277 |
+
</td>
|
278 |
+
</tr>
|
279 |
+
</table>
|
280 |
+
<p> </p>
|
281 |
+
<table class="form-table">
|
282 |
+
<tr>
|
283 |
+
<td width="40%" valign="top">
|
284 |
+
<strong><?php _e('Reverse Proxy Check', 'wp-ban'); ?>:</strong><br />
|
285 |
+
<?php _e( 'This will assume that incoming requests include the user\'s IP address in the HTTP_X_FORWARDED_FOR (and the request IP will be from your proxy).', 'wp-ban' ); ?>
|
286 |
+
</td>
|
287 |
+
<td width="60%">
|
288 |
+
<label>
|
289 |
+
<input type="checkbox" name="banned_option_reverse_proxy" value="1"<?php echo ( intval( $banned_options['reverse_proxy'] ) === 1 ) ? ' checked="checked"' : ''; ?> />
|
290 |
+
<?php _e( 'I am using a reverse proxy.', 'wp-ban' ); ?>
|
291 |
+
</label>
|
292 |
+
<p>
|
293 |
+
<?php _e( 'If you\'re not sure, leave this unchecked. Ticking this box when you don\'t have a reverse proxy will make it easy to bypass the IP ban.', 'wp-ban' ); ?>
|
294 |
+
</p>
|
295 |
+
</td>
|
296 |
+
</tr>
|
297 |
+
<tr>
|
298 |
+
<td valign="top">
|
299 |
+
<strong><?php _e('Banned IPs', 'wp-ban'); ?>:</strong><br />
|
300 |
+
<?php _e('Use <strong>*</strong> for wildcards.', 'wp-ban'); ?><br />
|
301 |
+
<?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
|
302 |
+
<?php _e('Examples:', 'wp-ban'); ?>
|
303 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">192.168.1.100</span></p>
|
304 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">192.168.1.*</span></p>
|
305 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">192.168.*.*</span></p>
|
306 |
+
</td>
|
307 |
+
<td>
|
308 |
+
<textarea cols="40" rows="10" name="banned_ips" dir="ltr"><?php echo $banned_ips_display; ?></textarea>
|
309 |
+
</td>
|
310 |
+
</tr>
|
311 |
+
<tr>
|
312 |
+
<td valign="top">
|
313 |
+
<strong><?php _e('Banned IP Range', 'wp-ban'); ?>:</strong><br />
|
314 |
+
<?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
|
315 |
+
<?php _e('Examples:', 'wp-ban'); ?><br />
|
316 |
+
<strong>»</strong> <span dir="ltr">192.168.1.1-192.168.1.255</span><br /><br />
|
317 |
+
<?php _e('Notes:', 'wp-ban'); ?><br />
|
318 |
+
<strong>»</strong> <?php _e('No Wildcards Allowed.', 'wp-ban'); ?><br />
|
319 |
+
</td>
|
320 |
+
<td>
|
321 |
+
<textarea cols="40" rows="10" name="banned_ips_range" dir="ltr"><?php echo $banned_ips_range_display; ?></textarea>
|
322 |
+
</td>
|
323 |
+
</tr>
|
324 |
+
<tr>
|
325 |
+
<td valign="top">
|
326 |
+
<strong><?php _e('Banned Host Names', 'wp-ban'); ?>:</strong><br />
|
327 |
+
<?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
|
328 |
+
<?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
|
329 |
+
<?php _e('Examples:', 'wp-ban'); ?>
|
330 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">*.sg</span></p>
|
331 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">*.cn</span></p>
|
332 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">*.th</span></p>
|
333 |
+
</td>
|
334 |
+
<td>
|
335 |
+
<textarea cols="40" rows="10" name="banned_hosts" dir="ltr"><?php echo $banned_hosts_display; ?></textarea>
|
336 |
+
</td>
|
337 |
+
</tr>
|
338 |
+
<tr>
|
339 |
+
<td valign="top">
|
340 |
+
<strong><?php _e('Banned Referers', 'wp-ban'); ?>:</strong><br />
|
341 |
+
<?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
|
342 |
+
<?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
|
343 |
+
<?php _e('Examples:', 'wp-ban'); ?><br />
|
344 |
+
<strong>»</strong> <span dir="ltr">http://*.blogspot.com</span><br /><br />
|
345 |
+
<?php _e('Notes:', 'wp-ban'); ?><br />
|
346 |
+
<strong>»</strong> <?php _e('There are ways to bypass this method of banning.', 'wp-ban'); ?>
|
347 |
+
</td>
|
348 |
+
<td>
|
349 |
+
<textarea cols="40" rows="10" name="banned_referers" dir="ltr"><?php echo $banned_referers_display; ?></textarea>
|
350 |
+
</td>
|
351 |
+
</tr>
|
352 |
+
<tr>
|
353 |
+
<td valign="top">
|
354 |
+
<strong><?php _e('Banned User Agents', 'wp-ban'); ?>:</strong><br />
|
355 |
+
<?php _e('Use <strong>*</strong> for wildcards', 'wp-ban'); ?>.<br />
|
356 |
+
<?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
|
357 |
+
<?php _e('Examples:', 'wp-ban'); ?>
|
358 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">EmailSiphon*</span></p>
|
359 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">LMQueueBot*</span></p>
|
360 |
+
<p style="margin: 2px 0"><strong>»</strong> <span dir="ltr">ContactBot*</span></p>
|
361 |
+
<?php _e('Suggestions:', 'wp-ban'); ?><br />
|
362 |
+
<strong>»</strong> <?php _e('See <a href="http://www.user-agents.org/">http://www.user-agents.org/</a>', 'wp-ban'); ?>
|
363 |
+
</td>
|
364 |
+
<td>
|
365 |
+
<textarea cols="40" rows="10" name="banned_user_agents" dir="ltr"><?php echo $banned_user_agents_display; ?></textarea>
|
366 |
+
</td>
|
367 |
+
</tr>
|
368 |
+
<tr>
|
369 |
+
<td valign="top">
|
370 |
+
<strong><?php _e('Banned Exclude IPs', 'wp-ban'); ?>:</strong><br />
|
371 |
+
<?php _e('Start each entry on a new line.', 'wp-ban'); ?><br /><br />
|
372 |
+
<?php _e('Examples:', 'wp-ban'); ?><br />
|
373 |
+
<strong>»</strong> <span dir="ltr">192.168.1.100</span><br /><br />
|
374 |
+
<?php _e('Notes:', 'wp-ban'); ?><br />
|
375 |
+
<strong>»</strong> <?php _e('No Wildcards Allowed.', 'wp-ban'); ?><br />
|
376 |
+
<strong>»</strong> <?php _e('These Users Will Not Get Banned.', 'wp-ban'); ?>
|
377 |
+
</td>
|
378 |
+
<td>
|
379 |
+
<textarea cols="40" rows="10" name="banned_exclude_ips" dir="ltr"><?php echo $banned_exclude_ips_display; ?></textarea>
|
380 |
+
</td>
|
381 |
+
</tr>
|
382 |
+
<tr>
|
383 |
+
<td valign="top">
|
384 |
+
<strong><?php _e('Banned Message', 'wp-ban'); ?>:</strong><br /><br /><br />
|
385 |
+
<?php _e('Allowed Variables:', 'wp-ban'); ?>
|
386 |
+
<p style="margin: 2px 0">- %SITE_NAME%</p>
|
387 |
+
<p style="margin: 2px 0">- %SITE_URL%</p>
|
388 |
+
<p style="margin: 2px 0">- %USER_ATTEMPTS_COUNT%</p>
|
389 |
+
<p style="margin: 2px 0">- %USER_IP%</p>
|
390 |
+
<p style="margin: 2px 0">- %USER_HOSTNAME%</p>
|
391 |
+
<p style="margin: 2px 0">- %TOTAL_ATTEMPTS_COUNT%</p><br />
|
392 |
+
<p><?php printf(__('Note: Your message must be within %s', 'wp-ban'), htmlspecialchars('<div id="wp-ban-container"></div>')); ?></p><br />
|
393 |
+
<input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-ban'); ?>" onclick="banned_default_templates('message');" class="button" /><br /><br />
|
394 |
+
<input type="button" id="show_button" value="<?php _e('Show Current Banned Message', 'wp-ban'); ?>" class="button" /><br />
|
395 |
+
</td>
|
396 |
+
<td>
|
397 |
+
<textarea cols="100" style="width: 100%;" rows="20" id="banned_template_message" name="banned_template_message"><?php echo stripslashes(get_option('banned_message')); ?></textarea>
|
398 |
+
<div id="banned_preview_message"></div>
|
399 |
+
</td>
|
400 |
+
</tr>
|
401 |
+
</table>
|
402 |
+
<p style="text-align: center;">
|
403 |
+
<input type="submit" name="Submit" class="button" value="<?php _e('Save Changes', 'wp-ban'); ?>" />
|
404 |
+
</p>
|
405 |
</div>
|
406 |
</form>
|
407 |
<p> </p>
|
409 |
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
|
410 |
<?php wp_nonce_field('wp-ban_stats'); ?>
|
411 |
<div class="wrap">
|
412 |
+
<h3><?php _e('Ban Stats', 'wp-ban'); ?></h3>
|
413 |
+
<br style="clear" />
|
414 |
+
<table class="widefat">
|
415 |
+
<thead>
|
416 |
+
<tr>
|
417 |
+
<th width="40%" style="text-align: center;"><?php _e('IPs', 'wp-ban'); ?></th>
|
418 |
+
<th width="30%" style="text-align: center;"><?php _e('Attempts', 'wp-ban'); ?></th>
|
419 |
+
<th width="30%"><input type="checkbox" id="toogle_checkbox" name="toogle_checkbox" value="1" onclick="toggle_checkbox();" /> <label for="toogle_checkbox"><?php _e('Action', 'wp-ban'); ?></label></th>
|
420 |
+
</tr>
|
421 |
+
</thead>
|
422 |
+
<?php
|
423 |
+
// Credits To Joe (Ttech) - http://blog.fileville.net/
|
424 |
+
if(!empty($banned_stats['users'])) {
|
425 |
+
$i = 0;
|
426 |
+
ksort($banned_stats['users']);
|
427 |
+
foreach($banned_stats['users'] as $key => $value) {
|
428 |
+
if($i%2 == 0) {
|
429 |
+
$style = '';
|
430 |
+
} else {
|
431 |
+
$style = ' class="alternate"';
|
432 |
+
}
|
433 |
+
echo "<tr$style>\n";
|
434 |
+
echo "<td style=\"text-align: center;\">$key</td>\n";
|
435 |
+
echo "<td style=\"text-align: center;\">".number_format_i18n(intval($value))."</td>\n";
|
436 |
+
echo "<td><input type=\"checkbox\" id=\"ban-$i\" name=\"delete_ips[]\" value=\"$key\" /> <label for=\"ban-$i\">".__('Reset this IP ban stat?', 'wp-ban')."</label></td>\n";
|
437 |
+
echo '</tr>'."\n";
|
438 |
+
$i++;
|
439 |
+
}
|
440 |
+
} else {
|
441 |
+
echo "<tr>\n";
|
442 |
+
echo '<td colspan="3" align="center">'.__('No Attempts', 'wp-ban').'</td>'."\n";
|
443 |
+
echo '</tr>'."\n";
|
444 |
+
}
|
445 |
+
?>
|
446 |
+
<tr class="thead">
|
447 |
+
<td style="text-align: center;"><strong><?php _e('Total Attempts:', 'wp-ban'); ?></strong></td>
|
448 |
+
<td style="text-align: center;"><strong><?php echo number_format_i18n(intval($banned_stats['count'])); ?></strong></td>
|
449 |
+
<td><input type="checkbox" id="reset_ban_stats" name="reset_ban_stats" value="yes" /> <label for="reset_ban_stats"><?php _e('Reset all IP ban stats and total ban stat?', 'wp-ban'); ?></label></td>
|
450 |
+
</tr>
|
451 |
+
</table>
|
452 |
+
<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>
|
453 |
</div>
|
454 |
</form>
|
455 |
+
<p> </p>
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ 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: 4.3
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.
|
8 |
|
9 |
Ban users by IP, IP Range, host name, user agent and referrer url from visiting your WordPress's blog.
|
10 |
|
@@ -27,6 +27,9 @@ It will display a custom ban message when the banned IP, IP range, host name or
|
|
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 |
= Version 1.66 =
|
31 |
* FIXED: Cannot redeclare get_language_attributes()
|
32 |
|
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: 4.3
|
6 |
+
Tested up to: 4.4
|
7 |
+
Stable tag: 1.67
|
8 |
|
9 |
Ban users by IP, IP Range, host name, user agent and referrer url from visiting your WordPress's blog.
|
10 |
|
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 |
+
= Version 1.67 =
|
31 |
+
* FIXED: Notices
|
32 |
+
|
33 |
= Version 1.66 =
|
34 |
* FIXED: Cannot redeclare get_language_attributes()
|
35 |
|
wp-ban.php
CHANGED
@@ -3,7 +3,7 @@
|
|
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.
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: http://lesterchan.net
|
9 |
Text Domain: wp-ban
|
@@ -11,7 +11,7 @@ Text Domain: wp-ban
|
|
11 |
|
12 |
|
13 |
/*
|
14 |
-
|
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
|
@@ -32,225 +32,221 @@ Text Domain: wp-ban
|
|
32 |
### Create Text Domain For Translation
|
33 |
add_action( 'plugins_loaded', 'ban_textdomain' );
|
34 |
function ban_textdomain() {
|
35 |
-
|
36 |
}
|
37 |
|
38 |
|
39 |
### Function: Ban Menu
|
40 |
add_action('admin_menu', 'ban_menu');
|
41 |
function ban_menu() {
|
42 |
-
|
43 |
}
|
44 |
|
45 |
|
46 |
### Function: Get IP Address (http://stackoverflow.com/a/2031935)
|
47 |
function ban_get_ip() {
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
}
|
72 |
|
73 |
|
74 |
### Function: Preview Banned Message
|
75 |
add_action('wp_ajax_ban-admin', 'preview_banned_message');
|
76 |
-
function preview_banned_message()
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
exit();
|
88 |
}
|
89 |
|
90 |
|
91 |
### Function: Print Out Banned Message
|
92 |
function print_banned_message() {
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
}
|
108 |
|
109 |
|
110 |
### Function: Process Banning
|
111 |
function process_ban($banarray, $against) {
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
}
|
121 |
|
122 |
|
123 |
### Function: Process Banned IP Range
|
124 |
function process_ban_ip_range($banned_ips_range) {
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
}
|
137 |
|
138 |
|
139 |
### Function: Banned
|
140 |
add_action('init', 'banned');
|
141 |
function banned() {
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
}
|
198 |
|
199 |
|
200 |
### Function: Check Whether Or Not The IP Address Belongs To Admin
|
201 |
function is_admin_ip($check) {
|
202 |
-
|
203 |
}
|
204 |
|
205 |
|
206 |
### Function: Check Whether IP Within A Given IP Range
|
207 |
function check_ip_within_range($ip, $range_start, $range_end) {
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
}
|
216 |
|
217 |
|
218 |
### Function: Check Whether Or Not The Hostname Belongs To Admin
|
219 |
function is_admin_hostname($check) {
|
220 |
-
|
221 |
}
|
222 |
|
223 |
|
224 |
### Function: Check Whether Or Not The Referer Belongs To This Site
|
225 |
function is_admin_referer($check) {
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
}
|
234 |
|
235 |
|
236 |
### Function: Check Whether Or Not The User Agent Is Used by Admin
|
237 |
function is_admin_user_agent($check) {
|
238 |
-
|
239 |
}
|
240 |
|
241 |
|
242 |
### Function: Wildcard Check
|
243 |
function preg_match_wildcard($regex, $subject) {
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
{
|
252 |
-
return false;
|
253 |
-
}
|
254 |
}
|
255 |
|
256 |
|
@@ -258,49 +254,49 @@ function preg_match_wildcard($regex, $subject) {
|
|
258 |
register_activation_hook( __FILE__, 'ban_activation' );
|
259 |
function ban_activation( $network_wide )
|
260 |
{
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
}
|
281 |
|
282 |
function ban_activate() {
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
}
|
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.67
|
7 |
Author: Lester 'GaMerZ' Chan
|
8 |
Author URI: http://lesterchan.net
|
9 |
Text Domain: wp-ban
|
11 |
|
12 |
|
13 |
/*
|
14 |
+
Copyright 2015 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
|
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 (http://stackoverflow.com/a/2031935)
|
47 |
function ban_get_ip() {
|
48 |
+
$banned_options = get_option( 'banned_options' );
|
49 |
+
|
50 |
+
if( intval( $banned_options['reverse_proxy'] ) === 1 ) {
|
51 |
+
foreach ( array( 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR' ) as $key ) {
|
52 |
+
if ( array_key_exists( $key, $_SERVER ) === true ) {
|
53 |
+
foreach ( explode( ',', $_SERVER[$key] ) as $ip ) {
|
54 |
+
$ip = trim( $ip );
|
55 |
+
if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
|
56 |
+
return esc_attr( $ip );
|
57 |
+
}
|
58 |
+
}
|
59 |
+
}
|
60 |
+
}
|
61 |
+
} else if( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
|
62 |
+
$ip = $_SERVER['REMOTE_ADDR'];
|
63 |
+
if( strpos( $ip, ',' ) !== false ) {
|
64 |
+
$ip = explode( ',', $ip );
|
65 |
+
$ip = $ip[0];
|
66 |
+
}
|
67 |
+
return esc_attr( $ip );
|
68 |
+
}
|
69 |
+
|
70 |
+
return '';
|
71 |
}
|
72 |
|
73 |
|
74 |
### Function: Preview Banned Message
|
75 |
add_action('wp_ajax_ban-admin', 'preview_banned_message');
|
76 |
+
function preview_banned_message() {
|
77 |
+
$banned_stats = get_option('banned_stats');
|
78 |
+
$banned_message = stripslashes(get_option('banned_message'));
|
79 |
+
$banned_message = str_replace("%SITE_NAME%", get_option('blogname'), $banned_message);
|
80 |
+
$banned_message = str_replace("%SITE_URL%", get_option('siteurl'), $banned_message);
|
81 |
+
$banned_message = str_replace("%USER_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['users'][ban_get_ip()]), $banned_message);
|
82 |
+
$banned_message = str_replace("%USER_IP%", ban_get_ip(), $banned_message);
|
83 |
+
$banned_message = str_replace("%USER_HOSTNAME%", @gethostbyaddr(ban_get_ip()), $banned_message);
|
84 |
+
$banned_message = str_replace("%TOTAL_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['count']), $banned_message);
|
85 |
+
echo $banned_message;
|
86 |
+
exit();
|
|
|
87 |
}
|
88 |
|
89 |
|
90 |
### Function: Print Out Banned Message
|
91 |
function print_banned_message() {
|
92 |
+
// Credits To Joe (Ttech) - http://blog.fileville.net/
|
93 |
+
$banned_stats = get_option('banned_stats');
|
94 |
+
$banned_stats['count'] = intval($banned_stats['count']) + 1;
|
95 |
+
$banned_stats['users'][ban_get_ip()] = intval($banned_stats['users'][ban_get_ip()]) + 1;
|
96 |
+
update_option('banned_stats', $banned_stats);
|
97 |
+
$banned_message = stripslashes(get_option('banned_message'));
|
98 |
+
$banned_message = str_replace("%SITE_NAME%", get_option('blogname'), $banned_message);
|
99 |
+
$banned_message = str_replace("%SITE_URL%", get_option('siteurl'), $banned_message);
|
100 |
+
$banned_message = str_replace("%USER_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['users'][ban_get_ip()]), $banned_message);
|
101 |
+
$banned_message = str_replace("%USER_IP%", ban_get_ip(), $banned_message);
|
102 |
+
$banned_message = str_replace("%USER_HOSTNAME%", @gethostbyaddr(ban_get_ip()), $banned_message);
|
103 |
+
$banned_message = str_replace("%TOTAL_ATTEMPTS_COUNT%", number_format_i18n($banned_stats['count']), $banned_message);
|
104 |
+
echo $banned_message;
|
105 |
+
exit();
|
106 |
}
|
107 |
|
108 |
|
109 |
### Function: Process Banning
|
110 |
function process_ban($banarray, $against) {
|
111 |
+
if(!empty($banarray) && !empty($against)) {
|
112 |
+
foreach($banarray as $cban) {
|
113 |
+
if(preg_match_wildcard($cban, $against)) {
|
114 |
+
print_banned_message();
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
118 |
+
return;
|
119 |
}
|
120 |
|
121 |
|
122 |
### Function: Process Banned IP Range
|
123 |
function process_ban_ip_range($banned_ips_range) {
|
124 |
+
if(!empty($banned_ips_range)) {
|
125 |
+
foreach($banned_ips_range as $banned_ip_range) {
|
126 |
+
$range = explode('-', $banned_ip_range);
|
127 |
+
$range_start = trim($range[0]);
|
128 |
+
$range_end = trim($range[1]);
|
129 |
+
if(check_ip_within_range(ban_get_ip(), $range_start, $range_end)) {
|
130 |
+
print_banned_message();
|
131 |
+
break;
|
132 |
+
}
|
133 |
+
}
|
134 |
+
}
|
135 |
}
|
136 |
|
137 |
|
138 |
### Function: Banned
|
139 |
add_action('init', 'banned');
|
140 |
function banned() {
|
141 |
+
$ip = ban_get_ip();
|
142 |
+
if($ip == 'unknown') {
|
143 |
+
return;
|
144 |
+
}
|
145 |
+
$banned_ips = get_option('banned_ips');
|
146 |
+
if(is_array($banned_ips))
|
147 |
+
$banned_ips = array_filter($banned_ips);
|
148 |
+
|
149 |
+
$banned_ips_range = get_option('banned_ips_range');
|
150 |
+
if(is_array($banned_ips_range))
|
151 |
+
$banned_ips_range = array_filter($banned_ips_range);
|
152 |
+
|
153 |
+
$banned_hosts = get_option('banned_hosts');
|
154 |
+
if(is_array($banned_hosts))
|
155 |
+
$banned_hosts = array_filter($banned_hosts);
|
156 |
+
|
157 |
+
$banned_referers = get_option('banned_referers');
|
158 |
+
if(is_array($banned_referers))
|
159 |
+
$banned_referers = array_filter($banned_referers);
|
160 |
+
|
161 |
+
$banned_user_agents = get_option('banned_user_agents');
|
162 |
+
if(is_array($banned_user_agents))
|
163 |
+
$banned_user_agents = array_filter($banned_user_agents);
|
164 |
+
|
165 |
+
$banned_exclude_ips = get_option('banned_exclude_ips');
|
166 |
+
if(is_array($banned_exclude_ips))
|
167 |
+
$banned_exclude_ips = array_filter($banned_exclude_ips);
|
168 |
+
|
169 |
+
$is_excluded = false;
|
170 |
+
if(!empty($banned_exclude_ips)) {
|
171 |
+
foreach($banned_exclude_ips as $banned_exclude_ip) {
|
172 |
+
if($ip == $banned_exclude_ip) {
|
173 |
+
$is_excluded = true;
|
174 |
+
break;
|
175 |
+
}
|
176 |
+
}
|
177 |
+
}
|
178 |
+
|
179 |
+
if( ! $is_excluded ) {
|
180 |
+
if( ! empty( $banned_ips ) ) {
|
181 |
+
process_ban( $banned_ips, $ip );
|
182 |
+
}
|
183 |
+
if( ! empty( $banned_ips_range ) ) {
|
184 |
+
process_ban_ip_range( $banned_ips_range );
|
185 |
+
}
|
186 |
+
if( ! empty( $banned_hosts ) ) {
|
187 |
+
process_ban( $banned_hosts, @gethostbyaddr( $ip ) );
|
188 |
+
}
|
189 |
+
if( ! empty( $banned_referers ) && ! empty( $_SERVER['HTTP_REFERER'] ) ) {
|
190 |
+
process_ban( $banned_referers, $_SERVER['HTTP_REFERER'] );
|
191 |
+
}
|
192 |
+
if( ! empty( $banned_user_agents ) && ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
|
193 |
+
process_ban( $banned_user_agents, $_SERVER['HTTP_USER_AGENT'] );
|
194 |
+
}
|
195 |
+
}
|
196 |
}
|
197 |
|
198 |
|
199 |
### Function: Check Whether Or Not The IP Address Belongs To Admin
|
200 |
function is_admin_ip($check) {
|
201 |
+
return preg_match_wildcard($check, ban_get_ip());
|
202 |
}
|
203 |
|
204 |
|
205 |
### Function: Check Whether IP Within A Given IP Range
|
206 |
function check_ip_within_range($ip, $range_start, $range_end) {
|
207 |
+
$range_start = ip2long($range_start);
|
208 |
+
$range_end = ip2long($range_end);
|
209 |
+
$ip = ip2long($ip);
|
210 |
+
if($ip !== false && $ip >= $range_start && $ip <= $range_end) {
|
211 |
+
return true;
|
212 |
+
}
|
213 |
+
return false;
|
214 |
}
|
215 |
|
216 |
|
217 |
### Function: Check Whether Or Not The Hostname Belongs To Admin
|
218 |
function is_admin_hostname($check) {
|
219 |
+
return preg_match_wildcard($check, @gethostbyaddr(ban_get_ip()));
|
220 |
}
|
221 |
|
222 |
|
223 |
### Function: Check Whether Or Not The Referer Belongs To This Site
|
224 |
function is_admin_referer($check) {
|
225 |
+
$url_patterns = array(get_option('siteurl'), get_option('home'), get_option('siteurl').'/', get_option('home').'/', get_option('siteurl').'/ ', get_option('home').'/ ', $_SERVER['HTTP_REFERER']);
|
226 |
+
foreach($url_patterns as $url) {
|
227 |
+
if(preg_match_wildcard($check, $url)) {
|
228 |
+
return true;
|
229 |
+
}
|
230 |
+
}
|
231 |
+
return false;
|
232 |
}
|
233 |
|
234 |
|
235 |
### Function: Check Whether Or Not The User Agent Is Used by Admin
|
236 |
function is_admin_user_agent($check) {
|
237 |
+
return preg_match_wildcard($check, $_SERVER['HTTP_USER_AGENT']);
|
238 |
}
|
239 |
|
240 |
|
241 |
### Function: Wildcard Check
|
242 |
function preg_match_wildcard($regex, $subject) {
|
243 |
+
$regex = preg_quote($regex, '#');
|
244 |
+
$regex = str_replace('\*', '.*', $regex);
|
245 |
+
if(preg_match("#^$regex$#", $subject)) {
|
246 |
+
return true;
|
247 |
+
} else {
|
248 |
+
return false;
|
249 |
+
}
|
|
|
|
|
|
|
250 |
}
|
251 |
|
252 |
|
254 |
register_activation_hook( __FILE__, 'ban_activation' );
|
255 |
function ban_activation( $network_wide )
|
256 |
{
|
257 |
+
if ( is_multisite() && $network_wide )
|
258 |
+
{
|
259 |
+
$ms_sites = wp_get_sites();
|
260 |
+
|
261 |
+
if( 0 < sizeof( $ms_sites ) )
|
262 |
+
{
|
263 |
+
foreach ( $ms_sites as $ms_site )
|
264 |
+
{
|
265 |
+
switch_to_blog( $ms_site['blog_id'] );
|
266 |
+
ban_activate();
|
267 |
+
}
|
268 |
+
}
|
269 |
+
|
270 |
+
restore_current_blog();
|
271 |
+
}
|
272 |
+
else
|
273 |
+
{
|
274 |
+
ban_activate();
|
275 |
+
}
|
276 |
}
|
277 |
|
278 |
function ban_activate() {
|
279 |
+
add_option('banned_ips', array());
|
280 |
+
add_option('banned_hosts',array());
|
281 |
+
add_option('banned_stats', array('users' => array(), 'count' => 0));
|
282 |
+
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".
|
283 |
+
'<html xmlns="http://www.w3.org/1999/xhtml" '.get_language_attributes().'>'."\n".
|
284 |
+
'<head>'."\n".
|
285 |
+
'<meta http-equiv="Content-Type" content="text/html; charset='.get_option('blog_charset').'" />'."\n".
|
286 |
+
'<title>%SITE_NAME% - %SITE_URL%</title>'."\n".
|
287 |
+
'</head>'."\n".
|
288 |
+
'<body>'."\n".
|
289 |
+
'<div id="wp-ban-container">'."\n".
|
290 |
+
'<p style="text-align: center; font-weight: bold;">'.__('You Are Banned.', 'wp-ban').'</p>'."\n".
|
291 |
+
'</div>'."\n".
|
292 |
+
'</body>'."\n".
|
293 |
+
'</html>', 'Banned Message');
|
294 |
+
// Database Upgrade For WP-Ban 1.11
|
295 |
+
add_option('banned_referers', array());
|
296 |
+
add_option('banned_exclude_ips', array());
|
297 |
+
add_option('banned_ips_range', array());
|
298 |
+
// Database Upgrade For WP-Ban 1.30
|
299 |
+
add_option('banned_user_agents', array());
|
300 |
+
// Database Upgrade For WP-Ban 1.64
|
301 |
+
add_option( 'banned_options', array( 'reverse_proxy' => 0 ) );
|
302 |
}
|