Beispiel #1
0
 /**
  * Shopware\EventListener: Enlight_Controller_Front_RouteShutdown
  *
  * @param \Enlight_Controller_EventArgs $args
  */
 public function registerBackendTheme(\Enlight_Controller_EventArgs $args)
 {
     if ($args->getRequest()->getModuleName() != 'backend') {
         return;
     }
     $directory = $this->container->get('theme_path_resolver')->getExtJsThemeDirectory();
     $this->container->get('template')->setTemplateDir(array('backend' => $directory, 'include_dir' => '.'));
 }
 /**
  * @param \Enlight_Controller_EventArgs $args
  */
 public function onPostDispatch(\Enlight_Controller_EventArgs $args)
 {
     $exceptions = $args->getResponse()->getException();
     if (empty($exceptions)) {
         return;
     }
     foreach ($exceptions as $exception) {
         $this->exceptions[] = $exception;
     }
 }
Beispiel #3
0
    /**
     * Event listener method
     *
     * @param Enlight_Controller_EventArgs $args
     */
    public function onRouteShutdown(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();
        if ($request->getModuleName() == 'backend' || $request->getModuleName() == 'api') {
            return;
        }

        $intVars = array('sCategory', 'sContent', 'sCustom');
        foreach ($intVars as $parameter) {
            if (!empty($_GET[$parameter])) {
                $_GET[$parameter] = (int)$_GET[$parameter];
            }
            if (!empty($_POST[$parameter])) {
                $_POST[$parameter] = (int)$_POST[$parameter];
            }
        }

        $config = $this->Config();

        $regex = array();
        if (!empty($config->sql_protection) && !empty($config->sql_regex)) {
            $regex[] = $config->sql_regex;
        }
        if (!empty($config->xss_protection) && !empty($config->xss_regex)) {
            $regex[] = $config->xss_regex;
        }
        if (!empty($config->rfi_protection) && !empty($config->rfi_regex)) {
            $regex[] = $config->rfi_regex;
        }

        if (empty($regex)) {
            return;
        }

        $regex = '#' . implode('|', $regex) . '#msi';

        $userParams = $request->getUserParams();
        $process = array(
            &$_GET, &$_POST, &$_COOKIE, &$_REQUEST, &$_SERVER, &$userParams
        );
        while (list($key, $val) = each($process)) {
            foreach ($val as $k => $v) {
                unset($process[$key][$k]);
                if (is_array($v)) {
                    $process[$key][self::filterValue($k, $regex)] = $v;
                    $process[] = &$process[$key][self::filterValue($k, $regex)];
                } else {
                    $process[$key][self::filterValue($k, $regex)] = self::filterValue($v, $regex);
                }
            }
        }

        unset($process);
        $request->setParams($userParams);
    }
Beispiel #4
0
 /**
  * @param \Enlight_Controller_EventArgs $args
  */
 public function onPreDispatch(\Enlight_Controller_EventArgs $args)
 {
     /** @var $front \Enlight_Controller_Front */
     $front = $args->getSubject();
     $request = $front->Request();
     /** @var $router \Shopware\Components\Routing\RouterInterface  */
     $router = $front->Router();
     // Fix context on forward
     $context = $router->getContext();
     $context->setGlobalParams($context::getGlobalParamsFromRequest($request));
 }
Beispiel #5
0
 /**
  * Checks the url / the request and passes it around if necessary.
  *
  * @param Enlight_Controller_EventArgs $args
  */
 public function onPreDispatch(Enlight_Controller_EventArgs $args)
 {
     $request = $args->getRequest();
     $response = $args->getResponse();
     if ($response->isException() || $request->isPost() || $request->isXmlHttpRequest() || $request->has('callback') || $request->getModuleName() && $request->getModuleName() != 'frontend' || !$request->getParam('rewriteAlias') && !$request->getParam('rewriteOld') || !Shopware()->Session()->Bot && !$request->getCookie()) {
         return;
     }
     $router = $args->getSubject()->Router();
     $query = $request->getQuery();
     $location = $router->assemble($query);
     $current = $request->getScheme() . '://' . $request->getHttpHost() . $request->getRequestUri();
     if ($location !== $current) {
         $response->setRedirect($location, 301);
     }
 }
