コード例 #1
0
ファイル: request.php プロジェクト: Romua1d/core
 public function testGetRemoteAddress()
 {
     $_SERVER['REMOTE_ADDR'] = '10.0.0.2';
     $_SERVER['HTTP_X_FORWARDED'] = '10.4.0.5, 10.4.0.4';
     $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.0.233';
     // Without having specified a trusted remote address
     $this->assertEquals('10.0.0.2', OC_Request::getRemoteAddress());
     // With specifying a trusted remote address but no trusted header
     OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.0.0.2'));
     $this->assertEquals('10.0.0.2', OC_Request::getRemoteAddress());
     // With specifying a trusted remote address and trusted headers
     OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.0.0.2'));
     OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_X_FORWARDED'));
     $this->assertEquals('10.4.0.5', OC_Request::getRemoteAddress());
     OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED'));
     $this->assertEquals('192.168.0.233', OC_Request::getRemoteAddress());
     // With specifying multiple trusted remote addresses and trusted headers
     OC::$server->getConfig()->setSystemValue('trusted_proxies', array('10.3.4.2', '10.0.0.2', '127.0.3.3'));
     OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_X_FORWARDED'));
     $this->assertEquals('10.4.0.5', OC_Request::getRemoteAddress());
     OC::$server->getConfig()->setSystemValue('forwarded_for_headers', array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED'));
     $this->assertEquals('192.168.0.233', OC_Request::getRemoteAddress());
 }
コード例 #2
0
ファイル: owncloud.php プロジェクト: Romua1d/core
 /**
  * write a message in the log
  * @param string $app
  * @param string $message
  * @param int $level
  */
 public static function write($app, $message, $level)
 {
     $minLevel = min(OC_Config::getValue("loglevel", OC_Log::WARN), OC_Log::ERROR);
     if ($level >= $minLevel) {
         // default to ISO8601
         $format = OC_Config::getValue('logdateformat', 'c');
         $logtimezone = OC_Config::getValue("logtimezone", 'UTC');
         try {
             $timezone = new DateTimeZone($logtimezone);
         } catch (Exception $e) {
             $timezone = new DateTimeZone('UTC');
         }
         $time = new DateTime(null, $timezone);
         $reqId = \OC_Request::getRequestID();
         $remoteAddr = \OC_Request::getRemoteAddress();
         // remove username/passwords from URLs before writing the to the log file
         $time = $time->format($format);
         if ($minLevel == OC_Log::DEBUG) {
             $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '--';
             $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '--';
             $entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time', 'method', 'url');
         } else {
             $entry = compact('reqId', 'remoteAddr', 'app', 'message', 'level', 'time');
         }
         $entry = json_encode($entry);
         $handle = @fopen(self::$logFile, 'a');
         @chmod(self::$logFile, 0640);
         if ($handle) {
             fwrite($handle, $entry . "\n");
             fclose($handle);
         } else {
             // Fall back to error_log
             error_log($entry);
         }
     }
 }
コード例 #3
0
 /**
  * print error page using Exception details
  * @param Exception $exception
  */
 public static function printExceptionErrorPage(Exception $exception)
 {
     $content = new \OC_Template('', 'exception', 'error', false);
     $content->assign('errorMsg', $exception->getMessage());
     $content->assign('errorCode', $exception->getCode());
     $content->assign('file', $exception->getFile());
     $content->assign('line', $exception->getLine());
     $content->assign('trace', $exception->getTraceAsString());
     $content->assign('debugMode', defined('DEBUG') && DEBUG === true);
     $content->assign('remoteAddr', OC_Request::getRemoteAddress());
     $content->assign('requestID', OC_Request::getRequestID());
     $content->printPage();
     die;
 }