getScheme() public method

Gets the request's scheme.
public getScheme ( ) : string
return string
 public function serialize(JsonSerializationVisitor $visitor, OwnerData $owner, array $type)
 {
     $scheme = $this->request->getScheme() . '://' . $this->request->getHttpHost();
     $data = $owner->getData();
     if ($owner->getAvatarFileName()) {
         $data['avatar_file_path'] = $this->uh->asset($owner, 'avatar');
     } else {
         $data['avatar_file_path'] = $scheme . $owner->getDefaultAvatar();
     }
     return $data;
 }
Example #2
0
 public function __construct($routes, Request $request, EventDispatcher $dispatcher, ControllerResolver $resolver)
 {
     $this->deflRes = new NodeResponse();
     $this->context = new RequestContext($request->getBaseUrl(), $request->getMethod(), $request->getHost(), $request->getScheme(), $request->getPort(), $request->getPort());
     $this->matcher = new UrlMatcher($routes, $this->context);
     parent::__construct($dispatcher, $resolver);
 }
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $data = ['request-id' => $request->headers->get('X-Request-Id'), 'datetime' => date('Y-m-d H:i:s'), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHttpHost(), 'uri' => $request->getRequestUri(), 'route' => $request->get('_route')];
     /*
     if (isset($this['current_user'])) {
         $data['username'] = $this['current_user']->getName();
     }
     */
     $data['address'] = $request->getClientIp();
     if ($request->getSession()) {
         $data['session-id'] = $request->getSession()->getId();
     }
     if ($request->headers->has('User-Agent')) {
         $data['agent'] = $request->headers->get('User-Agent');
     }
     if ($request->headers->has('referer')) {
         $data['referer'] = $request->headers->get('referer');
     }
     $this->log($data);
     $response = $this->app->handle($request, $type, $catch);
     /*
     // response details
     $data['status'] = $response->getStatusCode();
     if ($response->headers->has('Content-Type')) {
         $data['content-type'] = $response->headers->get('content-type');
     }
     */
     return $response;
 }
 /**
  * Action for locale switch
  *
  * @param Request $request
  *
  * @throws \InvalidArgumentException
  * @return RedirectResponse
  */
 public function switchAction(Request $request)
 {
     $_locale = $request->attributes->get('_locale', $request->getLocale());
     $statusCode = $request->attributes->get('statusCode', $this->statusCode);
     $useReferrer = $request->attributes->get('useReferrer', $this->useReferrer);
     $redirectToRoute = $request->attributes->get('route', $this->redirectToRoute);
     $metaValidator = $this->metaValidator;
     if (!$metaValidator->isAllowed($_locale)) {
         throw new \InvalidArgumentException(sprintf('Not allowed to switch to locale %s', $_locale));
     }
     // Redirect the User
     if ($useReferrer && $request->headers->has('referer')) {
         $response = new RedirectResponse($request->headers->get('referer'), $statusCode);
     } elseif ($this->router && $redirectToRoute) {
         $target = $this->router->generate($redirectToRoute, array('_locale' => $_locale));
         if ($request->getQueryString()) {
             if (!strpos($target, '?')) {
                 $target .= '?';
             }
             $target .= $request->getQueryString();
         }
         $response = new RedirectResponse($target, $statusCode);
     } else {
         // TODO: this seems broken, as it will not handle if the site runs in a subdir
         // TODO: also it doesn't handle the locale at all and can therefore lead to an infinite redirect
         $response = new RedirectResponse($request->getScheme() . '://' . $request->getHttpHost() . '/', $statusCode);
     }
     return $response;
 }
