21 private $redirectMax = 5;
22 private $redirectsMade = 0;
23 private static $lastSetStatus =
"";
28 if(isset($defaultOptions[
"socketTimeout"]))
30 $this->http_timeout = intval($defaultOptions[
"socketTimeout"]);
33 $this->user_agent =
'BitrixSM ' . __CLASS__ .
' class';
39 public static function URN2URI($urn, $server_name =
'')
44 if(preg_match(
"/^[a-z]+:\\/\\//", $urn))
55 if($server_name <>
'')
56 $server_name = preg_replace(
"/:(443|80)$/",
"", $server_name);
58 $server_name = preg_replace(
"/:(443|80)$/",
"",
$_SERVER[
"HTTP_HOST"]);
60 $uri = $proto.$server_name.$urn;
67 if (is_resource($file))
74 $this->fp = fopen($file,
"wb");
77 if(is_resource($this->fp))
81 if (!is_resource($file))
87 return $res && ($this->status == 200);
109 $postdata = static::PrepareData($arPostData);
111 if($this->
HTTPQuery(
'POST', $url, $postdata))
122 if(!is_array($arPostData))
128 foreach ($arPostData as
$key => $value)
130 $name = $prefix ==
"" ? urlencode(
$key) : $prefix.
"[".urlencode(
$key).
"]";
134 $str .= static::PrepareData($value,
$name);
138 $str .=
'&'.$name.
'='.urlencode($value);
143 if($prefix ==
'' && str_starts_with(
$str,
'&'))
156 if(is_resource($this->fp))
157 $file_pos = ftell($this->fp);
159 $this->redirectsMade = 0;
165 if (!$this->
Query(
$method, $arUrl[
'host'], $arUrl[
'port'], $arUrl[
'path_query'], $postdata, $arUrl[
'proto']))
171 $this->follow_redirect
172 && isset($this->headers[
'Location'])
173 && $this->headers[
'Location'] <>
''
176 $url = $this->headers[
'Location'];
177 if($this->redirectsMade < $this->redirectMax)
181 if(is_resource($this->fp))
184 ftruncate($this->fp, $file_pos);
185 fseek($this->fp, $file_pos, SEEK_SET);
187 $this->redirectsMade++;
192 trigger_error(
"Maximum number of redirects (".$this->redirectMax.
") has been reached at URL ".
$url, E_USER_WARNING);
207 public function Query(
$method,
$host, $port,
$path, $postdata =
false, $proto =
'', $post_content_type =
'N', $dont_wait_answer =
false)
211 $this->headers =
array();
212 $this->cookies =
array();
213 $fp = fsockopen($proto.$host, $port, $this->errno, $this->errstr, $this->http_timeout);
216 $strRequest =
"$method $path HTTP/1.0\r\n";
217 $strRequest .=
"Connection: close\r\n";
218 $strRequest .=
"User-Agent: {$this->user_agent}\r\n";
219 $strRequest .=
"Accept: */*\r\n";
220 $strRequest .=
"Host: $host\r\n";
221 $strRequest .=
"Accept-Language: en\r\n";
223 foreach ($this->additional_headers as
$key => $value)
224 $strRequest .=
$key.
": ".$value.
"\r\n";
228 if (
'N' !== $post_content_type)
229 $strRequest .= $post_content_type ==
'' ?
'' :
"Content-type: ".$post_content_type.
"\r\n";
231 $strRequest.=
"Content-type: application/x-www-form-urlencoded\r\n";
233 if(!array_key_exists(
"Content-Length", $this->additional_headers))
234 $strRequest.=
"Content-Length: ".strlen($postdata) .
"\r\n";
236 $strRequest .=
"\r\n";
237 fwrite(
$fp, $strRequest);
241 if(is_resource($postdata))
243 while(!feof($postdata))
244 fwrite(
$fp, fread($postdata, 1024*1024));
248 fwrite(
$fp, $postdata);
252 if ($dont_wait_answer)
261 $line = fgets(
$fp, 4096);
262 if($line ==
"\r\n" || $line ===
false)
271 if(is_resource($this->fp))
275 $buf = fread(
$fp, 40960);
278 fwrite($this->fp, $buf);
287 $buf = fread(
$fp, 4096);
290 $this->result .= $buf;
302 sprintf(
"Error connecting to %s:%s. Error code: \"%s\", error description: \"%s\"",
314 $this->additional_headers[
'Authorization'] =
"Basic ".base64_encode(
$user.
":".
$pass);
322 $arUrl = parse_url(
$url);
324 $arUrl[
'proto'] =
'';
325 if (array_key_exists(
'scheme', $arUrl))
327 $arUrl[
'scheme'] = mb_strtolower($arUrl[
'scheme']);
331 $arUrl[
'scheme'] =
'http';
334 if (!array_key_exists(
'port', $arUrl))
336 if ($arUrl[
'scheme'] ==
'https')
338 $arUrl[
'port'] = 443;
346 if ($arUrl[
'scheme'] ==
'https')
348 $arUrl[
'proto'] =
'ssl://';
351 $arUrl[
'path_query'] = array_key_exists(
'path', $arUrl) ? $arUrl[
'path'] :
'/';
352 if (array_key_exists(
'query', $arUrl) && $arUrl[
'query'] <>
'')
354 $arUrl[
'path_query'] .=
'?' . $arUrl[
'query'];
362 $arHeaders = explode(
"\n", $strHeaders);
363 foreach ($arHeaders as
$k => $header)
367 if (preg_match(
',HTTP\S+ (\d+),', $header, $arFind))
369 $this->status = intval($arFind[1]);
372 elseif(str_contains($header,
':'))
374 $arHeader = explode(
':', $header, 2);
375 if ($arHeader[0] ==
'Set-Cookie')
377 if (($pos = mb_strpos($arHeader[1],
';')) !==
false && $pos > 0)
379 $cookie = trim(mb_substr($arHeader[1], 0, $pos));
383 $cookie = trim($arHeader[1]);
385 $arCookie = explode(
'=', $cookie, 2);
386 $this->cookies[$arCookie[0]] = rawurldecode($arCookie[1]);
390 $this->headers[$arHeader[0]] = trim($arHeader[1]);
398 $this->follow_redirect = $follow;
403 $this->redirectMax =
$n;
413 return $ob->Get(
$url);
423 return $ob->Post(
$url, $arPostData);
428 foreach($arHeader as
$name => $value)
431 $value = str_replace(
array(
"\r",
"\n"),
"", $value);
432 $this->additional_headers[
$name] = $value;
446 $httpTimeout = intval($httpTimeout);
448 if(!empty($arHeader))
449 $ob->SetAdditionalHeaders($arHeader);
451 $ob->http_timeout = $httpTimeout;
453 return $ob->Get(
$url);
469 if(!empty($arHeader))
470 $ob->SetAdditionalHeaders($arHeader);
473 return $ob->Post(
$url, $arPostData);
478 $bCgi = (stristr(php_sapi_name(),
"cgi") !==
false);
479 if($bCgi && (!defined(
"BX_HTTP_STATUS") || BX_HTTP_STATUS ==
false))
483 self::$lastSetStatus =
$status;
488 return self::$lastSetStatus;
495 if(defined(
'BX_HTTP_AUTH_REALM'))
496 $realm = BX_HTTP_AUTH_REALM;
498 $realm =
"Bitrix Site Manager";
500 header(
'WWW-Authenticate: Basic realm="'.$realm.
'"');
502 if($bDigestEnabled !==
false && COption::GetOptionString(
"main",
"use_digest_auth",
"N") ==
"Y")
506 header(
'WWW-Authenticate: Digest realm="'.$realm.
'", nonce="'.uniqid().
'"');
515 return Main\Context::getCurrent()->getServer()->parseAuthRequest();
523 if (!empty($add_params))
526 foreach ($add_params as
$name => $value)
528 if (is_array($value))
533 if (!empty(
$options[
"skip_empty"]) && (
string)$value ==
'')
549 $ch = (mb_strpos(
$url,
"?") ===
false ?
"?" :
"&");
551 $p2 = mb_strpos(
$url,
"#");
570 $url_parts = explode(
"?",
$url, 2);
571 if(
count($url_parts) == 2 && $url_parts[1] <>
'')
573 if((
$options[
"delete_system_params"] ??
false))
576 $params_pairs = explode(
"&", $url_parts[1]);
577 foreach($params_pairs as
$i => $param_pair)
579 $name_value_pair = explode(
"=", $param_pair, 2);
580 if(
count($name_value_pair) == 2 && in_array($name_value_pair[0], $delete_params))
581 unset($params_pairs[
$i]);
584 if(empty($params_pairs))
585 return $url_parts[0];
587 return $url_parts[0].
"?".implode(
"&", $params_pairs);
615 return $uri->isPathTraversal();
static getSystemParameters()
static urnDecode($str, $charset=false)
static urnEncode($str, $charset='UTF-8')
static sGetHeader($url, $arHeader=array(), $httpTimeout=0)
static SetStatus($status)
HTTPQuery($method, $url, $postdata='')
setFollowRedirect($follow)
static sGet($url, $follow_redirect=false)
static urlDeleteParams($url, $delete_params, $options=array())
static PrepareData($arPostData, $prefix='')
SetAdditionalHeaders($arHeader=array())
static SetAuthHeader($bDigestEnabled=true)
Query($method, $host, $port, $path, $postdata=false, $proto='', $post_content_type='N', $dont_wait_answer=false)
static urnDecode($str, $charset=false)
ParseHeaders($strHeaders)
static ParseAuthRequest()
static sPostHeader($url, $arPostData, $arHeader=array(), $http_timeout=0)
static sPost($url, $arPostData, $follow_redirect=false)
static URN2URI($urn, $server_name='')
static isPathTraversalUri($url)
static urnEncode($str, $charset=false)
static urlAddParams($url, $add_params, $options=[])
SetAuthBasic($user, $pass)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']