Example #1
0
 /**
  * Secure cron actions according to system settings
  *
  * @param Enlight_Controller_Request_Request $request
  * @return bool If cron action is authorized
  */
 public function authorizeCronAction($request)
 {
     // If called using CLI, always execute the cron tasks
     if (php_sapi_name() == 'cli') {
         return true;
     }
     // At least one of the security policies is enabled.
     // If at least one of them validates, cron tasks will be executed
     $cronSecureAllowedKey = Shopware()->Config()->get('cronSecureAllowedKey');
     $cronSecureAllowedIp = Shopware()->Config()->get('cronSecureAllowedIp');
     $cronSecureByAccount = Shopware()->Config()->get('cronSecureByAccount');
     // No security policy specified, accept all requests
     if (empty($cronSecureAllowedKey) && empty($cronSecureAllowedIp) && !$cronSecureByAccount) {
         return true;
     }
     // Validate key
     if (!empty($cronSecureAllowedKey)) {
         $urlKey = $request->getParam('key');
         if (strcmp($cronSecureAllowedKey, $urlKey) == 0) {
             return true;
         }
     }
     // Validate ip
     if (!empty($cronSecureAllowedIp)) {
         $requestIp = $request->getServer('REMOTE_ADDR');
         if (in_array($requestIp, explode(';', $cronSecureAllowedIp))) {
             return true;
         }
     }
     // Validate user auth
     if ($cronSecureByAccount) {
         if (Shopware()->Auth()->hasIdentity() === true) {
             return true;
         }
     }
     return false;
 }
Example #2
0
 /**
  * @param Enlight_Controller_Request_Request $request
  */
 public function refreshBasket($request)
 {
     $currentController = $request->getParam('requestController', $request->getControllerName());
     $sessionId = (string) Enlight_Components_Session::getId();
     if (!empty($currentController) && !empty($sessionId)) {
         $userId = (int) Shopware()->Session()->sUserId;
         $userAgent = (string) $request->getServer("HTTP_USER_AGENT");
         $sql = "\n                UPDATE s_order_basket\n                SET lastviewport = ?,\n                    useragent = ?,\n                    userID = ?\n                WHERE sessionID=?\n            ";
         Shopware()->Db()->query($sql, array($currentController, $userAgent, $userId, $sessionId));
     }
 }
 /**
  * Helper function to get all preferred browser languages
  *
  * @param Enlight_Controller_Request_Request $request
  * @return array|mixed
  */
 private function getBrowserLanguages(Enlight_Controller_Request_Request $request)
 {
     $languages = $request->getServer('HTTP_ACCEPT_LANGUAGE');
     $languages = str_replace('-', '_', $languages);
     if (strpos($languages, ',') == true) {
         $languages = explode(',', $languages);
     } else {
         $languages = (array) $languages;
     }
     foreach ($languages as $key => $language) {
         $language = explode(';', $language);
         $languages[$key] = $language[0];
     }
     return (array) $languages;
 }