/**
  * Sends the given HTTP request
  *
  * @param Http\Request $httpRequest
  * @return Http\Response
  * @throws Http\Exception
  * @api
  */
 public function sendRequest(Http\Request $httpRequest)
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if (!$requestHandler instanceof FunctionalTestRequestHandler) {
         throw new Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
     }
     $this->securityContext->clearContext();
     $this->validatorResolver->reset();
     $response = new Http\Response();
     $requestHandler->setHttpRequest($httpRequest);
     $requestHandler->setHttpResponse($response);
     $objectManager = $this->bootstrap->getObjectManager();
     $baseComponentChain = $objectManager->get(\TYPO3\Flow\Http\Component\ComponentChain::class);
     $componentContext = new ComponentContext($httpRequest, $response);
     if (version_compare(PHP_VERSION, '6.0.0') >= 0) {
         try {
             $baseComponentChain->handle($componentContext);
         } catch (\Throwable $throwable) {
             $this->prepareErrorResponse($throwable, $response);
         }
     } else {
         try {
             $baseComponentChain->handle($componentContext);
         } catch (\Exception $exception) {
             $this->prepareErrorResponse($exception, $response);
         }
     }
     $session = $this->bootstrap->getObjectManager()->get(\TYPO3\Flow\Session\SessionInterface::class);
     if ($session->isStarted()) {
         $session->close();
     }
     return $response;
 }
 /**
  * @param string $path
  * @return string
  * @throws \Exception
  */
 public function render($path = NULL)
 {
     if ($path === NULL) {
         $path = '404';
     }
     /** @var RequestHandler $activeRequestHandler */
     $activeRequestHandler = $this->bootstrap->getActiveRequestHandler();
     $parentHttpRequest = $activeRequestHandler->getHttpRequest();
     $requestPath = $parentHttpRequest->getUri()->getPath();
     $language = explode('/', ltrim($requestPath, '/'))[0];
     if ($language === 'neos') {
         throw new \Exception('NotFoundViewHelper can not be used for neos-routes.', 1435648210);
     }
     $language = $this->localeDetector->detectLocaleFromLocaleTag($language)->getLanguage();
     if ($this->contentDimensionPresetSource->findPresetByUriSegment('language', $language) === NULL) {
         $language = '';
     }
     if ($language !== '') {
         $language .= '/';
     }
     $request = Request::create(new Uri(rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $language . $path));
     $matchingRoute = $this->router->route($request);
     if (!$matchingRoute) {
         throw new \Exception(sprintf('Uri with path "%s" could not be found.', rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $language . $path), 1426446160);
     }
     $response = new Response();
     $objectManager = $this->bootstrap->getObjectManager();
     $baseComponentChain = $objectManager->get('TYPO3\\Flow\\Http\\Component\\ComponentChain');
     $componentContext = new ComponentContext($request, $response);
     $baseComponentChain->handle($componentContext);
     return $response->getContent();
 }
 /**
  * @return \TYPO3\Neos\Domain\Model\Domain
  */
 public function findOneByActiveRequest()
 {
     $matchingDomain = null;
     $activeRequestHandler = $this->bootstrap->getActiveRequestHandler();
     if ($activeRequestHandler instanceof \TYPO3\Flow\Http\HttpRequestHandlerInterface) {
         $matchingDomain = $this->findOneByHost($activeRequestHandler->getHttpRequest()->getUri()->getHost(), true);
     }
     return $matchingDomain;
 }
