1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cloud_monitor_request.php
См. документацию.
1<?
8
14{
15 const BITRIX_CHECKER_URL_PATH = "/bitrix/site_checker.php";
16 const REMOTE_STATUS_OK = "ok";
17 const REMOTE_STATUS_ERROR = "error";
18 const REMOTE_STATUS_FATAL_ERROR = "fatal_error";
19 const TIMEOUT = 10;
20
21 private static $validActions = array("check", "get_results");
22 protected $response = array();
23 protected $checkingToken = "";
24 protected $protocolVersion = 2;
25
26 public function __construct($action, $protocolVersion, $token = "")
27 {
28 if(!in_array($action, self::$validActions))
29 return null;
30
31 $this->checkingToken = $token;
32 $this->response = $this->receiveData($action);
33 $this->protocolVersion = $protocolVersion;
34 }
35
41 {
42 $this->checkingToken = $checkingToken;
43
44 return $this;
45 }
46
50 public function getCheckingToken()
51 {
53 }
54
60 public function receiveData($action)
61 {
62 $payload = $this->getPayload($action, false);
63 if(!$payload)
64 return false;
65
66 $response = self::sendRequest($payload);
67 if(!$response)
68 {
69 $response = array();
70 }
71
72 if(!isset($response["status"]))
73 {
74 $response["status"] = self::REMOTE_STATUS_FATAL_ERROR;
75 $response["error_text"] = GetMessage("SECURITY_SITE_CHECKER_CONNECTION_ERROR");
76 }
77
78 return $response;
79 }
80
84 public function isOk()
85 {
86 return $this->checkStatus(self::REMOTE_STATUS_OK);
87 }
88
92 public function isFatalError()
93 {
94 return $this->checkStatus(self::REMOTE_STATUS_FATAL_ERROR);
95 }
96
100 public function isError()
101 {
102 return $this->checkStatus(self::REMOTE_STATUS_ERROR);
103 }
104
108 public function isSuccess()
109 {
110 return (isset($this->response["status"]));
111 }
112
117 public function getValue($key)
118 {
119 if(isset($this->response[$key]))
120 {
121 return $this->response[$key];
122 }
123 else
124 {
125 return "";
126 }
127 }
128
133 protected function checkStatus($status)
134 {
135 return (isset($this->response["status"]) && $this->response["status"] === $status);
136 }
137
144 protected function getPayload($action = "check", $collectInformation = true)
145 {
146 if(!in_array($action, self::$validActions))
147 return false;
148
149 $payload = array(
150 "action" => $action,
151 "host" => self::getHostName(),
152 "lang" => LANGUAGE_ID,
153 "license_key" => self::getLicenseKey(),
154 "testing_token" => $this->checkingToken,
155 "version" => $this->protocolVersion
156 );
157
158 if($collectInformation || $action === "check")
159 {
160 $payload["system_information"] = base64_encode(serialize(self::getSystemInformation()));
161 $payload["additional_information"] = base64_encode(serialize(self::getAdditionalInformation()));
162 }
163
164 return $payload;
165 }
166
167
172 protected static function decodeResponse($response)
173 {
174 $result = json_decode($response, true);
175
176 return $result;
177 }
178
184 protected static function sendRequest(array $payload)
185 {
187 $targetHost = $license->getDomainStoreLicense() . self::BITRIX_CHECKER_URL_PATH;
188
189 $httpClient = new \Bitrix\Main\Web\HttpClient(array(
190 'streamTimeout' => static::TIMEOUT
191 ));
192
193 $response = $httpClient->post($targetHost, $payload);
194 if ($response && $httpClient->getStatus() == 200)
195 {
197 }
198
199 return false;
200 }
201
206 protected static function getLicenseKey()
207 {
208 if (defined("LICENSE_KEY"))
209 {
210 $licenseKey = LICENSE_KEY;
211 }
212 else
213 {
214 $licenseKey = "DEMO";
215 }
216 return md5($licenseKey);
217 }
218
223 protected static function getSystemInformation()
224 {
225 return CSecuritySystemInformation::getSystemInformation();
226 }
227
234 protected static function getAdditionalInformation()
235 {
236 return CSecuritySystemInformation::getAdditionalInformation();
237 }
238
243 protected function getHostName()
244 {
245 $sheme = (CMain::IsHTTPS() ? "https" : "http")."://";
246 $serverPort = self::getServerPort();
248 $url .= ($serverPort && mb_strpos($url, ":") === false) ? ":".$serverPort : "";
249 return $sheme.$url;
250 }
251
256 protected static function getServerPort()
257 {
258 if($_SERVER["SERVER_PORT"] && !in_array($_SERVER["SERVER_PORT"], array(80, 443)))
259 return $_SERVER["SERVER_PORT"];
260 else
261 return false;
262 }
263
268 protected static function getDomainName()
269 {
270 return CSecuritySystemInformation::getCurrentHost();
271 }
272}
static getInstance()
Определения application.php:98
__construct($action, $protocolVersion, $token="")
Определения cloud_monitor_request.php:26
static decodeResponse($response)
Определения cloud_monitor_request.php:172
static getAdditionalInformation()
Определения cloud_monitor_request.php:234
static sendRequest(array $payload)
Определения cloud_monitor_request.php:184
setCheckingToken($checkingToken)
Определения cloud_monitor_request.php:40
getPayload($action="check", $collectInformation=true)
Определения cloud_monitor_request.php:144
static getSystemInformation()
Определения cloud_monitor_request.php:223
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
if(file_exists(( $_fname=__DIR__ . "/classes/general/update_db_updater.php"))) if(($_fname=getLocalPath("init.php")) !==false) if(( $_fname=getLocalPath("php_interface/init.php", BX_PERSONAL_ROOT)) !==false) if(($_fname=getLocalPath("php_interface/" . SITE_ID . "/init.php", BX_PERSONAL_ROOT)) !==false) if((!(defined("STATISTIC_ONLY") &&STATISTIC_ONLY &&!str_starts_with( $GLOBALS["APPLICATION"]->GetCurPage(), BX_ROOT . "/admin/"))) &&COption::GetOptionString("main", "include_charset", "Y")=="Y" &&LANG_CHARSET !='') if(COption::GetOptionString("main", "set_p3p_header", "Y")=="Y") $license
Определения include.php:158
$status
Определения session.php:10
const LICENSE_KEY($show_sql_stat=='Y')
Определения start.php:84
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if(empty($signedUserToken)) $key
Определения quickway.php:257
$action
Определения file_dialog.php:21
$url
Определения iframe.php:7