Ejemplo n.º 1
0
 /**
  * Parse requests log and blacklist flooding IPs.
  * Should be called by cron job every minute.
  */
 public function parseLogForFloodingIps()
 {
     $tablesToLock = array(Tbl::get('TBL_SECURITY_REQUESTS_LOG'), Tbl::get('TBL_SECURITY_FLOODER_IPS'));
     MySqlDbManager::getDbObject()->startTransaction();
     $qb = new QueryBuilder();
     $qbSelect = new QueryBuilder();
     $qbSelect->select(new Field('ip'))->from(Tbl::get('TBL_SECURITY_REQUESTS_LOG'))->where($qbSelect->expr()->greaterEqual(new Field('count'), $this->config->requestsLimit));
     $qb->insertIgnore(Tbl::get('TBL_SECURITY_FLOODER_IPS'))->fields('ip')->values($qbSelect);
     $this->query->exec($qb->getSQL());
     $this->query->exec("TRUNCATE TABLE `" . Tbl::get('TBL_SECURITY_REQUESTS_LOG') . "`");
     if (!MySqlDbManager::getDbObject()->commit()) {
         MySqlDbManager::getDbObject()->rollBack();
     }
 }
Ejemplo n.º 2
0
 public function insertSession($inviterUserId, $invitedUserId)
 {
     if (empty($inviterUserId) or !is_numeric($inviterUserId)) {
         throw new InvalidArgumentException("Invalid inviterUser specified!");
     }
     if (empty($invitedUserId) or !is_numeric($invitedUserId)) {
         throw new InvalidArgumentException("Invalid invitedUser specified!");
     }
     $qb = new QueryBuilder();
     $qb->insertIgnore(Tbl::get('TBL_CHAT_SESSIONS'))->values(array('inviter_user_id' => $inviterUserId, 'invited_user_id' => $invitedUserId));
     $this->query->exec($qb->getSQL());
     $newSessionId = $this->query->getLastInsertId();
     //$this->insertSessionLog($inviterUserId, $invitedUserId);
     return $newSessionId;
 }