Пример #1
0
 /**
  * @param \Jelix\Logger\MessageInterface $message the message to log
  */
 function logMessage($message)
 {
     $type = $message->getCategory();
     if (\Jelix\Core\App::router()->request) {
         $ip = \Jelix\Core\App::router()->request->getIP();
     } else {
         $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     }
     error_log(date("Y-m-d H:i:s") . "\t" . $ip . "\t{$type}\t" . $message->getFormatedMessage(), 0);
 }
Пример #2
0
 /**
  * @param \Jelix\Routing\ServerResponse $response
  */
 function output($response)
 {
     if (!\Jelix\Core\App::router()->request) {
         return;
     }
     $email = \Jelix\Core\App::config()->mailLogger['email'];
     $headers = str_replace(array('\\r', '\\n'), array("\r", "\n"), \Jelix\Core\App::config()->mailLogger['emailHeaders']);
     $message = '';
     foreach ($this->messages as $msg) {
         $message .= "\n\n" . $msg->getFormatedMessage();
     }
     error_log(wordwrap($message, 70), 1, $email, $headers);
 }
Пример #3
0
 /**
  * @param \Jelix\Logger\MessageInterface $message the message to log
  */
 function logMessage($message)
 {
     if (!is_writable(\Jelix\Core\App::logPath())) {
         return;
     }
     $type = $message->getCategory();
     $appConf = \Jelix\Core\App::config();
     if ($appConf) {
         $conf =& \Jelix\Core\App::config()->fileLogger;
         if (!isset($conf[$type])) {
             return;
         }
         $f = $conf[$type];
         $f = str_replace('%m%', date("m"), $f);
         $f = str_replace('%Y%', date("Y"), $f);
         $f = str_replace('%d%', date("d"), $f);
         $f = str_replace('%H%', date("H"), $f);
     } else {
         $f = 'errors.log';
     }
     $coord = \Jelix\Core\App::router();
     if ($coord && $coord->request) {
         $ip = $coord->request->getIP();
     } else {
         $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     }
     $f = str_replace('%ip%', $ip, $f);
     try {
         if (!preg_match("/^([\\w\\.\\/]+)\$/", $f, $m)) {
             throw new Exception("Invalid file name for file logger name {$f}");
         }
         $file = \Jelix\Core\App::logPath($f);
         @error_log(date("Y-m-d H:i:s") . "\t" . $ip . "\t{$type}\t" . $message->getFormatedMessage() . "\n", 3, $file);
         @chmod($file, \Jelix\Core\App::config()->chmodFile);
     } catch (\Exception $e) {
         $file = \Jelix\Core\App::logPath('errors.log');
         @error_log(date("Y-m-d H:i:s") . "\t" . $ip . "\terror\t" . $e->getMessage() . "\n", 3, $file);
         @chmod($file, \Jelix\Core\App::config()->chmodFile);
     }
 }
Пример #4
0
 /**
  * get a response object.
  * @param string $name the name of the response type (ex: "html")
  * @param boolean $useOriginal true:don't use the response object redefined by the application
  * @return \Jelix\Routing\ServerResponse the response object
  */
 public function getResponse($type = '', $useOriginal = false)
 {
     if ($type == '') {
         $type = $this->defaultResponseType;
     }
     if ($useOriginal) {
         $responses =& App::config()->_coreResponses;
     } else {
         $responses =& App::config()->responses;
     }
     $coord = App::router();
     if (!isset($responses[$type])) {
         if ($coord->action) {
             $action = $coord->action->resource;
             $path = $coord->action->getPath();
         } else {
             $action = $coord->moduleName . '~' . $coord->actionName;
             $path = '';
         }
         if ($type == $this->defaultResponseType) {
             throw new \jException('jelix~errors.default.response.type.unknown', array($action, $type));
         } else {
             throw new \jException('jelix~errors.ad.response.type.unknown', array($action, $type, $path));
         }
     }
     $respclass = $responses[$type];
     $path = $responses[$type . '.path'];
     if (!class_exists($respclass, false)) {
         require $path;
     }
     $response = new $respclass();
     if (!$this->isAllowedResponse($response)) {
         throw new \jException('jelix~errors.ad.response.type.notallowed', array($coord->action->resource, $type, $coord->action->getPath()));
     }
     $coord->response = $response;
     return $response;
 }
