Ejemplo n.º 1
0
 /**
  * Log each appropiate request on the application
  *
  */
 private function log_request()
 {
     $command = Yii::app()->db->createCommand();
     //Do NOT log some specific actions in some specific conditions
     //ie:We should not be logging each user subject fetch unless there is a new subject(that would be a line in the log every 10 sec)
     if ($this->action->Id == 'js') {
         $this->no_log = true;
     }
     if (Log::is_bot($_SERVER['HTTP_USER_AGENT'])) {
         $this->no_log = true;
     }
     ///Dont log if its a bot request
     if ($this->no_log == false) {
         try {
             $command->insert('log', array('time' => SiteLibrary::utc_time(), 'session_id' => Yii::app()->getSession()->getSessionID(), 'user_id' => (int) Yii::app()->user->id, 'controller' => $this->id, 'action' => $this->action->Id, 'uri' => Yii::App()->request->getRequestUri(), 'model' => get_class($this->model), 'model_id' => isset($this->model->id) ? (int) $this->model->id : 0, 'theme' => Yii::app()->getTheme() ? strtolower(substr(Yii::app()->getTheme()->getName(), 0, 2)) : 're'));
             //Get real clients ip if from a proxy
             $client_ip = "";
             $client_host = !empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? $_SERVER["HTTP_X_FORWARDED_HOST"] : "";
             if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
                 $client_ip = $_SERVER["HTTP_CLIENT_IP"];
                 //first verify ip from share internet
             } elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
                 $client_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
                 //if not then for a proxy user
             } else {
             }
             //Only the first request should go here
             //if(Yii::App()->request->getCookies()->getCount() == 0)//If cookies are not set this might be the first request
             if (Yii::app()->session->get('site_loaded') != "yes") {
                 $command->insert('log_detail', array('log_id' => Yii::app()->db->getLastInsertID(), 'session' => Yii::app()->getSession()->getSessionID(), 'client_ip' => $client_ip, 'client_host' => $client_host, 'request_ip' => $_SERVER['REMOTE_ADDR'], 'request_host' => $_SERVER['REMOTE_HOST'], 'agent' => $_SERVER['HTTP_USER_AGENT'], 'referer' => $_SERVER['HTTP_REFERER'], 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'], 'language' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], 'device' => substr(SiteLibrary::get_device(), 0, 2)));
             }
         } catch (CException $e) {
             Yii::log($e, 'warning', 'system.web.Controller');
         }
         //'params'=>serialize($this->actionParams)
     }
 }