Beispiel #6
0
 /**
  * Updates the base url and the http host on route startup.
  * Adds the support for the HTTPS proxy system.
  *
  * @param Enlight_Controller_EventArgs $args
  */
 public function onRouteStartup(Enlight_Controller_EventArgs $args)
 {
     $request = $args->getRequest();
     if (($host = $request->getHeader('X_FORWARDED_HOST') !== null) && $host === $this->Config()->secureHttpHost) {
         $request->setSecure();
     }
     if ($request->isSecure()) {
         $request->getPathInfo();
         $request->setBaseUrl($this->Config()->secureBaseUrl);
         $request->setHttpHost($this->Config()->secureHttpHost);
     } else {
         $request->getPathInfo();
         $request->setBaseUrl($this->Config()->baseUrl);
         $request->setHttpHost($this->Config()->httpHost);
     }
 }
Beispiel #7
0
    /**
     * Event listener method
     *
     * @param Enlight_Controller_EventArgs $args
     */
    public function onDispatchLoopShutdown(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();
        $response = $args->getResponse();

        if ($response->isException()
            || $request->isXmlHttpRequest()
            || $request->getModuleName() != 'frontend'
            || $request->getControllerName() == 'captcha'
        ) {
            return;
        }

        if (!Shopware()->Shop()->get('esi')) {
            $this->updateLog($request, $response);
        }
    }
Beispiel #8
0
 /**
  * Checks the url / the request and passes it around if necessary.
  *
  * @param Enlight_Controller_EventArgs $args
  */
 public function onPreDispatch(Enlight_Controller_EventArgs $args)
 {
     $request = $args->getRequest();
     $response = $args->getResponse();
     if ($response->isException() || $request->isPost() || $request->isXmlHttpRequest() || $request->has('callback') || $request->getModuleName() != 'frontend' || !$request->getParam('rewriteAlias')) {
         return;
     }
     $router = $args->getSubject()->Router();
     $query = $request->getQuery();
     $location = $router->assemble($query);
     // Fix shop redirect / if it's not a seo url
     if (preg_match('#\\/[0-9]+$#', $location, $match) > 0) {
         $location = $request->getBaseUrl() . '/';
     }
     $current = $request->getScheme() . '://' . $request->getHttpHost() . $request->getRequestUri();
     if ($location !== $current) {
         $response->setRedirect($location, 301);
     }
 }
Beispiel #9
0
 /**
  * This pre-dispatch event-hook checks permissions
  *
  * @param \Enlight_Controller_EventArgs $args
  * @return void
  */
 public function onFrontPreDispatch(Enlight_Controller_EventArgs $args)
 {
     $request = $args->getRequest();
     $response = $args->getResponse();
     if ($request->getModuleName() != 'api') {
         return;
     }
     /** @var $auth Shopware_Components_Auth */
     $auth = $this->get('auth');
     $result = $auth->authenticate();
     if (!$result->isValid()) {
         $request->setControllerName('index');
         $request->setActionName('noauth');
         return;
     }
     $identity = $result->getIdentity();
     $db = $this->get('db');
     $select = $db->select()->from('s_core_auth')->where('username LIKE ?', $identity['username']);
     $user = $db->query($select)->fetchObject();
     if (!empty($user->roleID)) {
         $user->role = $this->get('models')->find('Shopware\\Models\\User\\Role', $user->roleID);
     }
     $auth->getStorage()->write($user);
     $rawBody = $request->getRawBody();
     try {
         $input = Zend_Json::decode($rawBody);
     } catch (Zend_Json_Exception $e) {
         $response->setHttpResponseCode(400);
         $request->setControllerName('index');
         $request->setActionName('invalid');
         return;
     }
     foreach ((array) $input as $key => $value) {
         if ($value !== null) {
             $request->setPost($key, $value);
         }
     }
 }
 /**
  * Adds the headers to the response once it's created
  */
 public function onRouteStartUp(\Enlight_Controller_EventArgs $args)
 {
     $response = $args->getResponse();
     $request = $args->getRequest();
     $this->setUp($request, $response);
 }
 /**
  * This function extends a new Template. This Template replaces the original password forgotten form with
  * a extended Version.
  *
  * @param Enlight_Controller_EventArgs $args
  */
 public function onPostDispatchAccount(Enlight_Controller_EventArgs $args)
 {
     if (!$this->Config()->get('activatePlugin')) {
         return;
     }
     /** @var Shopware_Controllers_Frontend_Account $controller */
     $controller = $args->getSubject();
     $view = $controller->View();
     $this->registerComponents();
     if ($controller->Request()->getActionName() == 'password') {
         $view->extendsTemplate('frontend/plugins/swag_password_restore/index.tpl');
     } else {
         $view->extendsTemplate('frontend/plugins/swag_password_restore/messages.tpl');
     }
 }
