$loginsec_options[ SIXSCAN_LOGIN_LIMIT_LOGINS ] ){ if ( $login_inf[ 'is_blocked' ] == false ){ /* Every new failed request should not trigger email */ sixscan_signatures_loginsec_notify_admin( $login_inf , $user_ip ); $login_inf[ 'blocked_start_time' ] = time(); } $login_inf[ 'is_blocked' ] = true; } $is_to_block_user = $login_inf[ 'is_blocked' ]; /* Save current login counters */ $login_logs[ $user_ip ] = $login_inf; update_option( SIXSCAN_LOGIN_LOGS , $login_logs ); } /* Error object means login failed. No message passed, just empty blocked login */ if ( $is_to_block_user ) return new WP_Error(); return $user; } /* Clear the failed login count */ function sixscan_signatures_loginsec_login_success( $user_name ){ /* If the user passed authorization - clear the counters. */ if ( get_current_user_id() == 0 ) return; $user_ip = $_SERVER[ 'REMOTE_ADDR' ]; $login_logs = get_option( SIXSCAN_LOGIN_LOGS , array() ); /* Clear the logs */ if ( array_key_exists( $user_ip , $login_logs) ){ unset( $login_logs[ $user_ip ] ); } update_option( SIXSCAN_LOGIN_LOGS , $login_logs ); } /* Removes failed login message */ function sixscan_signatures_loginsec_fault_message( $message ){ $loginsec_options = get_option( SIXSCAN_OPTION_LOGIN_SETTINGS , array() ); /* Hide login errors */ if ( array_key_exists( SIXSCAN_LOGIN_ERRORS_HIDE_OPTION , $loginsec_options ) && ( $loginsec_options[ SIXSCAN_LOGIN_ERRORS_HIDE_OPTION ] == 'True' ) ){ $message = "Login failed"; } return $message; } function sixscan_signatures_loginsec_notify_admin( $locked_out_user , $user_ip ){ $loginsec_options = get_option( SIXSCAN_OPTION_LOGIN_SETTINGS ); $email_to_address = @$loginsec_options[ SIXSCAN_LOGIN_NOTIFY_ADMIN_EMAIL ]; /* If no email defined - do not send notification */ if ( strlen( $email_to_address ) == 0 ) return; $locked_for_minutes = ( $loginsec_options[ SIXSCAN_LOGIN_LOCKED_OUT_SECONDS ] / 60 ); $login_attempts_minutes = ( $loginsec_options[ SIXSCAN_LOGIN_WITHIN_TIME_LIMIT_SECONDS ] / 60 ); $email_from = get_bloginfo( 'admin_email' ); $email_headers = 'MIME-Version: 1.0' . "\r\n"; $email_headers .= 'Content-type: text/html; charset=utf8' . "\r\n"; $email_headers .= "From: $email_from\r\n"; $email_subject = "6Scan Security has performed a lockout on " . home_url(); $email_message = sixscan_signatures_loginsec_prepare_mail_content( $user_ip , $locked_for_minutes , $loginsec_options[ SIXSCAN_LOGIN_LIMIT_LOGINS ] , $login_attempts_minutes, $locked_out_user[ 'username' ] ); @mail( $email_to_address , $email_subject , $email_message , $email_headers ); } function sixscan_signatures_loginsec_prepare_mail_content( $blocked_ip, $locked_for_minutes, $blocked_attempts, $blocked_attempts_during_time, $blocked_usernames ){ $dashboard_link = get_admin_url() . "admin.php?page=six-scan-dashboard"; $site_address = home_url(); $template_vals = array("{{site.root_url}}" , "{{dashboard_link}}" , "{{locked.ip}}" , "{{locked.minutes}}" , "{{locked.failed_count}}" , "{{locked.failed_minutes}}" , "{{locked.usernames}}" ); $replaced_vals = array( $site_address , $dashboard_link , $blocked_ip , $locked_for_minutes , $blocked_attempts , $blocked_attempts_during_time , $blocked_usernames ); $mail_template = file_get_contents( SIXSCAN_PLUGIN_DIR . SIXSCAN_SECURITY_LOCK_NOTIFY_FILENAME ); return str_replace( $template_vals , $replaced_vals , $mail_template ); } ?>