コード例 #1
0
ファイル: LogInOut.php プロジェクト: fia3876/iqmas-portal
 public function EventLoginFailure($username)
 {
     list($y, $m, $d) = explode('-', date('Y-m-d'));
     $ip = $this->plugin->settings->GetMainClientIP();
     $username = $_POST["log"];
     $newAlertCode = 1003;
     $user = get_user_by('login', $username);
     $site_id = function_exists('get_current_blog_id') ? get_current_blog_id() : 0;
     if ($user) {
         $newAlertCode = 1002;
         $userRoles = $this->plugin->settings->GetCurrentUserRoles($user->roles);
         if ($this->plugin->settings->IsLoginSuperAdmin($username)) {
             $userRoles[] = 'superadmin';
         }
     }
     if ($this->IsPastLoginFailureLimit($ip, $site_id, $user)) {
         return;
     }
     $objOcc = new WSAL_Models_Occurrence();
     if ($newAlertCode == 1002) {
         if (!$this->plugin->alerts->CheckEnableUserRoles($username, $userRoles)) {
             return;
         }
         $occ = $objOcc->CheckKnownUsers(array($ip, $username, 1002, $site_id, mktime(0, 0, 0, $m, $d, $y), mktime(0, 0, 0, $m, $d + 1, $y) - 1));
         $occ = count($occ) ? $occ[0] : null;
         if (!empty($occ)) {
             // update existing record exists user
             $this->IncrementLoginFailure($ip, $site_id, $user);
             $new = $occ->GetMetaValue('Attempts', 0) + 1;
             if ($new > $this->GetLoginFailureLogLimit()) {
                 $new = $this->GetLoginFailureLogLimit() . '+';
             }
             $occ->UpdateMetaValue('Attempts', $new);
             $occ->UpdateMetaValue('Username', $username);
             //$occ->SetMetaValue('CurrentUserRoles', $userRoles);
             $occ->created_on = null;
             $occ->Save();
         } else {
             // create a new record exists user
             $this->plugin->alerts->Trigger($newAlertCode, array('Attempts' => 1, 'Username' => $username, 'CurrentUserRoles' => $userRoles));
         }
     } else {
         $occUnknown = $objOcc->CheckUnKnownUsers(array($ip, 1003, $site_id, mktime(0, 0, 0, $m, $d, $y), mktime(0, 0, 0, $m, $d + 1, $y) - 1));
         $occUnknown = count($occUnknown) ? $occUnknown[0] : null;
         if (!empty($occUnknown)) {
             // update existing record not exists user
             $this->IncrementLoginFailure($ip, $site_id, false);
             $new = $occUnknown->GetMetaValue('Attempts', 0) + 1;
             if ($new > $this->GetLoginFailureLogLimit()) {
                 $new = $this->GetLoginFailureLogLimit() . '+';
             }
             $occUnknown->UpdateMetaValue('Attempts', $new);
             $occUnknown->created_on = null;
             $occUnknown->Save();
         } else {
             // create a new record not exists user
             $this->plugin->alerts->Trigger($newAlertCode, array('Attempts' => 1));
         }
     }
 }