Exemplo n.º 4
0
 /**
  * Adds a CSRF token as argument in ExtDirect requests
  *
  * @Flow\Around("method(TYPO3\ExtJS\ExtDirect\Transaction->buildRequest()) && setting(TYPO3.Flow.security.enable)")
  * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point
  * @return \TYPO3\Flow\Mvc\ActionRequest
  */
 public function transferCsrfTokenToExtDirectRequests(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint)
 {
     $extDirectRequest = $joinPoint->getAdviceChain()->proceed($joinPoint);
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if ($requestHandler instanceof \TYPO3\Flow\Http\HttpRequestHandlerInterface) {
         $arguments = $requestHandler->getHttpRequest()->getArguments();
         if (isset($arguments['__csrfToken'])) {
             $requestArguments = $extDirectRequest->getMainRequest()->getArguments();
             $requestArguments['__csrfToken'] = $arguments['__csrfToken'];
             $extDirectRequest->getMainRequest()->setArguments($requestArguments);
         }
     }
     return $extDirectRequest;
 }
Exemplo n.º 5
0
 /**
  * @return \TYPO3\Flow\Http\Request
  */
 protected function getHttpRequest()
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if ($requestHandler instanceof \TYPO3\Flow\Http\HttpRequestHandlerInterface) {
         return $requestHandler->getHttpRequest();
     }
 }
Exemplo n.º 6
0
 /**
  * @param string $path
  * @return string
  * @throws \Exception
  */
 public function render($path = NULL)
 {
     /** @var RequestHandler $activeRequestHandler */
     $activeRequestHandler = $this->bootstrap->getActiveRequestHandler();
     $parentHttpRequest = $activeRequestHandler->getHttpRequest();
     $httpRequest = Request::create(new Uri($parentHttpRequest->getBaseUri() . $path . '.html'));
     $matchingRoute = $this->router->route($httpRequest);
     if (!$matchingRoute) {
         throw new \Exception(sprintf('Uri with path "%s" could not be found.', $parentHttpRequest->getBaseUri() . $path . '.html'), 1426446160);
     }
     $request = new ActionRequest($parentHttpRequest);
     foreach ($matchingRoute as $argumentName => $argumentValue) {
         $request->setArgument($argumentName, $argumentValue);
     }
     $response = new Response($activeRequestHandler->getHttpResponse());
     $this->dispatcher->dispatch($request, $response);
     return $response->getContent();
 }
 /**
  * Sets up a virtual browser and web environment for seamless HTTP and MVC
  * related tests.
  *
  * @return void
  */
 protected function setupHttp()
 {
     $this->browser = new \TYPO3\Flow\Http\Client\Browser();
     $this->browser->setRequestEngine(new \TYPO3\Flow\Http\Client\InternalRequestEngine());
     $this->router = $this->browser->getRequestEngine()->getRouter();
     $requestHandler = self::$bootstrap->getActiveRequestHandler();
     $requestHandler->setHttpRequest(Request::create(new \TYPO3\Flow\Http\Uri('http://localhost/typo3/flow/test')));
     $requestHandler->setHttpResponse(new \TYPO3\Flow\Http\Response());
 }
 /**
  * Detects the (resources) base URI and stores it as a protected class variable.
  *
  * $this->resourcesPublishingPath must be set prior to calling this method.
  *
  * @return void
  */
 protected function detectResourcesBaseUri()
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if ($requestHandler instanceof \TYPO3\Flow\Http\HttpRequestHandlerInterface) {
         $uri = $requestHandler->getHttpRequest()->getBaseUri();
     } else {
         $uri = '';
     }
     $this->resourcesBaseUri = $uri . substr($this->resourcesPublishingPath, strlen(FLOW_PATH_WEB));
 }
 /**
  * @return HttpRequest
  */
 protected function getHttpRequest()
 {
     if ($this->httpRequest === NULL) {
         $requestHandler = $this->bootstrap->getActiveRequestHandler();
         if (!$requestHandler instanceof HttpRequestHandlerInterface) {
             return NULL;
         }
         $this->httpRequest = $requestHandler->getHttpRequest();
     }
     return $this->httpRequest;
 }
 /**
  * Sends the given HTTP request
  *
  * @param Http\Request $httpRequest
  * @return Http\Response
  * @throws Http\Exception
  * @api
  */
 public function sendRequest(Http\Request $httpRequest)
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if (!$requestHandler instanceof FunctionalTestRequestHandler) {
         throw new Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
     }
     $this->securityContext->clearContext();
     $this->validatorResolver->reset();
     $response = new Http\Response();
     $requestHandler->setHttpRequest($httpRequest);
     $requestHandler->setHttpResponse($response);
     $objectManager = $this->bootstrap->getObjectManager();
     $baseComponentChain = $objectManager->get(\TYPO3\Flow\Http\Component\ComponentChain::class);
     $componentContext = new ComponentContext($httpRequest, $response);
     try {
         $baseComponentChain->handle($componentContext);
     } catch (\Exception $exception) {
         $pathPosition = strpos($exception->getFile(), 'Packages/');
         $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
         $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
         $content = PHP_EOL . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
         $content .= 'thrown in file ' . $filePathAndName . PHP_EOL;
         $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL;
         $content .= Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL;
         if ($exception instanceof Exception) {
             $statusCode = $exception->getStatusCode();
         } else {
             $statusCode = 500;
         }
         $response->setStatus($statusCode);
         $response->setContent($content);
         $response->setHeader('X-Flow-ExceptionCode', $exception->getCode());
         $response->setHeader('X-Flow-ExceptionMessage', $exception->getMessage());
     }
     $session = $this->bootstrap->getObjectManager()->get(\TYPO3\Flow\Session\SessionInterface::class);
     if ($session->isStarted()) {
         $session->close();
     }
     return $response;
 }
