1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
base_test.php
См. документацию.
1<?php
8
13abstract class CSecurityBaseTest
14{
15 const STATUS_FAILED = "failed";
16 const STATUS_PASSED = "passed";
17
18 protected $internalName = "BaseTest";
19 protected $isDebug = false;
20 protected $params = array();
21 protected $tests = array();
22 protected $detailErrors = array();
23
28 public function getName()
29 {
30 return GetMessage("SECURITY_SITE_CHECKER_".$this->getInternalName()."_NAME");
31 }
32
39 public function checkRequirements($params = array())
40 {
41 return true;
42 }
43
49 public function check(array $params = array())
50 {
52 $neededTests = self::getParam("needed_tests", null);
53 if(is_string($neededTests) && $neededTests)
54 {
55 $neededTests = array($neededTests);
56 }
57
58 foreach($this->tests as $name => $test)
59 {
60 if($neededTests && !empty($neededTests) && !in_array($name, $neededTests, true))
61 continue;
62
63 if(isset($test["params"]) && is_array($test["params"]))
64 {
65 $testParams = $test["params"];
66 }
67 else
68 {
69 $testParams = array();
70 }
71
72 $result = call_user_func_array(array($this, $test["method"]), $testParams);
73 if($result === self::STATUS_FAILED || $result === false)
74 {
75 if(isset($test["base_message_key"]) && $test["base_message_key"])
76 {
77 if(isset($test["critical"]) && $test["critical"])
78 {
79 $critical = $test["critical"];
80 }
81 else
82 {
84 }
85
86 $this->addUnformattedDetailError($test["base_message_key"], $critical);
87 }
88 }
89 }
90
91
92 $result = array(
93 'name' => $this->getName(),
94 'problem_count' => count($this->getDetailErrors()),
95 'errors' => $this->getDetailErrors(),
96 'status' => !count($this->getDetailErrors())
97 );
98
99 return $result;
100 }
101
106 public function getInternalName()
107 {
108 return $this->internalName;
109 }
110
115 protected function initializeParams(array $params = array())
116 {
117 if(is_array($params) && !empty($params))
118 {
119 $this->params = $params;
120 }
121 $this->isDebug = (self::getParam("debug", false) === true);
122 }
123
127 protected function isRunOnWin()
128 {
129 return (mb_strtoupper(mb_substr(PHP_OS, 0, 3)) === "WIN");
130 }
131
137 protected static function getFilePerm($path)
138 {
139 if(!(is_dir($path) || is_file($path)))
140 return false;
141
142 return fileperms($path);
143 }
144
150 protected static function isWorldWritable($path)
151 {
152 return (self::getFilePerm($path) & 0x0002) > 0;
153 }
154
160 protected static function isWorldReadable($path)
161 {
162 return (self::getFilePerm($path) & 0x0004) > 0;
163 }
164
170 protected static function isWorldAccessible($path)
171 {
172 $perms = self::getFilePerm($path);
173 return ($perms & 0x0004 > 0) || ($perms & 0x0002 > 0);
174 }
175
182 protected function getParam($name, $defaultValue = "")
183 {
184 if(isset($this->params[$name]))
185 {
186 return $this->params[$name];
187 }
188 else
189 {
190 return $defaultValue;
191 }
192 }
193
197 protected function isDebug()
198 {
199 return $this->isDebug;
200 }
201
206 protected function getDetailErrors()
207 {
208 return $this->detailErrors;
209 }
210
216 protected static function getDetailText($baseMessageKey, array $placeholders = array())
217 {
218 return GetMessage($baseMessageKey."_DETAIL", $placeholders);
219 }
220
226 protected static function getRecommendationText($baseMessageKey, array $placeholders = array())
227 {
228 return GetMessage($baseMessageKey."_RECOMMENDATION", $placeholders);
229 }
230
236 protected static function getTitleText($baseMessageKey, array $placeholders = array())
237 {
238 return GetMessage($baseMessageKey, $placeholders);
239 }
240
250 protected function addDetailError($title, $critical, $detail, $recommendation = "", $additionalInfo = "")
251 {
252 $detailError = array(
253 "title" => $title,
254 "critical" => $critical,
255 "detail" => $detail,
256 "recommendation" => $recommendation,
257 "additional_info" => $additionalInfo
258 );
259 $this->pushDetailError($detailError);
260 }
261
266 private function pushDetailError(array $error)
267 {
268 if(is_array($error) && !empty($error))
269 {
270 array_push($this->detailErrors, $error);
271 }
272 return $this;
273 }
274
283 protected function addUnformattedDetailError($baseMessageKey, $critical, $additionalInfo = "")
284 {
285 $detailError = self::formatDetailError($baseMessageKey, $critical, $additionalInfo);
286 $this->pushDetailError($detailError);
287 return $this;
288 }
289
297 protected static function formatDetailError($baseMessageKey, $critical, $additionalInfo = "")
298 {
299 return array(
300 "title" => self::getTitleText($baseMessageKey),
301 "critical" => $critical,
302 "detail" => self::getDetailText($baseMessageKey),
303 "recommendation" => self::getRecommendationText($baseMessageKey),
304 "additional_info" => $additionalInfo
305 );
306 }
307
313 protected static function removeDocumentRoot($path)
314 {
316 return $path;
317 }
318}
$path
Определения access_edit.php:21
if($_SERVER $defaultValue['REQUEST_METHOD']==="GET" &&!empty($RestoreDefaults) && $bizprocPerms==="W" &&check_bitrix_sessid())
Определения options.php:32
Определения base_test.php:14
checkRequirements($params=array())
Определения base_test.php:39
isDebug()
Определения base_test.php:197
static isWorldReadable($path)
Определения base_test.php:160
const STATUS_PASSED
Определения base_test.php:16
static getDetailText($baseMessageKey, array $placeholders=array())
Определения base_test.php:216
static getTitleText($baseMessageKey, array $placeholders=array())
Определения base_test.php:236
getName()
Определения base_test.php:28
static isWorldAccessible($path)
Определения base_test.php:170
static removeDocumentRoot($path)
Определения base_test.php:313
addDetailError($title, $critical, $detail, $recommendation="", $additionalInfo="")
Определения base_test.php:250
$tests
Определения base_test.php:21
check(array $params=array())
Определения base_test.php:49
$isDebug
Определения base_test.php:19
$internalName
Определения base_test.php:18
initializeParams(array $params=array())
Определения base_test.php:115
const STATUS_FAILED
Определения base_test.php:15
static isWorldWritable($path)
Определения base_test.php:150
addUnformattedDetailError($baseMessageKey, $critical, $additionalInfo="")
Определения base_test.php:283
getInternalName()
Определения base_test.php:106
isRunOnWin()
Определения base_test.php:127
getDetailErrors()
Определения base_test.php:206
$detailErrors
Определения base_test.php:22
static getRecommendationText($baseMessageKey, array $placeholders=array())
Определения base_test.php:226
static getFilePerm($path)
Определения base_test.php:137
getParam($name, $defaultValue="")
Определения base_test.php:182
static formatDetailError($baseMessageKey, $critical, $additionalInfo="")
Определения base_test.php:297
$params
Определения base_test.php:20
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
removeDocRoot($path)
Определения tools.php:3382
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$name
Определения menu_edit.php:35
</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
$title
Определения pdf.php:123
$error
Определения subscription_card_product.php:20