PluginProbe
Loginizer / 1.0.1
Loginizer v1.0.1
2.1.0 2.0.9 2.0.8 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 74 releases
← All changes | loginizer.php +536 -394 1.01.0.1 View file →
@@ -1,14 +1,14 @@
1 1 <?php
2 2 /**
3 3 * @package loginizer
4 - * @version 1.4.2
4 + * @version 1.0.1
5 5 */
6 6 /*
7 7 Plugin Name: Loginizer
8 8 Plugin URI: http://wordpress.org/extend/plugins/loginizer/
9 9 Description: Loginizer is a WordPress plugin which helps you fight against bruteforce attack by blocking login for the IP after it reaches maximum retries allowed. You can blacklist or whitelist IPs for login using Loginizer.
10 -Version: 1.0
10 +Version: 1.0.1
11 11 Author: Raj Kothari
12 12 Author URI: http://www.loginizer.com
13 13 License: GPLv3 or later
14 14 */
@@ -33,9 +33,9 @@
33 33 echo 'You are not allowed to access this page directly.';
34 34 exit;
35 35 }
36 36
37 -define('lz_version', '1.0');
37 +define('LOGINIZER_VERSION', '1.0.1');
38 38
39 39 include_once('functions.php');
40 40
41 41 // Ok so we are now ready to go
@@ -40,128 +40,219 @@
40 40
41 41 // Ok so we are now ready to go
42 42 register_activation_hook( __FILE__, 'loginizer_activation');
43 43
44 +// Is called when the ADMIN enables the plugin
44 45 function loginizer_activation(){
45 46
46 -global $wpdb;
47 + global $wpdb;
47 48
48 -$sql = array();
49 -$sql[] = "
49 + $sql = array();
50 +
51 + $sql[] = "CREATE TABLE `".$wpdb->prefix."loginizer_logs` (
52 + `username` varchar(255) NOT NULL DEFAULT '',
53 + `time` int(10) NOT NULL DEFAULT '0',
54 + `count` int(10) NOT NULL DEFAULT '0',
55 + `lockout` int(10) NOT NULL DEFAULT '0',
56 + `ip` varchar(255) NOT NULL DEFAULT '',
57 + UNIQUE KEY `ip` (`ip`)
58 + ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
50 59
51 -CREATE TABLE `".$wpdb->prefix."lz_failed_logs` (
52 - `username` varchar(255) NOT NULL DEFAULT '',
53 - `time` int(10) NOT NULL DEFAULT '0',
54 - `count` int(10) NOT NULL DEFAULT '0',
55 - `lockout` int(10) NOT NULL DEFAULT '0',
56 - `ip` varchar(255) NOT NULL DEFAULT '',
57 - UNIQUE KEY `ip` (`ip`)
58 -) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
59 -
60 -$sql[] = "
61 -
62 -CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."lz_options` (
63 - `id` int(11) NOT NULL AUTO_INCREMENT,
64 - `option_name` varchar(255) NOT NULL,
65 - `option_value` varchar(255) NOT NULL,
66 - `updated` int(11) NOT NULL,
67 - PRIMARY KEY (`id`),
68 - UNIQUE KEY `option_name` (`option_name`)
69 -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
70 -
71 -$sql[] = "
72 -
73 -CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."lz_iprange` (
74 - `rid` int(10) NOT NULL AUTO_INCREMENT,
75 - `start` bigint(20) NOT NULL,
76 - `end` bigint(20) NOT NULL,
77 - `blacklist` tinyint(2) NOT NULL DEFAULT '0',
78 - `whitelist` tinyint(2) NOT NULL DEFAULT '0',
79 - `date` int(10) NOT NULL,
80 - PRIMARY KEY (`rid`)
81 -) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;";
82 -
83 60 foreach($sql as $sk => $sv){
84 61 $wpdb->query($sv);
85 62 }
86 63
87 - add_option('lz_version', lz_version);
64 + add_option('loginizer_version', LOGINIZER_VERSION);
65 + add_option('loginizer_options', array());
66 + add_option('loginizer_last_reset', 0);
67 + add_option('loginizer_whitelist', array());
68 + add_option('loginizer_blacklist', array());
88 69
89 70 }
90 71
91 -add_action( 'plugins_loaded', 'loginizer_load_plugin' );
92 -
72 +// Checks if we are to update ?
93 73 function loginizer_update_check(){
94 74
95 75 global $wpdb;
96 76
97 77 $sql = array();
98 - $current_version = get_option('lz_version');
78 + $current_version = get_option('loginizer_version');
79 +
80 + // It must be the 1.0 pre stuff
81 + if(empty($current_version)){
82 + $current_version = get_option('lz_version');
83 + }
84 +
85 + $version = (int) str_replace('.', '', $current_version);
86 +
87 + // No update required
88 + if($current_version == LOGINIZER_VERSION){
89 + return true;
90 + }
91 +
92 + // Is it first run ?
93 + if(empty($current_version)){
94 +
95 + // Reinstall
96 + loginizer_activation();
97 +
98 + // Trick the following if conditions to not run
99 + $version = (int) str_replace('.', '', LOGINIZER_VERSION);
100 +
101 + }
102 +
103 + // Is it less than 1.0.1 ?
104 + if($version < 101){
105 +
106 + // TODO : GET the existing settings
107 +
108 + // Get the existing settings
109 + $lz_failed_logs = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_failed_logs`;", 1);
110 + $lz_options = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_options`;", 1);
111 + $lz_iprange = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_iprange`;", 1);
112 +
113 + // Delete the three tables
114 + $sql = array();
115 + $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_failed_logs;";
116 + $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_options;";
117 + $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_iprange;";
99 118
100 - if($current_version < lz_version){
101 119 foreach($sql as $sk => $sv){
102 120 $wpdb->query($sv);
103 121 }
122 +
123 + // Delete option
124 + delete_option('lz_version');
125 +
126 + // Reinstall
127 + loginizer_activation();
128 +
129 + // TODO : Save the existing settings
104 130
105 - update_option('lz_version', lz_version);
131 + // Update the existing failed logs to new table
132 + if(is_array($lz_failed_logs)){
133 + foreach($lz_failed_logs as $fk => $fv){
134 + $wpdb->query("INSERT INTO ".$wpdb->prefix."loginizer_logs SET `username` = '".$fv['username']."', `time` = '".$fv['time']."', `count` = '".$fv['count']."', `lockout` = '".$fv['lockout']."', `ip` = '".$fv['ip']."';");
135 + }
136 + }
137 +
138 + // Update the existing options to new structure
139 + if(is_array($lz_options)){
140 + foreach($lz_options as $ok => $ov){
141 +
142 + if($ov['option_name'] == 'lz_last_reset'){
143 + update_option('loginizer_last_reset', $ov['option_value']);
144 + continue;
145 + }
146 +
147 + $old_option[str_replace('lz_', '', $ov['option_name'])] = $ov['option_value'];
148 + }
149 + // Save the options
150 + update_option('loginizer_options', $old_option);
151 + }
152 +
153 + // Update the existing iprange to new structure
154 + if(is_array($lz_iprange)){
155 +
156 + $old_blacklist = array();
157 + $old_whitelist = array();
158 + $bid = 1;
159 + $wid = 1;
160 + foreach($lz_iprange as $ik => $iv){
161 +
162 + if(!empty($iv['blacklist'])){
163 + $old_blacklist[$bid] = array();
164 + $old_blacklist[$bid]['start'] = long2ip($iv['start']);
165 + $old_blacklist[$bid]['end'] = long2ip($iv['end']);
166 + $old_blacklist[$bid]['time'] = strtotime($iv['date']);
167 + $bid = $bid + 1;
168 + }
169 +
170 + if(!empty($iv['whitelist'])){
171 + $old_whitelist[$wid] = array();
172 + $old_whitelist[$wid]['start'] = long2ip($iv['start']);
173 + $old_whitelist[$wid]['end'] = long2ip($iv['end']);
174 + $old_whitelist[$wid]['time'] = strtotime($iv['date']);
175 + $wid = $wid + 1;
176 + }
177 + }
178 +
179 + if(!empty($old_blacklist)) update_option('loginizer_blacklist', $old_blacklist);
180 + if(!empty($old_whitelist)) update_option('loginizer_whitelist', $old_whitelist);
181 + }
182 +
106 183 }
184 +
185 + // Save the new Version
186 + update_option('loginizer_version', LOGINIZER_VERSION);
187 +
188 +}
107 189
108 -}
190 +// Add the action to load the plugin
191 +add_action('plugins_loaded', 'loginizer_load_plugin');
109 192
193 +// The function that will be called when the plugin is loaded
110 194 function loginizer_load_plugin(){
111 195
112 - global $lz_globals;
196 + global $loginizer;
113 197
198 + // Check if the installed version is outdated
114 199 loginizer_update_check();
115 200
116 - $lz_globals = array();
117 - $lz_globals['lz_max_retries'] = lz_get_option('lz_max_retries', 3);
118 - $lz_globals['lz_lockout_time'] = lz_get_option('lz_lockout_time', 900); // 15 minutes
119 - $lz_globals['lz_max_lockouts'] = lz_get_option('lz_max_lockouts', 5);
120 - $lz_globals['lz_lockouts_extend'] = lz_get_option('lz_lockouts_extend', 86400); // 24 hours
121 - $lz_globals['lz_reset_retries'] = lz_get_option('lz_reset_retries', 86400); // 24 hours
122 - $lz_globals['lz_last_reset'] = lz_get_option('lz_last_reset', 0); // 24 hours
123 - $lz_globals['lz_notify_email'] = lz_get_option('lz_notify_email', 0);
201 + $options = get_option('loginizer_options');
124 202
203 + $loginizer = array();
204 + $loginizer['max_retries'] = empty($options['max_retries']) ? 3 : $options['max_retries'];
205 + $loginizer['lockout_time'] = empty($options['lockout_time']) ? 900 : $options['lockout_time']; // 15 minutes
206 + $loginizer['max_lockouts'] = empty($options['max_lockouts']) ? 5 : $options['max_lockouts'];
207 + $loginizer['lockouts_extend'] = empty($options['lockouts_extend']) ? 86400 : $options['lockouts_extend']; // 24 hours
208 + $loginizer['reset_retries'] = empty($options['reset_retries']) ? 86400 : $options['reset_retries']; // 24 hours
209 + $loginizer['notify_email'] = empty($options['notify_email']) ? 0 : $options['notify_email'];
210 +
211 + $includes = get_included_files();
212 + if(basename($includes[0]) != 'wp-login.php'){
213 + return false;
214 + }
215 +
216 + // Load the blacklist and whitelist
217 + $loginizer['blacklist'] = get_option('loginizer_blacklist');
218 + $loginizer['whitelist'] = get_option('loginizer_whitelist');
219 +
220 + // When was the database cleared last time
221 + $loginizer_last_reset = get_option('loginizer_last_reset');
222 +
223 + //print_r($loginizer);
224 +
125 225 // Clear retries
126 - if((time() - $lz_globals['lz_last_reset']) >= $lz_globals['lz_reset_retries']){
127 - lz_reset_retries();
226 + if((time() - $loginizer_last_reset) >= $loginizer['reset_retries']){
227 + loginizer_reset_retries();
128 228 }
129 229
130 - $lz_globals['current_ip'] = lz_getip();
230 + // Set the current IP
231 + $loginizer['current_ip'] = lz_getip();
131 232
132 - /* Filters and actions */
133 - add_filter('wp_authenticate_user', 'lz_wp_authenticate_user', 99999, 2);// This is used for additional validation
134 - add_action('wp_login_failed', 'lz_login_failed');// Update our records login failed
135 - add_action('wp_authenticate', 'lz_wp_authenticate', 10, 2);// Use this to verify before WP tries to login
136 - add_action('login_errors', 'lz_update_error_msg');// Update Error message
137 -
138 -}
139 -
140 -function lz_wp_authenticate_user($user, $username){
233 + /* Filters and actions */
141 234
142 - global $lz_error, $lz_cannot_login;
235 + // Use this to verify before WP tries to login
236 + // Is always called and is the first function to be called
237 + add_action('wp_authenticate', 'loginizer_wp_authenticate', 10, 2);
143 238
144 - if(is_wp_error($user) || empty($lz_cannot_login)){
145 - return $user;
146 - }
239 + // This is used for additional validation
240 + // This function is called after the form is posted
241 + add_filter('wp_authenticate_user', 'loginizer_wp_authenticate_user', 99999, 2);
147 242
148 - $error = new WP_Error();
149 - $error->add('ip_blocked', implode('', $lz_error));
150 - return $error;
243 + // Is called when a login attempt fails
244 + // Hence Update our records that the login failed
245 + add_action('wp_login_failed', 'loginizer_login_failed');
246 +
247 + // Is called before displaying the error message so that we dont show that the username is wrong or the password
248 + // Update Error message
249 + add_action('login_errors', 'loginizer_update_error_msg');
250 +
151 251 }
152 252
153 -function lz_wp_authenticate($username, $password){
154 -
253 +function loginizer_wp_authenticate($username, $password){
254 +
155 255 global $lz_error, $lz_cannot_login, $lz_user_pass;
156 256
157 257 if(!empty($username) && !empty($password)){
158 258 $lz_user_pass = 1;
@@ -167,14 +258,14 @@
167 258 $lz_user_pass = 1;
168 259 }
169 260
170 261 // Are you whitelisted ?
171 - if(lz_is_whitelisted()){
262 + if(loginizer_is_whitelisted()){
172 263 return $username;
173 264 }
174 265
175 266 // Are you blacklisted ?
176 - if(lz_is_blacklisted()){
267 + if(loginizer_is_blacklisted()){
177 268 $lz_cannot_login = 1;
178 269 $error = new WP_Error();
179 270 $error->add('ip_blacklisted', implode('', $lz_error));
180 271 return $error;
@@ -179,9 +270,9 @@
179 270 $error->add('ip_blacklisted', implode('', $lz_error));
180 271 return $error;
181 272 }
182 273
183 - if(lz_can_login()){
274 + if(loginizer_can_login()){
184 275 return $username;
185 276 }
186 277
187 278 $lz_cannot_login = 1;
@@ -188,31 +279,32 @@
188 279
189 280 $error = new WP_Error();
190 281 $error->add('ip_blocked', implode('', $lz_error));
191 282 return $error;
283 +
192 284 }
193 285
194 -function lz_can_login(){
286 +function loginizer_can_login(){
195 287
196 - global $wpdb, $lz_globals, $lz_error;
288 + global $wpdb, $loginizer, $lz_error;
197 289
198 290 // Get the logs
199 - $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_failed_logs` WHERE `ip` = '".$lz_globals['current_ip']."';");
291 + $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = '".$loginizer['current_ip']."';");
200 292
201 - if(!empty($result['count']) && $result['count'] >= $lz_globals['lz_max_retries']){
293 + if(!empty($result['count']) && $result['count'] >= $loginizer['max_retries']){
202 294
203 295 // Has he reached max lockouts ?
204 - if($result['lockout'] >= $lz_globals['lz_max_lockouts']){
205 - $lz_globals['lz_lockout_time'] = $lz_globals['lz_lockouts_extend'];
296 + if($result['lockout'] >= $loginizer['max_lockouts']){
297 + $loginizer['lockout_time'] = $loginizer['lockouts_extend'];
206 298 }
207 299
208 300 // Is he in the lockout time ?
209 - if($result['time'] >= time() - $lz_globals['lz_lockout_time']){
210 - $banlift = ceil((($result['time'] + $lz_globals['lz_lockout_time']) - time()) / 60);
301 + if($result['time'] >= (time() - $loginizer['lockout_time'])){
302 + $banlift = ceil((($result['time'] + $loginizer['lockout_time']) - time()) / 60);
211 303
212 304 //echo 'Current Time '.date('m/d/Y H:i:s', time()).'<br />';
213 305 //echo 'Last attempt '.date('m/d/Y H:i:s', $result['time']).'<br />';
214 - //echo 'Unlock Time '.date('m/d/Y H:i:s', $result['time'] + $lz_globals['lz_lockout_time']).'<br />';
306 + //echo 'Unlock Time '.date('m/d/Y H:i:s', $result['time'] + $loginizer['lockout_time']).'<br />';
215 307
216 308 $_time = $banlift.' minute(s)';
217 309
218 310 if($banlift > 60){
@@ -225,22 +317,34 @@
225 317 return false;
226 318 }
227 319 }
228 320
229 - if(!empty($result['count']) && $result['count'] < $lz_globals['lz_max_retries']){
230 - $lz_globals['lz_retries_left'] = $lz_globals['lz_max_retries'] - $result['count'];
321 + // We need to add one as this is a failed attempt as well
322 + $result['count'] = $result['count'] + 1;
323 +
324 + if(!empty($result['count']) && $result['count'] <= $loginizer['max_retries']){
325 + $loginizer['retries_left'] = $loginizer['max_retries'] - $result['count'];
231 326 }
232 327
233 328 return true;
234 329 }
235 330
236 -function lz_is_blacklisted(){
331 +function loginizer_is_blacklisted(){
237 332
238 - global $wpdb, $lz_globals, $lz_error;
333 + global $wpdb, $loginizer, $lz_error;
239 334
240 - // Get the logs
241 - $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_iprange` WHERE (".ip2long($lz_globals['current_ip'])." BETWEEN `start` AND `end`) AND `blacklist` = '1';");
335 + $blacklist = $loginizer['blacklist'];
336 +
337 + foreach($blacklist as $k => $v){
242 338
339 + // Is the IP in the blacklist ?
340 + if(ip2long($v['start']) <= ip2long($loginizer['current_ip']) && ip2long($loginizer['current_ip']) <= ip2long($v['end'])){
341 + $result = 1;
342 + break;
343 + }
344 +
345 + }
346 +
243 347 // You are blacklisted
244 348 if(!empty($result)){
245 349 $lz_error['ip_blacklisted'] = 'Your IP has been blacklisted';
246 350 return true;
@@ -246,17 +350,27 @@
246 350 return true;
247 351 }
248 352
249 353 return false;
354 +
250 355 }
251 356
252 -function lz_is_whitelisted(){
357 +function loginizer_is_whitelisted(){
253 358
254 - global $wpdb, $lz_globals, $lz_error;
359 + global $wpdb, $loginizer, $lz_error;
255 360
256 - // Get the logs
257 - $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_iprange` WHERE (".ip2long($lz_globals['current_ip'])." BETWEEN `start` AND `end`) AND `whitelist` = '1';");
361 + $whitelist = $loginizer['whitelist'];
362 +
363 + foreach($whitelist as $k => $v){
258 364
365 + // Is the IP in the blacklist ?
366 + if(ip2long($v['start']) <= ip2long($loginizer['current_ip']) && ip2long($loginizer['current_ip']) <= ip2long($v['end'])){
367 + $result = 1;
368 + break;
369 + }
370 +
371 + }
372 +
259 373 // You are whitelisted
260 374 if(!empty($result)){
261 375 return true;
262 376 }
@@ -261,36 +375,61 @@
261 375 return true;
262 376 }
263 377
264 378 return false;
379 +
265 380 }
266 381
267 -function lz_login_failed($username){
382 +// Returns an error if the users IP is blocked
383 +function loginizer_wp_authenticate_user($user, $username){
268 384
269 - global $wpdb, $lz_globals, $lz_cannot_login;
385 + global $lz_error, $lz_cannot_login;
270 386
387 + // Is there a regulare error ?
388 + if(is_wp_error($user)){
389 + return $user;
390 + }
391 +
392 + // If we havent blocked it yet, just return $user
271 393 if(empty($lz_cannot_login)){
272 - $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_failed_logs` WHERE `ip` = '".$lz_globals['current_ip']."';");
394 + return $user;
395 + }
396 +
397 + // We have blocked the IP
398 + $error = new WP_Error();
399 + $error->add('ip_blocked', implode('', $lz_error));
400 + return $error;
401 +
402 +}
403 +
404 +// When the login fails, then this is called
405 +// We need to update the database
406 +function loginizer_login_failed($username){
407 +
408 + global $wpdb, $loginizer, $lz_cannot_login;
409 +
410 + if(empty($lz_cannot_login)){
273 411
412 + $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = '".$loginizer['current_ip']."';");
413 +
274 414 if(!empty($result)){
275 - $lockout = floor(($result['count'] / $lz_globals['lz_max_retries']));
276 - $sresult = $wpdb->query("UPDATE `".$wpdb->prefix."lz_failed_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = `count`+1, `lockout` = '".$lockout."' WHERE `ip` = '".$lz_globals['current_ip']."';");
415 + $lockout = floor((($result['count']+1) / $loginizer['max_retries']));
416 + $sresult = $wpdb->query("UPDATE `".$wpdb->prefix."loginizer_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = `count`+1, `lockout` = '".$lockout."' WHERE `ip` = '".$loginizer['current_ip']."';");
277 417
278 - // Do we need to email admin ?
279 - $lz_globals['lz_notify_email'] = 4;
280 - if(!empty($lz_globals['lz_notify_email']) && $lockout >= $lz_globals['lz_notify_email']){
418 + // Do we need to email admin ?
419 + if(!empty($loginizer['notify_email']) && $lockout >= $loginizer['notify_email']){
281 420
282 421 $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname');
283 422 $mail = array();
284 423 $mail['to'] = lz_is_multisite() ? get_site_option('admin_email') : get_option('admin_email');
285 - $mail['subject'] = 'Failed Login Attempts from IP '.$lz_globals['current_ip'].' ('.$sitename.')';
424 + $mail['subject'] = 'Failed Login Attempts from IP '.$loginizer['current_ip'].' ('.$sitename.')';
286 425 $mail['message'] = 'Hi,
287 426
288 -'.($result['count']+1).' failed login attempts and '.$lockout.' lockout(s) from IP '.$lz_globals['current_ip'].'
427 +'.($result['count']+1).' failed login attempts and '.$lockout.' lockout(s) from IP '.$loginizer['current_ip'].'
289 428
290 429 Last Login Attempt : '.date('d/m/Y H:i:s', time()).'
291 430 Last User Attempt : '.$username.'
292 -IP has been blocked until : '.date('m/d/Y H:i:s', time() + $lz_globals['lz_lockout_time']).'
431 +IP has been blocked until : '.date('m/d/Y H:i:s', time() + $loginizer['lockout_time']).'
293 432
294 433 Regards,
295 434 Loginizer';
296 435
@@ -296,30 +435,32 @@
296 435
297 436 @wp_mail($mail['to'], $mail['subject'], $mail['message']);
298 437 }
299 438 }else{
300 - $result = $wpdb->query("INSERT INTO `".$wpdb->prefix."lz_failed_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = '1', `ip` = '".$lz_globals['current_ip']."', `lockout` = '0';");
439 + $result = $wpdb->query("INSERT INTO `".$wpdb->prefix."loginizer_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = '1', `ip` = '".$loginizer['current_ip']."', `lockout` = '0';");
301 440 }
302 441 }
303 442 }
304 443
305 -function lz_update_error_msg($default_msg){
444 +// Modifies the default error messages shown
445 +function loginizer_update_error_msg($default_msg){
306 446
307 - global $wpdb, $lz_globals, $lz_user_pass, $lz_cannot_login;
447 + global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
308 448
309 449 $msg = '';
310 450
311 451 if(!empty($lz_user_pass) && empty($lz_cannot_login)){
312 452
313 - $msg = '<b>ERROR:</b> Incorrect Username or Password';
453 + $msg = '<b>ERROR:</b> Incorrect Username or Password';
314 454
315 - if(!empty($lz_globals['lz_retries_left'])){
316 - $msg .= '<br /><b>'.$lz_globals['lz_retries_left'].'</b> attempt(s) left';
455 + // If we are to show the number of retries left
456 + if(isset($loginizer['retries_left'])){
457 + $msg .= '<br /><b>'.$loginizer['retries_left'].'</b> attempt(s) left';
317 458 }
318 459 }
319 460
320 461 if(!empty($msg)){
321 - return $msg;
462 + return $msg;
322 463 }else{
323 464 return $default_msg;
324 465 }
325 466
@@ -324,31 +465,32 @@
324 465 }
325 466
326 467 }
327 468
328 -function lz_reset_retries(){
469 +function loginizer_reset_retries(){
329 470
330 - global $wpdb, $lz_globals;
471 + global $wpdb, $loginizer;
331 472
332 - $deltime = time() - $lz_globals['lz_reset_retries'];
333 - $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."lz_failed_logs` WHERE `time` <= '".$deltime."';");
473 + $deltime = time() - $loginizer['reset_retries'];
474 + $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs` WHERE `time` <= '".$deltime."';");
334 475
335 - lz_update_option('lz_last_reset', time());
476 + update_option('loginizer_last_reset', time());
336 477
337 478 }
338 479
339 480 // Add settings link on plugin page
340 -function lz_settings_link($links) {
341 - $settings_link = '<a href="options-general.php?page=loginizer">Settings</a>';
342 - array_unshift($links, $settings_link);
343 - return $links;
481 +function loginizer_settings_link($links) {
482 + $settings_link = '<a href="options-general.php?page=loginizer">Settings</a>';
483 + array_unshift($links, $settings_link);
484 + return $links;
344 485 }
345 486
346 487 $plugin = plugin_basename(__FILE__);
347 -add_filter("plugin_action_links_$plugin", 'lz_settings_link' );
488 +add_filter("plugin_action_links_$plugin", 'loginizer_settings_link' );
348 489
349 490 add_action('admin_menu', 'loginizer_admin_menu');
350 491
492 +// Shows the admin menu of Loginizer
351 493 function loginizer_admin_menu() {
352 494 global $wp_version;
353 495
354 496 // Modern WP?
@@ -366,11 +508,12 @@
366 508 // Older WP
367 509 add_options_page('Loginizer', 'Loginizer', 9, 'loginizer', 'loginizer_option_page');
368 510 }
369 511
512 +// The Loginizer Admin Options Page
370 513 function loginizer_option_page(){
371 514
372 - global $wpdb, $wp_roles, $lz_globals;
515 + global $wpdb, $wp_roles, $loginizer;
373 516
374 517 if(!current_user_can('manage_options')){
375 518 wp_die('Sorry, but you do not have permissions to change settings.');
376 519 }
@@ -379,30 +522,37 @@
379 522 if(count($_POST) > 0){
380 523 check_admin_referer('loginizer-options');
381 524 }
382 525
526 + // Load the blacklist and whitelist
527 + $loginizer['blacklist'] = get_option('loginizer_blacklist');
528 + $loginizer['whitelist'] = get_option('loginizer_whitelist');
529 +
383 530 if(isset($_POST['save_lz'])){
384 531
385 - $lz_max_retries = (int) lz_optpost('lz_max_retries');
386 - $lz_lockout_time = (int) lz_optpost('lz_lockout_time');
387 - $lz_max_lockouts = (int) lz_optpost('lz_max_lockouts');
388 - $lz_lockouts_extend = (int) lz_optpost('lz_lockouts_extend');
389 - $lz_reset_retries = (int) lz_optpost('lz_reset_retries');
390 - $lz_notify_email = (int) lz_optpost('lz_notify_email');
532 + $max_retries = (int) lz_optpost('max_retries');
533 + $lockout_time = (int) lz_optpost('lockout_time');
534 + $max_lockouts = (int) lz_optpost('max_lockouts');
535 + $lockouts_extend = (int) lz_optpost('lockouts_extend');
536 + $reset_retries = (int) lz_optpost('reset_retries');
537 + $notify_email = (int) lz_optpost('notify_email');
391 538
392 - $lz_lockout_time = $lz_lockout_time * 60;
393 - $lz_lockouts_extend = $lz_lockouts_extend * 60 * 60;
394 - $lz_reset_retries = $lz_reset_retries * 60 * 60;
539 + $lockout_time = $lockout_time * 60;
540 + $lockouts_extend = $lockouts_extend * 60 * 60;
541 + $reset_retries = $reset_retries * 60 * 60;
395 542
396 543 if(empty($error)){
397 544
398 - lz_update_option('lz_max_retries', $lz_max_retries);
399 - lz_update_option('lz_lockout_time', $lz_lockout_time);
400 - lz_update_option('lz_max_lockouts', $lz_max_lockouts);
401 - lz_update_option('lz_lockouts_extend', $lz_lockouts_extend);
402 - lz_update_option('lz_reset_retries', $lz_reset_retries);
403 - lz_update_option('lz_notify_email', $lz_notify_email);
545 + $option['max_retries'] = $max_retries;
546 + $option['lockout_time'] = $lockout_time;
547 + $option['max_lockouts'] = $max_lockouts;
548 + $option['lockouts_extend'] = $lockouts_extend;
549 + $option['reset_retries'] = $reset_retries;
550 + $option['notify_email'] = $notify_email;
404 551
552 + // Save the options
553 + update_option('loginizer_options', $option);
554 +
405 555 $saved = true;
406 556
407 557 }else{
408 558 lz_report_error($error);
@@ -419,16 +569,38 @@
419 569 }
420 570
421 571 }
422 572
573 + // Delete a Blackist IP range
574 + if(isset($_GET['bdelid'])){
575 +
576 + $delid = (int) lz_optreq('bdelid');
577 +
578 + // Unset and save
579 + $blacklist = $loginizer['blacklist'];
580 + unset($blacklist[$delid]);
581 + update_option('loginizer_blacklist', $blacklist);
582 +
583 + echo '<div id="message" class="updated fade"><p>'
584 + . __('The Blacklist IP range has been deleted successfully', 'loginizer')
585 + . '</p></div>';
586 +
587 + }
588 +
589 + // Delete a Whitelist IP range
423 590 if(isset($_GET['delid'])){
424 591
425 592 $delid = (int) lz_optreq('delid');
426 593
427 - $wpdb->query("DELETE FROM ".$wpdb->prefix."lz_iprange WHERE `rid` = '".$delid."'");
594 + // Unset and save
595 + $whitelist = $loginizer['whitelist'];
596 + unset($whitelist[$delid]);
597 + update_option('loginizer_whitelist', $whitelist);
598 +
428 599 echo '<div id="message" class="updated fade"><p>'
429 - . __('IP range has been deleted successfully', 'loginizer')
430 - . '</p></div>';
600 + . __('The Whitelist IP range has been deleted successfully', 'loginizer')
601 + . '</p></div>';
602 +
431 603 }
432 604
433 605 if(isset($_POST['blacklist_iprange'])){
434 606
@@ -457,65 +629,48 @@
457 629 }
458 630
459 631 if(empty($error)){
460 632
461 - // This is to check if there is any other range exists with the same Start or End IP
462 - $ip_exists_query = "SELECT * FROM ".$wpdb->prefix."lz_iprange WHERE
463 - `blacklist` = '1' AND
464 - (`start` BETWEEN '".ip2long($start_ip)."' AND '".ip2long($end_ip)."'
465 - OR `end` BETWEEN '".ip2long($start_ip)."' AND '".ip2long($end_ip)."');";
633 + $blacklist = $loginizer['blacklist'];
466 634
467 - $ip_exists = $wpdb->get_results($ip_exists_query);
468 - //print_r($ip_exists);
469 -
470 - if(!empty($ip_exists)){
471 - $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range!';
635 + foreach($blacklist as $k => $v){
636 +
637 + // This is to check if there is any other range exists with the same Start or End IP
638 + if(( ip2long($start_ip) <= ip2long($v['start']) && ip2long($v['start']) <= ip2long($end_ip) )
639 + || ( ip2long($start_ip) <= ip2long($v['end']) && ip2long($v['end']) <= ip2long($end_ip) )
640 + ){
641 + $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
642 + break;
643 + }
644 +
645 + // This is to check if there is any other range exists with the same Start IP
646 + if(ip2long($v['start']) <= ip2long($start_ip) && ip2long($start_ip) <= ip2long($v['end'])){
647 + $error[] = 'The Start IP is present in an existing range !';
648 + break;
649 + }
650 +
651 + // This is to check if there is any other range exists with the same End IP
652 + if(ip2long($v['start']) <= ip2long($end_ip) && ip2long($end_ip) <= ip2long($v['end'])){
653 + $error[] = 'The End IP is present in an existing range!';
654 + break;
655 + }
656 +
472 657 }
473 658
474 - // This is to check if there is any other range exists with the same Start IP
475 - $start_ip_exists_query = "SELECT * FROM ".$wpdb->prefix."lz_iprange WHERE
476 - `blacklist` = '1' AND
477 - ('".ip2long($start_ip)."' BETWEEN `start` AND `end`);";
478 -
479 - $start_ip_exists = $wpdb->get_results($start_ip_exists_query);
480 - //print_r($start_ip_exists);
481 -
482 - if(!empty($start_ip_exists)){
483 - $error[] = 'The Start IP is present in an existing range!';
484 - }
485 -
486 - // This is to check if there is any other range exists with the same End IP
487 - $end_ip_exists_query = "SELECT * FROM ".$wpdb->prefix."lz_iprange WHERE
488 - `blacklist` = '1' AND
489 - ('".ip2long($end_ip)."' BETWEEN `start` AND `end`);";
490 -
491 - $end_ip_exists = $wpdb->get_results($end_ip_exists_query);
492 - //print_r($end_ip_exists);
493 -
494 - if(!empty($end_ip_exists)){
495 - $error[] = 'The End IP is present in an existing range!';
496 - }
659 + $newid = ( empty($blacklist) ? 0 : max(array_keys($blacklist)) ) + 1;
497 660
498 661 if(empty($error)){
499 662
500 - $options = array();
501 - $options['start'] = ip2long($start_ip);
502 - $options['end'] = ip2long($end_ip);
503 - $options['blacklist'] = 1;
504 - $options['whitelist'] = 0;
505 - $options['date'] = date('Ymd');
663 + $blacklist[$newid] = array();
664 + $blacklist[$newid]['start'] = $start_ip;
665 + $blacklist[$newid]['end'] = $end_ip;
666 + $blacklist[$newid]['time'] = time();
506 667
507 - $wpdb->insert($wpdb->prefix.'lz_iprange', $options);
668 + update_option('loginizer_blacklist', $blacklist);
508 669
509 - if(!empty($wpdb->insert_id)){
510 - echo '<div id="message" class="updated fade"><p>'
670 + echo '<div id="message" class="updated fade"><p>'
511 671 . __('Blacklist IP range added successfully', 'loginizer')
512 672 . '</p></div>';
513 - }else{
514 - echo '<div id="message" class="updated fade"><p>'
515 - . __('There were some errors while adding the blacklist IP range', 'loginizer')
516 - . '</p></div>';
517 - }
518 673
519 674 }
520 675
521 676 }
@@ -522,8 +677,9 @@
522 677
523 678 if(!empty($error)){
524 679 lz_report_error($error);
525 680 }
681 +
526 682 }
527 683
528 684 if(isset($_POST['whitelist_iprange'])){
529 685
@@ -552,65 +708,48 @@
552 708 }
553 709
554 710 if(empty($error)){
555 711
556 - // This is to check if there is any other range exists with the same Start or End IP
557 - $ip_exists_query = "SELECT * FROM ".$wpdb->prefix."lz_iprange WHERE
558 - `whitelist` = '1' AND
559 - (`start` BETWEEN '".ip2long($start_ip)."' AND '".ip2long($end_ip)."'
560 - OR `end` BETWEEN '".ip2long($start_ip)."' AND '".ip2long($end_ip)."');";
712 + $whitelist = $loginizer['whitelist'];
561 713
562 - $ip_exists = $wpdb->get_results($ip_exists_query);
563 - //print_r($ip_exists);
564 -
565 - if(!empty($ip_exists)){
566 - $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range!';
714 + foreach($whitelist as $k => $v){
715 +
716 + // This is to check if there is any other range exists with the same Start or End IP
717 + if(( ip2long($start_ip) <= ip2long($v['start']) && ip2long($v['start']) <= ip2long($end_ip) )
718 + || ( ip2long($start_ip) <= ip2long($v['end']) && ip2long($v['end']) <= ip2long($end_ip) )
719 + ){
720 + $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
721 + break;
722 + }
723 +
724 + // This is to check if there is any other range exists with the same Start IP
725 + if(ip2long($v['start']) <= ip2long($start_ip) && ip2long($start_ip) <= ip2long($v['end'])){
726 + $error[] = 'The Start IP is present in an existing range !';
727 + break;
728 + }
729 +
730 + // This is to check if there is any other range exists with the same End IP
731 + if(ip2long($v['start']) <= ip2long($end_ip) && ip2long($end_ip) <= ip2long($v['end'])){
732 + $error[] = 'The End IP is present in an existing range!';
733 + break;
734 + }
735 +
567 736 }
568 737
569 - // This is to check if there is any other range exists with the same Start IP
570 - $start_ip_exists_query = "SELECT * FROM ".$wpdb->prefix."lz_iprange WHERE
571 - `whitelist` = '1' AND
572 - ('".ip2long($start_ip)."' BETWEEN `start` AND `end`);";
738 + $newid = ( empty($whitelist) ? 0 : max(array_keys($whitelist)) ) + 1;
573 739
574 - $start_ip_exists = $wpdb->get_results($start_ip_exists_query);
575 - //print_r($start_ip_exists);
576 -
577 - if(!empty($start_ip_exists)){
578 - $error[] = 'The Start IP is present in an existing range!';
579 - }
580 -
581 - // This is to check if there is any other range exists with the same End IP
582 - $end_ip_exists_query = "SELECT * FROM ".$wpdb->prefix."lz_iprange WHERE
583 - `whitelist` = '1' AND
584 - ('".ip2long($end_ip)."' BETWEEN `start` AND `end`);";
585 -
586 - $end_ip_exists = $wpdb->get_results($end_ip_exists_query);
587 - //print_r($end_ip_exists);
588 -
589 - if(!empty($end_ip_exists)){
590 - $error[] = 'The End IP is present in an existing range!';
591 - }
592 -
593 740 if(empty($error)){
594 741
595 - $options = array();
596 - $options['start'] = ip2long($start_ip);
597 - $options['end'] = ip2long($end_ip);
598 - $options['blacklist'] = 0;
599 - $options['whitelist'] = 1;
600 - $options['date'] = date('Ymd');
742 + $whitelist[$newid] = array();
743 + $whitelist[$newid]['start'] = $start_ip;
744 + $whitelist[$newid]['end'] = $end_ip;
745 + $whitelist[$newid]['time'] = time();
601 746
602 - $wpdb->insert($wpdb->prefix.'lz_iprange', $options);
747 + update_option('loginizer_whitelist', $whitelist);
603 748
604 - if(!empty($wpdb->insert_id)){
605 - echo '<div id="message" class="updated fade"><p>'
749 + echo '<div id="message" class="updated fade"><p>'
606 750 . __('Whitelist IP range added successfully', 'loginizer')
607 751 . '</p></div>';
608 - }else{
609 - echo '<div id="message" class="updated fade"><p>'
610 - . __('There were some errors while adding the whitelist IP range', 'loginizer')
611 - . '</p></div>';
612 - }
613 752
614 753 }
615 754
616 755 }
@@ -621,24 +760,17 @@
621 760 }
622 761
623 762 // Get the logs
624 763 $result = array();
625 - $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_failed_logs` ORDER BY `count` DESC LIMIT 0, 10;", 1);
764 + $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` ORDER BY `count` DESC LIMIT 0, 10;", 1);
626 765 //print_r($result);
627 766
628 - // Get the Blacklist IP ranges
629 - $blacklist_ips = array();
630 - $blacklist_ips = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_iprange` WHERE `blacklist` = 1;", 1);
631 - //print_r($blacklist_ips);
767 + // Reload the settings
768 + $loginizer['blacklist'] = get_option('loginizer_blacklist');
769 + $loginizer['whitelist'] = get_option('loginizer_whitelist');
632 770
633 - // Get the Whitelist IP ranges
634 - $whitelist_ips = array();
635 - $whitelist_ips = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_iprange` WHERE `whitelist` = 1;", 1);
636 - //print_r($whitelist_ips);
637 -
638 771 ?>
639 -
640 - <div class="wrap">
772 +<div class="wrap">
641 773 <!--This is intentional-->
642 774 <h2></h2>
643 775
644 776 <h1><center><?php echo __('Loginizer','loginizer'); ?></center></h1><hr /><br />
@@ -644,9 +776,9 @@
644 776 <h1><center><?php echo __('Loginizer','loginizer'); ?></center></h1><hr /><br />
645 777
646 778 <script src="http://api.loginizer.com/news.js""></script>
647 779
648 - <h2><?php echo __('Failed Login Attempts Logs &nbsp; (Past '.($lz_globals['lz_reset_retries']/60/60).' hours)','loginizer'); ?></h2><hr /><br />
780 + <h2><?php echo __('Failed Login Attempts Logs &nbsp; (Past '.($loginizer['reset_retries']/60/60).' hours)','loginizer'); ?></h2><hr /><br />
649 781
650 782 <table class="wp-list-table widefat fixed users" border="0">
651 783 <tr>
652 784 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('IP','loginizer'); ?></th>
@@ -683,180 +815,181 @@
683 815 }
684 816 }
685 817 ?>
686 818 </table>
687 - <br />
688 - <h2><?php echo __('Loginizer Settings','loginizer'); ?></h2><hr /><br />
689 -
690 - <form action="options-general.php?page=loginizer" method="post" enctype="multipart/form-data">
691 - <?php wp_nonce_field('loginizer-options'); ?>
692 - <table class="form-table">
693 - <tr>
694 - <th scope="row" valign="top"><label for="lz_max_retries"><?php echo __('Max Retries','loginizer'); ?></label></th>
819 + <br />
820 + <h2><?php echo __('Loginizer Settings','loginizer'); ?></h2><hr /><br />
821 +
822 + <form action="options-general.php?page=loginizer" method="post" enctype="multipart/form-data">
823 + <?php wp_nonce_field('loginizer-options'); ?>
824 + <table class="form-table">
825 + <tr>
826 + <th scope="row" valign="top"><label for="max_retries"><?php echo __('Max Retries','loginizer'); ?></label></th>
695 827 <td>
696 - <input type="text" size="3" value="<?php echo lz_optpost('lz_max_retries', $lz_globals['lz_max_retries']); ?>" name="lz_max_retries" id="lz_max_retries" /> <?php echo __('Maximum failed attempts allowed before lockout','loginizer'); ?> <br />
828 + <input type="text" size="3" value="<?php echo lz_optpost('max_retries', $loginizer['max_retries']); ?>" name="max_retries" id="max_retries" /> <?php echo __('Maximum failed attempts allowed before lockout','loginizer'); ?> <br />
697 829 </td>
698 - </tr>
699 - <tr>
700 - <th scope="row" valign="top"><label for="lz_lockout_time"><?php echo __('Lockout Time','loginizer'); ?></label></th>
830 + </tr>
831 + <tr>
832 + <th scope="row" valign="top"><label for="lockout_time"><?php echo __('Lockout Time','loginizer'); ?></label></th>
701 833 <td>
702 - <input type="text" size="3" value="<?php echo (!empty($lz_lockout_time) ? $lz_lockout_time : $lz_globals['lz_lockout_time']) / 60; ?>" name="lz_lockout_time" id="lz_lockout_time" /> <?php echo __('minutes','loginizer'); ?> <br />
834 + <input type="text" size="3" value="<?php echo (!empty($lockout_time) ? $lockout_time : $loginizer['lockout_time']) / 60; ?>" name="lockout_time" id="lockout_time" /> <?php echo __('minutes','loginizer'); ?> <br />
703 835 </td>
704 - </tr>
705 - <tr>
706 - <th scope="row" valign="top"><label for="lz_max_lockouts"><?php echo __('Max Lockouts','loginizer'); ?></label></th>
836 + </tr>
837 + <tr>
838 + <th scope="row" valign="top"><label for="max_lockouts"><?php echo __('Max Lockouts','loginizer'); ?></label></th>
707 839 <td>
708 - <input type="text" size="3" value="<?php echo lz_optpost('lz_max_lockouts', $lz_globals['lz_max_lockouts']); ?>" name="lz_max_lockouts" id="lz_max_lockouts" /> <?php echo __('','loginizer'); ?> <br />
840 + <input type="text" size="3" value="<?php echo lz_optpost('max_lockouts', $loginizer['max_lockouts']); ?>" name="max_lockouts" id="max_lockouts" /> <?php echo __('','loginizer'); ?> <br />
709 841 </td>
710 - </tr>
711 - <tr>
712 - <th scope="row" valign="top"><label for="lz_lockouts_extend"><?php echo __('Extend Lockout','loginizer'); ?></label></th>
842 + </tr>
843 + <tr>
844 + <th scope="row" valign="top"><label for="lockouts_extend"><?php echo __('Extend Lockout','loginizer'); ?></label></th>
713 845 <td>
714 - <input type="text" size="3" value="<?php echo (!empty($lz_lockouts_extend) ? $lz_lockouts_extend : $lz_globals['lz_lockouts_extend']) / 60 / 60; ?>" name="lz_lockouts_extend" id="lz_lockouts_extend" /> <?php echo __('hours. Extend Lockout time after Max Lockouts','loginizer'); ?> <br />
846 + <input type="text" size="3" value="<?php echo (!empty($lockouts_extend) ? $lockouts_extend : $loginizer['lockouts_extend']) / 60 / 60; ?>" name="lockouts_extend" id="lockouts_extend" /> <?php echo __('hours. Extend Lockout time after Max Lockouts','loginizer'); ?> <br />
715 847 </td>
716 - </tr>
717 - <tr>
718 - <th scope="row" valign="top"><label for="lz_reset_retries"><?php echo __('Reset Retries','loginizer'); ?></label></th>
848 + </tr>
849 + <tr>
850 + <th scope="row" valign="top"><label for="reset_retries"><?php echo __('Reset Retries','loginizer'); ?></label></th>
719 851 <td>
720 - <input type="text" size="3" value="<?php echo (!empty($lz_reset_retries) ? $lz_reset_retries : $lz_globals['lz_reset_retries']) / 60 / 60; ?>" name="lz_reset_retries" id="lz_reset_retries" /> <?php echo __('hours','loginizer'); ?> <br />
852 + <input type="text" size="3" value="<?php echo (!empty($reset_retries) ? $reset_retries : $loginizer['reset_retries']) / 60 / 60; ?>" name="reset_retries" id="reset_retries" /> <?php echo __('hours','loginizer'); ?> <br />
721 853 </td>
722 - </tr>
723 - <tr>
724 - <th scope="row" valign="top"><label for="lz_notify_email"><?php echo __('Email Notification','loginizer'); ?></label></th>
854 + </tr>
855 + <tr>
856 + <th scope="row" valign="top"><label for="notify_email"><?php echo __('Email Notification','loginizer'); ?></label></th>
725 857 <td>
726 - <?php echo __('after ','loginizer'); ?>
727 - <input type="text" size="3" value="<?php echo (!empty($lz_notify_email) ? $lz_notify_email : $lz_globals['lz_notify_email']); ?>" name="lz_notify_email" id="lz_notify_email" /> <?php echo __('lockouts <br />0 to disable email notifications','loginizer'); ?>
858 + <?php echo __('after ','loginizer'); ?>
859 + <input type="text" size="3" value="<?php echo (!empty($notify_email) ? $notify_email : $loginizer['notify_email']); ?>" name="notify_email" id="notify_email" /> <?php echo __('lockouts <br />0 to disable email notifications','loginizer'); ?>
728 860 </td>
729 - </tr>
730 - </table><br />
731 - <input name="save_lz" class="button action" value="<?php echo __('Save Settings','loginizer'); ?>" type="submit" />
732 - </form>
861 + </tr>
862 + </table><br />
863 + <input name="save_lz" class="button action" value="<?php echo __('Save Settings','loginizer'); ?>" type="submit" />
864 + </form>
733 865
734 - <br /><br />
735 - <hr />
736 - <h2><?php echo __('Blacklist IP','loginizer'); ?></h2>
737 - <?php echo __('Enter the IP you want to blacklist from login','loginizer'); ?>
738 - <form action="options-general.php?page=loginizer" method="post">
739 - <?php wp_nonce_field('loginizer-options'); ?>
740 - <table class="form-table">
741 - <tr>
866 + <br /><br />
867 + <hr />
868 + <h2><?php echo __('Blacklist IP','loginizer'); ?></h2>
869 + <?php echo __('Enter the IP you want to blacklist from login','loginizer'); ?>
870 + <form action="options-general.php?page=loginizer" method="post">
871 + <?php wp_nonce_field('loginizer-options'); ?>
872 + <table class="form-table">
873 + <tr>
742 874 <th scope="row" valign="top"><label for="start_ip"><?php echo __('Start IP','loginizer'); ?></label></th>
743 875 <td>
744 - <input type="text" size="25" value="<?php echo(lz_optpost('start_ip')); ?>" name="start_ip" id="start_ip"/> <?php echo __('Start IP of the range','loginizer'); ?> <br />
876 + <input type="text" size="25" value="<?php echo(lz_optpost('start_ip')); ?>" name="start_ip" id="start_ip"/> <?php echo __('Start IP of the range','loginizer'); ?> <br />
745 877 </td>
746 - </tr>
747 - <tr>
878 + </tr>
879 + <tr>
748 880 <th scope="row" valign="top"><label for="end_ip"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
749 881 <td>
750 - <input type="text" size="25" value="<?php echo(lz_optpost('end_ip')); ?>" name="end_ip" id="end_ip"/> <?php echo __('End IP of the range. <br />If you want to blacklist single IP leave this field blank.','loginizer'); ?> <br />
882 + <input type="text" size="25" value="<?php echo(lz_optpost('end_ip')); ?>" name="end_ip" id="end_ip"/> <?php echo __('End IP of the range. <br />If you want to blacklist single IP leave this field blank.','loginizer'); ?> <br />
751 883 </td>
752 - </tr>
753 - </table><br />
754 - <input name="blacklist_iprange" class="button action" value="<?php echo __('Blacklist IP range','loginizer'); ?>" type="submit" />
755 - </form>
756 - <br />
757 - <table class="wp-list-table widefat fixed users" border="0">
758 - <tr>
759 - <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
760 - <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
761 - <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
762 - <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Options','loginizer'); ?></th>
763 - </tr>
764 - <?php
765 - if(empty($blacklist_ips)){
884 + </tr>
885 + </table><br />
886 + <input name="blacklist_iprange" class="button action" value="<?php echo __('Blacklist IP range','loginizer'); ?>" type="submit" />
887 + </form>
888 + <br />
889 + <table class="wp-list-table widefat fixed users" border="0">
890 + <tr>
891 + <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
892 + <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
893 + <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
894 + <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Options','loginizer'); ?></th>
895 + </tr>
896 + <?php
897 + if(empty($loginizer['blacklist'])){
898 + echo '
899 + <tr>
900 + <td colspan="4">
901 + No Blacklist IPs. You will see blacklisted IP ranges here.
902 + </td>
903 + </tr>';
904 + }else{
905 + foreach($loginizer['blacklist'] as $ik => $iv){
766 906 echo '
767 907 <tr>
768 - <td colspan="4">
769 - No Blacklist IPs. You will see blacklisted IP ranges here.
908 + <td>
909 + '.$iv['start'].'
770 910 </td>
911 + <td>
912 + '.$iv['end'].'
913 + </td>
914 + <td>
915 + '.date('d/m/Y', $iv['time']).'
916 + </td>
917 + <td>
918 + <a class="submitdelete" href="options-general.php?page=loginizer&bdelid='.$ik.'" onclick="return confirm(\'Are you sure you want to delete this IP range ?\')">Delete</a>
919 + </td>
771 920 </tr>';
772 - }else{
773 - foreach($blacklist_ips as $ik => $iv){
774 - echo '
775 - <tr>
776 - <td>
777 - '.long2ip($iv['start']).'
778 - </td>
779 - <td>
780 - '.long2ip($iv['end']).'
781 - </td>
782 - <td>
783 - '.date('d/m/Y', strtotime($iv['date'])).'
784 - </td>
785 - <td>
786 - <a class="submitdelete" href="options-general.php?page=loginizer&delid='.$iv['rid'].'" onclick="return confirm(\'Are you sure you want to delete this IP range ?\')">Delete</a>
787 - </td>
788 - </tr>';
789 - }
790 921 }
791 - ?>
792 - </table>
793 - <br />
794 - <hr />
795 - <h2><?php echo __('Whitelist IP','loginizer'); ?></h2>
796 - <?php echo __('Enter the IP you want to whitelist for login','loginizer'); ?>
797 - <form action="options-general.php?page=loginizer" method="post">
798 - <?php wp_nonce_field('loginizer-options'); ?>
799 - <table class="form-table">
800 - <tr>
922 + }
923 + ?>
924 + </table>
925 + <br />
926 + <hr />
927 + <h2><?php echo __('Whitelist IP','loginizer'); ?></h2>
928 + <?php echo __('Enter the IP you want to whitelist for login','loginizer'); ?>
929 + <form action="options-general.php?page=loginizer" method="post">
930 + <?php wp_nonce_field('loginizer-options'); ?>
931 + <table class="form-table">
932 + <tr>
801 933 <th scope="row" valign="top"><label for="start_ip_w"><?php echo __('Start IP','loginizer'); ?></label></th>
802 934 <td>
803 - <input type="text" size="25" value="<?php echo(lz_optpost('start_ip_w')); ?>" name="start_ip_w" id="start_ip_w"/> <?php echo __('Start IP of the range','loginizer'); ?> <br />
935 + <input type="text" size="25" value="<?php echo(lz_optpost('start_ip_w')); ?>" name="start_ip_w" id="start_ip_w"/> <?php echo __('Start IP of the range','loginizer'); ?> <br />
804 936 </td>
805 - </tr>
806 - <tr>
937 + </tr>
938 + <tr>
807 939 <th scope="row" valign="top"><label for="end_ip_w"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
808 940 <td>
809 - <input type="text" size="25" value="<?php echo(lz_optpost('end_ip_w')); ?>" name="end_ip_w" id="end_ip_w"/> <?php echo __('End IP of the range. <br />If you want to whitelist single IP leave this field blank.','loginizer'); ?> <br />
941 + <input type="text" size="25" value="<?php echo(lz_optpost('end_ip_w')); ?>" name="end_ip_w" id="end_ip_w"/> <?php echo __('End IP of the range. <br />If you want to whitelist single IP leave this field blank.','loginizer'); ?> <br />
810 942 </td>
811 - </tr>
812 - </table><br />
813 - <input name="whitelist_iprange" class="button action" value="<?php echo __('Whitelist IP range','loginizer'); ?>" type="submit" />
814 - </form>
815 - <br />
816 - <table class="wp-list-table widefat fixed users" border="0">
943 + </tr>
944 + </table><br />
945 + <input name="whitelist_iprange" class="button action" value="<?php echo __('Whitelist IP range','loginizer'); ?>" type="submit" />
946 + </form>
947 + <br />
948 + <table class="wp-list-table widefat fixed users" border="0">
949 + <tr>
950 + <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
951 + <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
952 + <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
953 + <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Options','loginizer'); ?></th>
954 + </tr>
955 + <?php
956 + if(empty($loginizer['whitelist'])){
957 + echo '
817 958 <tr>
818 - <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
819 - <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
820 - <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
821 - <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Options','loginizer'); ?></th>
822 - </tr>
823 - <?php
824 - if(empty($whitelist_ips)){
825 - echo '
826 - <tr>
827 - <td colspan="4">
828 - No Whitelist IPs. You will see whitelisted IP ranges here.
829 - </td>
830 - </tr>';
831 - }else{
832 - foreach($whitelist_ips as $ik => $iv){
833 - echo '
834 - <tr>
835 - <td>
836 - '.long2ip($iv['start']).'
837 - </td>
838 - <td>
839 - '.long2ip($iv['end']).'
840 - </td>
841 - <td>
842 - '.date('d/m/Y', strtotime($iv['date'])).'
843 - </td>
844 - <td>
845 - <a class="submitdelete" href="options-general.php?page=loginizer&delid='.$iv['rid'].'" onclick="return confirm(\'Are you sure you want to delete this IP range ?\')">Delete</a>
846 - </td>
847 - </tr>';
848 - }
849 - }
850 - ?>
851 - </table>
852 - <br />
853 - </div>
959 + <td colspan="4">
960 + No Whitelist IPs. You will see whitelisted IP ranges here.
961 + </td>
962 + </tr>';
963 + }else{
964 + foreach($loginizer['whitelist'] as $ik => $iv){
965 + echo '
966 + <tr>
967 + <td>
968 + '.$iv['start'].'
969 + </td>
970 + <td>
971 + '.$iv['end'].'
972 + </td>
973 + <td>
974 + '.date('d/m/Y', $iv['time']).'
975 + </td>
976 + <td>
977 + <a class="submitdelete" href="options-general.php?page=loginizer&delid='.$ik.'" onclick="return confirm(\'Are you sure you want to delete this IP range ?\')">Delete</a>
978 + </td>
979 + </tr>';
980 + }
981 + }
982 + ?>
983 + </table>
984 + <br />
985 +</div>
854 986 <?php
855 987
856 988 echo '<br /><br /><hr />
857 - <a href="http://www.loginizer.com" target="_blank">Loginizer</a> v'.lz_version.'. <br />
989 + <a href="http://www.loginizer.com" target="_blank">Loginizer</a> v'.LOGINIZER_VERSION.' <br />
858 990 You can report any bugs <a href="http://wordpress.org/support/plugin/loginizer" target="_blank">here</a>.';
991 +
859 992 }
860 993
861 994 // Sorry to see you going
862 995 register_uninstall_hook( __FILE__, 'loginizer_deactivation');
@@ -865,18 +998,18 @@
865 998
866 999 global $wpdb;
867 1000
868 1001 $sql = array();
869 - $sql[] = "DROP TABLE ".$wpdb->prefix."lz_failed_logs;";
870 - $sql[] = "DROP TABLE ".$wpdb->prefix."lz_options;";
871 - $sql[] = "DROP TABLE ".$wpdb->prefix."lz_iprange;";
1002 + $sql[] = "DROP TABLE ".$wpdb->prefix."loginizer_logs;";
872 1003
873 1004 foreach($sql as $sk => $sv){
874 1005 $wpdb->query($sv);
875 1006 }
876 -
877 1007
878 -delete_option('lz_version');
1008 + delete_option('loginizer_version');
1009 + delete_option('loginizer_options');
1010 + delete_option('loginizer_last_reset');
1011 + delete_option('loginizer_whitelist');
1012 + delete_option('loginizer_blacklist');
879 1013
880 1014 }
881 1015
882 -?>