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

379 lines 11.8 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: ban, block, bots, users
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.5
12 Tested up to: 5.0
13 Stable tag: 1.5
14 Version: 1.5
15 Requires PHP: 5.2
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 2018 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, 'create_table'));
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_banhammer'));
54 add_action('admin_init', array($this, 'check_version'));
55 add_action('plugins_loaded', array($this, 'load_i18n'));
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
59 add_filter('removable_query_args', 'banhammer_remove_query_args');
60 add_action('admin_enqueue_scripts', 'banhammer_admin_enqueue_scripts');
61 add_action('admin_print_scripts', 'banhammer_admin_print_scripts');
62 add_action('admin_notices', 'banhammer_admin_notices');
63 add_action('admin_init', 'banhammer_register_settings');
64 add_action('admin_init', 'banhammer_reset_options');
65 add_action('admin_menu', 'banhammer_menu_pages');
66 add_action('admin_init', 'banhammer_add_target');
67
68 add_action('admin_init', 'banhammer_cron_update');
69 add_filter('cron_schedules', 'banhammer_cron_intervals');
70 add_action('banhammer_cron_reset', 'banhammer_cron_reset');
71
72 add_action('wp_ajax_banhammer_armory', 'banhammer_armory');
73 add_action('wp_ajax_banhammer_tower', 'banhammer_tower');
74 add_action('wp_ajax_banhammer_aux', 'banhammer_aux');
75
76 add_action('init', 'banhammer_init');
77
78 }
79
80 function constants() {
81
82 if (!defined('BANHAMMER_VERSION')) define('BANHAMMER_VERSION', '1.5');
83 if (!defined('BANHAMMER_REQUIRE')) define('BANHAMMER_REQUIRE', '4.5');
84 if (!defined('BANHAMMER_AUTHOR')) define('BANHAMMER_AUTHOR', 'Jeff Starr');
85 if (!defined('BANHAMMER_NAME')) define('BANHAMMER_NAME', __('Banhammer', 'banhammer'));
86 if (!defined('BANHAMMER_HOME')) define('BANHAMMER_HOME', esc_url('https://perishablepress.com/banhammer/'));
87 if (!defined('BANHAMMER_URL')) define('BANHAMMER_URL', plugin_dir_url(__FILE__));
88 if (!defined('BANHAMMER_DIR')) define('BANHAMMER_DIR', plugin_dir_path(__FILE__));
89 if (!defined('BANHAMMER_FILE')) define('BANHAMMER_FILE', plugin_basename(__FILE__));
90 if (!defined('BANHAMMER_SLUG')) define('BANHAMMER_SLUG', basename(dirname(__FILE__)));
91 if (!defined('BANHAMMER_BLANK')) define('BANHAMMER_BLANK', __('[blank]', 'banhammer'));
92
93 }
94
95 function includes() {
96
97 require_once BANHAMMER_DIR .'inc/banhammer-cron.php';
98 require_once BANHAMMER_DIR .'inc/banhammer-functions.php';
99 require_once BANHAMMER_DIR .'inc/banhammer-core.php';
100 require_once BANHAMMER_DIR .'lib/WPSimpleNonce.php';
101
102 if (is_admin()) {
103
104 require_once BANHAMMER_DIR .'inc/status-codes.php';
105 require_once BANHAMMER_DIR .'inc/contextual-help.php';
106 require_once BANHAMMER_DIR .'inc/resources-enqueue.php';
107 require_once BANHAMMER_DIR .'inc/settings-display.php';
108 require_once BANHAMMER_DIR .'inc/settings-register.php';
109 require_once BANHAMMER_DIR .'inc/settings-reset.php';
110 require_once BANHAMMER_DIR .'inc/armory-display.php';
111 require_once BANHAMMER_DIR .'inc/armory-ajax.php';
112 require_once BANHAMMER_DIR .'inc/tower-display.php';
113 require_once BANHAMMER_DIR .'inc/tower-ajax.php';
114
115 }
116
117 }
118
119 function options() {
120
121 $options = array(
122
123 'enable_plugin' => true,
124 'ignore_logged' => true,
125 'protect_login' => false,
126 'protect_admin' => false,
127 'banned_response' => 'default',
128 'custom_message' => '<p>You has been banned!</p>',
129 'redirect_url' => 'https://example.com/',
130 'status_code' => '403',
131 'reset_interval' => 'banhammer_one_day',
132 'target_key' => banhammer_get_random_alphanumeric(),
133
134 );
135
136 return apply_filters('banhammer_settings', $options);
137
138 }
139
140 function armory() {
141
142 $options = array(
143
144 'rows' => 3,
145 'view' => 2,
146 'fx' => 0,
147
148 );
149
150 return apply_filters('banhammer_armory', $options);
151
152 }
153
154 function tower() {
155
156 $options = array(
157 array(
158 'date' => '2050-01-01 @ 01:01:01 ('. esc_html__('EXAMPLE ONLY: NOT A REAL IP ADDRESS!', 'banhammer') .')',
159 'target' => '777.888.999.000',
160 'status' => 1,
161 'hits' => 3,
162 ),
163 );
164
165 return apply_filters('banhammer_tower', $options);
166
167 }
168
169 function create_table() {
170
171 global $wpdb;
172
173 if (!current_user_can('activate_plugins')) return;
174
175 $table = $wpdb->prefix .'banhammer';
176
177 $charset = $wpdb->get_charset_collate();
178
179 $check = $wpdb->get_var("SHOW TABLES LIKE '". $table ."'");
180
181 if ($check !== $table) {
182
183 $sql = "CREATE TABLE ". $table ." (
184
185 id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
186 date VARCHAR(50) NOT NULL DEFAULT '',
187
188 status TINYINT UNSIGNED NOT NULL DEFAULT 0,
189 process TINYINT UNSIGNED NOT NULL DEFAULT 0,
190
191 user VARCHAR(50) NOT NULL DEFAULT '',
192 type VARCHAR(25) NOT NULL DEFAULT '',
193 theme VARCHAR(50) NOT NULL DEFAULT '',
194 code VARCHAR(25) NOT NULL DEFAULT '',
195 country VARCHAR(50) NOT NULL DEFAULT '',
196 region VARCHAR(50) NOT NULL DEFAULT '',
197 city VARCHAR(50) NOT NULL DEFAULT '',
198 zip VARCHAR(25) NOT NULL DEFAULT '',
199 protocol VARCHAR(25) NOT NULL DEFAULT '',
200 method VARCHAR(25) NOT NULL DEFAULT '',
201 response VARCHAR(25) NOT NULL DEFAULT '',
202 connect VARCHAR(50) NOT NULL DEFAULT '',
203 domain VARCHAR(250) NOT NULL DEFAULT '',
204 ip VARCHAR(250) NOT NULL DEFAULT '',
205 proxy VARCHAR(250) NOT NULL DEFAULT '',
206 host VARCHAR(250) NOT NULL DEFAULT '',
207 request VARCHAR(2500) NOT NULL DEFAULT '',
208 postvars VARCHAR(2500) NOT NULL DEFAULT '',
209 files VARCHAR(2500) NOT NULL DEFAULT '',
210 ua VARCHAR(500) NOT NULL DEFAULT '',
211 refer VARCHAR(500) NOT NULL DEFAULT '',
212 cookies VARCHAR(1000) NOT NULL DEFAULT '',
213 headers VARCHAR(1000) NOT NULL DEFAULT '',
214 message VARCHAR(1000) NOT NULL DEFAULT '',
215 notes VARCHAR(1000) NOT NULL DEFAULT '',
216 custom VARCHAR(500) NOT NULL DEFAULT '',
217 data VARCHAR(500) NOT NULL DEFAULT '',
218 aux VARCHAR(100) NOT NULL DEFAULT '',
219
220 PRIMARY KEY (id)
221
222 ) ". $charset .";";
223
224 require_once(ABSPATH .'wp-admin/includes/upgrade.php');
225
226 dbDelta($sql);
227
228 }
229
230 }
231
232 function action_links($links, $file) {
233
234 if ($file === BANHAMMER_FILE) {
235
236 $pro_href = 'https://plugin-planet.com/banhammer-pro/?plugin';
237 $pro_title = esc_attr__('Get Banhammer Pro!', 'banhammer');
238 $pro_text = esc_html__('Go&nbsp;Pro', 'banhammer');
239 $pro_style = 'font-weight:bold;';
240
241 $pro = '<a target="_blank" rel="noopener noreferrer" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
242
243 $settings = '<a href="'. admin_url('admin.php?page=banhammer') .'">'. esc_html__('Settings', 'banhammer') .'</a>';
244
245 array_unshift($links, $pro, $settings);
246
247 }
248
249 return $links;
250
251 }
252
253 function plugin_links($links, $file) {
254
255 if ($file === BANHAMMER_FILE) {
256
257 $home_href = 'https://perishablepress.com/banhammer/';
258 $home_title = esc_attr__('Plugin Homepage', 'banhammer');
259 $home_text = esc_html__('Homepage', 'banhammer');
260
261 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
262
263 $rate_href = 'https://wordpress.org/support/plugin/'. BANHAMMER_SLUG .'/reviews/?rate=5#new-post';
264 $rate_title = esc_attr__('Click here to rate and review this plugin on WordPress.org', 'banhammer');
265 $rate_text = esc_html__('Rate this plugin', 'banhammer') .'&nbsp;&raquo;';
266
267 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
268
269 }
270
271 return $links;
272
273 }
274
275 function check_banhammer() {
276
277 if (class_exists('Banhammer_Pro')) {
278
279 if (is_plugin_active(BANHAMMER_FILE)) {
280
281 deactivate_plugins(BANHAMMER_FILE);
282
283 $msg = '<strong>'. esc_html__('Warning:', 'banhammer') .'</strong> ';
284
285 $msg .= esc_html__('Pro version of Banhammer currently active. Free and Pro versions cannot be activated at the same time. ', 'banhammer');
286
287 $msg .= esc_html__('Please return to the', 'banhammer');
288
289 $msg .= ' <a href="'. admin_url('plugins.php') .'">'. esc_html__('WP Admin Area', 'banhammer') .'</a> '. esc_html__('and try again.', 'banhammer');
290
291 wp_die($msg);
292
293 }
294
295 }
296
297 }
298
299 function check_version() {
300
301 $wp_version = get_bloginfo('version');
302
303 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
304
305 if (version_compare($wp_version, BANHAMMER_REQUIRE, '<')) {
306
307 if (is_plugin_active(BANHAMMER_FILE)) {
308
309 deactivate_plugins(BANHAMMER_FILE);
310
311 $msg = '<strong>'. BANHAMMER_NAME .'</strong> '. esc_html__('requires WordPress ', 'banhammer') . BANHAMMER_REQUIRE;
312 $msg .= esc_html__(' or higher, and has been deactivated! ', 'banhammer');
313 $msg .= esc_html__('Please return to the', 'banhammer') .' <a href="'. admin_url() .'">';
314 $msg .= esc_html__('WP Admin Area', 'banhammer') .'</a> '. esc_html__('to upgrade WordPress and try again.', 'banhammer');
315
316 wp_die($msg);
317
318 }
319
320 }
321
322 }
323
324 }
325
326 function load_i18n() {
327
328 $domain = 'banhammer';
329
330 $locale = apply_filters('banhammer_locale', get_locale(), $domain);
331
332 $dir = trailingslashit(WP_LANG_DIR);
333
334 $file = $domain .'-'. $locale .'.mo';
335
336 $path_1 = $dir . $file;
337
338 $path_2 = $dir . $domain .'/'. $file;
339
340 $path_3 = $dir .'plugins/'. $file;
341
342 $path_4 = $dir .'plugins/'. $domain .'/'. $file;
343
344 $paths = array($path_1, $path_2, $path_3, $path_4);
345
346 foreach ($paths as $path) {
347
348 if ($loaded = load_textdomain($domain, $path)) {
349
350 return $loaded;
351
352 } else {
353
354 return load_plugin_textdomain($domain, false, BANHAMMER_DIR .'languages/');
355
356 }
357
358 }
359
360 }
361
362 function __clone() {
363
364 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'banhammer'), BANHAMMER_VERSION);
365
366 }
367
368 function __wakeup() {
369
370 _doing_it_wrong(__FUNCTION__, esc_html__('Sorry, pal!', 'banhammer'), BANHAMMER_VERSION);
371
372 }
373
374 }
375
376 $BanhammerWP = new BanhammerWP();
377
378 }
379