PluginProbe
Loginizer / 1.4.6
Loginizer v1.4.6
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.6, at init.php

2,168 lines 67.0 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.6');
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('d/M/Y H:i:s P', time()).'<br />';
480 //echo 'Last attempt '.date('d/M/Y H:i:s P', $result['time']).'<br />';
481 //echo 'Unlock Time '.date('d/M/Y H:i:s P', $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 P', time()).'
610 Last User Attempt : '.$username.'
611 IP has been blocked until : '.date('d/M/Y H:i:s P', 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 global $loginizer;
786
787 ?>
788 <style>
789 .lz-right-ul{
790 padding-left: 10px !important;
791 }
792
793 .lz-right-ul li{
794 list-style: circle !important;
795 }
796 </style>
797 <?php
798
799 echo '<div style="margin: 10px 20px 0 2px;">
800 <div class="metabox-holder columns-2">
801 <div class="postbox-container">
802 <div id="top-sortables" class="meta-box-sortables ui-sortable">
803
804 <table cellpadding="2" cellspacing="1" width="100%" class="fixed" border="0">
805 <tr>
806 <td valign="top"><h3>'.$loginizer['prefix'].$title.'</h3></td>';
807
808 if(!defined('SITEPAD')){
809
810 echo '<td align="right"><a target="_blank" class="button button-primary" href="https://wordpress.org/support/view/plugin-reviews/loginizer">Review Loginizer</a></td>
811 <td align="right" width="40"><a target="_blank" href="https://twitter.com/loginizer"><img src="'.LOGINIZER_URL.'/twitter.png" /></a></td>
812 <td align="right" width="40"><a target="_blank" href="https://www.facebook.com/Loginizer-815504798591884"><img src="'.LOGINIZER_URL.'/facebook.png" /></a></td>';
813
814 }
815
816 echo '
817 </tr>
818 </table>
819 <hr />
820
821 <!--Main Table-->
822 <table cellpadding="8" cellspacing="1" width="100%" class="fixed">
823 <tr>
824 <td valign="top">';
825
826 }
827
828 // The Loginizer Theme footer
829 function loginizer_page_footer(){
830
831 echo '</td>
832 <td width="200" valign="top" id="loginizer-right-bar">';
833
834 if(!defined('SITEPAD')){
835
836 if(!defined('LOGINIZER_PREMIUM')){
837
838 echo '
839 <div class="postbox" style="min-width:0px !important;">
840 <h2 class="hndle ui-sortable-handle">
841 <span>Premium Version</span>
842 </h2>
843 <div class="inside">
844 <i>Upgrade to the premium version and get the following features </i>:<br>
845 <ul class="lz-right-ul">
846 <li>PasswordLess Login</li>
847 <li>Two Factor Auth - Email</li>
848 <li>Two Factor Auth - App</li>
849 <li>Login Challenge Question</li>
850 <li>reCAPTCHA</li>
851 <li>Rename Login Page</li>
852 <li>Disable XML-RPC</li>
853 <li>And many more ...</li>
854 </ul>
855 <center><a class="button button-primary" href="https://loginizer.com/pricing">Upgrade</a></center>
856 </div>
857 </div>';
858
859 }else{
860
861 echo '
862 <div class="postbox" style="min-width:0px !important;">
863 <h2 class="hndle ui-sortable-handle">
864 <span>Recommendations</span>
865 </h2>
866 <div class="inside">
867 <i>We recommed that you enable atleast one of the following security features</i>:<br>
868 <ul class="lz-right-ul">
869 <li>Rename Login Page</li>
870 <li>Login Challenge Question</li>
871 <li>reCAPTCHA</li>
872 <li>Two Factor Auth - Email</li>
873 <li>Two Factor Auth - App</li>
874 <li>Change \'admin\' Username</li>
875 </ul>
876 </div>
877 </div>';
878 }
879
880 echo '
881 <div class="postbox" style="min-width:0px !important;">
882 <h2 class="hndle ui-sortable-handle">
883 <span><a target="_blank" href="https://pagelayer.com/?from=loginizer-plugin"><img src="'.LOGINIZER_URL.'/images/pagelayer_product.png" width="100%" /></a></span>
884 </h2>
885 <div class="inside">
886 <i>Easily manage and make professional pages and content with our Pagelayer builder </i>:<br>
887 <ul class="lz-right-ul">
888 <li>30+ Free Widgets</li>
889 <li>60+ Premium Widgets</li>
890 <li>400+ Premium Sections</li>
891 <li>Theme Builder</li>
892 <li>WooCommerce Builder</li>
893 <li>Theme Creator and Exporter</li>
894 <li>Form Builder</li>
895 <li>Popup Builder</li>
896 <li>And many more ...</li>
897 </ul>
898 <center><a class="button button-primary" target="_blank" href="https://wordpress.org/plugins/pagelayer/">Visit Pagelayer</a></center>
899 </div>
900 </div>';
901
902 echo '
903 <div class="postbox" style="min-width:0px !important;">
904 <h2 class="hndle ui-sortable-handle">
905 <span><a target="_blank" href="https://wpcentral.co/?from=loginizer-plugin"><img src="'.LOGINIZER_URL.'/images/wpcentral_product.png" width="100%" /></a></span>
906 </h2>
907 <div class="inside">
908 <i>Manage all your WordPress sites from <b>1 dashboard</b> </i>:<br>
909 <ul class="lz-right-ul">
910 <li>1-click Admin Access</li>
911 <li>Update WordPress</li>
912 <li>Update Themes</li>
913 <li>Update Plugins</li>
914 <li>Backup your WordPress Site</li>
915 <li>Plugins & Theme Management</li>
916 <li>Post Management</li>
917 <li>And many more ...</li>
918 </ul>
919 <center><a class="button button-primary" target="_blank" href="https://wpcentral.co/?from=loginizer-plugin">Visit wpCentral</a></center>
920 </div>
921 </div>';
922
923 }
924
925 echo '</td>
926 </tr>
927 </table>';
928
929 if(!defined('SITEPAD')){
930
931 echo '<br />
932 <div style="width:45%;background:#FFF;padding:15px; margin:auto">
933 <b>Let your friends know that you have secured your website :</b>
934 <form method="get" action="https://twitter.com/intent/tweet" id="tweet" onsubmit="return dotweet(this);">
935 <textarea name="text" cols="45" row="3" style="resize:none;">I just secured my @WordPress site against #bruteforce using @loginizer</textarea>
936 &nbsp; &nbsp; <input type="submit" value="Tweet!" class="button button-primary" onsubmit="return false;" id="twitter-btn" style="margin-top:20px;"/>
937 </form>
938
939 </div>
940 <br />
941
942 <script>
943 function dotweet(ele){
944 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");
945 return false;
946 }
947 </script>
948
949 <hr />
950 <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>.';
951
952 }
953
954 echo '
955 </div>
956 </div>
957 </div>
958 </div>';
959
960 }
961
962 // The Loginizer Admin Options Page
963 function loginizer_page_dashboard(){
964
965 global $loginizer, $lz_error, $lz_env;
966
967 if(!current_user_can('manage_options')){
968 wp_die('Sorry, but you do not have permissions to change settings.');
969 }
970
971 // Dismiss the announcement
972 if(isset($_GET['dismiss_announcement'])){
973 update_option('loginizer_no_announcement', 1);
974 }
975
976 // Is there a license key ?
977 if(isset($_POST['save_lz'])){
978
979 $license = lz_optpost('lz_license');
980
981 // Check if its a valid license
982 if(empty($license)){
983 $lz_error['lic_invalid'] = __('The license key was not submitted', 'loginizer');
984 return loginizer_page_dashboard_T();
985 }
986
987 $resp = wp_remote_get(LOGINIZER_API.'license.php?license='.$license, array('timeout' => 30));
988
989 if(is_array($resp)){
990 $json = json_decode($resp['body'], true);
991 //print_r($json);
992 }else{
993
994 $lz_error['resp_invalid'] = __('The response was malformed<br>'.var_export($resp, true), 'loginizer');
995 return loginizer_page_dashboard_T();
996
997 }
998
999 // Save the License
1000 if(empty($json['license'])){
1001
1002 $lz_error['lic_invalid'] = __('The license key is invalid', 'loginizer');
1003 return loginizer_page_dashboard_T();
1004
1005 }else{
1006
1007 update_option('loginizer_license', $json);
1008
1009 // Mark as saved
1010 $GLOBALS['lz_saved'] = true;
1011 }
1012
1013 }
1014
1015
1016 // Is there a IP Method ?
1017 if(isset($_POST['save_lz_ip_method'])){
1018
1019 $ip_method = (int) lz_optpost('lz_ip_method');
1020 $custom_ip_method = lz_optpost('lz_custom_ip_method');
1021
1022 if($ip_method >= 0 && $ip_method <= 3){
1023 update_option('loginizer_ip_method', $ip_method);
1024 }
1025
1026 // Custom Method name ?
1027 if($ip_method == 3){
1028 update_option('loginizer_custom_ip_method', $custom_ip_method);
1029 }
1030
1031 }
1032
1033 loginizer_page_dashboard_T();
1034
1035 }
1036
1037 // The Loginizer Admin Options Page - THEME
1038 function loginizer_page_dashboard_T(){
1039
1040 global $loginizer, $lz_error, $lz_env;
1041
1042 loginizer_page_header('Dashboard');
1043 ?>
1044 <style>
1045 .welcome-panel{
1046 margin: 0px;
1047 padding: 10px;
1048 }
1049
1050 input[type="text"], textarea, select {
1051 width: 70%;
1052 }
1053
1054 .form-table label{
1055 font-weight:bold;
1056 }
1057
1058 .exp{
1059 font-size:12px;
1060 }
1061 </style>
1062
1063 <?php
1064
1065 $hide_announcement = get_option('loginizer_no_announcement');
1066 if(empty($hide_announcement)){
1067 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 />';
1068 }
1069
1070 echo '<script src="https://api.loginizer.com/'.(defined('LOGINIZER_PREMIUM') ? 'news_security.js' : 'news.js').'"></script><br>';
1071
1072 // Saved ?
1073 if(!empty($GLOBALS['lz_saved'])){
1074 echo '<div id="message" class="updated"><p>'. __('The settings were saved successfully', 'loginizer'). '</p></div><br />';
1075 }
1076
1077 // Any errors ?
1078 if(!empty($lz_error)){
1079 lz_report_error($lz_error);echo '<br />';
1080 }
1081
1082 ?>
1083
1084 <div class="postbox">
1085
1086 <button class="handlediv button-link" aria-expanded="true" type="button">
1087 <span class="screen-reader-text">Toggle panel: Getting Started</span>
1088 <span class="toggle-indicator" aria-hidden="true"></span>
1089 </button>
1090
1091 <h2 class="hndle ui-sortable-handle">
1092 <span><?php echo __('Getting Started', 'loginizer'); ?></span>
1093 </h2>
1094
1095 <div class="inside">
1096
1097 <form action="" method="post" enctype="multipart/form-data">
1098 <?php wp_nonce_field('loginizer-options'); ?>
1099 <table class="form-table">
1100 <tr>
1101 <td scope="row" valign="top" colspan="2" style="line-height:150%">
1102 <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>
1103 <?php
1104 if(defined('LOGINIZER_PREMIUM')){
1105 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>';
1106 }
1107 ?>
1108 </td>
1109 </tr>
1110 </table>
1111 </form>
1112
1113 </div>
1114 </div>
1115
1116 <div class="postbox">
1117
1118 <button class="handlediv button-link" aria-expanded="true" type="button">
1119 <span class="screen-reader-text">Toggle panel: System Information</span>
1120 <span class="toggle-indicator" aria-hidden="true"></span>
1121 </button>
1122
1123 <h2 class="hndle ui-sortable-handle">
1124 <span><?php echo __('System Information', 'loginizer'); ?></span>
1125 </h2>
1126
1127 <div class="inside">
1128
1129 <form action="" method="post" enctype="multipart/form-data">
1130 <?php wp_nonce_field('loginizer-options'); ?>
1131 <table class="wp-list-table fixed striped users" cellspacing="1" border="0" width="95%" cellpadding="10" align="center">
1132 <?php
1133 echo '
1134 <tr>
1135 <th align="left" width="25%">'.__('Loginizer Version', 'loginizer').'</th>
1136 <td>'.LOGINIZER_VERSION.(defined('LOGINIZER_PREMIUM') ? ' (Security PRO Version)' : '').'</td>
1137 </tr>';
1138
1139 if(defined('LOGINIZER_PREMIUM')){
1140 echo '
1141 <tr>
1142 <th align="left" valign="top">'.__('Loginizer License', 'loginizer').'</th>
1143 <td align="left">
1144 '.(empty($loginizer['license']) ? '<span style="color:red">Unlicensed</span> &nbsp; &nbsp;' : '').'
1145 <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;
1146 <input name="save_lz" class="button button-primary" value="Update License" type="submit" />';
1147
1148 if(!empty($loginizer['license'])){
1149
1150 $expires = $loginizer['license']['expires'];
1151 $expires = substr($expires, 0, 4).'/'.substr($expires, 4, 2).'/'.substr($expires, 6);
1152
1153 echo '<div style="margin-top:10px;">License Active : '.(empty($loginizer['license']['active']) ? '<span style="color:red">No</span>' : 'Yes').' &nbsp; &nbsp; &nbsp;
1154 License Expires : '.($loginizer['license']['expires'] <= date('Ymd') ? '<span style="color:red">'.$expires.'</span>' : $expires).'
1155 </div>';
1156 }
1157
1158
1159 echo
1160 '</td>
1161 </tr>';
1162 }
1163
1164 echo '<tr>
1165 <th align="left">'.__('URL', 'loginizer').'</th>
1166 <td>'.get_site_url().'</td>
1167 </tr>
1168 <tr>
1169 <th align="left">'.__('Path', 'loginizer').'</th>
1170 <td>'.ABSPATH.'</td>
1171 </tr>
1172 <tr>
1173 <th align="left">'.__('Server\'s IP Address', 'loginizer').'</th>
1174 <td>'.@$_SERVER['SERVER_ADDR'].'</td>
1175 </tr>
1176 <tr>
1177 <th align="left">'.__('Your IP Address', 'loginizer').'</th>
1178 <td>'.lz_getip().'
1179 <div style="float:right">
1180 Method :
1181 <select name="lz_ip_method" id="lz_ip_method" style="font-size:11px; width:150px" onchange="lz_ip_method_handle()">
1182 <option value="0" '.lz_POSTselect('lz_ip_method', 0, (@$loginizer['ip_method'] == 0)).'>REMOTE_ADDR</option>
1183 <option value="1" '.lz_POSTselect('lz_ip_method', 1, (@$loginizer['ip_method'] == 1)).'>HTTP_X_FORWARDED_FOR</option>
1184 <option value="2" '.lz_POSTselect('lz_ip_method', 2, (@$loginizer['ip_method'] == 2)).'>HTTP_CLIENT_IP</option>
1185 <option value="3" '.lz_POSTselect('lz_ip_method', 3, (@$loginizer['ip_method'] == 3)).'>CUSTOM</option>
1186 </select>
1187 <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" />
1188 <input name="save_lz_ip_method" class="button button-primary" value="Save" type="submit" />
1189 </div>
1190 </td>
1191 </tr>
1192 <tr>
1193 <th align="left">'.__('wp-config.php is writable', 'loginizer').'</th>
1194 <td>'.(is_writable(ABSPATH.'/wp-config.php') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td>
1195 </tr>';
1196
1197 if(file_exists(ABSPATH.'/.htaccess')){
1198 echo '
1199 <tr>
1200 <th align="left">'.__('.htaccess is writable', 'loginizer').'</th>
1201 <td>'.(is_writable(ABSPATH.'/.htaccess') ? '<span style="color:red">Yes</span>' : '<span style="color:green">No</span>').'</td>
1202 </tr>';
1203
1204 }
1205
1206 ?>
1207 </table>
1208 </form>
1209
1210 </div>
1211 </div>
1212
1213 <script type="text/javascript">
1214
1215 function lz_ip_method_handle(){
1216 var ele = jQuery('#lz_ip_method');
1217 if(ele.val() == 3){
1218 jQuery('#lz_custom_ip_method').show();
1219 }else{
1220 jQuery('#lz_custom_ip_method').hide();
1221 }
1222 };
1223
1224 lz_ip_method_handle();
1225
1226 </script>
1227
1228 <div id="" class="postbox">
1229
1230 <button class="handlediv button-link" aria-expanded="true" type="button">
1231 <span class="screen-reader-text">Toggle panel: File Permissions</span>
1232 <span class="toggle-indicator" aria-hidden="true"></span>
1233 </button>
1234
1235 <h2 class="hndle ui-sortable-handle">
1236 <span><?php echo __('File Permissions', 'loginizer'); ?></span>
1237 </h2>
1238
1239 <div class="inside">
1240
1241 <form action="" method="post" enctype="multipart/form-data">
1242 <?php wp_nonce_field('loginizer-options'); ?>
1243 <table class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
1244 <?php
1245
1246 echo '
1247 <tr>
1248 <th style="background:#EFEFEF;">'.__('Relative Path', 'loginizer').'</th>
1249 <th style="width:10%; background:#EFEFEF;">'.__('Suggested', 'loginizer').'</th>
1250 <th style="width:10%; background:#EFEFEF;">'.__('Actual', 'loginizer').'</th>
1251 </tr>';
1252
1253 $wp_content = basename(dirname(dirname(dirname(__FILE__))));
1254
1255 $files_to_check = array('/' => '0755',
1256 '/wp-admin' => '0755',
1257 '/wp-includes' => '0755',
1258 '/wp-config.php' => '0444',
1259 '/'.$wp_content => '0755',
1260 '/'.$wp_content.'/themes' => '0755',
1261 '/'.$wp_content.'/plugins' => '0755',
1262 '.htaccess' => '0444');
1263
1264 $root = ABSPATH;
1265
1266 foreach($files_to_check as $k => $v){
1267
1268 $path = $root.'/'.$k;
1269 $stat = @stat($path);
1270 $suggested = $v;
1271 $actual = substr(sprintf('%o', $stat['mode']), -4);
1272
1273 echo '
1274 <tr>
1275 <td>'.$k.'</td>
1276 <td>'.$suggested.'</td>
1277 <td><span '.($suggested != $actual ? 'style="color: red;"' : '').'>'.$actual.'</span></td>
1278 </tr>';
1279
1280 }
1281
1282 ?>
1283 </table>
1284 </form>
1285
1286 </div>
1287 </div>
1288
1289 <?php
1290
1291 loginizer_page_footer();
1292
1293 }
1294
1295 // The Loginizer Admin Options Page
1296 function loginizer_page_brute_force(){
1297
1298 global $wpdb, $wp_roles, $loginizer;
1299
1300 if(!current_user_can('manage_options')){
1301 wp_die('Sorry, but you do not have permissions to change settings.');
1302 }
1303
1304 /* Make sure post was from this page */
1305 if(count($_POST) > 0){
1306 check_admin_referer('loginizer-options');
1307 }
1308
1309 // BEGIN THEME
1310 loginizer_page_header('Brute Force Settings');
1311
1312 // Load the blacklist and whitelist
1313 $loginizer['blacklist'] = get_option('loginizer_blacklist');
1314 $loginizer['whitelist'] = get_option('loginizer_whitelist');
1315
1316 // Disable Brute Force
1317 if(isset($_POST['disable_brute_lz'])){
1318
1319 // Save the options
1320 update_option('loginizer_disable_brute', 1);
1321
1322 $loginizer['disable_brute'] = 1;
1323
1324 echo '<div id="message" class="updated"><p>'
1325 . __('The Brute Force Protection feature is now disabled', 'loginizer')
1326 . '</p></div><br />';
1327
1328 }
1329
1330 // Enable brute force
1331 if(isset($_POST['enable_brute_lz'])){
1332
1333 // Save the options
1334 update_option('loginizer_disable_brute', 0);
1335
1336 $loginizer['disable_brute'] = 0;
1337
1338 echo '<div id="message" class="updated"><p>'
1339 . __('The Brute Force Protection feature is now enabled', 'loginizer')
1340 . '</p></div><br />';
1341
1342 }
1343
1344 // The Brute Force Settings
1345 if(isset($_POST['save_lz'])){
1346
1347 $max_retries = (int) lz_optpost('max_retries');
1348 $lockout_time = (int) lz_optpost('lockout_time');
1349 $max_lockouts = (int) lz_optpost('max_lockouts');
1350 $lockouts_extend = (int) lz_optpost('lockouts_extend');
1351 $reset_retries = (int) lz_optpost('reset_retries');
1352 $notify_email = (int) lz_optpost('notify_email');
1353
1354 $lockout_time = $lockout_time * 60;
1355 $lockouts_extend = $lockouts_extend * 60 * 60;
1356 $reset_retries = $reset_retries * 60 * 60;
1357
1358 if(empty($error)){
1359
1360 $option['max_retries'] = $max_retries;
1361 $option['lockout_time'] = $lockout_time;
1362 $option['max_lockouts'] = $max_lockouts;
1363 $option['lockouts_extend'] = $lockouts_extend;
1364 $option['reset_retries'] = $reset_retries;
1365 $option['notify_email'] = $notify_email;
1366
1367 // Save the options
1368 update_option('loginizer_options', $option);
1369
1370 $saved = true;
1371
1372 }else{
1373 lz_report_error($error);
1374 }
1375
1376 if(!empty($notice)){
1377 lz_report_notice($notice);
1378 }
1379
1380 if(!empty($saved)){
1381 echo '<div id="message" class="updated"><p>'
1382 . __('The settings were saved successfully', 'loginizer')
1383 . '</p></div><br />';
1384 }
1385
1386 }
1387
1388 // Delete a Blackist IP range
1389 if(isset($_POST['bdelid'])){
1390
1391 $delid = (int) lz_optreq('bdelid');
1392
1393 // Unset and save
1394 $blacklist = $loginizer['blacklist'];
1395 unset($blacklist[$delid]);
1396 update_option('loginizer_blacklist', $blacklist);
1397
1398 echo '<div id="message" class="updated fade"><p>'
1399 . __('The Blacklist IP range has been deleted successfully', 'loginizer')
1400 . '</p></div><br />';
1401
1402 }
1403
1404 // Delete all Blackist IP ranges
1405 if(isset($_POST['del_all_blacklist'])){
1406
1407 // Unset and save
1408 update_option('loginizer_blacklist', array());
1409
1410 echo '<div id="message" class="updated fade"><p>'
1411 . __('The Blacklist IP range(s) have been cleared successfully', 'loginizer')
1412 . '</p></div><br />';
1413
1414 }
1415
1416 // Delete a Whitelist IP range
1417 if(isset($_POST['delid'])){
1418
1419 $delid = (int) lz_optreq('delid');
1420
1421 // Unset and save
1422 $whitelist = $loginizer['whitelist'];
1423 unset($whitelist[$delid]);
1424 update_option('loginizer_whitelist', $whitelist);
1425
1426 echo '<div id="message" class="updated fade"><p>'
1427 . __('The Whitelist IP range has been deleted successfully', 'loginizer')
1428 . '</p></div><br />';
1429
1430 }
1431
1432 // Delete all Blackist IP ranges
1433 if(isset($_POST['del_all_whitelist'])){
1434
1435 // Unset and save
1436 update_option('loginizer_whitelist', array());
1437
1438 echo '<div id="message" class="updated fade"><p>'
1439 . __('The Whitelist IP range(s) have been cleared successfully', 'loginizer')
1440 . '</p></div><br />';
1441
1442 }
1443
1444 // Reset All Logs
1445 if(isset($_POST['lz_reset_all_ip'])){
1446
1447 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs`
1448 WHERE `time` > 0");
1449
1450 echo '<div id="message" class="updated fade"><p>'
1451 . __('All the IP Logs have been cleared', 'loginizer')
1452 . '</p></div><br />';
1453 }
1454
1455 // Reset Logs
1456 if(isset($_POST['lz_reset_ips']) && is_array($_POST['lz_reset_ips'])){
1457
1458 $ips = $_POST['lz_reset_ips'];
1459
1460 foreach($ips as $ip){
1461 if(!lz_valid_ip($ip)){
1462 $error[] = 'The IP - '.$ip.' is invalid !';
1463 }
1464 }
1465
1466 if(count($ips) < 1){
1467 $error[] = 'There are no IPs submitted';
1468 }
1469
1470 // Should we start deleting logs
1471 if(empty($error)){
1472
1473 $result = $wpdb->query("DELETE FROM `".$wpdb->prefix."loginizer_logs`
1474 WHERE `ip` IN ('".implode("', '", $ips)."')");
1475
1476 if(empty($error)){
1477
1478 echo '<div id="message" class="updated fade"><p>'
1479 . __('The selected IP Logs have been reset', 'loginizer')
1480 . '</p></div><br />';
1481
1482 }
1483
1484 }
1485
1486 if(!empty($error)){
1487 lz_report_error($error);echo '<br />';
1488 }
1489
1490 }
1491
1492 if(isset($_POST['blacklist_iprange'])){
1493
1494 $start_ip = lz_optpost('start_ip');
1495 $end_ip = lz_optpost('end_ip');
1496
1497 if(empty($start_ip)){
1498 $error[] = 'Please enter the Start IP';
1499 }
1500
1501 // If no end IP we consider only 1 IP
1502 if(empty($end_ip)){
1503 $end_ip = $start_ip;
1504 }
1505
1506 if(!lz_valid_ip($start_ip)){
1507 $error[] = 'Please provide a valid start IP';
1508 }
1509
1510 if(!lz_valid_ip($end_ip)){
1511 $error[] = 'Please provide a valid end IP';
1512 }
1513
1514 // Regular ranges will work
1515 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1516
1517 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1518 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1519 // This is right
1520 }else{
1521 $error[] = 'The End IP cannot be smaller than the Start IP';
1522 }
1523
1524 }
1525
1526 if(empty($error)){
1527
1528 $blacklist = $loginizer['blacklist'];
1529
1530 foreach($blacklist as $k => $v){
1531
1532 // This is to check if there is any other range exists with the same Start or End IP
1533 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1534 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1535 ){
1536 $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
1537 break;
1538 }
1539
1540 // This is to check if there is any other range exists with the same Start IP
1541 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1542 $error[] = 'The Start IP is present in an existing range !';
1543 break;
1544 }
1545
1546 // This is to check if there is any other range exists with the same End IP
1547 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1548 $error[] = 'The End IP is present in an existing range!';
1549 break;
1550 }
1551
1552 }
1553
1554 $newid = ( empty($blacklist) ? 0 : max(array_keys($blacklist)) ) + 1;
1555
1556 if(empty($error)){
1557
1558 $blacklist[$newid] = array();
1559 $blacklist[$newid]['start'] = $start_ip;
1560 $blacklist[$newid]['end'] = $end_ip;
1561 $blacklist[$newid]['time'] = time();
1562
1563 update_option('loginizer_blacklist', $blacklist);
1564
1565 echo '<div id="message" class="updated fade"><p>'
1566 . __('Blacklist IP range added successfully', 'loginizer')
1567 . '</p></div><br />';
1568
1569 }
1570
1571 }
1572
1573 if(!empty($error)){
1574 lz_report_error($error);echo '<br />';
1575 }
1576
1577 }
1578
1579 if(isset($_POST['whitelist_iprange'])){
1580
1581 $start_ip = lz_optpost('start_ip_w');
1582 $end_ip = lz_optpost('end_ip_w');
1583
1584 if(empty($start_ip)){
1585 $error[] = 'Please enter the Start IP';
1586 }
1587
1588 // If no end IP we consider only 1 IP
1589 if(empty($end_ip)){
1590 $end_ip = $start_ip;
1591 }
1592
1593 if(!lz_valid_ip($start_ip)){
1594 $error[] = 'Please provide a valid start IP';
1595 }
1596
1597 if(!lz_valid_ip($end_ip)){
1598 $error[] = 'Please provide a valid end IP';
1599 }
1600
1601 if(inet_ptoi($start_ip) > inet_ptoi($end_ip)){
1602
1603 // BUT, if 0.0.0.1 - 255.255.255.255 is given, it will not work
1604 if(inet_ptoi($start_ip) >= 0 && inet_ptoi($end_ip) < 0){
1605 // This is right
1606 }else{
1607 $error[] = 'The End IP cannot be smaller than the Start IP';
1608 }
1609
1610 }
1611
1612 if(empty($error)){
1613
1614 $whitelist = $loginizer['whitelist'];
1615
1616 foreach($whitelist as $k => $v){
1617
1618 // This is to check if there is any other range exists with the same Start or End IP
1619 if(( inet_ptoi($start_ip) <= inet_ptoi($v['start']) && inet_ptoi($v['start']) <= inet_ptoi($end_ip) )
1620 || ( inet_ptoi($start_ip) <= inet_ptoi($v['end']) && inet_ptoi($v['end']) <= inet_ptoi($end_ip) )
1621 ){
1622 $error[] = 'The Start IP or End IP submitted conflicts with an existing IP range !';
1623 break;
1624 }
1625
1626 // This is to check if there is any other range exists with the same Start IP
1627 if(inet_ptoi($v['start']) <= inet_ptoi($start_ip) && inet_ptoi($start_ip) <= inet_ptoi($v['end'])){
1628 $error[] = 'The Start IP is present in an existing range !';
1629 break;
1630 }
1631
1632 // This is to check if there is any other range exists with the same End IP
1633 if(inet_ptoi($v['start']) <= inet_ptoi($end_ip) && inet_ptoi($end_ip) <= inet_ptoi($v['end'])){
1634 $error[] = 'The End IP is present in an existing range!';
1635 break;
1636 }
1637
1638 }
1639
1640 $newid = ( empty($whitelist) ? 0 : max(array_keys($whitelist)) ) + 1;
1641
1642 if(empty($error)){
1643
1644 $whitelist[$newid] = array();
1645 $whitelist[$newid]['start'] = $start_ip;
1646 $whitelist[$newid]['end'] = $end_ip;
1647 $whitelist[$newid]['time'] = time();
1648
1649 update_option('loginizer_whitelist', $whitelist);
1650
1651 echo '<div id="message" class="updated fade"><p>'
1652 . __('Whitelist IP range added successfully', 'loginizer')
1653 . '</p></div><br />';
1654
1655 }
1656
1657 }
1658
1659 if(!empty($error)){
1660 lz_report_error($error);echo '<br />';
1661 }
1662 }
1663
1664 // Save the messages
1665 if(isset($_POST['save_err_msgs_lz'])){
1666
1667 $msgs['inv_userpass'] = lz_optpost('msg_inv_userpass');
1668 $msgs['ip_blacklisted'] = lz_optpost('msg_ip_blacklisted');
1669
1670 // Update them
1671 update_option('loginizer_msg', $msgs);
1672
1673 echo '<div id="message" class="updated fade"><p>'
1674 . __('Error messages were saved successfully', 'loginizer')
1675 . '</p></div><br />';
1676
1677 }
1678
1679 // Count the Results
1680 $tmp = lz_selectquery("SELECT COUNT(*) AS num FROM `".$wpdb->prefix."loginizer_logs`");
1681 //print_r($tmp);
1682
1683 // Which Page is it
1684 $lz_env['res_len'] = 10;
1685 $lz_env['cur_page'] = lz_get_page('lzpage', $lz_env['res_len']);
1686 $lz_env['num_res'] = $tmp['num'];
1687 $lz_env['max_page'] = ceil($lz_env['num_res'] / $lz_env['res_len']);
1688
1689 // Get the logs
1690 $result = lz_selectquery("SELECT * FROM `".$wpdb->prefix."loginizer_logs`
1691 ORDER BY `time` DESC
1692 LIMIT ".$lz_env['cur_page'].", ".$lz_env['res_len']."", 1);
1693 //print_r($result);
1694
1695 $lz_env['cur_page'] = ($lz_env['cur_page'] / $lz_env['res_len']) + 1;
1696 $lz_env['cur_page'] = $lz_env['cur_page'] < 1 ? 1 : $lz_env['cur_page'];
1697 $lz_env['next_page'] = ($lz_env['cur_page'] + 1) > $lz_env['max_page'] ? $lz_env['max_page'] : ($lz_env['cur_page'] + 1);
1698 $lz_env['prev_page'] = ($lz_env['cur_page'] - 1) < 1 ? 1 : ($lz_env['cur_page'] - 1);
1699
1700 // Reload the settings
1701 $loginizer['blacklist'] = get_option('loginizer_blacklist');
1702 $loginizer['whitelist'] = get_option('loginizer_whitelist');
1703
1704 $saved_msgs = get_option('loginizer_msg');
1705
1706 ?>
1707
1708 <div id="" class="postbox">
1709
1710 <button class="handlediv button-link" aria-expanded="true" type="button">
1711 <span class="screen-reader-text">Toggle panel: Failed Login Attempts Logs</span>
1712 <span class="toggle-indicator" aria-hidden="true"></span>
1713 </button>
1714
1715 <h2 class="hndle ui-sortable-handle">
1716 <?php echo __('<span>Failed Login Attempts Logs</span> &nbsp; (Past '.($loginizer['reset_retries']/60/60).' hours)','loginizer'); ?>
1717 </h2>
1718
1719 <script>
1720 function yesdsd(){
1721 window.location = '<?php echo menu_page_url('loginizer_brute_force', false);?>&lzpage='+jQuery("#current-page-selector").val();
1722 return false;
1723 }
1724 </script>
1725
1726 <form method="get" onsubmit="return yesdsd();">
1727 <div class="tablenav">
1728 <p class="tablenav-pages" style="margin: 5px 10px" align="right">
1729 <span class="displaying-num"><?php echo $lz_env['num_res'];?> items</span>
1730 <span class="pagination-links">
1731 <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>
1732 <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>
1733 <span class="paging-input">
1734 <label for="current-page-selector" class="screen-reader-text">Current Page</label>
1735 <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>
1736 </span>
1737 <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>
1738 <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>
1739 </span>
1740 </p>
1741 </div>
1742 </form>
1743
1744 <form action="" method="post" enctype="multipart/form-data">
1745 <?php wp_nonce_field('loginizer-options'); ?>
1746 <div class="inside">
1747 <table class="wp-list-table widefat fixed users" border="0">
1748 <tr>
1749 <th scope="row" valign="top" style="background:#EFEFEF;" width="20">#</th>
1750 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('IP','loginizer'); ?></th>
1751 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Attempted Username','loginizer'); ?></th>
1752 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Last Failed Attempt (DD/MM/YYYY)','loginizer'); ?></th>
1753 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Failed Attempts Count','loginizer'); ?></th>
1754 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Lockouts Count','loginizer'); ?></th>
1755 <th scope="row" valign="top" style="background:#EFEFEF;" width="150"><?php echo __('URL Attacked','loginizer'); ?></th>
1756 </tr>
1757 <?php
1758
1759 if(empty($result)){
1760 echo '
1761 <tr>
1762 <td colspan="4">
1763 No Logs. You will see logs about failed login attempts here.
1764 </td>
1765 </tr>';
1766 }else{
1767 foreach($result as $ik => $iv){
1768 $status_button = (!empty($iv['status']) ? 'disable' : 'enable');
1769 echo '
1770 <tr>
1771 <td>
1772 <input type="checkbox" value="'.$iv['ip'].'" name="lz_reset_ips[]" />
1773 </td>
1774 <td>
1775 '.$iv['ip'].'
1776 </td>
1777 <td>
1778 '.$iv['username'].'
1779 </td>
1780 <td>
1781 '.date('d/M/Y H:i:s P', $iv['time']).'
1782 </td>
1783 <td>
1784 '.$iv['count'].'
1785 </td>
1786 <td>
1787 '.$iv['lockout'].'
1788 </td>
1789 <td>
1790 '.$iv['url'].'
1791 </td>
1792 </tr>';
1793 }
1794 }
1795
1796 ?>
1797 </table>
1798
1799 <br>
1800 <input name="lz_reset_ip" class="button button-primary action" value="<?php echo __('Remove From Logs', 'loginizer'); ?>" type="submit" />
1801 &nbsp; &nbsp;
1802 <input name="lz_reset_all_ip" class="button button-primary action" value="<?php echo __('Clear All Logs', 'loginizer'); ?>" type="submit" />
1803 </div>
1804 </div>
1805 </form>
1806 <br />
1807
1808 <div id="" class="postbox">
1809
1810 <button class="handlediv button-link" aria-expanded="true" type="button">
1811 <span class="screen-reader-text">Toggle panel: Brute Force Settings</span>
1812 <span class="toggle-indicator" aria-hidden="true"></span>
1813 </button>
1814
1815 <h2 class="hndle ui-sortable-handle">
1816 <span><?php echo __('Brute Force Settings', 'loginizer'); ?></span>
1817 </h2>
1818
1819 <div class="inside">
1820
1821 <form action="" method="post" enctype="multipart/form-data">
1822 <?php wp_nonce_field('loginizer-options'); ?>
1823 <table class="form-table">
1824 <tr>
1825 <th scope="row" valign="top"><label for="max_retries"><?php echo __('Max Retries','loginizer'); ?></label></th>
1826 <td>
1827 <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 />
1828 </td>
1829 </tr>
1830 <tr>
1831 <th scope="row" valign="top"><label for="lockout_time"><?php echo __('Lockout Time','loginizer'); ?></label></th>
1832 <td>
1833 <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 />
1834 </td>
1835 </tr>
1836 <tr>
1837 <th scope="row" valign="top"><label for="max_lockouts"><?php echo __('Max Lockouts','loginizer'); ?></label></th>
1838 <td>
1839 <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 />
1840 </td>
1841 </tr>
1842 <tr>
1843 <th scope="row" valign="top"><label for="lockouts_extend"><?php echo __('Extend Lockout','loginizer'); ?></label></th>
1844 <td>
1845 <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 />
1846 </td>
1847 </tr>
1848 <tr>
1849 <th scope="row" valign="top"><label for="reset_retries"><?php echo __('Reset Retries','loginizer'); ?></label></th>
1850 <td>
1851 <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 />
1852 </td>
1853 </tr>
1854 <tr>
1855 <th scope="row" valign="top"><label for="notify_email"><?php echo __('Email Notification','loginizer'); ?></label></th>
1856 <td>
1857 <?php echo __('after ','loginizer'); ?>
1858 <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'); ?>
1859 </td>
1860 </tr>
1861 </table><br />
1862 <input name="save_lz" class="button button-primary action" value="<?php echo __('Save Settings','loginizer'); ?>" type="submit" />
1863 <?php
1864
1865 if(empty($loginizer['disable_brute'])){
1866
1867 echo '<input name="disable_brute_lz" class="button action" value="'.__('Disable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
1868
1869 }else{
1870
1871 echo '<input name="enable_brute_lz" class="button button-primary action" value="'.__('Enable Brute Force Protection','loginizer').'" type="submit" style="float:right" />';
1872
1873 }
1874
1875 ?>
1876 </form>
1877
1878 </div>
1879 </div>
1880 <br />
1881
1882 <?php
1883
1884 wp_enqueue_script('jquery-paginate', LOGINIZER_URL.'/jquery-paginate.js', array('jquery'), '1.10.15');
1885
1886 ?>
1887
1888 <style>
1889 .page-navigation a {
1890 margin: 5px 2px;
1891 display: inline-block;
1892 padding: 5px 8px;
1893 color: #0073aa;
1894 background: #e5e5e5 none repeat scroll 0 0;
1895 border: 1px solid #ccc;
1896 text-decoration: none;
1897 transition-duration: 0.05s;
1898 transition-property: border, background, color;
1899 transition-timing-function: ease-in-out;
1900 }
1901
1902 .page-navigation a[data-selected] {
1903 background-color: #00a0d2;
1904 color: #fff;
1905 }
1906 </style>
1907
1908 <script>
1909
1910 jQuery(document).ready(function(){
1911 jQuery('#lz_bl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_bl_nav')});
1912 jQuery('#lz_wl_table').paginate({ limit: 11, navigationWrapper: jQuery('#lz_wl_nav')});
1913 });
1914
1915 // Delete a Blacklist / Whitelist IP Range
1916 function del_confirm(field, todo_id, msg){
1917 var ret = confirm(msg);
1918
1919 if(ret){
1920 jQuery('#lz_bl_wl_todo').attr('name', field);
1921 jQuery('#lz_bl_wl_todo').val(todo_id);
1922 jQuery('#lz_bl_wl_form').submit();
1923 }
1924
1925 return false;
1926
1927 }
1928
1929 // Delete all Blacklist / Whitelist IP Ranges
1930 function del_confirm_all(msg){
1931 var ret = confirm(msg);
1932
1933 if(ret){
1934 return true;
1935 }
1936
1937 return false;
1938
1939 }
1940
1941 </script>
1942
1943 <div id="" class="postbox">
1944
1945 <button class="handlediv button-link" aria-expanded="true" type="button">
1946 <span class="screen-reader-text">Toggle panel: Blacklist IP</span>
1947 <span class="toggle-indicator" aria-hidden="true"></span>
1948 </button>
1949
1950 <h2 class="hndle ui-sortable-handle">
1951 <span><?php echo __('Blacklist IP','loginizer'); ?></span>
1952 </h2>
1953
1954 <div class="inside">
1955
1956 <?php echo __('Enter the IP you want to blacklist from login','loginizer'); ?>
1957
1958 <form action="" method="post">
1959 <?php wp_nonce_field('loginizer-options'); ?>
1960 <table class="form-table">
1961 <tr>
1962 <th scope="row" valign="top"><label for="start_ip"><?php echo __('Start IP','loginizer'); ?></label></th>
1963 <td>
1964 <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 />
1965 </td>
1966 </tr>
1967 <tr>
1968 <th scope="row" valign="top"><label for="end_ip"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
1969 <td>
1970 <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 />
1971 </td>
1972 </tr>
1973 </table><br />
1974 <input name="blacklist_iprange" class="button button-primary action" value="<?php echo __('Add Blacklist IP Range','loginizer'); ?>" type="submit" />
1975 <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" />
1976 </form>
1977 </div>
1978
1979 <div id="lz_bl_nav" style="margin: 5px 10px; text-align:right"></div>
1980 <table id="lz_bl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
1981 <tr>
1982 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
1983 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
1984 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
1985 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
1986 </tr>
1987 <?php
1988 if(empty($loginizer['blacklist'])){
1989 echo '
1990 <tr>
1991 <td colspan="4">
1992 No Blacklist IPs. You will see blacklisted IP ranges here.
1993 </td>
1994 </tr>';
1995 }else{
1996 foreach($loginizer['blacklist'] as $ik => $iv){
1997 echo '
1998 <tr>
1999 <td>
2000 '.$iv['start'].'
2001 </td>
2002 <td>
2003 '.$iv['end'].'
2004 </td>
2005 <td>
2006 '.date('d/m/Y', $iv['time']).'
2007 </td>
2008 <td>
2009 <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>
2010 </td>
2011 </tr>';
2012 }
2013 }
2014 ?>
2015 </table>
2016 <br />
2017 <form action="" method="post" id="lz_bl_wl_form">
2018 <?php wp_nonce_field('loginizer-options'); ?>
2019 <input type="hidden" value="" name="" id="lz_bl_wl_todo"/>
2020 </form>
2021 </div>
2022
2023 <br />
2024
2025 <div id="" class="postbox">
2026
2027 <button class="handlediv button-link" aria-expanded="true" type="button">
2028 <span class="screen-reader-text">Toggle panel: Whitelist IP</span>
2029 <span class="toggle-indicator" aria-hidden="true"></span>
2030 </button>
2031
2032 <h2 class="hndle ui-sortable-handle">
2033 <span><?php echo __('Whitelist IP', 'loginizer'); ?></span>
2034 </h2>
2035
2036 <div class="inside">
2037
2038 <?php echo __('Enter the IP you want to whitelist for login','loginizer'); ?>
2039 <form action="" method="post">
2040 <?php wp_nonce_field('loginizer-options'); ?>
2041 <table class="form-table">
2042 <tr>
2043 <th scope="row" valign="top"><label for="start_ip_w"><?php echo __('Start IP','loginizer'); ?></label></th>
2044 <td>
2045 <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 />
2046 </td>
2047 </tr>
2048 <tr>
2049 <th scope="row" valign="top"><label for="end_ip_w"><?php echo __('End IP (Optional)','loginizer'); ?></label></th>
2050 <td>
2051 <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 />
2052 </td>
2053 </tr>
2054 </table><br />
2055 <input name="whitelist_iprange" class="button button-primary action" value="<?php echo __('Add Whitelist IP Range','loginizer'); ?>" type="submit" />
2056 <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" />
2057 </form>
2058 </div>
2059
2060 <div id="lz_wl_nav" style="margin: 5px 10px; text-align:right"></div>
2061 <table id="lz_wl_table" class="wp-list-table fixed striped users" border="0" width="95%" cellpadding="10" align="center">
2062 <tr>
2063 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Start IP','loginizer'); ?></th>
2064 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('End IP','loginizer'); ?></th>
2065 <th scope="row" valign="top" style="background:#EFEFEF;"><?php echo __('Date (DD/MM/YYYY)','loginizer'); ?></th>
2066 <th scope="row" valign="top" style="background:#EFEFEF;" width="100"><?php echo __('Options','loginizer'); ?></th>
2067 </tr>
2068 <?php
2069 if(empty($loginizer['whitelist'])){
2070 echo '
2071 <tr>
2072 <td colspan="4">
2073 No Whitelist IPs. You will see whitelisted IP ranges here.
2074 </td>
2075 </tr>';
2076 }else{
2077 foreach($loginizer['whitelist'] as $ik => $iv){
2078 echo '
2079 <tr>
2080 <td>
2081 '.$iv['start'].'
2082 </td>
2083 <td>
2084 '.$iv['end'].'
2085 </td>
2086 <td>
2087 '.date('d/m/Y', $iv['time']).'
2088 </td>
2089 <td>
2090 <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>
2091 </td>
2092 </tr>';
2093 }
2094 }
2095 ?>
2096 </table>
2097 <br />
2098
2099 </div>
2100
2101 <div id="" class="postbox">
2102
2103 <button class="handlediv button-link" aria-expanded="true" type="button">
2104 <span class="screen-reader-text">Toggle panel: Error Messages</span>
2105 <span class="toggle-indicator" aria-hidden="true"></span>
2106 </button>
2107
2108 <h2 class="hndle ui-sortable-handle">
2109 <span><?php echo __('Error Messages', 'loginizer'); ?></span>
2110 </h2>
2111
2112 <div class="inside">
2113
2114 <form action="" method="post" enctype="multipart/form-data">
2115 <?php wp_nonce_field('loginizer-options'); ?>
2116 <table class="form-table">
2117 <tr>
2118 <th scope="row" valign="top"><label for="msg_inv_userpass"><?php echo __('Failed Login Attempt','loginizer'); ?></label></th>
2119 <td>
2120 <input type="text" size="25" value="<?php echo esc_attr($saved_msgs['inv_userpass']); ?>" name="msg_inv_userpass" id="msg_inv_userpass" />
2121 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['inv_userpass']. '&quot;</em>', 'loginizer'); ?><br />
2122 </td>
2123 </tr>
2124 <tr>
2125 <th scope="row" valign="top"><label for="msg_ip_blacklisted"><?php echo __('Blacklisted IP','loginizer'); ?></label></th>
2126 <td>
2127 <input type="text" size="25" value="<?php echo esc_attr($saved_msgs['ip_blacklisted']); ?>" name="msg_ip_blacklisted" id="msg_ip_blacklisted" />
2128 <?php echo __('Default: <em>&quot;' . $loginizer['d_msg']['ip_blacklisted']. '&quot;</em>', 'loginizer'); ?><br />
2129 </td>
2130 </tr>
2131 </table><br />
2132 <input name="save_err_msgs_lz" class="button button-primary action" value="<?php echo __('Save Error Messages','loginizer'); ?>" type="submit" />
2133 </form>
2134 </div>
2135 </div>
2136 <?php
2137
2138 loginizer_page_footer();
2139
2140 }
2141
2142
2143 // Sorry to see you going
2144 register_uninstall_hook(LOGINIZER_FILE, 'loginizer_deactivation');
2145
2146 function loginizer_deactivation(){
2147
2148 global $wpdb;
2149
2150 $sql = array();
2151 $sql[] = "DROP TABLE ".$wpdb->prefix."loginizer_logs;";
2152
2153 foreach($sql as $sk => $sv){
2154 $wpdb->query($sv);
2155 }
2156
2157 delete_option('loginizer_version');
2158 delete_option('loginizer_options');
2159 delete_option('loginizer_last_reset');
2160 delete_option('loginizer_whitelist');
2161 delete_option('loginizer_blacklist');
2162 delete_option('loginizer_msg');
2163 delete_option('loginizer_security');
2164 delete_option('loginizer_wp_admin');
2165
2166 }
2167
2168