PluginProbe
Loginizer / 1.4.5
Loginizer v1.4.5
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
loginizer / init.php

init.php in Loginizer 1.4.5, at init.php

2,166 lines 66.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(!function_exists('add_action')){
4 echo 'You are not allowed to access this page directly.';
5 exit;
6 }
7
8 define('LOGINIZER_VERSION', '1.4.5');
9 define('LOGINIZER_DIR', dirname(LOGINIZER_FILE));
10 define('LOGINIZER_URL', plugins_url('', LOGINIZER_FILE));
11 define('LOGINIZER_PRO_URL', 'https://loginizer.com/features#compare');
12 define('LOGINIZER_DOCS', 'https://loginizer.com/docs/');
13
14 include_once(LOGINIZER_DIR.'/functions.php');
15
16 // Ok so we are now ready to go
17 register_activation_hook(LOGINIZER_FILE, 'loginizer_activation');
18
19 // Is called when the ADMIN enables the plugin
20 function loginizer_activation(){
21
22 global $wpdb;
23
24 $sql = array();
25
26 $sql[] = "DROP TABLE IF EXISTS `".$wpdb->prefix."loginizer_logs`";
27
28 $sql[] = "CREATE TABLE `".$wpdb->prefix."loginizer_logs` (
29 `username` varchar(255) NOT NULL DEFAULT '',
30 `time` int(10) NOT NULL DEFAULT '0',
31 `count` int(10) NOT NULL DEFAULT '0',
32 `lockout` int(10) NOT NULL DEFAULT '0',
33 `ip` varchar(255) NOT NULL DEFAULT '',
34 `url` varchar(255) NOT NULL DEFAULT '',
35 UNIQUE KEY `ip` (`ip`)
36 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
37
38 foreach($sql as $sk => $sv){
39 $wpdb->query($sv);
40 }
41
42 add_option('loginizer_version', LOGINIZER_VERSION);
43 add_option('loginizer_options', array());
44 add_option('loginizer_last_reset', 0);
45 add_option('loginizer_whitelist', array());
46 add_option('loginizer_blacklist', array());
47
48 }
49
50 // Checks if we are to update ?
51 function loginizer_update_check(){
52
53 global $wpdb;
54
55 $sql = array();
56 $current_version = get_option('loginizer_version');
57
58 // It must be the 1.0 pre stuff
59 if(empty($current_version)){
60 $current_version = get_option('lz_version');
61 }
62
63 $version = (int) str_replace('.', '', $current_version);
64
65 // No update required
66 if($current_version == LOGINIZER_VERSION){
67 return true;
68 }
69
70 // Is it first run ?
71 if(empty($current_version)){
72
73 // Reinstall
74 loginizer_activation();
75
76 // Trick the following if conditions to not run
77 $version = (int) str_replace('.', '', LOGINIZER_VERSION);
78
79 }
80
81 // Is it less than 1.0.1 ?
82 if($version < 101){
83
84 // TODO : GET the existing settings
85
86 // Get the existing settings
87 $lz_failed_logs = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_failed_logs`;", 1);
88 $lz_options = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_options`;", 1);
89 $lz_iprange = lz_selectquery("SELECT * FROM `".$wpdb->prefix."lz_iprange`;", 1);
90
91 // Delete the three tables
92 $sql = array();
93 $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_failed_logs;";
94 $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_options;";
95 $sql[] = "DROP TABLE IF EXISTS ".$wpdb->prefix."lz_iprange;";
96
97 foreach($sql as $sk => $sv){
98 $wpdb->query($sv);
99 }
100
101 // Delete option
102 delete_option('lz_version');
103
104 // Reinstall
105 loginizer_activation();
106
107 // TODO : Save the existing settings
108
109 // Update the existing failed logs to new table
110 if(is_array($lz_failed_logs)){
111 foreach($lz_failed_logs as $fk => $fv){
112 $wpdb->query("INSERT INTO ".$wpdb->prefix."loginizer_logs SET `username` = '".$fv['username']."', `time` = '".$fv['time']."', `count` = '".$fv['count']."', `lockout` = '".$fv['lockout']."', `ip` = '".$fv['ip']."';");
113 }
114 }
115
116 // Update the existing options to new structure
117 if(is_array($lz_options)){
118 foreach($lz_options as $ok => $ov){
119
120 if($ov['option_name'] == 'lz_last_reset'){
121 update_option('loginizer_last_reset', $ov['option_value']);
122 continue;
123 }
124
125 $old_option[str_replace('lz_', '', $ov['option_name'])] = $ov['option_value'];
126 }
127 // Save the options
128 update_option('loginizer_options', $old_option);
129 }
130
131 // Update the existing iprange to new structure
132 if(is_array($lz_iprange)){
133
134 $old_blacklist = array();
135 $old_whitelist = array();
136 $bid = 1;
137 $wid = 1;
138 foreach($lz_iprange as $ik => $iv){
139
140 if(!empty($iv['blacklist'])){
141 $old_blacklist[$bid] = array();
142 $old_blacklist[$bid]['start'] = long2ip($iv['start']);
143 $old_blacklist[$bid]['end'] = long2ip($iv['end']);
144 $old_blacklist[$bid]['time'] = strtotime($iv['date']);
145 $bid = $bid + 1;
146 }
147
148 if(!empty($iv['whitelist'])){
149 $old_whitelist[$wid] = array();
150 $old_whitelist[$wid]['start'] = long2ip($iv['start']);
151 $old_whitelist[$wid]['end'] = long2ip($iv['end']);
152 $old_whitelist[$wid]['time'] = strtotime($iv['date']);
153 $wid = $wid + 1;
154 }
155 }
156
157 if(!empty($old_blacklist)) update_option('loginizer_blacklist', $old_blacklist);
158 if(!empty($old_whitelist)) update_option('loginizer_whitelist', $old_whitelist);
159 }
160
161 }
162
163 // Is it less than 1.3.9 ?
164 if($version < 139){
165
166 $wpdb->query("ALTER TABLE ".$wpdb->prefix."loginizer_logs ADD `url` VARCHAR(255) NOT NULL DEFAULT '' AFTER `ip`;");
167
168 }
169
170 // Save the new Version
171 update_option('loginizer_version', LOGINIZER_VERSION);
172
173 // In Sitepad Math Captcha is enabled by default
174 if(defined('SITEPAD') && get_option('loginizer_captcha') === false){
175 $option['captcha_no_google'] = 1;
176 add_option('loginizer_captcha', $option);
177 }
178
179 }
180
181 // Add the action to load the plugin
182 add_action('plugins_loaded', 'loginizer_load_plugin');
183
184 // The function that will be called when the plugin is loaded
185 function loginizer_load_plugin(){
186
187 global $loginizer;
188
189 // Check if the installed version is outdated
190 loginizer_update_check();
191
192 // Set the array
193 $loginizer = array();
194
195 $loginizer['prefix'] = !defined('SITEPAD') ? 'Loginizer ' : 'SitePad ';
196 $loginizer['app'] = !defined('SITEPAD') ? 'WordPress' : 'SitePad';
197 $loginizer['login_basename'] = !defined('SITEPAD') ? 'wp-login.php' : 'login.php';
198 $loginizer['wp-includes'] = !defined('SITEPAD') ? 'wp-includes' : 'site-inc';
199
200 // The IP Method to use
201 $loginizer['ip_method'] = get_option('loginizer_ip_method');
202 if($loginizer['ip_method'] == 3){
203 $loginizer['custom_ip_method'] = get_option('loginizer_custom_ip_method');
204 }
205
206 // Load settings
207 $options = get_option('loginizer_options');
208 $loginizer['max_retries'] = empty($options['max_retries']) ? 3 : $options['max_retries'];
209 $loginizer['lockout_time'] = empty($options['lockout_time']) ? 900 : $options['lockout_time']; // 15 minutes
210 $loginizer['max_lockouts'] = empty($options['max_lockouts']) ? 5 : $options['max_lockouts'];
211 $loginizer['lockouts_extend'] = empty($options['lockouts_extend']) ? 86400 : $options['lockouts_extend']; // 24 hours
212 $loginizer['reset_retries'] = empty($options['reset_retries']) ? 86400 : $options['reset_retries']; // 24 hours
213 $loginizer['notify_email'] = empty($options['notify_email']) ? 0 : $options['notify_email'];
214
215 // Default messages
216 $loginizer['d_msg']['inv_userpass'] = 'Incorrect Username or Password';
217 $loginizer['d_msg']['ip_blacklisted'] = 'Your IP has been blacklisted';
218
219 // Message Strings
220 $loginizer['msg'] = get_option('loginizer_msg');
221
222 foreach($loginizer['d_msg'] as $lk => $lv){
223 if(empty($loginizer['msg'][$lk])){
224 $loginizer['msg'][$lk] = $loginizer['d_msg'][$lk];
225 }
226 }
227
228 // Load the blacklist and whitelist
229 $loginizer['blacklist'] = get_option('loginizer_blacklist');
230 $loginizer['whitelist'] = get_option('loginizer_whitelist');
231
232 // When was the database cleared last time
233 $loginizer['last_reset'] = get_option('loginizer_last_reset');
234
235 //print_r($loginizer);
236
237 // Clear retries
238 if((time() - $loginizer['last_reset']) >= $loginizer['reset_retries']){
239 loginizer_reset_retries();
240 }
241
242 $ins_time = get_option('loginizer_ins_time');
243 if(empty($ins_time)){
244 $ins_time = time();
245 update_option('loginizer_ins_time', $ins_time);
246 }
247 $loginizer['ins_time'] = $ins_time;
248
249 // Set the current IP
250 $loginizer['current_ip'] = lz_getip();
251
252 // Is Brute Force Disabled ?
253 $loginizer['disable_brute'] = get_option('loginizer_disable_brute');
254
255 // Filters and actions
256 if(empty($loginizer['disable_brute'])){
257
258 // Use this to verify before WP tries to login
259 // Is always called and is the first function to be called
260 //add_action('wp_authenticate', 'loginizer_wp_authenticate', 10, 2);// Not called by XML-RPC
261 add_filter('authenticate', 'loginizer_wp_authenticate', 10001, 3);// This one is called by xmlrpc as well as GUI
262
263 // Is called when a login attempt fails
264 // Hence Update our records that the login failed
265 add_action('wp_login_failed', 'loginizer_login_failed');
266
267 // Is called before displaying the error message so that we dont show that the username is wrong or the password
268 // Update Error message
269 add_action('wp_login_errors', 'loginizer_error_handler', 10001, 2);
270 add_action('woocommerce_login_failed', 'loginizer_woocommerce_error_handler', 10001);
271
272 }
273
274 // Is the premium features there ?
275 if(file_exists(LOGINIZER_DIR.'/premium.php')){
276
277 // Include the file
278 include_once(LOGINIZER_DIR.'/premium.php');
279
280 loginizer_security_init();
281
282 // Its the free version
283 }else{
284
285 // The promo time
286 $loginizer['promo_time'] = get_option('loginizer_promo_time');
287 if(empty($loginizer['promo_time'])){
288 $loginizer['promo_time'] = time();
289 update_option('loginizer_promo_time', $loginizer['promo_time']);
290 }
291
292 // Are we to show the loginizer promo
293 if(!empty($loginizer['promo_time']) && $loginizer['promo_time'] > 0 && $loginizer['promo_time'] < (time() - (30*24*3600))){
294
295 add_action('admin_notices', 'loginizer_promo');
296
297 }
298
299 // Are we to disable the promo
300 if(isset($_GET['loginizer_promo']) && (int)$_GET['loginizer_promo'] == 0){
301 update_option('loginizer_promo_time', (0 - time()) );
302 die('DONE');
303 }
304
305 }
306
307 }
308
309 // Show the promo
310 function loginizer_promo(){
311
312 echo '
313 <style>
314 .lz_button {
315 background-color: #4CAF50; /* Green */
316 border: none;
317 color: white;
318 padding: 8px 16px;
319 text-align: center;
320 text-decoration: none;
321 display: inline-block;
322 font-size: 16px;
323 margin: 4px 2px;
324 -webkit-transition-duration: 0.4s; /* Safari */
325 transition-duration: 0.4s;
326 cursor: pointer;
327 }
328
329 .lz_button:focus{
330 border: none;
331 color: white;
332 }
333
334 .lz_button1 {
335 color: white;
336 background-color: #4CAF50;
337 border:3px solid #4CAF50;
338 }
339
340 .lz_button1:hover {
341 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
342 color: white;
343 border:3px solid #4CAF50;
344 }
345
346 .lz_button2 {
347 color: white;
348 background-color: #0085ba;
349 }
350
351 .lz_button2:hover {
352 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
353 color: white;
354 }
355
356 .lz_button3 {
357 color: white;
358 background-color: #365899;
359 }
360
361 .lz_button3:hover {
362 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
363 color: white;
364 }
365
366 .lz_button4 {
367 color: white;
368 background-color: rgb(66, 184, 221);
369 }
370
371 .lz_button4:hover {
372 box-shadow: 0 6px 8px 0 rgba(0,0,0,0.24), 0 9px 25px 0 rgba(0,0,0,0.19);
373 color: white;
374 }
375
376 .loginizer_promo-close{
377 float:right;
378 text-decoration:none;
379 margin: 5px 10px 0px 0px;
380 }
381
382 .loginizer_promo-close:hover{
383 color: red;
384 }
385 </style>
386
387 <script>
388 jQuery(document).ready( function() {
389 (function($) {
390 $("#loginizer_promo .loginizer_promo-close").click(function(){
391 var data;
392
393 // Hide it
394 $("#loginizer_promo").hide();
395
396 // Save this preference
397 $.post("'.admin_url('?loginizer_promo=0').'", data, function(response) {
398 //alert(response);
399 });
400 });
401 })(jQuery);
402 });
403 </script>
404
405 <div class="notice notice-success" id="loginizer_promo" style="min-height:120px">
406 <a class="loginizer_promo-close" href="javascript:" aria-label="Dismiss this Notice">
407 <span class="dashicons dashicons-dismiss"></span> Dismiss
408 </a>
409 <img src="'.LOGINIZER_URL.'/loginizer-200.png" style="float:left; margin:10px 20px 10px 10px" width="100" />
410 <p style="font-size:16px">We are glad you like Loginizer and have been using it since the past few days. It is time to take the next step </p>
411 <p>
412 <a class="lz_button lz_button1" target="_blank" href="https://loginizer.com/features">Upgrade to Pro</a>
413 <a class="lz_button lz_button2" target="_blank" href="https://wordpress.org/support/view/plugin-reviews/loginizer">Rate it 5�
414 \'s</a>
415 <a class="lz_button lz_button3" target="_blank" href="https://www.facebook.com/Loginizer-815504798591884/">Like Us on Facebook</a>
416 <a class="lz_button lz_button4" target="_blank" href="https://twitter.com/home?status='.rawurlencode('I use @loginizer to secure my #WordPress site - https://loginizer.com').'">Tweet about Loginizer</a>
417 </p>
418 </div>';
419
420 }
421
422 // Should return NULL if everything is fine
423 function loginizer_wp_authenticate($user, $username, $password){
424
425 global $loginizer, $lz_error, $lz_cannot_login, $lz_user_pass;
426
427 if(!empty($username) && !empty($password)){
428 $lz_user_pass = 1;
429 }
430
431 // Are you whitelisted ?
432 if(loginizer_is_whitelisted()){
433 $loginizer['ip_is_whitelisted'] = 1;
434 return $user;
435 }
436
437 // Are you blacklisted ?
438 if(loginizer_is_blacklisted()){
439 $lz_cannot_login = 1;
440 return new WP_Error('ip_blacklisted', implode('', $lz_error), 'loginizer');
441 }
442
443 // Is the username blacklisted ?
444 if(function_exists('loginizer_user_blacklisted')){
445 if(loginizer_user_blacklisted($username)){
446 $lz_cannot_login = 1;
447 return new WP_Error('user_blacklisted', implode('', $lz_error), 'loginizer');
448 }
449 }
450
451 if(loginizer_can_login()){
452 return $user;
453 }
454
455 $lz_cannot_login = 1;
456
457 return new WP_Error('ip_blocked', implode('', $lz_error), 'loginizer');
458
459 }
460
461 function loginizer_can_login(){
462
463 global $wpdb, $loginizer, $lz_error;
464
465 // Get the logs
466 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = '".$loginizer['current_ip']."';");
467
468 if(!empty($result['count']) && ($result['count'] % $loginizer['max_retries']) == 0){
469
470 // Has he reached max lockouts ?
471 if($result['lockout'] >= $loginizer['max_lockouts']){
472 $loginizer['lockout_time'] = $loginizer['lockouts_extend'];
473 }
474
475 // Is he in the lockout time ?
476 if($result['time'] >= (time() - $loginizer['lockout_time'])){
477 $banlift = ceil((($result['time'] + $loginizer['lockout_time']) - time()) / 60);
478
479 //echo 'Current Time '.date('m/d/Y H:i:s', time()).'<br />';
480 //echo 'Last attempt '.date('m/d/Y H:i:s', $result['time']).'<br />';
481 //echo 'Unlock Time '.date('m/d/Y H:i:s', $result['time'] + $loginizer['lockout_time']).'<br />';
482
483 $_time = $banlift.' minute(s)';
484
485 if($banlift > 60){
486 $banlift = ceil($banlift / 60);
487 $_time = $banlift.' hour(s)';
488 }
489
490 $lz_error['ip_blocked'] = 'You have exceeded maximum login retries<br /> Please try after '.$_time;
491
492 return false;
493 }
494 }
495
496 return true;
497 }
498
499 function loginizer_is_blacklisted(){
500
501 global $wpdb, $loginizer, $lz_error;
502
503 $blacklist = $loginizer['blacklist'];
504
505 foreach($blacklist as $k => $v){
506
507 // Is the IP in the blacklist ?
508 if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) && inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
509 $result = 1;
510 break;
511 }
512
513 // Is it in a wider range ?
514 if(inet_ptoi($v['start']) >= 0 && inet_ptoi($v['end']) < 0){
515
516 // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi,
517 // if the current IP is <= than the start of the range, it is within the range
518 // OR
519 // if the current IP is <= than the end of the range, it is within the range
520 if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip'])
521 || inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
522 $result = 1;
523 break;
524 }
525
526 }
527
528 }
529
530 // You are blacklisted
531 if(!empty($result)){
532 $lz_error['ip_blacklisted'] = $loginizer['msg']['ip_blacklisted'];
533 return true;
534 }
535
536 return false;
537
538 }
539
540 function loginizer_is_whitelisted(){
541
542 global $wpdb, $loginizer, $lz_error;
543
544 $whitelist = $loginizer['whitelist'];
545
546 foreach($whitelist as $k => $v){
547
548 // Is the IP in the blacklist ?
549 if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) && inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
550 $result = 1;
551 break;
552 }
553
554 // Is it in a wider range ?
555 if(inet_ptoi($v['start']) >= 0 && inet_ptoi($v['end']) < 0){
556
557 // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi,
558 // if the current IP is <= than the start of the range, it is within the range
559 // OR
560 // if the current IP is <= than the end of the range, it is within the range
561 if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip'])
562 || inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
563 $result = 1;
564 break;
565 }
566
567 }
568
569 }
570
571 // You are whitelisted
572 if(!empty($result)){
573 return true;
574 }
575
576 return false;
577
578 }
579
580
581 // When the login fails, then this is called
582 // We need to update the database
583 function loginizer_login_failed($username){
584
585 global $wpdb, $loginizer, $lz_cannot_login;
586
587 if(empty($lz_cannot_login) && empty($loginizer['ip_is_whitelisted']) && empty($loginizer['no_loginizer_logs'])){
588
589 $url = @addslashes((!empty($_SERVER['HTTPS']) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
590 $url = esc_url($url);
591
592 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = '".$loginizer['current_ip']."';");
593
594 if(!empty($result)){
595 $lockout = floor((($result['count']+1) / $loginizer['max_retries']));
596 $sresult = $wpdb->query("UPDATE `".$wpdb->prefix."loginizer_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = `count`+1, `lockout` = '".$lockout."', `url` = '".$url."' WHERE `ip` = '".$loginizer['current_ip']."';");
597
598 // Do we need to email admin ?
599 if(!empty($loginizer['notify_email']) && $lockout >= $loginizer['notify_email']){
600
601 $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname');
602 $mail = array();
603 $mail['to'] = lz_is_multisite() ? get_site_option('admin_email') : get_option('admin_email');
604 $mail['subject'] = 'Failed Login Attempts from IP '.$loginizer['current_ip'].' ('.$sitename.')';
605 $mail['message'] = 'Hi,
606
607 '.($result['count']+1).' failed login attempts and '.$lockout.' lockout(s) from IP '.$loginizer['current_ip'].'
608
609 Last Login Attempt : '.date('d/m/Y H:i:s', time()).'
610 Last User Attempt : '.$username.'
611 IP has been blocked until : '.date('d/m/Y H:i:s', time() + $loginizer['lockout_time']).'
612
613 Regards,
614 Loginizer';
615
616 @wp_mail($mail['to'], $mail['subject'], $mail['message']);
617 }
618 }else{
619 $insert = $wpdb->query("INSERT INTO `".$wpdb->prefix."loginizer_logs` SET `username` = '".$username."', `time` = '".time()."', `count` = '1', `ip` = '".$loginizer['current_ip']."', `lockout` = '0', `url` = '".$url."';");
620 }
621
622 // We need to add one as this is a failed attempt as well
623 $result['count'] = $result['count'] + 1;
624 $loginizer['retries_left'] = ($loginizer['max_retries'] - ($result['count'] % $loginizer['max_retries']));
625 $loginizer['retries_left'] = $loginizer['retries_left'] == $loginizer['max_retries'] ? 0 : $loginizer['retries_left'];
626
627 }
628 }
629
630 // Handles the error of the password not being there
631 function loginizer_error_handler($errors, $redirect_to){
632
633 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
634
635 //echo 'loginizer_error_handler :';print_r($errors->errors);echo '<br>';
636
637 // Remove the empty password error
638 if(is_wp_error($errors)){
639
640 $codes = $errors->get_error_codes();
641
642 foreach($codes as $k => $v){
643 if($v == 'invalid_username' || $v == 'incorrect_password'){
644 $show_error = 1;
645 }
646 }
647
648 $errors->remove('invalid_username');
649 $errors->remove('incorrect_password');
650
651 }
652
653 // Add the error
654 if(!empty($lz_user_pass) && !empty($show_error) && empty($lz_cannot_login)){
655 $errors->add('invalid_userpass', '<b>ERROR:</b> ' . $loginizer['msg']['inv_userpass']);
656 }
657
658 // Add the number of retires left as well
659 if(count($errors->get_error_codes()) > 0 && isset($loginizer['retries_left'])){
660 $errors->add('retries_left', loginizer_retries_left());
661 }
662
663 return $errors;
664
665 }
666
667
668
669 // Handles the error of the password not being there
670 function loginizer_woocommerce_error_handler(){
671
672 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
673
674 if(function_exists('wc_add_notice')){
675 wc_add_notice( loginizer_retries_left(), 'error' );
676 }
677
678 }
679
680 // Returns a string with the number of retries left
681 function loginizer_retries_left(){
682
683 global $wpdb, $loginizer, $lz_user_pass, $lz_cannot_login;
684
685 // If we are to show the number of retries left
686 if(isset($loginizer['retries_left'])){
687 return '<b>'.$loginizer['retries_left'].'</b> attempt(s) left';
688 }
689
690 }
691
692 function loginizer_reset_retries(){
693
694 global $wpdb, $loginizer;
695
696 $deltime = time() - $loginizer['reset_retries'];
697 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs` WHERE `time` <= '".$deltime."';");
698
699 update_option('loginizer_last_reset', time());
700
701 }
702
703 add_filter("plugin_action_links_$plugin_loginizer", 'loginizer_plugin_action_links');
704
705 // Add settings link on plugin page
706 function loginizer_plugin_action_links($links) {
707
708 if(!defined('LOGINIZER_PREMIUM')){
709 $links[] = '<a href="'.LOGINIZER_PRO_URL.'" style="color:#3db634;" target="_blank">'._x('Upgrade', 'Plugin action link label.', 'loginizer').'</a>';
710 }
711
712 $settings_link = '<a href="admin.php?page=loginizer">Settings</a>';
713 array_unshift($links, $settings_link);
714
715 return $links;
716 }
717
718 add_action('admin_menu', 'loginizer_admin_menu');
719
720 // Shows the admin menu of Loginizer
721 function loginizer_admin_menu() {
722
723 global $wp_version, $loginizer;
724
725 if(!defined('SITEPAD')){
726
727 // Add the menu page
728 add_menu_page(__('Loginizer Dashboard'), __('Loginizer Security'), 'activate_plugins', 'loginizer', 'loginizer_page_dashboard');
729
730 // Dashboard
731 add_submenu_page('loginizer', __('Loginizer Dashboard'), __('Dashboard'), 'activate_plugins', 'loginizer', 'loginizer_page_dashboard');
732
733 }else{
734
735 // Add the menu page
736 add_menu_page(__('Security'), __('Security'), 'activate_plugins', 'loginizer', 'loginizer_page_security', 'dashicons-shield', 85);
737
738 // Rename Login
739 add_submenu_page('loginizer', __('Security Settings'), __('Rename Login'), 'activate_plugins', 'loginizer', 'loginizer_page_security');
740
741 }
742
743 // Brute Force
744 add_submenu_page('loginizer', __('Brute Force Settings'), __('Brute Force'), 'activate_plugins', 'loginizer_brute_force', 'loginizer_page_brute_force');
745
746 if(defined('LOGINIZER_PREMIUM')){
747
748 // PasswordLess
749 add_submenu_page('loginizer', __($loginizer['prefix'].'PasswordLess Settings'), __('PasswordLess'), 'activate_plugins', 'loginizer_passwordless', 'loginizer_page_passwordless');
750
751 // Security Settings
752 if(!defined('SITEPAD')){
753
754 // Two Factor Auth
755 add_submenu_page('loginizer', __($loginizer['prefix'].' Two Factor Authentication'), __('Two Factor Auth'), 'activate_plugins', 'loginizer_2fa', 'loginizer_page_2fa');
756
757 }
758
759 // reCaptcha
760 add_submenu_page('loginizer', __($loginizer['prefix'].'reCAPTCHA Settings'), __('reCAPTCHA'), 'activate_plugins', 'loginizer_recaptcha', 'loginizer_page_recaptcha');
761
762 // Security Settings
763 if(!defined('SITEPAD')){
764
765 // Security Settings
766 add_submenu_page('loginizer', __($loginizer['prefix'].'Security Settings'), __('Security Settings'), 'activate_plugins', 'loginizer_security', 'loginizer_page_security');
767
768 // File Checksums
769 add_submenu_page('loginizer', __('Loginizer File Checksums'), __('File Checksums'), 'activate_plugins', 'loginizer_checksums', 'loginizer_page_checksums');
770
771 }
772
773 }elseif(!defined('LOGINIZER_PREMIUM') && !empty($loginizer['ins_time']) && $loginizer['ins_time'] < (time() - (30*24*3600))){
774
775 // Go Pro link
776 add_submenu_page('loginizer', __('Loginizer Go Pro'), __('Go Pro'), 'activate_plugins', LOGINIZER_PRO_URL);
777
778 }
779
780 }
781
782 // The Loginizer Admin Options Page
783 function loginizer_page_header($title = 'Loginizer'){
784
785 ?>
786 <style>
787 .lz-right-ul{
788 padding-left: 10px !important;
789 }
790
791 .lz-right-ul li{
792 list-style: circle !important;
793 }
794 </style>
795 <?php
796
797 echo '<div style="margin: 10px 20px 0 2px;">
798 <div class="metabox-holder columns-2">
799 <div class="postbox-container">
800 <div id="top-sortables" class="meta-box-sortables ui-sortable">
801
802 <table cellpadding="2" cellspacing="1" width="100%" class="fixed" border="0">
803 <tr>
804 <td valign="top"><h3>'.$loginizer['prefix'].$title.'</h3></td>';
805
806 if(!defined('SITEPAD')){
807
808 echo '<td align="right"><a target="_blank" class="button button-primary" href="https://wordpress.org/support/view/plugin-reviews/loginizer">Review Loginizer</a></td>
809 <td align="right" width="40"><a target="_blank" href="https://twitter.com/loginizer"><img src="'.LOGINIZER_URL.'/twitter.png" /></a></td>
810 <td align="right" width="40"><a target="_blank" href="https://www.facebook.com/Loginizer-815504798591884"><img src="'.LOGINIZER_URL.'/facebook.png" /></a></td>';
811
812 }
813
814 echo '
815 </tr>
816 </table>
817 <hr />
818
819 <!--Main Table-->
820 <table cellpadding="8" cellspacing="1" width="100%" class="fixed">
821 <tr>
822 <td valign="top">';
823
824 }
825
826 // The Loginizer Theme footer
827 function loginizer_page_footer(){
828
829 echo '</td>
830 <td width="200" valign="top" id="loginizer-right-bar">';
831
832 if(!defined('SITEPAD')){
833
834 if(!defined('LOGINIZER_PREMIUM')){
835
836 echo '
837 <div class="postbox" style="min-width:0px !important;">
838 <h2 class="hndle ui-sortable-handle">
839 <span>Premium Version</span>
840 </h2>
841 <div class="inside">
842 <i>Upgrade to the premium version and get the following features </i>:<br>
843 <ul class="lz-right-ul">
844 <li>PasswordLess Login</li>
845 <li>Two Factor Auth - Email</li>
846 <li>Two Factor Auth - App</li>
847 <li>Login Challenge Question</li>
848 <li>reCAPTCHA</li>
849 <li>Rename Login Page</li>
850 <li>Disable XML-RPC</li>
851 <li>And many more ...</li>
852 </ul>
853 <center><a class="button button-primary" href="https://loginizer.com/pricing">Upgrade</a></center>
854 </div>
855 </div>';
856
857 }else{
858
859 echo '
860 <div class="postbox" style="min-width:0px !important;">
861 <h2 class="hndle ui-sortable-handle">
862 <span>Recommendations</span>
863 </h2>
864 <div class="inside">
865 <i>We recommed that you enable atleast one of the following security features</i>:<br>
866 <ul class="lz-right-ul">
867 <li>Rename Login Page</li>
868 <li>Login Challenge Question</li>
869 <li>reCAPTCHA</li>
870 <li>Two Factor Auth - Email</li>
871 <li>Two Factor Auth - App</li>
872 <li>Change \'admin\' Username</li>
873 </ul>
874 </div>
875 </div>';
876 }
877
878 echo '
879 <div class="postbox" style="min-width:0px !important;">
880 <h2 class="hndle ui-sortable-handle">
881 <span><a target="_blank" href="https://pagelayer.com/?from=loginizer-plugin"><img src="'.LOGINIZER_URL.'/images/pagelayer_product.png" width="100%" /></a></span>
882 </h2>
883 <div class="inside">
884 <i>Easily manage and make professional pages and content with our Pagelayer builder </i>:<br>
885 <ul class="lz-right-ul">
886 <li>30+ Free Widgets</li>
887 <li>60+ Premium Widgets</li>
888 <li>400+ Premium Sections</li>
889 <li>Theme Builder</li>
890 <li>WooCommerce Builder</li>
891 <li>Theme Creator and Exporter</li>
892 <li>Form Builder</li>
893 <li>Popup Builder</li>
894 <li>And many more ...</li>
895 </ul>
896 <center><a class="button button-primary" target="_blank" href="https://wordpress.org/plugins/pagelayer/">Visit Pagelayer</a></center>
897 </div>
898 </div>';
899
900 echo '
901 <div class="postbox" style="min-width:0px !important;">
902 <h2 class="hndle ui-sortable-handle">
903 <span><a target="_blank" href="https://wpcentral.co/?from=loginizer-plugin"><img src="'.LOGINIZER_URL.'/images/wpcentral_product.png" width="100%" /></a></span>
904 </h2>
905 <div class="inside">
906 <i>Manage all your WordPress sites from <b>1 dashboard</b> </i>:<br>
907 <ul class="lz-right-ul">
908 <li>1-click Admin Access</li>
909 <li>Update WordPress</li>
910 <li>Update Themes</li>
911 <li>Update Plugins</li>
912 <li>Backup your WordPress Site</li>
913 <li>Plugins & Theme Management</li>
914 <li>Post Management</li>
915 <li>And many more ...</li>
916 </ul>
917 <center><a class="button button-primary" target="_blank" href="https://wpcentral.co/?from=loginizer-plugin">Visit wpCentral</a></center>
918 </div>
919 </div>';
920
921 }
922
923 echo '</td>
924 </tr>
925 </table>';
926
927 if(!defined('SITEPAD')){
928
929 echo '<br />
930 <div style="width:45%;background:#FFF;padding:15px; margin:auto">
931 <b>Let your friends know that you have secured your website :</b>
932 <form method="get" action="https://twitter.com/intent/tweet" id="tweet" onsubmit="return dotweet(this);">
933 <textarea name="text" cols="45" row="3" style="resize:none;">I just secured my @WordPress site against #bruteforce using @loginizer</textarea>
934 &nbsp; &nbsp; <input type="submit" value="Tweet!" class="button button-primary" onsubmit="return false;" id="twitter-btn" style="margin-top:20px;"/>
935 </form>
936
937 </div>
938 <br />
939
940 <script>
941 function dotweet(ele){
942 window.open(jQuery("#"+ele.id).attr("action")+"?"+jQuery("#"+ele.id).serialize(), "_blank", "scrollbars=no, menubar=no, height=400, width=500, resizable=yes, toolbar=no, status=no");
943 return false;
944 }
945 </script>
946
947 <hr />
948 <a href="http://loginizer.com" target="_blank">Loginizer</a> v'.LOGINIZER_VERSION.'. You can report any bugs <a href="http://wordpress.org/support/plugin/loginizer" target="_blank">here</a>.';
949
950 }
951
952 echo '
953 </div>
954 </div>
955 </div>
956 </div>';
957
958 }
959
960 // The Loginizer Admin Options Page
961 function loginizer_page_dashboard(){
962
963 global $loginizer, $lz_error, $lz_env;
964
965 if(!current_user_can('manage_options')){
966 wp_die('Sorry, but you do not have permissions to change settings.');
967 }
968
969 // Dismiss the announcement
970 if(isset($_GET['dismiss_announcement'])){
971 update_option('loginizer_no_announcement', 1);
972 }
973
974 // Is there a license key ?
975 if(isset($_POST['save_lz'])){
976
977 $license = lz_optpost('lz_license');
978
979 // Check if its a valid license
980 if(empty($license)){
981 $lz_error['lic_invalid'] = __('The license key was not submitted', 'loginizer');
982 return loginizer_page_dashboard_T();
983 }
984
985 $resp = wp_remote_get(LOGINIZER_API.'license.php?license='.$license, array('timeout' => 30));
986
987 if(is_array($resp)){
988 $json = json_decode($resp['body'], true);
989 //print_r($json);
990 }else{
991
992 $lz_error['resp_invalid'] = __('The response was malformed<br>'.var_export($resp, true), 'loginizer');
993 return loginizer_page_dashboard_T();
994
995 }
996
997 // Save the License
998 if(empty($json['license'])){
999
1000 $lz_error['lic_invalid'] = __('The license key is invalid', 'loginizer');
1001 return loginizer_page_dashboard_T();
1002
1003 }else{
1004
1005 update_option('loginizer_license', $json);
1006
1007 // Mark as saved
1008 $GLOBALS['lz_saved'] = true;
1009 }
1010
1011 }
1012
1013
1014 // Is there a IP Method ?
1015 if(isset($_POST['save_lz_ip_method'])){
1016
1017 $ip_method = (int) lz_optpost('lz_ip_method');
1018 $custom_ip_method = lz_optpost('lz_custom_ip_method');
1019
1020 if($ip_method >= 0 && $ip_method <= 3){
1021 update_option('loginizer_ip_method', $ip_method);
1022 }
1023
1024 // Custom Method name ?
1025 if($ip_method == 3){
1026 update_option('loginizer_custom_ip_method', $custom_ip_method);
1027 }
1028
1029 }
1030
1031 loginizer_page_dashboard_T();
1032
1033 }
1034
1035 // The Loginizer Admin Options Page - THEME
1036 function loginizer_page_dashboard_T(){
1037
1038 global $loginizer, $lz_error, $lz_env;
1039
1040 loginizer_page_header('Dashboard');
1041 ?>
1042 <style>
1043 .welcome-panel{
1044 margin: 0px;
1045 padding: 10px;
1046 }
1047
1048 input[type="text"], textarea, select {
1049 width: 70%;
1050 }
1051
1052 .form-table label{
1053 font-weight:bold;
1054 }
1055
1056 .exp{
1057 font-size:12px;
1058 }
1059 </style>
1060
1061 <?php
1062
1063 $hide_announcement = get_option('loginizer_no_announcement');
1064 if(empty($hide_announcement)){
1065 echo '<div id="message" class="welcome-panel">'. __('<a href="https://loginizer.com/blog/loginizer-has-been-acquired-by-softaculous/" target="_blank" style="text-decoration:none;">We are excited to announce that we have joined forces with Softaculous and have been acquired by them 😊. Read full announcement here.</a>', 'loginizer'). '<a class="welcome-panel-close" style="top:3px;right:2px;" href="'.menu_page_url('loginizer', false).'&dismiss_announcement=1" aria-label="Dismiss announcement"></a></div><br />';
1066 }
1067
1068 echo '<script src="https://api.loginizer.com/'.(defined('LOGINIZER_PREMIUM') ? 'news_security.js' : 'news.js').'"></script><br>';
1069
1070 // Saved ?
1071 if(!empty($GLOBALS['lz_saved'])){
1072 echo '<div id="message" class="updated"><p>'. __('The settings were saved successfully', 'loginizer'). '</p></div><br />';
1073 }
1074
1075 // Any errors ?
1076 if(!empty($lz_error)){
1077 lz_report_error($lz_error);echo '<br />';
1078 }
1079
1080 ?>
1081
1082 <div class="postbox">
1083
1084 <button class="handlediv button-link" aria-expanded="true" type="button">
1085 <span class="screen-reader-text">Toggle panel: Getting Started</span>
1086 <span class="toggle-indicator" aria-hidden="true"></span>
1087 </button>
1088
1089 <h2 class="hndle ui-sortable-handle">
1090 <span><?php echo __('Getting Started', 'loginizer'); ?></span>
1091 </h2>
1092
1093 <div class="inside">
1094
1095 <form action="" method="post" enctype="multipart/form-data">
1096 <?php wp_nonce_field('loginizer-options'); ?>
1097 <table class="form-table">
1098 <tr>
1099 <td scope="row" valign="top" colspan="2" style="line-height:150%">
1100 <i>Welcome to Loginizer Security. By default the <b>Brute Force Protection</b> is immediately enabled. You should start by going over the default settings and tweaking them as per your needs.</i>
1101 <?php
1102 if(defined('LOGINIZER_PREMIUM')){
1103 echo '<br><i>In the Premium version of Loginizer you have many more features. We recommend you enable features like <b>reCAPTCHA, Two Factor Auth or Email based PasswordLess</b> login. These features will improve your websites security.</i>';
1104 }
1105 ?>
1106 </td>
1107 </tr>
1108 </table>
1109 </form>
1110
1111 </div>
1112 </div>
1113
1114 <div class="postbox">
1115
1116 <button class="handlediv button-link" aria-expanded="true" type="button">
1117 <span class="screen-reader-text">Toggle panel: System Information</span>
1118 <span class="toggle-indicator" aria-hidden="true"></span>
1119 </button>
1120
1121 <h2 class="hndle ui-sortable-handle">
1122 <span><?php echo __('System Information', 'loginizer'); ?></span>
1123 </h2>
1124
1125 <div class="inside">
1126
1127 <form action="" method="post" enctype="multipart/form-data">
1128 <?php wp_nonce_field('loginizer-options'); ?>
1129 <table class="wp-list-table fixed striped users" cellspacing="1" border="0" width="95%" cellpadding="10" align="center">
1130 <?php
1131 echo '
1132 <tr>
1133 <th align="left" width="25%">'.__('Loginizer Version', 'loginizer').'</th>
1134 <td>'.LOGINIZER_VERSION.(defined('LOGINIZER_PREMIUM') ? ' (Security PRO Version)' : '').'</td>
1135 </tr>';
1136
1137 if(defined('LOGINIZER_PREMIUM')){
1138 echo '
1139 <tr>
1140 <th align="left" valign="top">'.__('Loginizer License', 'loginizer').'</th>
1141 <td align="left">
1142 '.(empty($loginizer['license']) ? '<span style="color:red">Unlicensed</span> &nbsp; &nbsp;' : '').'
1143 <input type="text" name="lz_license" value="'.(empty($loginizer['license']) ? '' : $loginizer['license']['license']).'" size="30" placeholder="e.g. WXCSE-SFJJX-XXXXX-AAAAA-BBBBB" style="width:300px;" /> &nbsp;
1144 <input name="save_lz" class="button button-primary" value="Update License" type="submit" />';
1145
1146 if(!empty($loginizer['license'])){
1147
1148 $expires = $loginizer['license']['expires'];
1149 $expires = substr($expires, 0, 4).'/'.substr($expires, 4, 2).'/'.substr($expires, 6);
1150
1151 echo '<div style="margin-top:10px;">License Active : '.(empty($loginizer['license']['active']) ? '<span style="color:red">No</span>' : 'Yes').' &nbsp; &nbsp; &nbsp;
1152 License Expires : '.($loginizer['license']['expires'] <= date('Ymd') ? '<span style="color:red">'.$expires.'</span>' : $expires).'
1153 </div>';
1154 }
1155
1156
1157 echo
1158 '</td>
1159 </tr>';
1160 }
1161
1162 echo '<tr>
1163 <th align="left">'.__('URL', 'loginizer').'</th>
1164 <td>'.get_site_url().'</td>
1165 </tr>
1166 <tr>
1167 <th align="left">'.__('Path', 'loginizer').'</th>
1168 <td>'.ABSPATH.'</td>
1169 </tr>
1170 <tr>
1171 <th align="left">'.__('Server\'s IP Address', 'loginizer').'</th>
1172 <td>'.@$_SERVER['SERVER_ADDR'].'</td>
1173 </tr>
1174 <tr>
1175 <th align="left">'.__('Your IP Address', 'loginizer').'</th>
1176 <td>'.lz_getip().'
1177 <div style="float:right">
1178 Method :
1179 <select name="lz_ip_method" id="lz_ip_method" style="font-size:11px; width:150px" onchange="lz_ip_method_handle()">
1180 <option value="0" '.lz_POSTselect('lz_ip_method', 0, (@$loginizer['ip_method'] == 0)).'>REMOTE_ADDR</option>
1181 <option value="1" '.lz_POSTselect('lz_ip_method', 1, (@$loginizer['ip_method'] == 1)).'>HTTP_X_FORWARDED_FOR</option>
1182 <option value="2" '.lz_POSTselect('lz_ip_method', 2, (@$loginizer['ip_method'] == 2)).'>HTTP_CLIENT_IP</option>
1183 <option value="3" '.lz_POSTselect('lz_ip_method', 3, (@$loginizer['ip_method'] == 3)).'>CUSTOM</option>
1184 </select>
1185 <input name="lz_custom_ip_method" id="lz_custom_ip_method" type="text" value="'.lz_optpost('lz_custom_ip_method', @$loginizer['custom_ip_method']).'" style="font-size:11px; width:100px; display:none" />
1186 <input name="save_lz_ip_method" class="button button-primary" value="Save" type="submit" />
1187 </div>
1188 </td>
1189 </tr>
1190 <tr>
1191 <th align="left">'.__('wp-config.php is writable', 'loginizer').'</th>
1192 <td>'.(is_writable(ABSPATH.'/wp-config.php') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td>
1193 </tr>';
1194
1195 if(file_exists(ABSPATH.'/.htaccess')){
1196 echo '
1197 <tr>
1198 <th align="left">'.__('.htaccess is writable', 'loginizer').'</th>
1199 <td>'.(is_writable(ABSPATH.'/.htaccess') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td>
1200 </tr>';
1201
1202 }
1203
1204 ?>
1205 </table>
1206 </form>
1207
1208 </div>
1209 </div>
1210
1211 <script type="text/javascript">
1212
1213 function lz_ip_method_handle(){
1214 var ele = jQuery('#lz_ip_method');
1215 if(ele.val() == 3){
1216 jQuery('#lz_custom_ip_method').show();
1217 }else{
1218 jQuery('#lz_custom_ip_method').hide();
1219 }
1220 };
1221
1222 lz_ip_method_handle();
1223
1224 </script>
1225
1226 <div id="" class="postbox">
1227
1228 <button class="handlediv button-link" aria-expanded="true" type="button">
1229 <span class="screen-reader-text">Toggle panel: File Permissions</span>
1230 <span class="toggle-indicator" aria-hidden="true"></span>
1231 </button>
1232
1233 <h2 class="hndle ui-sortable-handle">
1234 <span><?php echo __('File Permissions', 'loginizer'); ?></span>
1235 </h2>
1236
1237 <div class="inside">
1238
1239 <form action="" method="post" enctype="multipart/form-data">
1240 <?php wp_nonce_field('loginizer-options'); ?>
1241 <table class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
1242 <?php
1243
1244 echo '
1245 <tr>
1246 <th style="background:#EFEFEF;">'.__('Relative Path', 'loginizer').'</th>
1247 <th style="width:10%; background:#EFEFEF;">'.__('Suggested', 'loginizer').'</th>
1248 <th style="width:10%; background:#EFEFEF;">'.__('Actual', 'loginizer').'</th>
1249 </tr>';
1250
1251 $wp_content = basename(dirname(dirname(dirname(__FILE__))));
1252
1253 $files_to_check = array('/' => '0755',
1254 '/wp-admin' => '0755',
1255 '/wp-includes' => '0755',
1256 '/wp-config.php' => '0444',
1257 '/'.$wp_content => '0755',
1258 '/'.$wp_content.'/themes' => '0755',
1259 '/'.$wp_content.'/plugins' => '0755',
1260 '.htaccess' => '0444');
1261
1262 $root = ABSPATH;
1263
1264 foreach($files_to_check as $k => $v){
1265
1266 $path = $root.'/'.$k;
1267 $stat = @stat($path);
1268 $suggested = $v;
1269 $actual = substr(sprintf('%o', $stat['mode']), -4);
1270
1271 echo '
1272 <tr>
1273 <td>'.$k.'</td>
1274 <td>'.$suggested.'</td>
1275 <td><span '.($suggested != $actual ? 'style="color: red;"' : '').'>'.$actual.'</span></td>
1276 </tr>';
1277
1278 }
1279
1280 ?>
1281 </table>
1282 </form>
1283
1284 </div>
1285 </div>
1286
1287 <?php
1288
1289 loginizer_page_footer();
1290
1291 }
1292
1293 // The Loginizer Admin Options Page
1294 function loginizer_page_brute_force(){
1295
1296 global $wpdb, $wp_roles, $loginizer;
1297
1298 if(!current_user_can('manage_options')){
1299 wp_die('Sorry, but you do not have permissions to change settings.');
1300 }
1301
1302 /* Make sure post was from this page */
1303 if(count($_POST) > 0){
1304 check_admin_referer('loginizer-options');
1305 }
1306
1307 // BEGIN THEME
1308 loginizer_page_header('Brute Force Settings');
1309
1310 // Load the blacklist and whitelist
1311 $loginizer['blacklist'] = get_option('loginizer_blacklist');
1312 $loginizer['whitelist'] = get_option('loginizer_whitelist');
1313
1314 // Disable Brute Force
1315 if(isset($_POST['disable_brute_lz'])){
1316
1317 // Save the options
1318 update_option('loginizer_disable_brute', 1);
1319
1320 $loginizer['disable_brute'] = 1;
1321
1322 echo '<div id="message" class="updated"><p>'
1323 . __('The Brute Force Protection feature is now disabled', 'loginizer')
1324 . '</p></div><br />';
1325
1326 }
1327
1328 // Enable brute force
1329 if(isset($_POST['enable_brute_lz'])){
1330
1331 // Save the options
1332 update_option('loginizer_disable_brute', 0);
1333
1334 $loginizer['disable_brute'] = 0;
1335
1336 echo '<div id="message" class="updated"><p>'
1337 . __('The Brute Force Protection feature is now enabled', 'loginizer')
1338 . '</p></div><br />';
1339
1340 }
1341
1342 // The Brute Force Settings
1343 if(isset($_POST['save_lz'])){
1344
1345 $max_retries = (int) lz_optpost('max_retries');
1346 $lockout_time = (int) lz_optpost('lockout_time');
1347 $max_lockouts = (int) lz_optpost('max_lockouts');
1348 $lockouts_extend = (int) lz_optpost('lockouts_extend');
1349 $reset_retries = (int) lz_optpost('reset_retries');
1350 $notify_email = (int) lz_optpost('notify_email');
1351
1352 $lockout_time = $lockout_time * 60;
1353 $lockouts_extend = $lockouts_extend * 60 * 60;
1354 $reset_retries = $reset_retries * 60 * 60;
1355
1356 if(empty($error)){
1357
1358 $option['max_retries'] = $max_retries;
1359 $option['lockout_time'] = $lockout_time;
1360 $option['max_lockouts'] = $max_lockouts;
1361 $option['lockouts_extend'] = $lockouts_extend;
1362 $option['reset_retries'] = $reset_retries;
1363 $option['notify_email'] = $notify_email;
1364
1365 // Save the options
1366 update_option('loginizer_options', $option);
1367
1368 $saved = true;
1369
1370 }else{
1371 lz_report_error($error);
1372 }
1373
1374 if(!empty($notice)){
1375 lz_report_notice($notice);
1376 }
1377
1378 if(!empty($saved)){
1379 echo '<div id="message" class="updated"><p>'
1380 . __('The settings were saved successfully', 'loginizer')
1381 . '</p></div><br />';
1382 }
1383
1384 }
1385
1386 // Delete a Blackist IP range
1387 if(isset($_POST['bdelid'])){
1388
1389 $delid = (int) lz_optreq('bdelid');
1390
1391 // Unset and save
1392 $blacklist = $loginizer['blacklist'];
1393 unset($blacklist[$delid]);
1394 update_option('loginizer_blacklist', $blacklist);
1395
1396 echo '<div id="message" class="updated fade"><p>'
1397 . __('The Blacklist IP range has been deleted successfully', 'loginizer')
1398 . '</p></div><br />';
1399
1400 }
1401
1402 // Delete all Blackist IP ranges
1403 if(isset($_POST['del_all_blacklist'])){
1404
1405 // Unset and save
1406 update_option('loginizer_blacklist', array());
1407
1408 echo '<div id="message" class="updated fade"><p>'
1409 . __('The Blacklist IP range(s) have been cleared successfully', 'loginizer')
1410 . '</p></div><br />';
1411
1412 }
1413
1414 // Delete a Whitelist IP range
1415 if(isset($_POST['delid'])){
1416
1417 $delid = (int) lz_optreq('delid');
1418
1419 // Unset and save
1420 $whitelist = $loginizer['whitelist'];
1421 unset($whitelist[$delid]);
1422 update_option('loginizer_whitelist', $whitelist);
1423
1424 echo '<div id="message" class="updated fade"><p>'
1425 . __('The Whitelist IP range has been deleted successfully', 'loginizer')
1426 . '</p></div><br />';
1427
1428 }
1429
1430 // Delete all Blackist IP ranges
1431 if(isset($_POST['del_all_whitelist'])){
1432
1433 // Unset and save
1434 update_option('loginizer_whitelist', array());
1435
1436 echo '<div id="message" class="updated fade"><p>'
1437 . __('The Whitelist IP range(s) have been cleared successfully', 'loginizer')
1438 . '</p></div><br />';
1439
1440 }
1441
1442 // Reset All Logs
1443 if(isset($_POST['lz_reset_all_ip'])){
1444
1445 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs`
1446 WHERE `time` > 0");
1447
1448 echo '<div id="message" class="updated fade"><p>'
1449 . __('All the IP Logs have been cleared', 'loginizer')
1450 . '</p></div><br />';
1451 }
1452
1453 // Reset Logs
1454 if(isset($_POST['lz_reset_ips']) && is_array($_POST['lz_reset_ips'])){
1455
1456 $ips = $_POST['lz_reset_ips'];
1457
1458 foreach($ips as $ip){
1459 if(!lz_valid_ip($ip)){
1460 $error[] = 'The IP - '.$ip.' is invalid !';
1461 }
1462 }
1463
1464 if(count($ips) < 1){
1465 $error[] = 'There are no IPs submitted';
1466 }
1467
1468 // Should we start deleting logs
1469 if(empty($error)){
1470
1471 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs`
1472 WHERE `ip` IN ('".implode("', '", $ips)."')");
1473
1474 if(empty($error)){
1475
1476 echo '<div id="message" class="updated fade"><p>'
1477 . __('The selected IP Logs have been reset', 'loginizer')
1478 . '</p></div><br />';
1479
1480 }
1481
1482 }
1483
1484 if(!empty($error)){
1485 lz_report_error($error);echo '<br />';
1486 }
1487
1488 }
1489
1490 if(isset($_POST['blacklist_iprange'])){
1491
1492 $start_ip = lz_optpost('start_ip');
1493 $end_ip = lz_optpost('end_ip');
1494
1495 if(empty($start_ip)){
1496 $error[] = 'Please enter the Start IP';
1497 }
1498
1499 // If no end IP we consider only 1 IP
1500 if(empty($end_ip)){
1501 $end_ip = $start_ip;
1502 }
1503
1504 if(!lz_valid_ip($start_ip)){
1505 $error[] = 'Please provide a valid start IP';
1506 }
1507
1508 if(!lz_valid_ip($end_ip)){
1509 $error[] = 'Please provide a valid end IP';
1510 }
1511
1512 // Regular ranges will work
1513 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1514
1515 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1516 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1517 // This is right
1518 }else{
1519 $error[] = 'The End IP cannot be smaller than the Start IP';
1520 }
1521
1522 }
1523
1524 if(empty($error)){
1525
1526 $blacklist = $loginizer['blacklist'];
1527
1528 foreach($blacklist as $k => $v){
1529
1530 // This is to check if there is any other range exists with the same Start or End IP
1531 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1532 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1533 ){
1534 $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
1535 break;
1536 }
1537
1538 // This is to check if there is any other range exists with the same Start IP
1539 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1540 $error[] = 'The Start IP is present in an existing range !';
1541 break;
1542 }
1543
1544 // This is to check if there is any other range exists with the same End IP
1545 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1546 $error[] = 'The End IP is present in an existing range!';
1547 break;
1548 }
1549
1550 }
1551
1552 $newid = ( empty($blacklist) ? 0 : max(array_keys($blacklist)) ) + 1;
1553
1554 if(empty($error)){
1555
1556 $blacklist[$newid] = array();
1557 $blacklist[$newid]['start'] = $start_ip;
1558 $blacklist[$newid]['end'] = $end_ip;
1559 $blacklist[$newid]['time'] = time();
1560
1561 update_option('loginizer_blacklist', $blacklist);
1562
1563 echo '<div id="message" class="updated fade"><p>'
1564 . __('Blacklist IP range added successfully', 'loginizer')
1565 . '</p></div><br />';
1566
1567 }
1568
1569 }
1570
1571 if(!empty($error)){
1572 lz_report_error($error);echo '<br />';
1573 }
1574
1575 }
1576
1577 if(isset($_POST['whitelist_iprange'])){
1578
1579 $start_ip = lz_optpost('start_ip_w');
1580 $end_ip = lz_optpost('end_ip_w');
1581
1582 if(empty($start_ip)){
1583 $error[] = 'Please enter the Start IP';
1584 }
1585
1586 // If no end IP we consider only 1 IP
1587 if(empty($end_ip)){
1588 $end_ip = $start_ip;
1589 }
1590
1591 if(!lz_valid_ip($start_ip)){
1592 $error[] = 'Please provide a valid start IP';
1593 }
1594
1595 if(!lz_valid_ip($end_ip)){
1596 $error[] = 'Please provide a valid end IP';
1597 }
1598
1599 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1600
1601 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1602 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1603 // This is right
1604 }else{
1605 $error[] = 'The End IP cannot be smaller than the Start IP';
1606 }
1607
1608 }
1609
1610 if(empty($error)){
1611
1612 $whitelist = $loginizer['whitelist'];
1613
1614 foreach($whitelist as $k => $v){
1615
1616 // This is to check if there is any other range exists with the same Start or End IP
1617 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1618 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1619 ){
1620 $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
1621 break;
1622 }
1623
1624 // This is to check if there is any other range exists with the same Start IP
1625 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1626 $error[] = 'The Start IP is present in an existing range !';
1627 break;
1628 }
1629
1630 // This is to check if there is any other range exists with the same End IP
1631 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1632 $error[] = 'The End IP is present in an existing range!';
1633 break;
1634 }
1635
1636 }
1637
1638 $newid = ( empty($whitelist) ? 0 : max(array_keys($whitelist)) ) + 1;
1639
1640 if(empty($error)){
1641
1642 $whitelist[$newid] = array();
1643 $whitelist[$newid]['start'] = $start_ip;
1644 $whitelist[$newid]['end'] = $end_ip;
1645 $whitelist[$newid]['time'] = time();
1646
1647 update_option('loginizer_whitelist', $whitelist);
1648
1649 echo '<div id="message" class="updated fade"><p>'
1650 . __('Whitelist IP range added successfully', 'loginizer')
1651 . '</p></div><br />';
1652
1653 }
1654
1655 }
1656
1657 if(!empty($error)){
1658 lz_report_error($error);echo '<br />';
1659 }
1660 }
1661
1662 // Save the messages
1663 if(isset($_POST['save_err_msgs_lz'])){
1664
1665 $msgs['inv_userpass'] = lz_optpost('msg_inv_userpass');
1666 $msgs['ip_blacklisted'] = lz_optpost('msg_ip_blacklisted');
1667
1668 // Update them
1669 update_option('loginizer_msg', $msgs);
1670
1671 echo '<div id="message" class="updated fade"><p>'
1672 . __('Error messages were saved successfully', 'loginizer')
1673 . '</p></div><br />';
1674
1675 }
1676
1677 // Count the Results
1678 $tmp = lz_selectquery("SELECT COUNT(*) AS num FROM `".$wpdb->prefix."loginizer_logs`");
1679 //print_r($tmp);
1680
1681 // Which Page is it
1682 $lz_env['res_len'] = 10;
1683 $lz_env['cur_page'] = lz_get_page('lzpage', $lz_env['res_len']);
1684 $lz_env['num_res'] = $tmp['num'];
1685 $lz_env['max_page'] = ceil($lz_env['num_res'] / $lz_env['res_len']);
1686
1687 // Get the logs
1688 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs`
1689 ORDER BY `time` DESC
1690 LIMIT ".$lz_env['cur_page'].", ".$lz_env['res_len']."", 1);
1691 //print_r($result);
1692
1693 $lz_env['cur_page'] = ($lz_env['cur_page'] / $lz_env['res_len']) + 1;
1694 $lz_env['cur_page'] = $lz_env['cur_page'] < 1 ? 1 : $lz_env['cur_page'];
1695 $lz_env['next_page'] = ($lz_env['cur_page'] + 1) > $lz_env['max_page'] ? $lz_env['max_page'] : ($lz_env['cur_page'] + 1);
1696 $lz_env['prev_page'] = ($lz_env['cur_page'] - 1) < 1 ? 1 : ($lz_env['cur_page'] - 1);
1697
1698 // Reload the settings
1699 $loginizer['blacklist'] = get_option('loginizer_blacklist');
1700 $loginizer['whitelist'] = get_option('loginizer_whitelist');
1701
1702 $saved_msgs = get_option('loginizer_msg');
1703
1704 ?>
1705
1706 <div id="" class="postbox">
1707
1708 <button class="handlediv button-link" aria-expanded="true" type="button">
1709 <span class="screen-reader-text">Toggle panel: Failed Login Attempts Logs</span>
1710 <span class="toggle-indicator" aria-hidden="true"></span>
1711 </button>
1712
1713 <h2 class="hndle ui-sortable-handle">
1714 <?php echo __('<span>Failed Login Attempts Logs</span> &nbsp; (Past '.($loginizer['reset_retries']/60/60).' hours)','loginizer'); ?>
1715 </h2>
1716
1717 <script>
1718 function yesdsd(){
1719 window.location = '<?php echo menu_page_url('loginizer_brute_force', false);?>&lzpage='+jQuery("#current-page-selector").val();
1720 return false;
1721 }
1722 </script>
1723
1724 <form method="get" onsubmit="return yesdsd();">
1725 <div class="tablenav">
1726 <p class="tablenav-pages" style="margin: 5px 10px" align="right">
1727 <span class="displaying-num"><?php echo $lz_env['num_res'];?> items</span>
1728 <span class="pagination-links">
1729 <a class="first-page" href="<?php echo menu_page_url('loginizer_brute_force', false).'&lzpage=1';?>"><span class="screen-reader-text">First page</span><span aria-hidden="true">«</span></a>
1730 <a class="prev-page" href="<?php echo menu_page_url('loginizer_brute_force', false).'&lzpage='.$lz_env['prev_page'];?>"><span class="screen-reader-text">Previous page</span><span aria-hidden="true">‹</span></a>
1731 <span class="paging-input">
1732 <label for="current-page-selector" class="screen-reader-text">Current Page</label>
1733 <input class="current-page" id="current-page-selector" name="lzpage" value="<?php echo $lz_env['cur_page'];?>" size="3" aria-describedby="table-paging" type="text"><span class="tablenav-paging-text"> of <span class="total-pages"><?php echo $lz_env['max_page'];?></span></span>
1734 </span>
1735 <a class="next-page" href="<?php echo menu_page_url('loginizer_brute_force', false).'&lzpage='.$lz_env['next_page'];?>"><span class="screen-reader-text">Next page</span><span aria-hidden="true">›</span></a>
1736 <a class="last-page" href="<?php echo menu_page_url('loginizer_brute_force', false).'&lzpage='.$lz_env['max_page'];?>"><span class="screen-reader-text">Last page</span><span aria-hidden="true">»</span></a>
1737 </span>
1738 </p>
1739 </div>
1740 </form>
1741
1742 <form action="" method="post" enctype="multipart/form-data">
1743 <?php wp_nonce_field('loginizer-options'); ?>
1744 <div class="inside">
1745 <table class="wp-list-table widefat fixed users" border="0">
1746 <tr>
1747 <th scope="row" valign="top" style="background:#EFEFEF;" width="20">#</th>
1748 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('IP','loginizer'); ?></th>
1749 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Attempted Username','loginizer'); ?></th>
1750 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Last Failed Attempt (DD/MM/YYYY)','loginizer'); ?></th>
1751 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Failed Attempts Count','loginizer'); ?></th>
1752 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Lockouts Count','loginizer'); ?></th>
1753 <th scope="row" valign="top" style="background:#EFEFEF;" width="150"><?php echo __('URL Attacked','loginizer'); ?></th>
1754 </tr>
1755 <?php
1756
1757 if(empty($result)){
1758 echo '
1759 <tr>
1760 <td colspan="4">
1761 No Logs. You will see logs about failed login attempts here.
1762 </td>
1763 </tr>';
1764 }else{
1765 foreach($result as $ik => $iv){
1766 $status_button = (!empty($iv['status']) ? 'disable' : 'enable');
1767 echo '
1768 <tr>
1769 <td>
1770 <input type="checkbox" value="'.$iv['ip'].'" name="lz_reset_ips[]" />
1771 </td>
1772 <td>
1773 '.$iv['ip'].'
1774 </td>
1775 <td>
1776 '.$iv['username'].'
1777 </td>
1778 <td>
1779 '.date('d/m/Y H:i:s', $iv['time']).'
1780 </td>
1781 <td>
1782 '.$iv['count'].'
1783 </td>
1784 <td>
1785 '.$iv['lockout'].'
1786 </td>
1787 <td>
1788 '.$iv['url'].'
1789 </td>
1790 </tr>';
1791 }
1792 }
1793
1794 ?>
1795 </table>
1796
1797 <br>
1798 <input name="lz_reset_ip" class="button button-primary action" value="<?php echo __('Remove From Logs', 'loginizer'); ?>" type="submit" />
1799 &nbsp; &nbsp;
1800 <input name="lz_reset_all_ip" class="button button-primary action" value="<?php echo __('Clear All Logs', 'loginizer'); ?>" type="submit" />
1801 </div>
1802 </div>
1803 </form>
1804 <br />
1805
1806 <div id="" class="postbox">
1807
1808 <button class="handlediv button-link" aria-expanded="true" type="button">
1809 <span class="screen-reader-text">Toggle panel: Brute Force Settings</span>
1810 <span class="toggle-indicator" aria-hidden="true"></span>
1811 </button>
1812
1813 <h2 class="hndle ui-sortable-handle">
1814 <span><?php echo __('Brute Force Settings', 'loginizer'); ?></span>
1815 </h2>
1816
1817 <div class="inside">
1818
1819 <form action="" method="post" enctype="multipart/form-data">
1820 <?php wp_nonce_field('loginizer-options'); ?>
1821 <table class="form-table">
1822 <tr>
1823 <th scope="row" valign="top"><label for="max_retries"><?php echo __('Max Retries','loginizer'); ?></label></th>
1824 <td>
1825 <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 />
1826 </td>
1827 </tr>
1828 <tr>
1829 <th scope="row" valign="top"><label for="lockout_time"><?php echo __('Lockout Time','loginizer'); ?></label></th>
1830 <td>
1831 <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 />
1832 </td>
1833 </tr>
1834 <tr>
1835 <th scope="row" valign="top"><label for="max_lockouts"><?php echo __('Max Lockouts','loginizer'); ?></label></th>
1836 <td>
1837 <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 />
1838 </td>
1839 </tr>
1840 <tr>
1841 <th scope="row" valign="top"><label for="lockouts_extend"><?php echo __('Extend Lockout','loginizer'); ?></label></th>
1842 <td>
1843 <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 />
1844 </td>
1845 </tr>
1846 <tr>
1847 <th scope="row" valign="top"><label for="reset_retries"><?php echo __('Reset Retries','loginizer'); ?></label></th>
1848 <td>
1849 <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 />
1850 </td>
1851 </tr>
1852 <tr>
1853 <th scope="row" valign="top"><label for="notify_email"><?php echo __('Email Notification','loginizer'); ?></label></th>
1854 <td>
1855 <?php echo __('after ','loginizer'); ?>
1856 <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'); ?>
1857 </td>
1858 </tr>
1859 </table><br />
1860 <input name="save_lz" class="button button-primary action" value="<?php echo __('Save Settings','loginizer'); ?>" type="submit" />
1861 <?php
1862
1863 if(empty($loginizer['disable_brute'])){
1864
1865 echo '<input name="disable_brute_lz" class="button action" value="'.__('Disable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
1866
1867 }else{
1868
1869 echo '<input name="enable_brute_lz" class="button button-primary action" value="'.__('Enable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
1870
1871 }
1872
1873 ?>
1874 </form>
1875
1876 </div>
1877 </div>
1878 <br />
1879
1880 <?php
1881
1882 wp_enqueue_script('jquery-paginate', LOGINIZER_URL.'/jquery-paginate.js', array('jquery'), '1.10.15');
1883
1884 ?>
1885
1886 <style>
1887 .page-navigation a {
1888 margin: 5px 2px;
1889 display: inline-block;
1890 padding: 5px 8px;
1891 color: #0073aa;
1892 background: #e5e5e5 none repeat scroll 0 0;
1893 border: 1px solid #ccc;
1894 text-decoration: none;
1895 transition-duration: 0.05s;
1896 transition-property: border, background, color;
1897 transition-timing-function: ease-in-out;
1898 }
1899
1900 .page-navigation a[data-selected] {
1901 background-color: #00a0d2;
1902 color: #fff;
1903 }
1904 </style>
1905
1906 <script>
1907
1908 jQuery(document).ready(function(){
1909 jQuery('#lz_bl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_bl_nav')});
1910 jQuery('#lz_wl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_wl_nav')});
1911 });
1912
1913 // Delete a Blacklist / Whitelist IP Range
1914 function del_confirm(field, todo_id, msg){
1915 var ret = confirm(msg);
1916
1917 if(ret){
1918 jQuery('#lz_bl_wl_todo').attr('name', field);
1919 jQuery('#lz_bl_wl_todo').val(todo_id);
1920 jQuery('#lz_bl_wl_form').submit();
1921 }
1922
1923 return false;
1924
1925 }
1926
1927 // Delete all Blacklist / Whitelist IP Ranges
1928 function del_confirm_all(msg){
1929 var ret = confirm(msg);
1930
1931 if(ret){
1932 return true;
1933 }
1934
1935 return false;
1936
1937 }
1938
1939 </script>
1940
1941 <div id="" class="postbox">
1942
1943 <button class="handlediv button-link" aria-expanded="true" type="button">
1944 <span class="screen-reader-text">Toggle panel: Blacklist IP</span>
1945 <span class="toggle-indicator" aria-hidden="true"></span>
1946 </button>
1947
1948 <h2 class="hndle ui-sortable-handle">
1949 <span><?php echo __('Blacklist IP','loginizer'); ?></span>
1950 </h2>
1951
1952 <div class="inside">
1953
1954 <?php echo __('Enter the IP you want to blacklist from login','loginizer'); ?>
1955
1956 <form action="" method="post">
1957 <?php wp_nonce_field('loginizer-options'); ?>
1958 <table class="form-table">
1959 <tr>
1960 <th scope="row" valign="top"><label for="start_ip"><?php echo __('Start IP','loginizer'); ?></label></th>
1961 <td>
1962 <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 />
1963 </td>
1964 </tr>
1965 <tr>
1966 <th scope="row" valign="top"><label for="end_ip"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
1967 <td>
1968 <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 />
1969 </td>
1970 </tr>
1971 </table><br />
1972 <input name="blacklist_iprange" class="button button-primary action" value="<?php echo __('Add Blacklist IP Range','loginizer'); ?>" type="submit" />
1973 <input style="float:right" name="del_all_blacklist" onclick="return del_confirm_all('<?php echo __('Are you sure you want to delete all Blacklist IP Range(s) ?','loginizer'); ?>')" class="button action" value="<?php echo __('Delete All Blacklist IP Range(s)','loginizer'); ?>" type="submit" />
1974 </form>
1975 </div>
1976
1977 <div id="lz_bl_nav" style="margin: 5px 10px; text-align:right"></div>
1978 <table id="lz_bl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
1979 <tr>
1980 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
1981 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
1982 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
1983 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
1984 </tr>
1985 <?php
1986 if(empty($loginizer['blacklist'])){
1987 echo '
1988 <tr>
1989 <td colspan="4">
1990 No Blacklist IPs. You will see blacklisted IP ranges here.
1991 </td>
1992 </tr>';
1993 }else{
1994 foreach($loginizer['blacklist'] as $ik => $iv){
1995 echo '
1996 <tr>
1997 <td>
1998 '.$iv['start'].'
1999 </td>
2000 <td>
2001 '.$iv['end'].'
2002 </td>
2003 <td>
2004 '.date('d/m/Y', $iv['time']).'
2005 </td>
2006 <td>
2007 <a class="submitdelete" href="javascript:void(0)" onclick="return del_confirm(\'bdelid\', '.$ik.', \'Are you sure you want to delete this IP range ?\')">Delete</a>
2008 </td>
2009 </tr>';
2010 }
2011 }
2012 ?>
2013 </table>
2014 <br />
2015 <form action="" method="post" id="lz_bl_wl_form">
2016 <?php wp_nonce_field('loginizer-options'); ?>
2017 <input type="hidden" value="" name="" id="lz_bl_wl_todo"/>
2018 </form>
2019 </div>
2020
2021 <br />
2022
2023 <div id="" class="postbox">
2024
2025 <button class="handlediv button-link" aria-expanded="true" type="button">
2026 <span class="screen-reader-text">Toggle panel: Whitelist IP</span>
2027 <span class="toggle-indicator" aria-hidden="true"></span>
2028 </button>
2029
2030 <h2 class="hndle ui-sortable-handle">
2031 <span><?php echo __('Whitelist IP', 'loginizer'); ?></span>
2032 </h2>
2033
2034 <div class="inside">
2035
2036 <?php echo __('Enter the IP you want to whitelist for login','loginizer'); ?>
2037 <form action="" method="post">
2038 <?php wp_nonce_field('loginizer-options'); ?>
2039 <table class="form-table">
2040 <tr>
2041 <th scope="row" valign="top"><label for="start_ip_w"><?php echo __('Start IP','loginizer'); ?></label></th>
2042 <td>
2043 <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 />
2044 </td>
2045 </tr>
2046 <tr>
2047 <th scope="row" valign="top"><label for="end_ip_w"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
2048 <td>
2049 <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 />
2050 </td>
2051 </tr>
2052 </table><br />
2053 <input name="whitelist_iprange" class="button button-primary action" value="<?php echo __('Add Whitelist IP Range','loginizer'); ?>" type="submit" />
2054 <input style="float:right" name="del_all_whitelist" onclick="return del_confirm_all('<?php echo __('Are you sure you want to delete all Whitelist IP Range(s) ?','loginizer'); ?>')" class="button action" value="<?php echo __('Delete All Whitelist IP Range(s)','loginizer'); ?>" type="submit" />
2055 </form>
2056 </div>
2057
2058 <div id="lz_wl_nav" style="margin: 5px 10px; text-align:right"></div>
2059 <table id="lz_wl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
2060 <tr>
2061 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
2062 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
2063 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
2064 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
2065 </tr>
2066 <?php
2067 if(empty($loginizer['whitelist'])){
2068 echo '
2069 <tr>
2070 <td colspan="4">
2071 No Whitelist IPs. You will see whitelisted IP ranges here.
2072 </td>
2073 </tr>';
2074 }else{
2075 foreach($loginizer['whitelist'] as $ik => $iv){
2076 echo '
2077 <tr>
2078 <td>
2079 '.$iv['start'].'
2080 </td>
2081 <td>
2082 '.$iv['end'].'
2083 </td>
2084 <td>
2085 '.date('d/m/Y', $iv['time']).'
2086 </td>
2087 <td>
2088 <a class="submitdelete" href="javascript:void(0)" onclick="return del_confirm(\'delid\', '.$ik.', \'Are you sure you want to delete this IP range ?\')">Delete</a>
2089 </td>
2090 </tr>';
2091 }
2092 }
2093 ?>
2094 </table>
2095 <br />
2096
2097 </div>
2098
2099 <div id="" class="postbox">
2100
2101 <button class="handlediv button-link" aria-expanded="true" type="button">
2102 <span class="screen-reader-text">Toggle panel: Error Messages</span>
2103 <span class="toggle-indicator" aria-hidden="true"></span>
2104 </button>
2105
2106 <h2 class="hndle ui-sortable-handle">
2107 <span><?php echo __('Error Messages', 'loginizer'); ?></span>
2108 </h2>
2109
2110 <div class="inside">
2111
2112 <form action="" method="post" enctype="multipart/form-data">
2113 <?php wp_nonce_field('loginizer-options'); ?>
2114 <table class="form-table">
2115 <tr>
2116 <th scope="row" valign="top"><label for="msg_inv_userpass"><?php echo __('Failed Login Attempt','loginizer'); ?></label></th>
2117 <td>
2118 <input type="text" size="25" value="<?php echo esc_attr($saved_msgs['inv_userpass']); ?>" name="msg_inv_userpass" id="msg_inv_userpass" />
2119 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['inv_userpass']. '&quot;</em>', 'loginizer'); ?><br />
2120 </td>
2121 </tr>
2122 <tr>
2123 <th scope="row" valign="top"><label for="msg_ip_blacklisted"><?php echo __('Blacklisted IP','loginizer'); ?></label></th>
2124 <td>
2125 <input type="text" size="25" value="<?php echo esc_attr($saved_msgs['ip_blacklisted']); ?>" name="msg_ip_blacklisted" id="msg_ip_blacklisted" />
2126 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['ip_blacklisted']. '&quot;</em>', 'loginizer'); ?><br />
2127 </td>
2128 </tr>
2129 </table><br />
2130 <input name="save_err_msgs_lz" class="button button-primary action" value="<?php echo __('Save Error Messages','loginizer'); ?>" type="submit" />
2131 </form>
2132 </div>
2133 </div>
2134 <?php
2135
2136 loginizer_page_footer();
2137
2138 }
2139
2140
2141 // Sorry to see you going
2142 register_uninstall_hook(LOGINIZER_FILE, 'loginizer_deactivation');
2143
2144 function loginizer_deactivation(){
2145
2146 global $wpdb;
2147
2148 $sql = array();
2149 $sql[] = "DROP TABLE ".$wpdb->prefix."loginizer_logs;";
2150
2151 foreach($sql as $sk => $sv){
2152 $wpdb->query($sv);
2153 }
2154
2155 delete_option('loginizer_version');
2156 delete_option('loginizer_options');
2157 delete_option('loginizer_last_reset');
2158 delete_option('loginizer_whitelist');
2159 delete_option('loginizer_blacklist');
2160 delete_option('loginizer_msg');
2161 delete_option('loginizer_security');
2162 delete_option('loginizer_wp_admin');
2163
2164 }
2165
2166