PluginProbe
Loginizer / 2.0.2
Loginizer v2.0.2
2.1.0 2.0.9 2.0.8 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 74 releases
← All changes | init.php +115 -93 trunk2.0.2 View file →
@@ -4,9 +4,9 @@
4 4 echo 'You are not allowed to access this page directly.';
5 5 exit;
6 6 }
7 7
8 -define('LOGINIZER_VERSION', '2.1.0');
8 +define('LOGINIZER_VERSION', '2.0.2');
9 9 define('LOGINIZER_DIR', dirname(LOGINIZER_FILE));
10 10 define('LOGINIZER_URL', plugins_url('', LOGINIZER_FILE));
11 11 define('LOGINIZER_PRO_URL', 'https://loginizer.com/features#compare');
12 12 define('LOGINIZER_PRICING_URL', 'https://loginizer.com/pricing');
@@ -332,22 +332,21 @@
332 332 // Is called before displaying the error message so that we dont show that the username is wrong or the password
333 333 // Update Error message
334 334 add_action('wp_login_errors', 'loginizer_error_handler', 10001, 2);
335 335 add_action('woocommerce_login_failed', 'loginizer_woocommerce_error_handler', 10001);
336 - add_action('wp_login', 'loginizer_login_success', 11, 2);
337 - add_action('rsssl_two_factor_user_authenticated', 'loginizer_rsssl_2fa_success');
336 + add_action('wp_login', 'loginizer_login_success', 10, 2);
338 337
339 338 if(!empty($loginizer['ultimate-member-active'])){
340 339 add_action('wp_login_failed', 'loginizer_ultimatemember_error_handler', 10001);
341 340 }
342 341
343 - if(!empty($_COOKIE['lz_social_error']) && !empty($loginizer['social_settings'])){
342 + if(!empty($_COOKIE['lz_social_error']) && !empty($loginizer['social_settings']) && !loginizer_is_blacklisted()){
344 343 add_filter('wp_login_errors', 'loginizer_social_login_error_handler', 10000, 2);
345 344 }
346 345 }
347 346
348 347 // Social Login Form Actions
349 - if(!empty($loginizer['social_settings'])){
348 + if(!empty($loginizer['social_settings']) && !loginizer_is_blacklisted()){
350 349 if(!empty($loginizer['social_settings']['login']['login_form'])){
351 350 add_action('login_form', 'loginizer_social_btn_login');
352 351 }
353 352 }
@@ -495,31 +494,26 @@
495 494
496 495 if(empty($blacklist)){
497 496 return false;
498 497 }
499 -
500 - $current_ip_inet = inet_ptoi($loginizer['current_ip']);
501 -
498 +
502 499 foreach($blacklist as $k => $v){
503 -
504 - $start_inet = inet_ptoi($v['start']);
505 - $end_inet = inet_ptoi($v['end']);
506 -
500 +
507 501 // Is the IP in the blacklist ?
508 - if($start_inet <= $current_ip_inet && $current_ip_inet <= $end_inet){
502 + if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) && inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
509 503 $result = 1;
510 504 break;
511 505 }
512 -
506 +
513 507 // Is it in a wider range ?
514 - if($start_inet >= 0 && $end_inet < 0){
508 + if(inet_ptoi($v['start']) >= 0 && inet_ptoi($v['end']) < 0){
515 509
516 510 // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi,
517 511 // if the current IP is <= than the start of the range, it is within the range
518 512 // OR
519 513 // if the current IP is <= than the end of the range, it is within the range
520 - if($start_inet <= $current_ip_inet
521 - || $current_ip_inet <= $end_inet){
514 + if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip'])
515 + || inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
522 516 $result = 1;
523 517 break;
524 518 }
525 519
@@ -525,9 +519,9 @@
525 519
526 520 }
527 521
528 522 }
529 -
523 +
530 524 // You are blacklisted
531 525 if(!empty($result)){
532 526 $lz_error['ip_blacklisted'] = $loginizer['msg']['ip_blacklisted'];
533 527 return true;
@@ -536,8 +530,52 @@
536 530 return false;
537 531
538 532 }
539 533
534 +function loginizer_is_whitelisted(){
535 +
536 + global $wpdb, $loginizer, $lz_error;
537 +
538 + $whitelist = $loginizer['whitelist'];
539 +
540 + if(empty($whitelist)){
541 + return false;
542 + }
543 +
544 + foreach($whitelist as $k => $v){
545 +
546 + // Is the IP in the blacklist ?
547 + if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip']) && inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
548 + $result = 1;
549 + break;
550 + }
551 +
552 + // Is it in a wider range ?
553 + if(inet_ptoi($v['start']) >= 0 && inet_ptoi($v['end']) < 0){
554 +
555 + // Since the end of the RANGE (i.e. current IP range) is beyond the +ve value of inet_ptoi,
556 + // if the current IP is <= than the start of the range, it is within the range
557 + // OR
558 + // if the current IP is <= than the end of the range, it is within the range
559 + if(inet_ptoi($v['start']) <= inet_ptoi($loginizer['current_ip'])
560 + || inet_ptoi($loginizer['current_ip']) <= inet_ptoi($v['end'])){
561 + $result = 1;
562 + break;
563 + }
564 +
565 + }
566 +
567 + }
568 +
569 + // You are whitelisted
570 + if(!empty($result)){
571 + return true;
572 + }
573 +
574 + return false;
575 +
576 +}
577 +
540 578 // When the login fails, then this is called
541 579 // We need to update the database
542 580 function loginizer_login_failed($username, $is_2fa = ''){
543 581
@@ -556,78 +594,53 @@
556 594
557 595 if(empty($lz_cannot_login) && empty($loginizer['ip_is_whitelisted']) && empty($loginizer['no_loginizer_logs'])){
558 596
559 597 // The params which comes when social login returns an error, have some characters, which WordPress could not save.
560 - // REQUEST_URI / HTTP_HOST are not always set (WP-CLI, some CGI and XML-RPC setups)
561 - $server_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
562 - $http_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
563 -
564 - if(!empty($server_uri) && strpos($server_uri, 'lz_social_provider') !== FALSE){
565 - $request_uri = explode('=', $server_uri);
598 + $server_uri = $_SERVER['REQUEST_URI'];
599 + if(!empty($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], 'lz_social_provider') !== FALSE){
600 + $request_uri = explode('=', $_SERVER['REQUEST_URI']);
566 601 $server_uri = $request_uri[0];
567 602 }
568 603
569 - // No addslashes() here, $wpdb->prepare() below does the escaping
570 - $url = esc_url((!empty($_SERVER['HTTPS']) ? 'https://' : 'http://').$http_host.$server_uri);
604 + $url = @addslashes((!empty($_SERVER['HTTPS']) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$server_uri);
605 + $url = esc_url($url);
571 606
572 - // Must never be 0, we divide by it below
573 - $max_retries = (int) $loginizer['max_retries'] < 1 ? 1 : (int) $loginizer['max_retries'];
574 -
575 - // This way is atomic now, the earlier one were causing race condition.
576 - // NOTE : In the UPDATE part `count` is already the new value, as MySQL / MariaDB
577 - // evaluate the assignments from left to right, so lockout must NOT add 1 again
578 - $upsert = $wpdb->prepare(
579 - "INSERT INTO `".$wpdb->prefix."loginizer_logs`
580 - (username, time, count, ip, lockout, url)
581 - VALUES
582 - (%s, %d, 1, %s, FLOOR(1 / %d), %s)
583 - ON DUPLICATE KEY UPDATE
584 - username = VALUES(username),
585 - time = VALUES(time),
586 - count = count + 1,
587 - lockout = FLOOR(count / %d),
588 - url = VALUES(url)",
589 - $username,
590 - time(),
591 - $loginizer['current_ip'],
592 - $max_retries,
593 - $url,
594 - $max_retries
595 - );
596 - $wpdb->query($upsert);
597 -
598 - // Re-read the persisted row so email/retries-left reflect the actual count
599 607 $sel_query = $wpdb->prepare("SELECT * FROM `".$wpdb->prefix."loginizer_logs` WHERE `ip` = %s", $loginizer['current_ip']);
600 608 $result = lz_selectquery($sel_query);
609 +
610 + if(!empty($result)){
611 + $lockout = floor((($result['count']+1) / $loginizer['max_retries']));
612 +
613 + $update_data = array('username' => $username,
614 + 'time' => time(),
615 + 'count' => $result['count']+1,
616 + 'lockout' => $lockout,
617 + 'url' => $url);
618 +
619 + $where_data = array('ip' => $loginizer['current_ip']);
620 +
621 + $format = array('%s','%d','%d','%d','%s');
622 + $where_format = array('%s');
623 +
624 + $wpdb->update($wpdb->prefix.'loginizer_logs', $update_data, $where_data, $format, $where_format);
625 +
626 + // Do we need to email admin ?
627 + if(!empty($loginizer['notify_email']) && $lockout >= $loginizer['notify_email']){
628 +
629 + $lockout_time = $loginizer['lockout_time'];
630 +
631 + if($lockout >= $loginizer['max_lockouts']){
632 + // extended lockout is in hours so we have to convert to minute
633 + $lockout_time = $loginizer['lockouts_extend'];
634 + }
635 +
636 + $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname');
637 + $mail = array();
638 + $mail['to'] = $loginizer['notify_email_address'];
639 + $mail['subject'] = 'Failed '.$fail_type.' Attempts from IP '.$loginizer['current_ip'].' ('.$sitename.')';
640 + $mail['message'] = 'Hi,
601 641
602 - if(empty($result)){
603 - $result = array('count' => 0);
604 - }
605 -
606 - $count = (int) $result['count'];
607 - $lockout = !empty($result['lockout']) ? (int) $result['lockout'] : 0;
608 -
609 - // The lockout goes up only on every max_retries'th failure, which is the
610 - // attempt that actually locks the IP out. On the failures in between there
611 - // is nothing new to report, so we must not email on each one of them
612 - $is_new_lockout = !empty($count) && ($count % $max_retries) == 0;
613 -
614 - // Do we need to email admin ?
615 - if(!empty($loginizer['notify_email']) && !empty($is_new_lockout) && $lockout >= $loginizer['notify_email']){
616 -
617 - $lockout_time = $loginizer['lockout_time'];
618 -
619 - if($lockout >= $loginizer['max_lockouts']){
620 - $lockout_time = $loginizer['lockouts_extend'];
621 - }
622 -
623 - $sitename = lz_is_multisite() ? get_site_option('site_name') : get_option('blogname');
624 - $mail = array();
625 - $mail['to'] = $loginizer['notify_email_address'];
626 - $mail['subject'] = 'Failed '.$fail_type.' Attempts from IP '.$loginizer['current_ip'].' ('.$sitename.')';
627 - $mail['message'] = 'Hi,
628 -
629 -'.(int) $result['count'].' failed '.strtolower($fail_type).' attempts and '.$lockout.' lockout(s) from IP '.$loginizer['current_ip'].' on your site :
642 +'.($result['count']+1).' failed '.strtolower($fail_type).' attempts and '.$lockout.' lockout(s) from IP '.$loginizer['current_ip'].' on your site :
630 643 '.home_url().'
631 644
632 645 Last '.$fail_type.' Attempt : '.date('d/M/Y H:i:s P', time()).'
633 646 Last User Attempt : '.$username.'
@@ -635,22 +648,35 @@
635 648
636 649 Regards,
637 650 Loginizer';
638 651
639 - @wp_mail($mail['to'], $mail['subject'], $mail['message']);
652 + @wp_mail($mail['to'], $mail['subject'], $mail['message']);
653 + }
654 + }else{
655 + $result = array();
656 + $result['count'] = 0;
657 +
658 + $insert_data = array('username' => $username,
659 + 'time' => time(),
660 + 'count' => 1,
661 + 'ip' => $loginizer['current_ip'],
662 + 'lockout' => 0,
663 + 'url' => $url);
664 +
665 + $format = array('%s','%d','%d','%s','%d','%s');
666 +
667 + $wpdb->insert($wpdb->prefix.'loginizer_logs', $insert_data, $format);
640 668 }
641 -
669 +
670 + // We need to add one as this is a failed attempt as well
671 + $result['count'] = $result['count'] + 1;
642 672 loginizer_update_attempt_stats(0);
643 - $loginizer['retries_left'] = $max_retries - ($count % $max_retries);
644 - $loginizer['retries_left'] = $loginizer['retries_left'] == $max_retries ? 0 : $loginizer['retries_left'];
673 + $loginizer['retries_left'] = ($loginizer['max_retries'] - ($result['count'] % $loginizer['max_retries']));
674 + $loginizer['retries_left'] = $loginizer['retries_left'] == $loginizer['max_retries'] ? 0 : $loginizer['retries_left'];
645 675
646 676 }
647 677 }
648 678
649 -function loginizer_rsssl_2fa_success($user){
650 - loginizer_login_success('', $user);
651 -}
652 -
653 679 function loginizer_login_success($user_login, $user) {
654 680 global $wp_version, $loginizer;
655 681
656 682 loginizer_update_attempt_stats(1);
@@ -814,12 +840,8 @@
814 840
815 841 // Handles social login URL
816 842 function loginizer_social_login_error_handler($errors = '', $redirect_to = ''){
817 843 global $loginizer;
818 -
819 - if(loginizer_is_blacklisted()){
820 - return $errors;
821 - }
822 844
823 845 loginizer_get_social_error();
824 846
825 847 if(empty($loginizer['social_errors'])){