Example #5
0
 public function indexAction(Request $request)
 {
     $form = $request->request->all();
     $no_js = $request->query->get('no-js') || 0;
     $script = $no_js == 1 ? 0 : 1;
     $db_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/data/databases";
     try {
         $this->datasources = new \SimpleXMLElement($db_dir . "/DataSources.xml", LIBXML_NOWARNING, true);
         $datasourcesCount = $this->datasources->DataSource->count();
     } catch (\Exception $e) {
         $datasourcesCount = 0;
     }
     $userManager = $this->get('fos_user.user_manager');
     $users = $userManager->findUsers();
     $finder = new Finder();
     $simu_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/data/simulators";
     $finder->depth('== 0')->files()->name('*.xml')->in($simu_dir);
     $simulatorsCount = $finder->count();
     $finder = new Finder();
     $views_dir = $this->get('kernel')->getBundle('EUREKAG6KBundle', true)->getPath() . "/Resources/views";
     $finder->depth('== 0')->ignoreVCS(true)->exclude(array('admin', 'base', 'Theme'))->directories()->in($views_dir);
     $viewsCount = $finder->count();
     $hiddens = array();
     $hiddens['script'] = $script;
     $silex = new Application();
     $silex->register(new MobileDetectServiceProvider());
     try {
         return $this->render('EUREKAG6KBundle:admin/pages:index.html.twig', array('ua' => $silex["mobile_detect"], 'path' => $request->getScheme() . '://' . $request->getHttpHost(), 'nav' => 'home', 'datasourcesCount' => $datasourcesCount, 'usersCount' => count($users), 'simulatorsCount' => $simulatorsCount, 'viewsCount' => $viewsCount, 'hiddens' => $hiddens));
     } catch (\Exception $e) {
         echo $e->getMessage();
         throw $this->createNotFoundException($this->get('translator')->trans("This template does not exist"));
     }
 }
Example #6
0
 /**
  * Action for locale switch
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param                                           $_locale The locale to set
  *
  * @return \Symfony\Bundle\FrameworkBundle\Controller\RedirectResponse
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 public function switchAction(Request $request, $_locale)
 {
     // Check if the Language is allowed
     if (!in_array(\Locale::getPrimaryLanguage($_locale), $this->allowedLanguages)) {
         throw new NotFoundHttpException('This language is not available');
     }
     // tries to detect a Region from the user-provided locales
     $providedLanguages = $request->getLanguages();
     $locales = array();
     foreach ($providedLanguages as $locale) {
         if (strpos($locale . '_', $_locale) !== false && strlen($locale) > 2) {
             $locales[] = $locale;
         }
     }
     if (count($locales) > 0) {
         $this->session->set('localeIdentified', $locales[0]);
     } else {
         $this->session->set('localeIdentified', $_locale);
     }
     // Add the listener
     $this->session->set('setLocaleCookie', true);
     // Redirect the User
     if ($request->headers->has('referer') && true === $this->useReferrer) {
         return new RedirectResponse($request->headers->get('referer'));
     }
     if (null !== $this->redirectToRoute) {
         return new RedirectResponse($this->router->generate($this->redirectToRoute));
     }
     return new RedirectResponse($request->getScheme() . '://' . $request->getHttpHost() . $this->redirectToUrl);
 }
Example #7
0
 /**
  * @Route("/lostPassword", name="lost_password_route")
  */
 public function lostPasswordAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $reset = false;
     if ($request->request->get('reset') == "true") {
         $reset = true;
     }
     if ($reset) {
         $user = $em->getRepository('BackendBundle:User')->findOneByEmail($request->request->get('email'));
         if (!is_null($user)) {
             $rb = uniqid(rand(), true);
             $random = md5($user->getEmail() . $rb);
             //guardar en la base de datos
             $restorer = $em->getRepository('BackendBundle:Restorer')->findOneByUser($user);
             if (is_null($restorer)) {
                 $restorer = new Restorer();
             }
             $restorer->setUser($user);
             $restorer->setTime(new \DateTime());
             $restorer->setAuth(md5($random));
             $em->persist($restorer);
             $em->flush();
             $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
             $url = $baseurl . '/resetPassword?token=' . $random;
             $message = \Swift_Message::newInstance()->setSubject('Recuperación de contraseña')->setFrom('gestionIPre@ing.puc.cl')->setTo(array($user->getEmail()))->setBody('<html>' . ' <head></head>' . ' <body>' . ' Hola, usa este link para recuperar tu contraseña: ' . '<a href="' . $url . '">' . $url . '</a></br>' . ' Si no pediste recuperar contraseña omite este email. (No responda este email)</body>' . '</html>', 'text/html');
             $this->get('mailer')->send($message);
         }
     }
     return $this->render('security/lostPassword.html.twig', array('reset' => $reset));
 }
