PluginProbe
Banhammer – Monitor Site Traffic, Block Bad Users and Bots / 3.5.2
Banhammer – Monitor Site Traffic, Block Bad Users and Bots v3.5.2
3.5.3 trunk 1.1 1.2 1.3 1.4 1.5 1.5.1 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.8.1 2.8.2 2.9 3.0 All 43 releases
banhammer / banhammer.php

banhammer.php in Banhammer – Monitor Site Traffic, Block Bad Users and Bots 3.5.2, at banhammer.php

440 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Banhammer
4 Plugin URI: https://perishablepress.com/banhammer/
5 Description: Monitor traffic and ban unwanted visitors.
6 Tags: monitor, security, ban, block, bots
7 Author: Jeff Starr
8 Author URI: https://plugin-planet.com/
9 Donate link: https://monzillamedia.com/donate.html
10 Contributors: specialk
11 Requires at least: 4.7
12 Tested up to: 7.0
13 Stable tag: 3.5.2
14 Version: 3.5.2
15 Requires PHP: 5.6.20
16 Text Domain: banhammer
17 Domain Path: /languages
18 License: GPL v2 or later
19
20 This program is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License
22 as published by the Free Software Foundation; either version
23 2 of the License, or (at your option) any later version.
24
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 with this program. If not, visit: https://www.gnu.org/licenses/
32
33 Copyright 2017-2026 Monzilla Media. All rights reserved.
34 */
35
36 if (!defined('ABSPATH')) die();
37
38 if (!class_exists('BanhammerWP')) {
39
40 class BanhammerWP {
41
42 function __construct() {
43
44 $this->constants();
45 $this->includes();
46
47 register_activation_hook (__FILE__, array($this, 'check_banhammer'));
48 register_activation_hook (__FILE__, array($this, 'create_table'));
49 register_activation_hook (__FILE__, 'banhammer_dismiss_notice_activate');
50 register_activation_hook (__FILE__, 'banhammer_cron_activation');
51 register_deactivation_hook(__FILE__, 'banhammer_cron_deactivation');
52
53 add_action('admin_init', array($this, 'check_version'));
54 add_action('init', array($this, 'load_i18n'));
55 add_action('upgrader_process_complete', array($this, 'private_key'), 10, 2);
56 add_filter('plugin_action_links', array($this, 'action_links'), 10, 2);
57 add_filter('plugin_row_meta', array($this, 'plugin_links'), 10, 2);
58 add_filter('admin_footer_text', array($this, 'footer_text'), 10, 1);
59
60 add_filter('removable_query_args', 'banhammer_remove_query_args');
61 add_action('admin_enqueue_scripts', 'banhammer_admin_enqueue_scripts');
62 add_action('admin_print_scripts', 'banhammer_admin_print_scripts');
63 add_action('admin_notices', 'banhammer_admin_notices');
64 add_action('admin_init', 'banhammer_register_settings');
65 add_action('admin_init', 'banhammer_reset_options');
66 add_action('admin_menu', 'banhammer_menu_pages');
67 add_action('admin_init', 'banhammer_add_target');
68 add_action('admin_init', 'banhammer_dismiss_notice_save');
69 add_action('admin_init', 'banhammer_dismiss_notice_version');
70
71 add_action('admin_init', 'banhammer_cron_update');
72 add_filter('cron_schedules', 'banhammer_cron_intervals');
73 add_action('banhammer_cron_reset', 'banhammer_cron_reset');
74
75 add_action('wp_ajax_banhammer_armory', 'banhammer_armory');
76 add_action('wp_ajax_banhammer_tower', 'banhammer_tower');
77 add_action('wp_ajax_banhammer_aux', 'banhammer_aux');
78
79 add_action('init', 'banhammer_init');
80
81 }
82
83 function constants() {
84
85 if (!defined('BANHAMMER_VERSION')) define('BANHAMMER_VERSION', '3.5.2');
86 if (!defined('BANHAMMER_REQUIRE')) define('BANHAMMER_REQUIRE', '4.7');
87 if (!defined('BANHAMMER_AUTHOR')) define('BANHAMMER_AUTHOR', 'Jeff Starr');
88 if (!defined('BANHAMMER_NAME')) define('BANHAMMER_NAME', 'Banhammer');
89 if (!defined('BANHAMMER_HOME')) define('BANHAMMER_HOME', esc_url('https://perishablepress.com/banhammer/'));
90 if (!defined('BANHAMMER_URL')) define('BANHAMMER_URL', plugin_dir_url(__FILE__));
91 if (!defined('BANHAMMER_DIR')) define('BANHAMMER_DIR', plugin_dir_path(__FILE__));
92 if (!defined('BANHAMMER_FILE')) define('BANHAMMER_FILE', plugin_basename(__FILE__));
93 if (!defined('BANHAMMER_SLUG')) define('BANHAMMER_SLUG', basename(dirname(__FILE__)));
94 if (!defined('BANHAMMER_BLANK')) define('BANHAMMER_BLANK', '[blank]');
95
96 }
97
98 function includes() {
99
100 require_once BANHAMMER_DIR .'inc/banhammer-cron.php';
101 require_once BANHAMMER_DIR .'inc/banhammer-functions.php';
102 require_once BANHAMMER_DIR .'inc/banhammer-core.php';
103
104 if (is_admin()) {
105
106 require_once BANHAMMER_DIR .'inc/status-codes.php';
107 require_once BANHAMMER_DIR .'inc/contextual-help.php';
108 require_once BANHAMMER_DIR .'inc/resources-enqueue.php';
109 require_once BANHAMMER_DIR .'inc/settings-display.php';
110 require_once BANHAMMER_DIR .'inc/settings-register.php';
111 require_once BANHAMMER_DIR .'inc/settings-reset.php';
112 require_once BANHAMMER_DIR .'inc/armory-display.php';
113 require_once BANHAMMER_DIR .'inc/armory-ajax.php';
114 require_once BANHAMMER_DIR .'inc/tower-display.php';
115 require_once BANHAMMER_DIR .'inc/tower-ajax.php';
116
117 }
118
119 }
120
121 function options() {
122
123 $options = array(
124
125 'enable_plugin' => true,
126 'ignore_logged' => true,
127 'protect_login' => false,
128 'protect_admin' => false,
129 'banned_response' => 'default',
130 'custom_message' => '<p>You has been banned!</p>',
131 'redirect_url' => 'https://example.com/',
132 'status_code' => '403',
133 'reset_interval' => 'banhammer_one_day',
134 'target_key' => banhammer_get_random_alphanumeric(),
135
136 );
137
138 return apply_filters('banhammer_settings', $options);
139
140 }
141
142 function armory() {
143
144 $options = array(
145
146 'rows' => 5,
147 'view' => 2,
148 'fx' => 0,
149
150 );
151
152 return apply_filters('banhammer_armory', $options);
153
154 }
155
156 function tower() {
157
158 $options = array(
159 array(
160 'date' => '2050-01-01 @ 01:01:01 ('. esc_html__('EXAMPLE ONLY: NOT A REAL IP ADDRESS!', 'banhammer') .')',
161 'target' => '777.888.999.000',
162 'status' => 1,
163 'hits' => 3,
164 ),
165 );
166
167 return apply_filters('banhammer_tower', $options);
168
169 }
170
171 function create_table() {
172
173 global $wpdb;
174
175 if (!current_user_can('activate_plugins')) return;
176
177 $table = $wpdb->prefix .'banhammer';
178
179 $charset = $wpdb->get_charset_collate();
180
181 $check = $wpdb->get_var("SHOW TABLES LIKE '". $table ."'");
182
183 if ($check !== $table) {
184
185 $sql = "CREATE TABLE ". $table ." (
186
187 id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
188 date VARCHAR(50) NOT NULL DEFAULT '',
189
190 status TINYINT UNSIGNED NOT NULL DEFAULT 0,
191 process TINYINT UNSIGNED NOT NULL DEFAULT 0,
192
193 user VARCHAR(50) NOT NULL DEFAULT '',
194 type VARCHAR(25) NOT NULL DEFAULT '',
195 theme VARCHAR(50) NOT NULL DEFAULT '',
196 code VARCHAR(25) NOT NULL DEFAULT '',
197 country VARCHAR(50) NOT NULL DEFAULT '',
198 region VARCHAR(50) NOT NULL DEFAULT '',
199 city VARCHAR(50) NOT NULL DEFAULT '',
200 zip VARCHAR(25) NOT NULL DEFAULT '',
201 protocol VARCHAR(25) NOT NULL DEFAULT '',
202 method VARCHAR(25) NOT NULL DEFAULT '',
203 response VARCHAR(25) NOT NULL DEFAULT '',
204 connect VARCHAR(50) NOT NULL DEFAULT '',
205 domain VARCHAR(250) NOT NULL DEFAULT '',
206 ip VARCHAR(250) NOT NULL DEFAULT '',
207 proxy VARCHAR(250) NOT NULL DEFAULT '',
208 host VARCHAR(250) NOT NULL DEFAULT '',
209 request VARCHAR(2500) NOT NULL DEFAULT '',
210 postvars VARCHAR(2500) NOT NULL DEFAULT '',
211 files VARCHAR(2500) NOT NULL DEFAULT '',
212 ua VARCHAR(500) NOT NULL DEFAULT '',
213 refer VARCHAR(500) NOT NULL DEFAULT '',
214 cookies VARCHAR(1000) NOT NULL DEFAULT '',
215 headers VARCHAR(1000) NOT NULL DEFAULT '',
216 message VARCHAR(1000) NOT NULL DEFAULT '',
217 notes VARCHAR(1000) NOT NULL DEFAULT '',
218 custom VARCHAR(500) NOT NULL DEFAULT '',
219 data VARCHAR(500) NOT NULL DEFAULT '',
220 aux VARCHAR(100) NOT NULL DEFAULT '',
221
222 PRIMARY KEY (id)
223
224 ) ". $charset .";";
225
226 require_once(ABSPATH .'wp-admin/includes/upgrade.php');
227
228 dbDelta($sql);
229
230 }
231
232 }
233
234 function private_key($upgrader_object, $options) {
235
236 if ((isset($options['action']) && $options['action'] === 'update') && (isset($options['type']) && $options['type'] === 'plugin')) {
237
238 if (isset($options['plugins'])) {
239
240 foreach($options['plugins'] as $plugin) {
241
242 if ($plugin === BANHAMMER_FILE) {
243
244 $key = banhammer_get_secret_key(30, 'plugin upgrade');
245
246 }
247
248 }
249
250 }
251
252 }
253
254 }
255
256 function action_links($links, $file) {
257
258 if ($file === BANHAMMER_FILE && current_user_can('manage_options')) {
259
260 $settings = '<a href="'. admin_url('admin.php?page=banhammer') .'">'. esc_html__('Settings', 'banhammer') .'</a>';
261
262 array_unshift($links, $settings);
263
264 }
265
266 if ($file === BANHAMMER_FILE) {
267
268 $pro_href = 'https://plugin-planet.com/banhammer-pro/';
269 $pro_title = esc_attr__('Get Banhammer Pro!', 'banhammer');
270 $pro_text = esc_html__('Go&nbsp;Pro', 'banhammer');
271 $pro_style = 'padding:2px 4px;font-weight:bold;border:1px solid #00CCCC;border-radius:2px;background-color:#fff;';
272
273 $pro = '<a target="_blank" rel="noopener noreferrer" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
274
275 array_unshift($links, $pro);
276
277 }
278
279 return $links;
280
281 }
282
283 function plugin_links($links, $file) {
284
285 if ($file === BANHAMMER_FILE) {
286
287 $home_href = 'https://perishablepress.com/banhammer/';
288 $home_title = esc_attr__('Plugin Homepage', 'banhammer');
289 $home_text = esc_html__('Homepage', 'banhammer');
290
291 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
292
293 $rate_href = 'https://wordpress.org/support/plugin/'. BANHAMMER_SLUG .'/reviews/?rate=5#new-post';
294 $rate_title = esc_attr__('Click here to rate and review this plugin at WordPress.org', 'banhammer');
295 $rate_text = esc_html__('Rate this plugin', 'banhammer') .'&nbsp;&raquo;';
296
297 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
298
299 }
300
301 return $links;
302
303 }
304
305 function footer_text($text) {
306
307 $screen_id = banhammer_get_current_screen_id();
308
309 $ids = array('toplevel_page_banhammer', 'banhammer_page_banhammer-armory', 'banhammer_page_banhammer-tower');
310
311 if ($screen_id && apply_filters('banhammer_admin_footer_text', in_array($screen_id, $ids))) {
312
313 $text = __('Like Banhammer? Give it a', 'banhammer');
314
315 $text .= ' <a target="_blank" rel="noopener noreferrer" href="https://wordpress.org/support/plugin/banhammer/reviews/?rate=5#new-post">';
316
317 $text .= __('�
318
319
320
321
322 rating&nbsp;&raquo;', 'banhammer') .'</a>';
323
324 }
325
326 return $text;
327
328 }
329
330 function check_banhammer() {
331
332 if (class_exists('Banhammer_Pro')) {
333
334 if (is_plugin_active(BANHAMMER_FILE)) {
335
336 deactivate_plugins(BANHAMMER_FILE);
337
338 $msg = '<strong>'. esc_html__('Warning:', 'banhammer') .'</strong> ';
339
340 $msg .= esc_html__('Pro version of Banhammer currently active. Free and Pro versions cannot be activated at the same time. ', 'banhammer');
341
342 $msg .= esc_html__('Please return to the', 'banhammer');
343
344 $msg .= ' <a href="'. admin_url('plugins.php') .'">'. esc_html__('WP Admin Area', 'banhammer') .'</a> '. esc_html__('and try again.', 'banhammer');
345
346 wp_die($msg);
347
348 }
349
350 }
351
352 }
353
354 function check_version() {
355
356 if (current_user_can('manage_options')) {
357
358 $wp_version = get_bloginfo('version');
359
360 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
361
362 if (version_compare($wp_version, BANHAMMER_REQUIRE, '<')) {
363
364 if (is_plugin_active(BANHAMMER_FILE)) {
365
366 deactivate_plugins(BANHAMMER_FILE);
367
368 $msg = '<strong>'. BANHAMMER_NAME .'</strong> '. esc_html__('requires WordPress ', 'banhammer') . BANHAMMER_REQUIRE;
369 $msg .= esc_html__(' or higher, and has been deactivated. ', 'banhammer');
370 $msg .= esc_html__('Please return to the', 'banhammer') .' <a href="'. admin_url('plugins.php') .'">';
371 $msg .= esc_html__('WordPress Admin Area', 'banhammer') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'banhammer');
372
373 wp_die($msg);
374
375 }
376
377 }
378
379 }
380
381 }
382
383 }
384
385 function load_i18n() {
386
387 $domain = 'banhammer';
388
389 $locale = apply_filters('banhammer_locale', get_locale(), $domain);
390
391 $dir = trailingslashit(WP_LANG_DIR);
392
393 $file = $domain .'-'. $locale .'.mo';
394
395 $path_1 = $dir . $file;
396
397 $path_2 = $dir . $domain .'/'. $file;
398
399 $path_3 = $dir .'plugins/'. $file;
400
401 $path_4 = $dir .'plugins/'. $domain .'/'. $file;
402
403 $paths = array($path_1, $path_2, $path_3, $path_4);
404
405 foreach ($paths as $path) {
406
407 if ($loaded = load_textdomain($domain, $path)) {
408
409 return $loaded;
410
411 } else {
412
413 return load_plugin_textdomain($domain, false, dirname(BANHAMMER_FILE) .'/languages/');
414
415 }
416
417 }
418
419 }
420
421 function __clone() {
422
423 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'banhammer'), BANHAMMER_VERSION);
424
425 }
426
427 function __wakeup() {
428
429 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'banhammer'), BANHAMMER_VERSION);
430
431 }
432
433 }
434
435 global $Banhammer;
436
437 $GLOBALS['BanhammerWP'] = $BanhammerWP = new BanhammerWP();
438
439 }
440