Example #1
0
 /**
  * Extract "login" and "password" credentials from HTTP-request
  *
  * Returns plain array with 2 items: login and password respectively
  *
  * @return array
  */
 public function getCredentials()
 {
     $server = $this->request->getServer();
     $user = '';
     $pass = '';
     if (empty($server['HTTP_AUTHORIZATION'])) {
         foreach ($server as $k => $v) {
             if (substr($k, -18) === 'HTTP_AUTHORIZATION' && !empty($v)) {
                 $server['HTTP_AUTHORIZATION'] = $v;
                 break;
             }
         }
     }
     if (isset($server['PHP_AUTH_USER']) && isset($server['PHP_AUTH_PW'])) {
         $user = $server['PHP_AUTH_USER'];
         $pass = $server['PHP_AUTH_PW'];
     } elseif (!empty($server['HTTP_AUTHORIZATION'])) {
         /**
          * IIS Note: for HTTP authentication to work with IIS,
          * the PHP directive cgi.rfc2616_headers must be set to 0 (the default value).
          */
         $auth = $server['HTTP_AUTHORIZATION'];
         list($user, $pass) = explode(':', base64_decode(substr($auth, strpos($auth, " ") + 1)));
     } elseif (!empty($server['Authorization'])) {
         $auth = $server['Authorization'];
         list($user, $pass) = explode(':', base64_decode(substr($auth, strpos($auth, " ") + 1)));
     }
     return array($user, $pass);
 }
Example #2
0
 /**
  * Retrieve Server IP address
  *
  * @param bool $ipToLong converting IP to long format
  * @return string IPv4|long
  */
 public function getServerAddress($ipToLong = false)
 {
     $address = $this->request->getServer('SERVER_ADDR');
     if (!$address) {
         return false;
     }
     return $ipToLong ? ip2long($address) : $address;
 }
Example #3
0
 /**
  * Retrieve HTTP "clean" value
  *
  * @param string $var
  * @param boolean $clean clean non UTF-8 characters
  * @return string
  */
 protected function _getHttpCleanValue($var, $clean = true)
 {
     $value = $this->_request->getServer($var, '');
     if ($clean) {
         $value = $this->_converter->cleanString($value);
     }
     return $value;
 }
 /**
  * Retrieve Client Remote Address
  *
  * @param bool $ipToLong converting IP to long format
  * @return string IPv4|long
  */
 public function getRemoteAddress($ipToLong = false)
 {
     if ($this->remoteAddress === null) {
         foreach ($this->alternativeHeaders as $var) {
             if ($this->request->getServer($var, false)) {
                 $this->remoteAddress = $this->request->getServer($var);
                 break;
             }
         }
         if (!$this->remoteAddress) {
             $this->remoteAddress = $this->request->getServer('REMOTE_ADDR');
         }
     }
     if (!$this->remoteAddress) {
         return false;
     }
     return $ipToLong ? ip2long($this->remoteAddress) : $this->remoteAddress;
 }
Example #5
0
 /**
  * @return string
  */
 protected function _getUrl()
 {
     $refererUrl = $this->_request->getServer('HTTP_REFERER');
     $url = (string) $this->_request->getParam(self::PARAM_NAME_REFERER_URL);
     if ($url) {
         $refererUrl = $url;
     }
     $url = $this->_request->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_BASE64_URL);
     if ($url) {
         $refererUrl = $this->_urlCoder->decode($url);
     }
     $url = $this->_request->getParam(\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED);
     if ($url) {
         $refererUrl = $this->_urlCoder->decode($url);
     }
     if (!$this->_isUrlInternal($refererUrl)) {
         $refererUrl = $this->_storeManager->getStore()->getBaseUrl();
     }
     return $refererUrl;
 }
Example #6
0
 /**
  * Retrieve current url
  *
  * @return string
  */
 public function getCurrentUrl()
 {
     $port = $this->_request->getServer('SERVER_PORT');
     if ($port) {
         $defaultPorts = [\Magento\Framework\App\Request\Http::DEFAULT_HTTP_PORT, \Magento\Framework\App\Request\Http::DEFAULT_HTTPS_PORT];
         $port = in_array($port, $defaultPorts) ? '' : ':' . $port;
     }
     $requestUri = $this->_request->getServer('REQUEST_URI');
     $url = $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . $port . $requestUri;
     return $url;
 }
Example #7
0
 /**
  * Check if users originated URL is one of the domain URLs assigned to scopes
  *
  * @return boolean
  */
 public function isOwnOriginUrl()
 {
     $scopeDomains = [];
     $referer = parse_url($this->_request->getServer('HTTP_REFERER'), PHP_URL_HOST);
     foreach ($this->_scopeResolver->getScopes() as $scope) {
         $scopeDomains[] = parse_url($scope->getBaseUrl(), PHP_URL_HOST);
         $scopeDomains[] = parse_url($scope->getBaseUrl(UrlInterface::URL_TYPE_LINK, true), PHP_URL_HOST);
     }
     $scopeDomains = array_unique($scopeDomains);
     if (empty($referer) || in_array($referer, $scopeDomains)) {
         return true;
     }
     return false;
 }
Example #8
0
 /**
  * Retrieve current url
  *
  * @return string
  */
 public function getCurrentUrl()
 {
     $httpHostWithPort = $this->_request->getHttpHost(false);
     $httpHostWithPort = explode(':', $httpHostWithPort);
     $httpHost = isset($httpHostWithPort[0]) ? $httpHostWithPort[0] : '';
     $port = '';
     if (isset($httpHostWithPort[1])) {
         $defaultPorts = [\Magento\Framework\App\Request\Http::DEFAULT_HTTP_PORT, \Magento\Framework\App\Request\Http::DEFAULT_HTTPS_PORT];
         if (!in_array($httpHostWithPort[1], $defaultPorts)) {
             /** Custom port */
             $port = ':' . $httpHostWithPort[1];
         }
     }
     return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getServer('REQUEST_URI');
 }
Example #9
0
 /**
  * Check if request was secure
  *
  * @return boolean
  */
 public function isCurrentlySecure()
 {
     if ($this->_request->isSecure()) {
         return true;
     }
     $secureBaseUrl = $this->_config->getValue(self::XML_PATH_SECURE_BASE_URL, ScopeInterface::SCOPE_STORE);
     $secureFrontend = $this->_config->getValue(self::XML_PATH_SECURE_IN_FRONTEND, ScopeInterface::SCOPE_STORE);
     if (!$secureBaseUrl || !$secureFrontend) {
         return false;
     }
     $uri = \Zend_Uri::factory($secureBaseUrl);
     $port = $uri->getPort();
     $serverPort = $this->_request->getServer('SERVER_PORT');
     $isSecure = $uri->getScheme() == 'https' && isset($serverPort) && $port == $serverPort;
     return $isSecure;
 }
Example #10
0
 /**
  * Get Document root of Magento instance
  *
  * @return string
  */
 protected function _getDocumentRoot()
 {
     return $this->_request->getServer('DOCUMENT_ROOT');
 }
Example #11
0
 /**
  * Returns true if doc root is pub/ and not BP
  *
  * @return bool
  */
 public function isPub()
 {
     $rootBasePath = $this->request->getServer('DOCUMENT_ROOT');
     $readDirectory = $this->readFactory->create(DirectoryList::ROOT);
     return substr($rootBasePath, -strlen('/pub')) === '/pub' && !$readDirectory->isExist($rootBasePath . 'setup');
 }