Example #8
0
 public function githubAction(Application $app, Request $request)
 {
     $clientID = getenv('GITHUB_API_KEY');
     $clientSecret = getenv('GITHUB_API_SECRET');
     $code = $request->query->get('code');
     $redirectUri = $request->getScheme() . '://' . $request->getHost();
     if (80 != $request->getPort()) {
         $redirectUri .= ':' . $request->getPort();
     }
     $redirectUri .= '/auth/github';
     $provider = new Github(['clientId' => $clientID, 'clientSecret' => $clientSecret, 'redirectUri' => $redirectUri, 'scopes' => ['user:email']]);
     if (empty($code)) {
         $authUrl = $provider->getAuthorizationUrl();
         $app['session']->set('oauth2state', $provider->state);
         return $app->redirect($authUrl);
     } else {
         $token = $provider->getAccessToken('authorization_code', ['code' => $code]);
         $userDetails = $provider->getUserDetails($token);
         try {
             $user = $app['user.manager']->fetchUserByGithubUid($userDetails->uid);
         } catch (UserNotFoundException $exception) {
             $email = null;
             foreach ($provider->getUserEmails($token) as $providerEmail) {
                 if ($providerEmail->primary) {
                     $email = $providerEmail->email;
                     break;
                 }
             }
             $user = $app['user.manager']->createUser(['email' => $email, 'roles' => ['ROLE_USER'], 'name' => $userDetails->name, 'githubUid' => $userDetails->uid]);
             $app['user.manager']->saveUser($user);
         }
         $app['session']->set('user', $user);
         return $app->redirect($app['url_generator']->generate('account.profile'));
     }
 }
Example #9
0
 public function clearAction(Request $request, $env = 'prod')
 {
     $form = $request->request->all();
     $no_js = $request->query->get('no-js') || 0;
     $script = $no_js == 1 ? 0 : 1;
     if (!$this->get('security.context')->isGranted('ROLE_ADMIN')) {
         throw $this->AccessDeniedException($this->get('translator')->trans("Access Denied!"));
     }
     $cache_dir = dirname($this->get('kernel')->getCacheDir());
     $this->log[] = "<b>" . $this->get('translator')->trans("cache directory : %cachedir%", array('%cachedir%' => $cache_dir)) . "</b>";
     if (is_dir($cache_dir)) {
         if (basename($cache_dir) == "cache") {
             $this->log[] = "<br/><br/><b>" . $this->get('translator')->trans("clearing cache") . " :</b>";
             $this->cc($cache_dir, $env);
             $this->log[] = "<br/><br/><b>" . $this->get('translator')->trans("done !") . "</b>";
         } else {
             $this->log[] = "<br/> " . $this->get('translator')->trans("Error : %cachedir% is not a named cache", array('%cachedir%' => $cache_dir));
         }
     } else {
         $this->log[] = "<br/> " . $this->get('translator')->trans("Error : %cachedir% is not a directory", array('%cachedir%' => $cache_dir));
     }
     $hiddens = array();
     $hiddens['script'] = $script;
     $silex = new Application();
     $silex->register(new MobileDetectServiceProvider());
     try {
         return $this->render('EUREKAG6KBundle:admin/pages:cache-clear.html.twig', array('ua' => $silex["mobile_detect"], 'path' => $request->getScheme() . '://' . $request->getHttpHost(), 'nav' => 'caches', 'log' => $this->log, 'hiddens' => $hiddens));
     } catch (\Exception $e) {
         throw $this->createNotFoundException($this->get('translator')->trans("This template does not exist"));
     }
 }
 /**
  * Get the scheme for a raw URL.
  *
  * @param  bool    $secure
  * @return string
  */
 protected function getScheme($secure)
 {
     if (is_null($secure)) {
         return $this->request->getScheme() . '://';
     } else {
         return $secure ? 'https://' : 'http://';
     }
 }
 /**
  * Save an image and resize it.
  *
  * @param Request $request
  *
  * @return Response
  *
  * @Route("/save", name="prh_image_save")
  * @Method("POST")
  */
 public function saveAction(Request $request)
 {
     $imageService = $this->get('prh.blog.service.image');
     $path = $this->getParameter('kernel.root_dir') . '/../web/uploads/images';
     /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
     $file = $request->files->get('file');
     $imageService->createResizedImages($path, $file);
     return new Response(sprintf('%s://%s/uploads/images/%s', $request->getScheme(), $request->getHttpHost(), $imageService->appendSizeExt($file->getClientOriginalName(), 'b')));
 }
 /**
  * {@inheritdoc}
  */
 public function getParameters()
 {
     $method = null;
     $format = null;
     $scheme = null;
     $ajax = null;
     $locale = null;
     $route = null;
     if (null !== $this->request) {
         $method = strtolower($this->request->getMethod());
         $format = $this->request->getRequestFormat();
         $scheme = $this->request->getScheme();
         $ajax = $this->request->isXmlHttpRequest() ? 'ajax' : 'not_ajax';
         $locale = $this->request->getLocale();
         $route = $this->request->attributes->get('_route');
     }
     return array('request_method' => $method, 'request_format' => $format, 'request_scheme' => $scheme, 'request_ajax' => $ajax, 'request_locale' => $locale, 'request_route' => $route);
 }
