public function CleanUp() { $now = current_time('timestamp'); $max_sdate = $this->plugin->settings->GetPruningDate(); $max_count = $this->plugin->settings->GetPruningLimit(); $is_date_e = $this->plugin->settings->IsPruningDateEnabled(); $is_limt_e = $this->plugin->settings->IsPruningLimitEnabled(); if (!$is_date_e && !$is_limt_e) { return; } // pruning disabled $occ = new WSAL_Models_Occurrence(); $cnt_items = $occ->Count(); // Check if there is something to delete if ($is_limt_e && $cnt_items < $max_count) { return; } $max_stamp = $now - (strtotime($max_sdate) - $now); $max_items = (int) max($cnt_items - $max_count + 1, 0); $query = new WSAL_Models_OccurrenceQuery(); $query->addOrderBy("created_on", false); // TO DO Fixing data if ($is_date_e) { $query->addCondition('created_on <= %s', intval($max_stamp)); } if ($is_limt_e) { $query->setLimit($max_items); } if ($max_items - 1 == 0) { return; } // nothing to delete $result = $query->getAdapter()->GetSqlDelete($query); $deletedCount = $query->getAdapter()->Delete($query); if ($deletedCount == 0) { return; } // nothing to delete // keep track of what we're doing $this->plugin->alerts->Trigger(03, array('Message' => 'Running system cleanup.', 'Query SQL' => $result['sql'], 'Query Args' => $result['args']), true); // notify system do_action('wsal_prune', $deletedCount, vsprintf($result['sql'], $result['args'])); }
/** * Triggered after save post for add revision link */ public function SetRevisionLink($post_id, $post, $update) { $revisions = wp_get_post_revisions($post_id); if (!empty($revisions)) { $revision = array_shift($revisions); $objOcc = new WSAL_Models_Occurrence(); $occ = $objOcc->GetByPostID($post_id); $occ = count($occ) ? $occ[0] : null; if (!empty($occ)) { $occ->SetMetaValue('RevisionLink', $this->getRevisionLink($revision->ID)); } } }
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)); } } }
public function AjaxRefresh() { if (!$this->_plugin->settings->CurrentUserCan('view')) { die('Access Denied.'); } if (!isset($_REQUEST['logcount'])) { die('Log count parameter expected.'); } $old = (int) $_REQUEST['logcount']; $max = 40; // 40*500msec = 20sec session_write_close(); // fixes session lock issue do { $occ = new WSAL_Models_Occurrence(); $new = $occ->Count(); usleep(500000); // 500msec } while ($old == $new && --$max > 0); echo $old == $new ? 'false' : $new; die; }