Beispiel #12
0
 /**
  * @param Enlight_Controller_EventArgs $args
  */
 public function onDispatchLoopShutdown(Enlight_Controller_EventArgs $args)
 {
     $response = $args->getSubject()->Response();
     $exceptions = $response->getException();
     if (empty($exceptions)) {
         return;
     }
     $logger = $this->get('corelogger');
     foreach ($exceptions as $exception) {
         $logger->error((string) $exception);
     }
 }
 /**
  * Initialize legacy SW4 handlers
  *
  * @param $args
  */
 private function initializeLegacy(Enlight_Controller_EventArgs $args)
 {
     $requestHelper = new \Shopware\SwagVariantFilter\Components\LegacyFilter\RequestHelper($args->getRequest());
     $this->Application()->Events()->addSubscriber(new \Shopware\SwagVariantFilter\Subscriber\LegacyServiceContainer($requestHelper));
     $this->Application()->Events()->addSubscriber(new Shopware\SwagVariantFilter\Subscriber\Legacy($requestHelper));
 }
Beispiel #14
0
    /**
     * Do http caching jobs
     *
     * @param \Enlight_Controller_EventArgs $args
     */
    public function onPreDispatch($args)
    {
        $this->action = $action = $args->getSubject();
        $this->request = $request = $args->getRequest();
        $this->response = $response = $args->getResponse();

        if ($request->getHeader('Surrogate-Capability') === false) {
            return;
        }

        $this->initConfig();

        if ($request->getModuleName() != 'frontend' && $request->getModuleName() != 'widgets') {
            return;
        }
        if (!Shopware()->Shop()->get('esi')) {
            return;
        }

        // Allow esi tags
        $this->response->setHeader('Surrogate-Control', 'content="ESI/1.0"');

        $this->setControllerOptions();
        $this->setCacheHeaders();
        $this->setNoCacheCookie();
        $this->setCacheIdHeader();
    }
Beispiel #15
0
 /**
  * This replaces the old event from the routerRewrite plugin
  *
  * The refreshSeoIndex method will only be called, if "live" mode is enabled. Else the process will be
  * triggered via plugin or manually
  *
  * @param Enlight_Controller_EventArgs $args
  */
 public function onAfterSendResponse(Enlight_Controller_EventArgs $args)
 {
     $request = $args->getRequest();
     if ($request->getModuleName() != 'frontend') {
         return;
     }
     if (!Shopware()->Bootstrap()->issetResource('Shop')) {
         return;
     }
     /**
      * If 'live' mode is configured, pass the request to the SeoIndex component and handle it as in SW < 4.1.0.
      */
     $refreshStrategy = $this->Application()->Config()->get('seoRefreshStrategy');
     if ($refreshStrategy !== self::STRATEGY_LIVE) {
         return;
     }
     $this->SeoIndex()->refreshSeoIndex();
 }
Beispiel #16
0
    /**
     * Listener method for the Enlight_Controller_Front_RouteStartup event.
     * Adds the user-agent and the remote-address to the log component.
     * Sets the request and the response object into the Zend_Wildfire_Channel_HttpHeaders.
     *
     * @param Enlight_Event_EventArgs $args
     */
    public function onRouteStartup(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();
        $response = $args->getResponse();

        /** @var $log Zend_Log */
        $log = $this->Resource();

        $log->setEventItem('remote_address', $request->getClientIp(false));
        $log->setEventItem('user_agent', $request->getHeader('USER_AGENT'));

        $channel = $this->FirebugChannel();
        $channel->setRequest($request);
        $channel->setResponse($response);
    }
