PluginProbe
Banhammer – Monitor Site Traffic, Block Bad Users and Bots / 3.4.8
Banhammer – Monitor Site Traffic, Block Bad Users and Bots v3.4.8
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.4.8, at banhammer.php

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