Example #13
0
 public function fromRequest(Request $request)
 {
     $this->setBaseUrl($request->getBaseUrl());
     $this->setMethod($request->getMethod());
     $this->setHost($request->getHost());
     $this->setScheme($request->getScheme());
     $this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
     $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
 }
Example #14
0
 /**
  * Sets all needed values from the request.
  *
  * @param Request $request A request to get values from.
  */
 public function setRequest(Request $request)
 {
     $this->setScheme($request->getScheme());
     $this->setHost($request->getHost());
     $this->setBasePath($request->getBasePath());
     if ($request->isSecure()) {
         $this->setHttpsPort($request->getPort());
     } else {
         $this->setHttpPort($request->getPort());
     }
 }
 public function checkDomainsValidity(Request $request)
 {
     $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
     //var_dump($baseurl);
     switch (true) {
         case $baseurl == 'http://agente3w.com':
             return 'core_dashboard';
             break;
     }
     return NULL;
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function analyze(Request $request)
 {
     if ($request->attributes->has('_sulu')) {
         return;
     }
     $attributes = new RequestAttributes(['host' => $request->getHost(), 'scheme' => $request->getScheme()]);
     foreach ($this->requestProcessors as $requestProcessor) {
         $attributes = $attributes->merge($requestProcessor->process($request, $attributes));
     }
     $request->attributes->set('_sulu', $attributes);
 }
Example #17
0
 /**
  * Updates the RequestContext info based on a HttpFoundation Request.
  *
  * @param Request $request A Request instance
  */
 public function fromRequest(Request $request)
 {
     $this->setBaseUrl($request->getBaseUrl());
     $this->setPathInfo($request->getPathInfo());
     $this->setMethod($request->getMethod());
     $this->setHost($request->getHost());
     $this->setScheme($request->getScheme());
     $this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
     $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
     $this->setQueryString($request->server->get('QUERY_STRING', ''));
 }
Example #18
0
    protected function initializeRequestAttributes(Request $request, $master)
    {
        if ($master) {
            // set the context even if the parsing does not need to be done
            // to have correct link generation
            $context = new RequestContext(
                $request->getBaseUrl(),
                $request->getMethod(),
                $request->getHost(),
                $request->getScheme(),
                $this->httpPort,
                $this->httpsPort
            );

            if ($session = $request->getSession()) {
                $context->setParameter('_locale', $session->getLocale());
            }

            $this->router->setContext($context);
        }

        if ($request->attributes->has('_controller')) {
            // routing is already done
            return;
        }

        // add attributes based on the path info (routing)
        try {
            $parameters = $this->router->match($request->getPathInfo());

            if (null !== $this->logger) {
                $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters)));
            }

            $request->attributes->add($parameters);
        } catch (NotFoundException $e) {
            $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo());
            if (null !== $this->logger) {
                $this->logger->err($message);
            }
            throw new NotFoundHttpException($message, $e);
        } catch (MethodNotAllowedException $e) {
            $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), strtoupper(implode(', ', $e->getAllowedMethods())));
            if (null !== $this->logger) {
                $this->logger->err($message);
            }
            throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e);
        }

        if ($master && $locale = $request->attributes->get('_locale')) {
            $request->getSession()->setLocale($locale);
            $context->setParameter('_locale', $locale);
        }
    }
 public function createContexts(Request $request)
 {
     $map = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_route' => $request->attributes->get('_route'), 'request_host' => $request->getHost(), 'request_port' => $request->getPort(), 'request_scheme' => $request->getScheme(), 'request_client_ip' => $request->getClientIp(), 'request_content_type' => $request->getContentType(), 'request_acceptable_content_types' => $request->getAcceptableContentTypes(), 'request_etags' => $request->getETags(), 'request_charsets' => $request->getCharsets(), 'request_languages' => $request->getLanguages(), 'request_locale' => $request->getLocale(), 'request_auth_user' => $request->getUser(), 'request_auth_has_password' => !is_null($request->getPassword()));
     // Attributes from newer versions.
     if (method_exists($request, 'getEncodings')) {
         $map['request_encodings'] = $request->getEncodings();
     }
     if (method_exists($request, 'getClientIps')) {
         $map['request_client_ips'] = $request->getClientIps();
     }
     return $map;
 }
 protected function logRequest(Request $request)
 {
     $msg = 'Request "{request_method} {request_uri}"';
     $map = array('request_method' => $request->getMethod(), 'request_uri' => $request->getRequestUri(), 'request_host' => $request->getHost(), 'request_port' => $request->getPort(), 'request_scheme' => $request->getScheme(), 'request_client_ip' => $request->getClientIp(), 'request_content_type' => $request->getContentType(), 'request_acceptable_content_types' => $request->getAcceptableContentTypes(), 'request_etags' => $request->getETags(), 'request_charsets' => $request->getCharsets(), 'request_languages' => $request->getLanguages(), 'request_locale' => $request->getLocale(), 'request_auth_user' => $request->getUser(), 'request_auth_has_password' => !is_null($request->getPassword()));
     // Attributes from newer versions.
     if (method_exists($request, 'getEncodings')) {
         $map['request_encodings'] = $request->getEncodings();
     }
     if (method_exists($request, 'getClientIps')) {
         $map['request_client_ips'] = $request->getClientIps();
     }
     $this->logger->log($this->logLevel, $msg, $map);
 }