Beispiel #17
0
 /**
  * Event listener method
  *
  * @param Enlight_Controller_EventArgs $args
  */
 public function onRouteShutdown(Enlight_Controller_EventArgs $args)
 {
     $request = $args->getRequest();
     $front = $args->getSubject();
     $response = $front->Response();
     $config = $this->Config();
     if ($request->getModuleName() == 'backend' || $request->getModuleName() == 'api') {
         return;
     }
     if (!empty($config->refererCheck) && $request->isPost() && in_array($request->getControllerName(), array('account')) && ($referer = $request->getHeader('Referer')) !== null && strpos($referer, 'http') === 0) {
         /** @var $shop Shopware_Models_Shop */
         $shop = Shopware()->Shop();
         $validHosts = array($shop->getHost(), $shop->getSecureHost());
         $host = parse_url($referer, PHP_URL_HOST);
         $hostWithPort = $host . ':' . parse_url($referer, PHP_URL_PORT);
         if (!in_array($host, $validHosts) && !in_array($hostWithPort, $validHosts)) {
             $response->setException(new Exception('Referer check for frontend session failed'));
         }
     }
     $intVars = array('sCategory', 'sContent', 'sCustom');
     foreach ($intVars as $parameter) {
         if (!empty($_GET[$parameter])) {
             $_GET[$parameter] = (int) $_GET[$parameter];
         }
         if (!empty($_POST[$parameter])) {
             $_POST[$parameter] = (int) $_POST[$parameter];
         }
     }
     $regex = array();
     if (!empty($config->sql_protection)) {
         $regex[] = $this->sqlRegex;
     }
     if (!empty($config->xss_protection)) {
         $regex[] = $this->xssRegex;
     }
     if (!empty($config->rfi_protection)) {
         $regex[] = $this->rfiRegex;
     }
     if (!empty($config->own_filter)) {
         $regex[] = $config->own_filter;
     }
     if (empty($regex)) {
         return;
     }
     $regex = '#' . implode('|', $regex) . '#msi';
     $userParams = $request->getUserParams();
     $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST, &$_SERVER, &$userParams);
     while (list($key, $val) = each($process)) {
         foreach ($val as $k => $v) {
             unset($process[$key][$k]);
             if (is_array($v)) {
                 $process[$key][self::filterValue($k, $regex)] = $v;
                 $process[] =& $process[$key][self::filterValue($k, $regex)];
             } else {
                 $process[$key][self::filterValue($k, $regex)] = self::filterValue($v, $regex);
             }
         }
     }
     unset($process);
     $request->setParams($userParams);
 }
Beispiel #18
0
 /**
  * Event listener method
  *
  * @param Enlight_Controller_EventArgs $args
  */
 public function onRouteShutdown(Enlight_Controller_EventArgs $args)
 {
     $request = $args->getRequest();
     $response = $args->getResponse();
     $bootstrap = $this->Application()->Bootstrap();
     if ($bootstrap->issetResource('Shop')) {
         $shop = $this->Application()->Shop();
         if ($request->isSecure() && $request->getHttpHost() !== $shop->getSecureHost()) {
             $newPath = $request::SCHEME_HTTPS . '://' . $shop->getSecureHost() . $shop->getBasePath();
         } elseif (!$request->isSecure() && $request->getHttpHost() !== $shop->getHost()) {
             $newPath = $request::SCHEME_HTTP . '://' . $shop->getHost() . $shop->getBasePath();
         }
         // Strip /shopware.php/ from string and perform a redirect
         $preferBasePath = $this->Application()->Config()->preferBasePath;
         if ($preferBasePath && strpos($request->getPathInfo(), '/shopware.php/') === 0) {
             $removePath = $request->getBasePath() . '/shopware.php';
             $newPath = str_replace($removePath, $request->getBasePath(), $request->getRequestUri());
         }
         if (isset($newPath)) {
             // reset the cookie so only one valid cookie will be set IE11 fix
             $response->setCookie("session-" . $shop->getId(), '', -1);
             $response->setRedirect($newPath, 301);
         } else {
             $this->upgradeShop($request, $response);
             $this->initServiceMode($request);
         }
     }
     $this->fixRequest($request);
     $this->initConfig($request);
 }
Beispiel #19
0
    /**
     * Listener method for the Enlight_Controller_Front_DispatchLoopStartup event.
     *
     * @param Enlight_Event_EventArgs $args
     */
    public function onDispatchLoopStartup(Enlight_Controller_EventArgs $args)
    {
        $this->request  = $args->getSubject()->Request();
        $this->response = $args->getSubject()->Response();

        if ($this->request->getModuleName() != 'api') {
            return;
        }
        $this->isApiCall = true;

        $this->assembleRoute($this->request, $this->response);
    }
