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

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