Example #21
0
 public function doInstall(Request $request)
 {
     set_time_limit(360);
     $servername = $request->getScheme() . '://' . $request->getHttpHost() . '/';
     $dbConn = null;
     $database_host = $request->request->get('hostname');
     $database_port = $request->request->get('port');
     $database_user = $request->request->get('user');
     $database_password = $request->request->get('db_password');
     $appbox_name = $request->request->get('ab_name');
     $databox_name = $request->request->get('db_name');
     try {
         $abInfo = ['host' => $database_host, 'port' => $database_port, 'user' => $database_user, 'password' => $database_password, 'dbname' => $appbox_name];
         /** @var Connection $abConn */
         $abConn = $this->app['dbal.provider']($abInfo);
         $abConn->connect();
     } catch (\Exception $e) {
         return $this->app->redirectPath('install_step2', ['error' => $this->app->trans('Appbox is unreachable')]);
     }
     try {
         if ($databox_name) {
             $dbInfo = ['host' => $database_host, 'port' => $database_port, 'user' => $database_user, 'password' => $database_password, 'dbname' => $databox_name];
             /** @var Connection $dbConn */
             $dbConn = $this->app['dbal.provider']($dbInfo);
             $dbConn->connect();
         }
     } catch (\Exception $e) {
         return $this->app->redirectPath('install_step2', ['error' => $this->app->trans('Databox is unreachable')]);
     }
     $this->app['dbs.options'] = array_merge($this->app['db.options.from_info']($dbInfo), $this->app['db.options.from_info']($abInfo), $this->app['dbs.options']);
     $this->app['orm.ems.options'] = array_merge($this->app['orm.em.options.from_info']($dbInfo), $this->app['orm.em.options.from_info']($abInfo), $this->app['orm.ems.options']);
     $email = $request->request->get('email');
     $password = $request->request->get('password');
     $template = $request->request->get('db_template');
     $dataPath = $request->request->get('datapath_noweb');
     try {
         $installer = $this->app['phraseanet.installer'];
         $binaryData = [];
         foreach (['php_binary' => $request->request->get('binary_php'), 'swf_extract_binary' => $request->request->get('binary_swfextract'), 'pdf2swf_binary' => $request->request->get('binary_pdf2swf'), 'swf_render_binary' => $request->request->get('binary_swfrender'), 'unoconv_binary' => $request->request->get('binary_unoconv'), 'ffmpeg_binary' => $request->request->get('binary_ffmpeg'), 'mp4box_binary' => $request->request->get('binary_MP4Box'), 'pdftotext_binary' => $request->request->get('binary_xpdf')] as $key => $path) {
             $binaryData[$key] = $path;
         }
         $user = $installer->install($email, $password, $abConn, $servername, $dataPath, $dbConn, $template, $binaryData);
         $this->app->getAuthenticator()->openAccount($user);
         return $this->app->redirectPath('admin', ['section' => 'taskmanager', 'notice' => 'install_success']);
     } catch (\Exception $e) {
         return $this->app->redirectPath('install_step2', ['error' => $this->app->trans('an error occured : %message%', ['%message%' => $e->getMessage()])]);
     }
 }