Exemplo n.º 11
0
 /**
  * Detects and returns the website's base URI
  *
  * @return string The website's base URI
  */
 protected function detectResourcesBaseUri()
 {
     $uri = '';
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if ($requestHandler instanceof HttpRequestHandlerInterface) {
         // In functional tests or some other obscure scenarios we might end up without a current HTTP request:
         $request = $requestHandler->getHttpRequest();
         if ($request instanceof Request) {
             $uri = $requestHandler->getHttpRequest()->getBaseUri();
         }
     }
     return (string) $uri;
 }
 /**
  * Detects and returns the website's absolute base URI
  *
  * @return string The resolved resource base URI, @see getResourcesBaseUri()
  * @throws Exception if the baseUri can't be resolved
  */
 protected function detectResourcesBaseUri()
 {
     if ($this->baseUri !== '' && ($this->baseUri[0] === '/' || strpos($this->baseUri, '://') !== false)) {
         return $this->baseUri;
     }
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if ($requestHandler instanceof HttpRequestHandlerInterface) {
         return $requestHandler->getHttpRequest()->getBaseUri() . $this->baseUri;
     }
     if ($this->httpBaseUri === null) {
         throw new Exception(sprintf('The base URI for resources could not be detected. Please specify the "TYPO3.Flow.http.baseUri" setting or use an absolute "baseUri" option for target "%s".', $this->name), 1438093977);
     }
     return $this->httpBaseUri . $this->baseUri;
 }