Beispiel #20
0
    /**
     * Tests the rewrite cache, and may be re-created them.
     *
     * @param Enlight_Controller_EventArgs $args
     */
    public function onAfterSendResponse(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();

        if ($request->getModuleName() != 'frontend') {
            return;
        }

        if (!Shopware()->Bootstrap()->issetResource('Shop')) {
            return;
        }

        $sql = "SELECT `id` FROM `s_core_config_elements` WHERE `name` LIKE 'routerlastupdate'";
        $elementId = Shopware()->Db()->fetchOne($sql);
        $shopId = Shopware()->Shop()->getId();
        $sql = "
            SELECT v.value
            FROM s_core_config_elements e, s_core_config_values v
            WHERE v.element_id=e.id AND e.id=? AND v.shop_id=?
        ";
        $cachedTime = Shopware()->Db()->fetchOne($sql, array($elementId, $shopId));
        if(!empty($cachedTime)) {
            $cachedTime = unserialize($cachedTime);
        }
        if(empty($cachedTime)) {
            $cachedTime = '0000-00-00 00:00:00';
        }

        $cache = (int) Shopware()->Config()->routerCache;
        $cache = $cache < 360 ? 86400 : $cache;
        $currentTime = Shopware()->Db()->fetchOne('SELECT ?', array(new Zend_Date()));

        if (strtotime($cachedTime) < strtotime($currentTime) - $cache) {

            $resultTime = Shopware()->Modules()->RewriteTable()->sCreateRewriteTable($cachedTime);
            if ($resultTime === $cachedTime) {
                $resultTime = $currentTime;
            }

            $sql = '
                DELETE FROM s_core_config_values
                WHERE element_id=? AND shop_id=?
            ';
            Shopware()->Db()->query($sql, array($elementId, $shopId));
            $sql = '
                INSERT INTO s_core_config_values (element_id, shop_id, value)
			    VALUES (?, ?, ?)
            ';
            Shopware()->Db()->query($sql, array($elementId, $shopId, serialize($resultTime)));

            Shopware()->Cache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Shopware_RouterRewrite'));
        }
    }
Beispiel #21
0
 /**
  * Do http caching jobs
  *
  * @param \Enlight_Controller_EventArgs $args
  */
 public function onPreDispatch(\Enlight_Controller_EventArgs $args)
 {
     $this->action = $args->getSubject();
     $this->request = $args->getRequest();
     $this->response = $args->getResponse();
     $this->Application()->Events()->registerListener(new Enlight_Event_Handler_Default('Enlight_Controller_Action_PostDispatchSecure', array($this, 'onPostDispatch')));
 }
Beispiel #22
0
 /**
  * @param Enlight_Controller_EventArgs $args
  */
 public function onStartDispatch($args)
 {
     $request = $args->getRequest();
     $templateDir = __DIR__ . '/Views/';
     $subscriber = new Subscriber\ResponsiveTheme($templateDir);
     $this->get('events')->addSubscriber($subscriber);
     if ($request->getModuleName() == 'frontend') {
         $subscriber = new Subscriber\Checkout($this);
         $this->get('events')->addSubscriber($subscriber);
     } elseif ($request->getModuleName() == 'backend') {
         $subscriber = new Subscriber\Backend($this);
         $this->get('events')->addSubscriber($subscriber);
     }
 }
Beispiel #23
0
    /**
     * Event listener method
     *
     * @param Enlight_Controller_EventArgs $args
     */
    public function onRouteShutdown(Enlight_Controller_EventArgs $args)
    {
        $request = $args->getRequest();
        $response = $args->getResponse();

        $bootstrap = $this->Application()->Bootstrap();
        if ($bootstrap->issetResource('Shop')) {
            $shop = $this->Application()->Shop();

            if ($request->isSecure() && $request->getHttpHost() !== $shop->getSecureHost()) {
                $newPath = $request::SCHEME_HTTPS . '://' . $shop->getSecureHost();
            } elseif ($request->getHttpHost() !== $shop->getHost()) {
                $newPath = $request::SCHEME_HTTP . '://' . $shop->getHost();
            }
            if(isset($newPath)) {
                $url = sprintf('%s%s',
                    $newPath,
                    $request->getRequestUri()
                );
                $response->setRedirect($url, 301);
            } else {
                $this->upgradeShop($request, $response);
                $this->initServiceMode($request);
            }
        }

        $this->fixRequest($request);
        $this->initConfig($request);
    }