Esempio n. 1
0
 /**
  * Returns script filename by URL
  *
  * @param string $site Site ID.
  * @param string $url URL.
  * @return string|null
  */
 public static function getRealPath($site, $url)
 {
     $docRoot = rtrim(\Bitrix\Main\SiteTable::getDocumentRoot($site), '/');
     $url = str_replace('\\', '/', $url);
     $url = \CHTTP::urnEncode($url);
     $uri = new Web\Uri($url);
     $path = \CHTTP::urnDecode($uri->getPath());
     if (substr($path, -1, 1) == '/') {
         $path .= 'index.php';
     }
     $file = new IO\File($docRoot . $path);
     if ($file->isExists()) {
         return substr($file->getPath(), strlen($docRoot));
     }
     if ($rewriteRules = AdminHelper::getRewriteRules($site)) {
         $pathQuery = \CHTTP::urnDecode($uri->getPathQuery());
         foreach ($rewriteRules as &$item) {
             if (preg_match($item['CONDITION'], $pathQuery)) {
                 $url = empty($item['PATH']) && !empty($item['RULE']) ? preg_replace($item['CONDITION'], $item['RULE'], $pathQuery) : $item['PATH'];
                 $url = \CHTTP::urnEncode($url);
                 $uri = new Web\Uri($url);
                 $path = \CHTTP::urnDecode($uri->getPath());
                 $file = new IO\File($docRoot . $path);
                 if ($file->isExists()) {
                     $pathTmp = str_replace('.', '', strtolower(ltrim($path, '/\\')));
                     $pathTmp7 = substr($pathTmp, 0, 7);
                     if ($pathTmp7 == 'upload/' || $pathTmp7 == 'bitrix/') {
                         continue;
                     }
                     if ($file->getExtension() != 'php') {
                         continue;
                     }
                     return substr($file->getPath(), strlen($docRoot));
                 }
             }
         }
     }
     return null;
 }
Esempio n. 2
0
 protected function sendRequest($method, Uri $url, $postData = null)
 {
     $this->status = 0;
     $this->result = '';
     $this->responseHeaders->clear();
     $this->responseCookies->clear();
     if ($this->proxyHost != '') {
         $path = $url->getUrl();
         if ($this->proxyUser != '') {
             $this->setHeader("Proxy-Authorization", "Basic " . base64_encode($this->proxyUser . ":" . $this->proxyPassword));
         }
     } else {
         $path = $url->getPathQuery();
     }
     $request = $method . " " . $path . " HTTP/" . $this->version . "\r\n";
     $this->setHeader("Host", $url->getHost());
     $this->setHeader("Connection", "close", false);
     $this->setHeader("Accept", "*/*", false);
     $this->setHeader("Accept-Language", "en", false);
     if (($user = $url->getUser()) != '') {
         $this->setAuthorization($user, $url->getPass());
     }
     $cookies = $this->requestCookies->toString();
     if ($cookies != '') {
         $this->setHeader("Cookie", $cookies);
     }
     if ($this->compress) {
         $this->setHeader("Accept-Encoding", "gzip");
     }
     if (!is_resource($postData) && ($method == self::HTTP_POST || $method == self::HTTP_PUT)) {
         if ($method != self::HTTP_PUT && $this->requestHeaders->get("Content-Type") === null) {
             $contentType = "application/x-www-form-urlencoded";
             if ($this->requestCharset != '') {
                 $contentType .= "; charset=" . $this->requestCharset;
             }
             $this->setHeader("Content-Type", $contentType);
         }
         if ($this->requestHeaders->get("Content-Length") === null) {
             $this->setHeader("Content-Length", String::getBinaryLength($postData));
         }
     }
     $request .= $this->requestHeaders->toString();
     $request .= "\r\n";
     $this->send($request);
     if ($method == self::HTTP_POST || $method == self::HTTP_PUT) {
         if (is_resource($postData)) {
             //PUT data can be file resource
             while (!feof($postData)) {
                 $this->send(fread($postData, self::BUF_POST_LEN));
             }
         } else {
             $this->send($postData);
         }
     }
 }