Exemplo n.º 13
0
 /**
  * Sets up a virtual browser and web environment for seamless HTTP and MVC
  * related tests.
  *
  * @return void
  */
 protected function setupHttp()
 {
     $_GET = array();
     $_POST = array();
     $_COOKIE = array();
     $_FILES = array();
     $_SERVER = array('REDIRECT_FLOW_CONTEXT' => 'Development', 'REDIRECT_FLOW_REWRITEURLS' => '1', 'REDIRECT_STATUS' => '200', 'FLOW_CONTEXT' => 'Testing', 'FLOW_REWRITEURLS' => '1', 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'en-us', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_CONNECTION' => 'keep-alive', 'PATH' => '/usr/bin:/bin:/usr/sbin:/sbin', 'SERVER_SIGNATURE' => '', 'SERVER_SOFTWARE' => 'Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/1.0.0e DAV/2 PHP/5.3.8', 'SERVER_NAME' => 'localhost', 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/opt/local/apache2/htdocs/', 'SERVER_ADMIN' => 'george@localhost', 'SCRIPT_FILENAME' => '/opt/local/apache2/htdocs/Web/index.php', 'REMOTE_PORT' => '51439', 'REDIRECT_QUERY_STRING' => '', 'REDIRECT_URL' => '', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'GET', 'QUERY_STRING' => '', 'REQUEST_URI' => '', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php', 'REQUEST_TIME' => 1326472534);
     $this->browser = new \TYPO3\Flow\Http\Client\Browser();
     $this->browser->setRequestEngine(new \TYPO3\Flow\Http\Client\InternalRequestEngine());
     $this->router = $this->browser->getRequestEngine()->getRouter();
     $requestHandler = self::$bootstrap->getActiveRequestHandler();
     $requestHandler->setHttpRequest(\TYPO3\Flow\Http\Request::create(new \TYPO3\Flow\Http\Uri('http://localhost/typo3/flow/test')));
     $requestHandler->setHttpResponse(new \TYPO3\Flow\Http\Response());
 }
Exemplo n.º 14
0
 /**
  * Stores log entries for given actions.
  *
  * @param string $component of the whole application
  * @param string $action the performed action to be logged
  */
 protected function writeLogEntry($component, $action)
 {
     $entry = new \Roketi\Panel\Domain\Model\LogEntry();
     $entry->setTimeStamp(new \DateTime());
     $entry->setAction($action);
     $entry->setComponent($component);
     if ($this->doLogTheCurrentUser === TRUE) {
         $account = $this->context->getAccount();
         $entry->setAccount($account);
     } else {
         $entry->unsetAccount();
     }
     // fiddle out the IP of the client
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if ($requestHandler instanceof \TYPO3\Flow\Http\HttpRequestHandlerInterface) {
         $ip = $requestHandler->getHttpRequest()->getClientIPAddress();
     } else {
         $ip = '';
     }
     $entry->setRemoteIp($ip);
     $this->logEntryRepository->add($entry);
     $this->persistenceManager->persistAll();
 }
 /**
  * Returns TRUE if there is a session that can be resumed.
  *
  * If a to-be-resumed session was inactive for too long, this function will
  * trigger the expiration of that session. An expired session cannot be resumed.
  *
  * NOTE that this method does a bit more than the name implies: Because the
  * session info data needs to be loaded, this method stores this data already
  * so it doesn't have to be loaded again once the session is being used.
  *
  * @return boolean
  * @api
  */
 public function canBeResumed()
 {
     if ($this->request === null) {
         $this->initializeHttpAndCookie($this->bootstrap->getActiveRequestHandler());
     }
     if ($this->sessionCookie === null || $this->request === null || $this->started === true) {
         return false;
     }
     $sessionMetaData = $this->metaDataCache->get($this->sessionCookie->getValue());
     if ($sessionMetaData === false) {
         return false;
     }
     $this->lastActivityTimestamp = $sessionMetaData['lastActivityTimestamp'];
     $this->storageIdentifier = $sessionMetaData['storageIdentifier'];
     $this->tags = $sessionMetaData['tags'];
     return !$this->autoExpire();
 }
 /**
  * Shows a single news object
  *
  * @param \Lelesys\Plugin\News\Domain\Model\News $news The news to show
  * @return void
  */
 public function showAction(\Lelesys\Plugin\News\Domain\Model\News $news = NULL)
 {
     if ($news !== NULL) {
         $related = $this->newsService->related($news);
         $this->view->assign('assetsdetail', $related['assets']);
         $this->view->assign('comments', $related['comments']);
         $this->view->assign('relatedFiles', $related['files']);
         $this->view->assign('relatedLinkData', $this->newsService->show($news));
         $this->view->assign('relatedNews', $related['news']);
         $this->view->assign('categories', $related['categories']);
         $this->view->assign('tags', $news->getTags());
         $this->view->assign('newsdetail', $news);
         $this->view->assign('currentUri', $this->bootstrap->getActiveRequestHandler()->getHttpRequest()->getUri());
     }
 }