Example #1
0
    /**
     * Initiate shopware auth resource
     * database adapter by default
     *
     * @param Enlight_Event_EventArgs $args
     * @throws Exception
     * @return null|\Zend_Auth
     */
    public function onInitResourceBackendSession(Enlight_Event_EventArgs $args)
    {
        $options = $this->Application()->getOption('backendSession', array());

        if (!isset($options['cookie_path']) && $this->request !== null) {
            $options['cookie_path'] = rtrim($this->request->getBaseUrl(), '/') . '/backend/';
        }
        if (empty($options['gc_maxlifetime'])) {
            $backendTimeout = $this->Config()->get('backendTimeout', 60 * 90);
            $options['gc_maxlifetime'] = $backendTimeout;
        }
        $refererCheck = false; $clientCheck = false;
        if(is_bool($options['referer_check'])) {
            $refererCheck = $options['referer_check'];
            unset($options['referer_check']);
        }
        if(!empty($options['client_check'])) {
            $clientCheck = true;
        }
        unset($options['client_check']);

        Enlight_Components_Session::start($options);

        $referer = $this->request->getHeader('referer');
        if($refererCheck && $referer !== null
          && strpos($referer, 'http') === 0) {
            $referer = substr($referer, 0, strpos($referer, '/backend/'));
            $referer .= '/backend/';
            if(!isset($_SESSION['__SW_REFERER'])) {
                $_SESSION['__SW_REFERER'] = $referer;
            } elseif (strpos($referer, $_SESSION['__SW_REFERER']) !== 0) {
                Enlight_Components_Session::destroy();
                throw new Exception('Referer check for backend session failed');
            }
        }
        $client = $this->request->getHeader('userAgent');
        if($clientCheck && $client !== null) {
            if(!isset($_SESSION['__SW_CLIENT'])) {
                $_SESSION['__SW_CLIENT'] = $client;
            } elseif ($client !==  $_SESSION['__SW_CLIENT']) {
                Enlight_Components_Session::destroy();
                throw new Exception('Client check for backend session failed');
            }
        }

        return new Enlight_Components_Session_Namespace('ShopwareBackend');
    }
Example #2
0
 /**
  * Initiate shopware auth resource
  * database adapter by default
  *
  * @param Enlight_Event_EventArgs $args
  * @throws Exception
  * @return null|\Zend_Auth
  */
 public function onInitResourceBackendSession(Enlight_Event_EventArgs $args)
 {
     $options = $this->Application()->getOption('backendSession', array());
     if (!isset($options['cookie_path']) && $this->request !== null) {
         $options['cookie_path'] = rtrim($this->request->getBaseUrl(), '/') . '/backend/';
     }
     if (empty($options['gc_maxlifetime'])) {
         $backendTimeout = $this->Config()->get('backendTimeout', 60 * 90);
         $options['gc_maxlifetime'] = $backendTimeout;
     }
     $refererCheck = false;
     $clientCheck = false;
     if (is_bool($options['referer_check'])) {
         $refererCheck = $options['referer_check'];
         unset($options['referer_check']);
     }
     if (!empty($options['client_check'])) {
         $clientCheck = true;
     }
     unset($options['client_check']);
     if (!isset($options['save_handler']) || $options['save_handler'] == 'db') {
         // SW-4819 Add database backend support
         $config_save_handler = array('name' => 's_core_sessions_backend', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'expiry');
         Enlight_Components_Session::setSaveHandler(new Enlight_Components_Session_SaveHandler_DbTable($config_save_handler));
     }
     Enlight_Components_Session::start($options);
     if ($refererCheck && ($referer = $this->request->getHeader('referer')) !== null && strpos($referer, 'http') === 0) {
         $referer = substr($referer, 0, strpos($referer, '/backend/'));
         $referer .= '/backend/';
         if (!isset($_SESSION['__SW_REFERER'])) {
             $_SESSION['__SW_REFERER'] = $referer;
         } elseif (strpos($referer, $_SESSION['__SW_REFERER']) !== 0) {
             Enlight_Components_Session::destroy();
             throw new Exception('Referer check for backend session failed');
         }
     }
     if ($clientCheck && ($client = $this->request->getHeader('userAgent')) !== null) {
         if (!isset($_SESSION['__SW_CLIENT'])) {
             $_SESSION['__SW_CLIENT'] = $client;
         } elseif ($client !== $_SESSION['__SW_CLIENT']) {
             Enlight_Components_Session::destroy();
             throw new Exception('Client check for backend session failed');
         }
     }
     return new Enlight_Components_Session_Namespace('ShopwareBackend');
 }
Example #3
0
 /**
  * @param EnlightRequest $request
  */
 public function updateFromEnlightRequest(EnlightRequest $request)
 {
     $this->setHost($request->getHttpHost());
     $this->setBaseUrl($request->getBaseUrl());
     $this->setSecure($request->isSecure());
     $this->setGlobalParams(self::getGlobalParamsFromRequest($request));
     $this->setParams($request->getQuery());
 }
Example #4
0
 /**
  * Returns the configured proxy-url.
  *
  * Fallbacks to autodetection if proxy-url is not configured and $request is given.
  * Returns null if $request is not given or autodetection fails.
  *
  * @param Enlight_Controller_Request_RequestHttp $request
  * @return string|null
  */
 public function getProxyUrl(\Enlight_Controller_Request_RequestHttp $request = null)
 {
     $proxyUrl = trim($this->Config()->get('proxy'));
     if (!empty($proxyUrl)) {
         return $proxyUrl;
     }
     // if proxy url is not set fall back to host detection
     if ($request !== null && $request->getHttpHost()) {
         return $request->getScheme() . '://' . $request->getHttpHost() . $request->getBaseUrl() . '/';
     }
     /** @var ModelManager $em */
     $em = $this->get('models');
     $repository = $em->getRepository('Shopware\\Models\\Shop\\Shop');
     /** @var Shopware\Models\Shop\Shop $shop */
     $shop = $repository->findOneBy(array('default' => true));
     if (!$shop->getHost()) {
         return null;
     }
     $url = sprintf('%s://%s%s/', 'http', $shop->getHost(), $shop->getBasePath());
     return $url;
 }
Example #5
0
 /**
  * Sets the shopware cache headers
  */
 public function setControllerOptions()
 {
     $controllerName = $this->request->getModuleName() . '/' . $this->request->getControllerName();
     if(isset($this->controllerOptions[$controllerName]) && $this->request->getParam('rewriteUrl')) {
         $options = $this->controllerOptions[$controllerName];
         $query = $this->request->getQuery();
         $result = array_intersect_key($query, $options);
         $cookie = 'controller-options-'
             . $this->request->getBaseUrl()
             . $this->request->getPathInfo();
         if(count($result) > 0) {
             $options = $this->request->getCookie($cookie);
             if($options !== null) {
                 parse_str($options, $options);
             } else {
                 $options = array();
             }
             $options = array_merge($options, $result);
             ksort($options);
             $options = http_build_query($options, '', '&');
             $this->response->setCookie(
                 $cookie, $options, 0,
                 null, //$this->request->getBasePath() . '/',
                 $this->request->getHttpHost()
             );
             $location = array_diff($query, $result);
             $location = $this->action->Front()->Router()->assemble($location);
             $this->action->redirect($location);
         } else {
             $options = $this->request->getCookie($cookie);
             if($options !== null) {
                 parse_str($options, $options);
                 $this->request->setQuery($options);
             }
         }
     }
 }