1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
filter_mask.php
См. документацию.
1
<?php
8
9
use \Bitrix\Main\ORM\Query\Query;
10
use \Bitrix\Security\FilterMaskTable;
11
12
class
CSecurityFilterMask
13
{
14
public
static
function
Update
($arMasks)
15
{
16
global
$CACHE_MANAGER
;
17
18
if
(is_array($arMasks))
19
{
20
$res
= FilterMaskTable::deleteList([]);
21
if
(
$res
)
22
{
23
$arLikeSearch =
array
(
"?"
,
"*"
,
"."
);
24
$arLikeReplace =
array
(
"_"
,
"%"
,
"\\."
);
25
$arPregSearch =
array
(
"\\"
,
"."
,
"?"
,
"*"
,
"'"
);
26
$arPregReplace =
array
(
"/"
,
"\."
,
"."
,
".*?"
,
"\'"
);
27
28
$added =
array
();
29
$i
= 10;
30
foreach
($arMasks as $arMask)
31
{
32
$site_id
= trim($arMask[
"SITE_ID"
]);
33
if
(
$site_id
==
"NOT_REF"
)
34
$site_id
=
""
;
35
36
$mask = trim($arMask[
"MASK"
]);
37
if
($mask && !array_key_exists($mask, $added))
38
{
39
$arMask =
array
(
40
"SORT"
=>
$i
,
41
"FILTER_MASK"
=> $mask,
42
"LIKE_MASK"
=> str_replace($arLikeSearch, $arLikeReplace, $mask),
43
"PREG_MASK"
=> str_replace($arPregSearch, $arPregReplace, $mask),
44
);
45
if
(
$site_id
)
46
$arMask[
"SITE_ID"
] =
$site_id
;
47
48
FilterMaskTable::add($arMask);
49
$i
+= 10;
50
$added[$mask] =
true
;
51
}
52
}
53
54
if
(CACHED_b_sec_filter_mask !==
false
)
55
$CACHE_MANAGER
->CleanDir(
"b_sec_filter_mask"
);
56
57
}
58
}
59
60
return
true
;
61
}
62
63
public
static
function
GetList
()
64
{
65
$res
= FilterMaskTable::getList([
'select'
=> [
'SITE_ID'
,
'FILTER_MASK'
],
'order'
=>
'sort'
]);
66
return
$res
;
67
}
68
69
public
static
function
Check
(
$siteId
,
$uri
)
70
{
71
global
$CACHE_MANAGER
;
72
$bFound
=
false
;
73
74
if
(CACHED_b_sec_filter_mask !==
false
&& is_object(
$CACHE_MANAGER
))
75
{
76
$cache_id =
"b_sec_filter_mask"
;
77
if
(
$CACHE_MANAGER
->Read(CACHED_b_sec_filter_mask, $cache_id,
"b_sec_filter_mask"
))
78
{
79
$arMasks =
$CACHE_MANAGER
->Get($cache_id);
80
}
81
else
82
{
83
$arMasks =
array
();
84
85
$rs
= FilterMaskTable::getList([
'select'
=> [
'SITE_ID'
,
'PREG_MASK'
,
'SORT'
],
'order'
=>
'sort'
]);
86
while
(
$ar
=
$rs
->Fetch())
87
{
88
$site_id
=
$ar
[
"SITE_ID"
]?
$ar
[
"SITE_ID"
]:
"-"
;
89
$arMasks[
$site_id
][
$ar
[
"SORT"
]] =
$ar
[
"PREG_MASK"
];
90
}
91
92
$CACHE_MANAGER
->Set($cache_id, $arMasks);
93
}
94
95
if
(isset($arMasks[
"-"
]) && is_array($arMasks[
"-"
]))
96
{
97
foreach
($arMasks[
"-"
] as $mask)
98
{
99
if
(preg_match(
"#^"
.$mask.
"$#"
,
$uri
))
100
{
101
$bFound
=
true
;
102
break
;
103
}
104
}
105
}
106
107
if
(
108
!
$bFound
109
&&
$siteId
110
&& isset($arMasks[
$siteId
])
111
)
112
{
113
foreach
($arMasks[
$siteId
] as $mask)
114
{
115
if
(preg_match(
"#^"
.$mask.
"$#"
,
$uri
))
116
{
117
$bFound
=
true
;
118
break
;
119
}
120
}
121
}
122
123
}
124
else
125
{
126
$sqlHelper =
\Bitrix\Main\Application::getConnection
()->getSqlHelper();
127
128
$filter
= Query::filter()
129
->whereNull(
'SITE_ID'
)
130
->whereExpr(
"'"
.$sqlHelper->forSql(
$uri
).
"' LIKE %s"
, [
'LIKE_MASK'
]);
131
132
if
(
$siteId
)
133
{
134
$filterOr = Query::filter()
135
->where(
'SITE_ID'
,
$siteId
)
136
->whereExpr(
"'"
.$sqlHelper->forSql(
$uri
).
"' LIKE %s"
, [
'LIKE_MASK'
]);
137
138
$filter
= Query::filter()
139
->logic(
'or'
)
140
->where(
$filter
)
141
->where($filterOr);
142
}
143
144
$rs
= FilterMaskTable::getList([
'select'
=> [
'ID'
],
'filter'
=>
$filter
,
'limit'
=> 1]);
145
146
if
(
$rs
->Fetch())
147
$bFound
=
true
;
148
}
149
150
return
$bFound
;
151
}
152
}
Bitrix\Main\Application\getConnection
static getConnection($name="")
Определения
application.php:638
CSecurityFilterMask
Определения
filter_mask.php:13
CSecurityFilterMask\GetList
static GetList()
Определения
filter_mask.php:63
CSecurityFilterMask\Update
static Update($arMasks)
Определения
filter_mask.php:14
CSecurityFilterMask\Check
static Check($siteId, $uri)
Определения
filter_mask.php:69
$CACHE_MANAGER
global $CACHE_MANAGER
Определения
clear_component_cache.php:7
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$bFound
$bFound
Определения
get_search.php:40
$filter
$filter
Определения
iblock_catalog_list.php:54
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
$siteId
$siteId
Определения
ajax.php:8
$ar
$ar
Определения
options.php:199
$i
$i
Определения
factura.php:643
$site_id
$site_id
Определения
sonet_set_content_view.php:9
$rs
$rs
Определения
action.php:82
bitrix
modules
security
classes
general
filter_mask.php
Создано системой
1.14.0