1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cloud_monitor.php
См. документацию.
1<?
8
14 extends CSecurityBaseTest
15{
19
20 protected $internalName = 'CloudMonitor';
22 protected $sessionData = null;
23 protected $checkingResults = array();
24 protected $protocolVersion = 2;
25
26 public function __construct()
27 {
28 IncludeModuleLangFile(__FILE__);
29 }
30
31 public function checkRequirements($params = array())
32 {
33 if(!function_exists('json_decode'))
34 throw new CSecurityRequirementsException(GetMessage('SECURITY_SITE_CHECKER_CLOUD_JSON_UNAVAILABLE'));
35 return true;
36 }
37
43 public function check(array $params = array())
44 {
46 $testID = $this->getParam('TEST_ID', $this->internalName);
47 $this->sessionData = new CSecurityTemporaryStorage($testID);
48
49 if($this->isCheckRequestNotSended())
50 {
51 $this->doCheckRequest();
52 }
53 else
54 {
55 $this->receiveResults();
56 }
57
58 return $this->getResult();
59 }
60
65 protected function getResult()
66 {
67 if(!is_array($this->checkingResults))
68 $this->checkingResults = array();
69 if(!isset($this->checkingResults['name']))
70 $this->checkingResults['name'] = $this->getName();
71 if(!isset($this->checkingResults['timeout']))
72 $this->checkingResults['timeout'] = $this->getTimeout();
73 if(!isset($this->checkingResults['status']))
74 $this->checkingResults['in_progress'] = true;
76 }
77
81 protected function receiveResults()
82 {
83 if($this->sessionData->getInt('results_repeat_count') > self::MAX_RESULTS_REQUEST_REPEAT_COUNT)
84 $this->stopChecking(GetMessage('SECURITY_SITE_CHECKER_CLOUD_UNAVAILABLE'));
85
86 $response = new CSecurityCloudMonitorRequest('get_results', $this->protocolVersion, $this->getCheckingToken());
87 if($response->isOk())
88 {
89 $this->sessionData->flushData();
90 $results = $response->getValue('results');
91 if(is_array($results) && count($results) > 0)
92 {
93 $isSomethingFound = true;
94 $problemCount = count($results);
95 $errors = self::formatResults($results);
96 }
97 else
98 {
99 $isSomethingFound = false;
100 $problemCount = 0;
101 $errors = array();
102 }
104 'problem_count' => $problemCount,
105 'errors' => $errors,
106 'status' => !$isSomethingFound
107 ));
108
109 }
110 elseif($response->isFatalError())
111 {
112 $this->stopChecking($response->getValue('error_text'));
113 }
114 else
115 {
116 $this->sessionData->increment('results_repeat_count');
117 }
118 }
119
123 protected function isCheckRequestNotSended()
124 {
125 return ($this->getParam('STEP', 0) === 0 || $this->sessionData->getBool('repeat_request'));
126 }
127
131 protected function doCheckRequest()
132 {
133 $response = new CSecurityCloudMonitorRequest('check', $this->protocolVersion);
134 if($response->isOk())
135 {
136 $this->sessionData->flushData();
137 $this->setTimeOut($response->getValue('processing_time'));
138 $this->setCheckingToken($response->getValue('testing_token'));
139 }
140 elseif($response->isFatalError())
141 {
142 $this->stopChecking($response->getValue('error_text'));
143 }
144 else
145 {
146 if($this->sessionData->getBool('repeat_request'))
147 {
148 if($this->sessionData->getInt('check_repeat_count') > self::MAX_CHECKING_REQUEST_REPEAT_COUNT)
149 {
150 $this->stopChecking(GetMessage('SECURITY_SITE_CHECKER_CLOUD_UNAVAILABLE'));
151 }
152 else
153 {
154 $this->sessionData->increment('check_repeat_count');
155 }
156 }
157 else
158 {
159 $this->sessionData->flushData();
160 $this->sessionData->setData('repeat_request', true);
161 }
162 }
163 }
164
168 protected function setCheckingToken($token)
169 {
170 if(is_string($token) && $token != '')
171 {
172 $this->sessionData->setData('testing_token', $token);
173 }
174 }
175
179 protected function getCheckingToken()
180 {
181 return $this->sessionData->getString('testing_token');
182 }
183
187 protected function setTimeOut($timeOut)
188 {
189 if(intval($timeOut) > 0 )
190 {
191 $this->sessionData->setData('timeout', $timeOut);
192 }
193 }
194
198 protected function setCheckingResult(array $result)
199 {
200 $this->checkingResults = $result;
201 }
202
206 protected function stopChecking($message = '')
207 {
208 $this->checkingResults['status'] = true;
209 $this->checkingResults['fatal_error_text'] = $message;
210 }
211
217 protected static function formatResults(array $results)
218 {
219 $formattedResult = array();
220 $count = 0;
221 foreach($results as $result)
222 {
223 if(isset($result['name']))
224 {
225 $formattedResult[$count]['title'] = $result['name'];
226 $formattedResult[$count]['critical'] = isset($result['critical'])? $result['critical']: CSecurityCriticalLevel::LOW;
227 }
228 if(isset($result['detail']))
229 {
230 $formattedResult[$count]['detail'] = $result['detail'];
231 }
232 if(isset($result['recommendation']))
233 {
234 $formattedResult[$count]['recommendation'] = $result['recommendation'];
235 }
236 if(isset($result['additional_info']))
237 {
238 $formattedResult[$count]['additional_info'] = $result['additional_info'];
239 }
240 $count++;
241 }
242 return $formattedResult;
243 }
244
248 protected function getTimeout()
249 {
250 if($this->sessionData->getString('timeout') > 0)
251 {
252 return intval($this->sessionData->getString('timeout'));
253 }
254 else
255 {
256 return self::DEFAULT_RECEIVE_RESULTS_TIME;
257 }
258 }
259}
$count
Определения admin_tab.php:4
Определения base_test.php:14
getName()
Определения base_test.php:28
initializeParams(array $params=array())
Определения base_test.php:115
getParam($name, $defaultValue="")
Определения base_test.php:182
$params
Определения base_test.php:20
checkRequirements($params=array())
Определения cloud_monitor.php:31
setCheckingResult(array $result)
Определения cloud_monitor.php:198
stopChecking($message='')
Определения cloud_monitor.php:206
const MAX_RESULTS_REQUEST_REPEAT_COUNT
Определения cloud_monitor.php:18
static formatResults(array $results)
Определения cloud_monitor.php:217
const DEFAULT_RECEIVE_RESULTS_TIME
Определения cloud_monitor.php:16
check(array $params=array())
Определения cloud_monitor.php:43
setTimeOut($timeOut)
Определения cloud_monitor.php:187
setCheckingToken($token)
Определения cloud_monitor.php:168
isCheckRequestNotSended()
Определения cloud_monitor.php:123
const MAX_CHECKING_REQUEST_REPEAT_COUNT
Определения cloud_monitor.php:17
const LOW
Определения critical_level.php:15
</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
$errors
Определения iblock_catalog_edit.php:74
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</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."%"
Определения waybill.php:936
$response
Определения result.php:21