Пример #5
0
 /**
  * @return string formated error message
  */
 public function getFormatedMessage()
 {
     if (isset($_SERVER['REQUEST_URI'])) {
         $url = $_SERVER['REQUEST_URI'];
     } elseif (isset($_SERVER['SCRIPT_NAME'])) {
         $url = $_SERVER['SCRIPT_NAME'];
     } else {
         $url = 'Unknow request';
     }
     // url params including module and action
     if (\Jelix\Core\App::router() && ($req = \Jelix\Core\App::router()->request)) {
         $params = str_replace("\n", ' ', var_export($req->params, true));
         $remoteAddr = $req->getIP();
     } else {
         $params = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
         // When we are in cmdline we need to fix the remoteAddr
         $remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     }
     $traceLog = "";
     foreach ($this->trace as $k => $t) {
         $traceLog .= "\n\t{$k}\t" . (isset($t['class']) ? $t['class'] . $t['type'] : '') . $t['function'] . "()\t";
         $traceLog .= (isset($t['file']) ? $t['file'] : '[php]') . ' : ' . (isset($t['line']) ? $t['line'] : '');
     }
     // referer
     $httpReferer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Unknown referer';
     $messageLog = strtr($this->format, array('%date%' => @date("Y-m-d H:i:s"), '%typeerror%' => $this->category, '%code%' => $this->code, '%msg%' => $this->message, '%ip%' => $remoteAddr, '%url%' => $url, '%referer%' => $httpReferer, '%params%' => $params, '%file%' => $this->file, '%line%' => $this->line, '%trace%' => $traceLog, '\\t' => "\t", '\\n' => "\n"));
     return $messageLog;
 }
Пример #6
0
 public static function coord()
 {
     //trigger_error("App::coord() is deprecated, use App::router() instead", E_USER_DEPRECATED);
     return \Jelix\Core\App::router();
 }
Пример #7
0
 /**
  * Create a jurl object with the given action data.
  *
  * @param \jUrlAction $url information about the action
  *
  * @return \jUrl the url correspondant to the action
  *
  * @author      Laurent Jouanneau
  * @copyright   2005 CopixTeam, 2005-2006 Laurent Jouanneau
  *   very few lines of code are copyrighted by CopixTeam, written by Laurent Jouanneau
  *   and released under GNU Lesser General Public Licence,
  *   in an experimental version of Copix Framework v2.3dev20050901,
  *   http://www.copix.org.
  */
 public function create(\jUrlAction $urlact)
 {
     $url = new \jUrl('', $urlact->params, '');
     // retrieve informations corresponding to the action
     // warning: it may delete module and action parameter from $url
     $urlinfo = $this->getUrlBuilderInfo($urlact, $url);
     // at this step, we have informations to build the url
     // setup script name
     $url->scriptName = App::urlBasePath() . $urlinfo[1];
     if ($urlinfo[2]) {
         $url->scriptName = App::router()->request->getServerURI(true) . $url->scriptName;
     }
     if ($urlinfo[1] && $this->config->extensionNeeded) {
         $url->scriptName .= '.php';
     }
     // for some request types, parameters aren't in the url
     // so we remove them
     // it's a bit dirty to do that hardcoded here, but it would be a pain
     // to load the request class to check whether we can remove or not
     if (in_array($urlact->requestType, $this->entryPointTypeHavingActionInBody)) {
         $url->clearParam();
         return $url;
     }
     if ($urlinfo[0] == 0) {
         $this->buildWithHandler($urlact, $url, $urlinfo);
     } elseif ($urlinfo[0] == 1) {
         $this->buildWithSpecificPathinfo($urlact, $url, $urlinfo);
     } elseif ($urlinfo[0] == 3) {
         $this->buildForDedicatedModule($urlact, $url, $urlinfo);
     } elseif ($urlinfo[0] == 5) {
         $this->buildForWholeController($urlact, $url, $urlinfo);
     } elseif ($urlinfo[0] == 2) {
         $url->pathInfo = '/' . $urlact->getParam('module', App::getCurrentModule()) . '/' . str_replace(':', '/', $urlact->getParam('action'));
         $url->delParam('module');
         $url->delParam('action');
     }
     return $url;
 }
Пример #8
0
 /**
  * Use the HTPP headers Last-Modified to see if the ressource in client cache is fresh
  *
  * @param mixed $dateLastModified Can be a jDateTime object, a DateTime object or a string understandable by strtotime
  * @param boolean $cleanCacheHeader True for clean/delete other cache headers. Default : true.
  *
  * @return boolean    True if the client ressource version is fresh, false otherwise
  */
 public function isValidCache($dateLastModified = null, $etag = null, $cleanCacheHeader = true)
 {
     if (!$this->_checkRequestType()) {
         return false;
     }
     $notModified = false;
     if ($cleanCacheHeader) {
         $this->cleanCacheHeaders();
     }
     if ($dateLastModified != null) {
         $dateLastModified = $this->_normalizeDate($dateLastModified);
         $lastModified = App::router()->request->header('If-Modified-Since');
         if ($lastModified !== null && $lastModified == $dateLastModified) {
             $notModified = true;
         } else {
             $this->addHttpHeader('Last-Modified', $dateLastModified);
         }
     }
     if ($etag != null) {
         $headerEtag = App::router()->request->header('If-None-Match');
         if ($headerEtag !== null && $etag == $headerEtag) {
             $notModified = true;
         } else {
             $this->addHttpHeader('Etag', $etag);
         }
     }
     if ($notModified) {
         $this->_outputOnlyHeaders = true;
         $this->setHttpStatus(304, 'Not Modified');
         $toClean = array('Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified', 'Etag');
         foreach ($toClean as $h) {
             unset($this->_httpHeaders[$h]);
         }
     }
     return $notModified;
 }