Esempio n. 1
0
 public function getCount()
 {
     $date = new DateTime('NOW', $this->registry['core.default_timezone']);
     $date->sub(new DateInterval('PT30M'));
     $con = new Condition();
     $con->add('ip', '=', $_SERVER['REMOTE_ADDR']);
     $con->add('date', '>', $date->format(DateTime::SQL));
     $count = $this->sql->select($this->registry['table.login_attempt'], array('count'), $con, Sql::SELECT_FIELD);
     return (int) $count;
 }
Esempio n. 2
0
 /**
  * onLoad
  *
  * @param count integer
  */
 public function onLoad()
 {
     parent::onLoad();
     $count = $this->args->get('count', 8);
     $now = new DateTime('NOW', $this->registry['core.default_timezone']);
     $past = new DateTime('NOW', $this->registry['core.default_timezone']);
     $past->sub(new DateInterval('P' . $count . 'D'));
     $act = array();
     // condition
     $con = new Condition();
     $con->add('scope', '=', 0);
     $con->add('date', '>=', $past->format(DateTime::SQL));
     // get activities
     $handler = $this->hm->getHandler('AmunService\\User\\Activity');
     $result = $handler->getAll(array('id', 'scope', 'summary', 'date', 'authorId', 'authorName', 'authorThumbnailUrl'), 0, 64, 'date', Sql::SORT_ASC, $con);
     foreach ($result as $row) {
         $date = new DateTime($row['date'], $this->registry['core.default_timezone']);
         $interval = $date->diff($now);
         $key = $interval->format('%d');
         if (!isset($act[$key])) {
             $act[$key] = 1;
         } else {
             $act[$key]++;
         }
     }
     // build params
     $chd = array();
     $labels = array();
     $max = 0;
     $days = 0;
     for ($i = $count - 1; $i >= 0; $i--) {
         if (isset($act[$i])) {
             if ($act[$i] > $max) {
                 $max = $act[$i];
             }
             $chd[$i] = $act[$i];
         } else {
             $chd[$i] = 0;
         }
         $labels[] = date('d M', time() - $i * 3600 * 24);
         $days++;
     }
     $params = array('cht' => 'ls', 'chd' => 't:' . implode(',', $chd), 'chs' => '320x100', 'chco' => '0077CC', 'chds' => '0,' . $max, 'chxt' => 'x', 'chxl' => '0:|' . implode('|', $labels), 'chxr' => '0,1,' . $days . ',1');
     $this->display($params);
 }
Esempio n. 3
0
File: User.php Progetto: visapi/amun
 /**
  * This method tries to figure out whether a user tries to abuse the system.
  * Every user can insert, update or delete "core.input_limit" records
  * in the last "core.input_interval" minutes without entering an captcha
  * After this the user has to solve an captcha
  *
  * @return boolean
  */
 public function hasInputExceeded()
 {
     if ($this->isAdministrator()) {
         return false;
     }
     $now = new DateTime('NOW', $this->registry['core.default_timezone']);
     $now->sub(new DateInterval($this->registry['core.input_interval']));
     $con = new Condition();
     $con->add('userId', '=', $this->id);
     $con->add('date', '>=', $now->format(DateTime::SQL));
     $count = $this->sql->count($this->registry['table.log'], $con);
     if ($count > $this->registry['core.input_limit']) {
         $expire = time() - $now->getTimestamp();
         $percentage = ceil($count * 100 / ($this->registry['core.input_limit'] * 2));
         $expire = $expire - $expire * ($percentage / 100);
         $lastVerified = isset($_SESSION['captcha_verified']) ? $_SESSION['captcha_verified'] : 0;
         $diff = time() - $lastVerified;
         if ($diff > $expire) {
             return true;
         }
     }
     return false;
 }