Example #22
0
 protected function prepareResponse(Response $response, Request $request)
 {
     $domains = array_merge(array($this->configuration->getBackend()), $this->configuration->getAliases());
     $response->setContent(str_ireplace(array_map(function ($value) use($request) {
         return $request->getScheme() . '://' . $value;
     }, $domains), $request->getSchemeAndHttpHost(), $response->getContent()));
     if ($response->headers->has('set-cookie')) {
         $response->headers->set('set-cookie', implode(';', array_map(function ($item) use($domains, $request) {
             if (strpos($item, 'domain') !== false) {
                 return str_replace($domains, $request->getHost(), $item);
             }
             return $item;
         }, explode(';', $response->headers->get('set-cookie')))));
     }
     return $response;
 }
 /**
  * @return string
  */
 protected function getBaseUrl()
 {
     $port = '';
     if ('https' == $this->request->getScheme() && $this->request->getPort() != 443) {
         $port = ":{$this->request->getPort()}";
     }
     if ('http' == $this->request->getScheme() && $this->request->getPort() != 80) {
         $port = ":{$this->request->getPort()}";
     }
     $baseUrl = $this->request->getBaseUrl();
     if ('.php' == substr($this->request->getBaseUrl(), -4)) {
         $baseUrl = pathinfo($this->request->getBaseurl(), PATHINFO_DIRNAME);
     }
     $baseUrl = rtrim($baseUrl, '/\\');
     return sprintf('%s://%s%s%s', $this->request->getScheme(), $this->request->getHost(), $port, $baseUrl);
 }
Example #24
0
 /**
  * Redirects to a URL.
  *
  * The response status code is 302 if the permanent parameter is false (default),
  * and 301 if the redirection is permanent.
  *
  * In case the path is empty, the status code will be 404 when permanent is false
  * and 410 otherwise.
  *
  * @param Request      $request   The request instance
  * @param string       $path      The absolute path or URL to redirect to
  * @param Boolean      $permanent Whether the redirect is permanent or not
  * @param string|null  $scheme    The URL scheme (null to keep the current one)
  * @param integer|null $httpPort  The HTTP port (null to keep the current one for the same scheme or the configured port in the container)
  * @param integer|null $httpsPort The HTTPS port (null to keep the current one for the same scheme or the configured port in the container)
  *
  * @return Response A Response instance
  */
 public function urlRedirectAction(Request $request, $path, $permanent = false, $scheme = null, $httpPort = null, $httpsPort = null)
 {
     if ('' == $path) {
         return new Response(null, $permanent ? 410 : 404);
     }
     $statusCode = $permanent ? 301 : 302;
     // redirect if the path is a full URL
     if (parse_url($path, PHP_URL_SCHEME)) {
         return new RedirectResponse($path, $statusCode);
     }
     if (null === $scheme) {
         $scheme = $request->getScheme();
     }
     $qs = $request->getQueryString();
     if ($qs) {
         $qs = '?' . $qs;
     }
     $port = '';
     if ('http' === $scheme) {
         if (null === $httpPort) {
             if ('http' === $request->getScheme()) {
                 $httpPort = $request->getPort();
             } elseif ($this->container->hasParameter('request_listener.http_port')) {
                 $httpPort = $this->container->getParameter('request_listener.http_port');
             }
         }
         if (null !== $httpPort && 80 != $httpPort) {
             $port = ":{$httpPort}";
         }
     } elseif ('https' === $scheme) {
         if (null === $httpsPort) {
             if ('https' === $request->getScheme()) {
                 $httpsPort = $request->getPort();
             } elseif ($this->container->hasParameter('request_listener.https_port')) {
                 $httpsPort = $this->container->getParameter('request_listener.https_port');
             }
         }
         if (null !== $httpsPort && 443 != $httpsPort) {
             $port = ":{$httpsPort}";
         }
     }
     $url = $scheme . '://' . $request->getHost() . $port . $request->getBaseUrl() . $path . $qs;
     return new RedirectResponse($url, $statusCode);
 }
Example #25
0
 public function doInstall(Application $app, Request $request)
 {
     set_time_limit(360);
     $servername = $request->getScheme() . '://' . $request->getHttpHost() . '/';
     $abConn = $dbConn = null;
     $hostname = $request->request->get('ab_hostname');
     $port = $request->request->get('ab_port');
     $user_ab = $request->request->get('ab_user');
     $ab_password = $request->request->get('ab_password');
     $appbox_name = $request->request->get('ab_name');
     $databox_name = $request->request->get('db_name');
     try {
         $abConn = $app['dbal.provider']->get(['host' => $hostname, 'port' => $port, 'user' => $user_ab, 'password' => $ab_password, 'dbname' => $appbox_name]);
         $abConn->connect();
     } catch (\Exception $e) {
         return $app->redirectPath('install_step2', ['error' => $app->trans('Appbox is unreachable')]);
     }
     try {
         if ($databox_name) {
             $dbConn = $app['dbal.provider']->get(['host' => $hostname, 'port' => $port, 'user' => $user_ab, 'password' => $ab_password, 'dbname' => $databox_name]);
             $dbConn->connect();
         }
     } catch (\Exception $e) {
         return $app->redirectPath('install_step2', ['error' => $app->trans('Databox is unreachable')]);
     }
     $email = $request->request->get('email');
     $password = $request->request->get('password');
     $template = $request->request->get('db_template');
     $dataPath = $request->request->get('datapath_noweb');
     try {
         $installer = $app['phraseanet.installer'];
         $installer->setPhraseaIndexerPath($request->request->get('binary_phraseanet_indexer'));
         $binaryData = [];
         foreach (['php_binary' => $request->request->get('binary_php'), 'phraseanet_indexer' => $request->request->get('binary_phraseanet_indexer'), 'swf_extract_binary' => $request->request->get('binary_swfextract'), 'pdf2swf_binary' => $request->request->get('binary_pdf2swf'), 'swf_render_binary' => $request->request->get('binary_swfrender'), 'unoconv_binary' => $request->request->get('binary_unoconv'), 'ffmpeg_binary' => $request->request->get('binary_ffmpeg'), 'mp4box_binary' => $request->request->get('binary_MP4Box'), 'pdftotext_binary' => $request->request->get('binary_xpdf'), 'recess_binary' => $request->request->get('binary_recess')] as $key => $path) {
             $binaryData[$key] = $path;
         }
         $user = $installer->install($email, $password, $abConn, $servername, $dataPath, $dbConn, $template, $binaryData);
         $app['authentication']->openAccount($user);
         return $app->redirectPath('admin', ['section' => 'taskmanager', 'notice' => 'install_success']);
     } catch (\Exception $e) {
         return $app->redirectPath('install_step2', ['error' => $app->trans('an error occured : %message%', ['%message%' => $e->getMessage()])]);
     }
 }
 public function clientAction(Request $request)
 {
     $uri = substr($this->generateUrl('moocsy_apis_xml_server'), 12) . '?wsdl';
     $baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . $uri;
     /**
      * API XML
      */
     //$client = new \SoapClient($baseurl);
     $token = "5FZ2Z8QIkA7UTZ4BYkoC==";
     $username = "@SoyDonCristian";
     $email = "cristianangulonova@hotmail.com";
     $sku = "EABR-K14";
     //$registrar = $client->registrar($token, $username, $email, $sku);
     /**
      * Service
      */
     $api = $this->get('moocsy.api_xml');
     $registrar = $api->registrar($token, $username, $email, $sku);
     return new Response($registrar);
 }
 public function redirectAction(Request $request, $path, $host = null, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
 {
     if (!$path) {
         return new Response(null, 410);
     }
     if (null === $scheme) {
         $scheme = $request->getScheme();
     }
     $qs = $request->getQueryString();
     if ($qs) {
         $qs = '?' . $qs;
     }
     $port = '';
     if ('http' === $scheme && 80 != $httpPort) {
         $port = ':' . $httpPort;
     } elseif ('https' === $scheme && 443 != $httpsPort) {
         $port = ':' . $httpsPort;
     }
     $url = $scheme . '://' . ($host ?: $request->getHost()) . $port . $request->getBaseUrl() . $path . $qs;
     return new RedirectResponse($url, $permanent ? 301 : 302);
 }
Example #28
0
 /**
  * Returns a rendered xmlsitemap.
  *
  * @return Response
  */
 public function indexAction(Request $request)
 {
     /** @var RequestAnalyzerInterface $requestAnalyzer */
     $requestAnalyzer = $this->get('sulu_core.webspace.request_analyzer');
     /** @var SitemapXMLGeneratorInterface $sitemapXMLGenerator */
     $sitemapXMLGenerator = $this->get('sulu_website.sitemap_xml_generator');
     $sitemap = $this->get('sulu_content.content_repository')->findAll($requestAnalyzer->getWebspace()->getXDefaultLocalization()->getLocalization(), $requestAnalyzer->getWebspace()->getKey(), MappingBuilder::create()->addProperties(['changed'])->setResolveUrl(true)->getMapping());
     $webspaceSitemaps = [['localizations' => array_map(function (Localization $localization) {
         return $localization->getLocalization();
     }, $requestAnalyzer->getWebspace()->getAllLocalizations()), 'defaultLocalization' => $requestAnalyzer->getWebspace()->getXDefaultLocalization()->getLocalization(), 'sitemap' => $sitemap]];
     $preferredDomain = $request->getHttpHost();
     // XML Response
     $response = new Response();
     $response->setMaxAge(240);
     $response->setSharedMaxAge(960);
     $response->headers->set(HttpCache::HEADER_REVERSE_PROXY_TTL, $response->getAge() + $this->container->getParameter('sulu_website.sitemap.cache.lifetime'));
     $response->headers->set('Content-Type', 'text/xml');
     $response->setContent($sitemapXMLGenerator->generate($webspaceSitemaps, $preferredDomain, $request->getScheme()));
     // Generate XML
     return $response;
 }
Example #29
0
 public function indexAction(Request $request, $crud = null)
 {
     $form = $request->request->all();
     $no_js = $request->query->get('no-js') || 0;
     $script = $no_js == 1 ? 0 : 1;
     if ($crud !== null) {
         if (!$this->get('security.context')->isGranted('ROLE_SUPER_ADMIN')) {
             return $this->errorResponse($form, "Access denied!");
         }
         switch ($crud) {
             case 'add':
                 return $this->addUser($form);
             case 'update':
                 return $this->updateUser($form);
             case 'delete':
                 return $this->deleteUser($form);
         }
     } else {
         if (!$this->get('security.context')->isGranted('ROLE_SUPER_ADMIN')) {
             throw $this->AccessDeniedException($this->get('translator')->trans("Access Denied!"));
         } else {
             $userManager = $this->get('fos_user.user_manager');
             $users = $userManager->findUsers();
             $hiddens = array();
             $hiddens['script'] = $script;
             $silex = new Application();
             $silex->register(new MobileDetectServiceProvider());
             try {
                 return $this->render('EUREKAG6KBundle:admin/pages:users.html.twig', array('ua' => $silex["mobile_detect"], 'path' => $request->getScheme() . '://' . $request->getHttpHost(), 'nav' => 'users', 'users' => $users, 'hiddens' => $hiddens));
             } catch (\Exception $e) {
                 echo $e->getMessage();
                 throw $this->createNotFoundException($this->get('translator')->trans("This template does not exist"));
             }
         }
     }
 }
Example #30
0
 public function addSignatureToSymfonyRequest(\Symfony\Component\HttpFoundation\Request $request, $api_token, $secret)
 {
     $method = $request->getMethod();
     // build URL without parameters
     $url = $this->buildURLPrefix($request->getScheme(), $request->getHost(), $request->getPort()) . $request->getPathInfo();
     // get parameters
     if ($method == 'GET') {
         $parameters = $request->query->all();
     } else {
         $is_json = strpos($request->header('CONTENT_TYPE'), '/json');
         if ($is_json) {
             $parameters = json_decode($request->getContent(), true);
         } else {
             $parameters = $request->request->all();
         }
     }
     // get signature
     $signature_info = $this->createSignatureParameters($method, $url, $parameters, $api_token, $secret);
     // add http headers
     $request->headers->set('X-' . $this->auth_header_namespace . '-AUTH-API-TOKEN', $api_token);
     $request->headers->set('X-' . $this->auth_header_namespace . '-AUTH-NONCE', $signature_info['nonce']);
     $request->headers->set('X-' . $this->auth_header_namespace . '-AUTH-SIGNATURE', $signature_info['signature']);
     return $request;
 }