1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
vendornotifier.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\Security\Notifications;
4
5
use Bitrix\Main\Application;
6
use Bitrix\Main\Config\Option;
7
use Bitrix\Main\Loader;
8
use Bitrix\Main\ModuleManager;
9
use Bitrix\Main\Web\HttpClient;
10
use Bitrix\Main\Web\Json;
11
use ReflectionExtension;
12
use CSecuritySystemInformation;
13
14
class
VendorNotifier
15
{
16
const
CACHE_RULES_TTL
= 86400;
17
18
public
static
function
refreshNotifications
()
19
{
20
try
21
{
22
$lastTime = Option::get(
'main_sec'
,
'SEC_ACTUALIZE_VENDOR_NOTIFICATIONS'
, 0);
23
24
if
((time() - $lastTime) < static::CACHE_RULES_TTL)
25
{
26
return
;
27
}
28
29
Option::set(
'main_sec'
,
'SEC_ACTUALIZE_VENDOR_NOTIFICATIONS'
, time());
30
31
$newData =
null
;
32
33
// get modules versions
34
$modules
= array_map(
function
($module) {
35
return
[
'v'
=> $module[
'version'
],
'i'
=> (int) $module[
'isInstalled'
]];
36
},
ModuleManager::getModulesFromDisk
());
37
38
// get php extensions
39
$phpExtensions = [];
40
foreach
(get_loaded_extensions() as $extension)
41
{
42
$extReflection =
new
ReflectionExtension($extension);
43
44
$phpExtensions[$extension] = [
45
'v'
=> $extReflection->getVersion(),
46
'ini'
=> $extReflection->getINIEntries()
47
];
48
}
49
50
$dataToSend = [
51
'modules'
=> json_encode(
$modules
),
52
'license'
=>
Application::getInstance
()->getLicense()->getHashLicenseKey(),
53
'php'
=> json_encode([
54
'v'
=> phpversion(),
55
'ext'
=> $phpExtensions
56
])
57
];
58
59
if
(
Loader::includeModule
(
'security'
))
60
{
61
$moreInfo = CSecuritySystemInformation::getSystemInformation();
62
63
if
(isset($moreInfo[
'db'
][
'type'
]) && isset($moreInfo[
'db'
][
'version'
]))
64
{
65
$dataToSend[
'db'
] = [
66
'type'
=> $moreInfo[
'db'
][
'type'
],
67
'version'
=> $moreInfo[
'db'
][
'version'
]
68
];
69
}
70
71
if
(isset($moreInfo[
'environment'
][
'vm_version'
]))
72
{
73
$dataToSend[
'vm'
] = [
'v'
=> $moreInfo[
'environment'
][
'vm_version'
]];
74
}
75
}
76
77
// get actual rules
78
$http =
new
HttpClient
([
79
'socketTimeout'
=> 5,
80
'streamTimeout'
=> 5
81
]);
82
83
$uri
=
Application::getInstance
()->getLicense()->getDomainStoreLicense().
'/box/notification.php'
;
84
85
$response
= $http->post(
86
$uri
,
87
$dataToSend
88
);
89
90
if
($http->getStatus() == 200 && !empty(
$response
))
91
{
92
$newData = Json::decode(
$response
);
93
}
94
95
//update db
96
if
($newData !==
null
)
97
{
98
$connection
=
Application::getConnection
();
99
$tableName =
VendorNotificationTable::getTableName
();
100
101
// remove current data
102
$connection
->truncateTable($tableName);
103
104
// prepare new data
105
if
(!empty($newData))
106
{
107
$records = [];
108
foreach
($newData as $dataItem)
109
{
110
if
(!empty($dataItem[
'id'
]) && !empty($dataItem[
'data'
][
'title'
]) && !empty($dataItem[
'data'
][
'text'
]))
111
{
112
$dataItem[
'data'
] = Json::encode($dataItem[
'data'
]);
113
114
$records[] =
"('"
.
115
$connection
->getSqlHelper()->forSql($dataItem[
'id'
])
116
.
"', '"
.
$connection
->getSqlHelper()->forSql($dataItem[
'data'
])
117
.
"')"
;
118
}
119
}
120
121
if
(!empty($records))
122
{
123
$recordsSql = join(
", "
, $records);
124
125
// save new data
126
$connection
->query(
"INSERT INTO {$tableName} (VENDOR_ID, DATA) VALUES {$recordsSql}"
);
127
128
// clean entity cache
129
VendorNotificationTable::cleanCache
();
130
}
131
}
132
}
133
}
134
catch
(\Throwable $e)
135
{
136
\CEventLog::log(
137
\
CEventLog::SEVERITY_SECURITY
,
138
'SECURITY_VENDOR_NOTIFICATION_EXCEPTION'
,
139
'main'
,
140
'FAIL_REFRESHING'
,
141
'Can not refresh security vendor notifications: '
. $e->getMessage() .
' Trace: '
. $e->getTraceAsString()
142
);
143
}
144
}
145
}
$connection
$connection
Определения
actionsdefinitions.php:38
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\Application\getConnection
static getConnection($name="")
Определения
application.php:638
Bitrix\Main\Loader\includeModule
static includeModule($moduleName)
Определения
loader.php:67
Bitrix\Main\ModuleManager\getModulesFromDisk
static getModulesFromDisk($withLocal=true, $withPartners=true, $withKernel=true)
Определения
modulemanager.php:32
Bitrix\Main\ORM\Data\DataManager\cleanCache
static cleanCache()
Определения
datamanager.php:1983
Bitrix\Main\Security\Notifications\VendorNotificationTable\getTableName
static getTableName()
Определения
vendornotificationtable.php:29
Bitrix\Main\Security\Notifications\VendorNotifier
Определения
vendornotifier.php:15
Bitrix\Main\Security\Notifications\VendorNotifier\CACHE_RULES_TTL
const CACHE_RULES_TTL
Определения
vendornotifier.php:16
Bitrix\Main\Security\Notifications\VendorNotifier\refreshNotifications
static refreshNotifications()
Определения
vendornotifier.php:18
Bitrix\Main\Web\HttpClient
Определения
httpclient.php:24
CEventLog\SEVERITY_SECURITY
const SEVERITY_SECURITY
Определения
event_log.php:22
$modules
$modules
Определения
bitrix.php:26
$uri
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения
urlrewrite.php:61
$response
$response
Определения
result.php:21
bitrix
modules
main
lib
security
notifications
vendornotifier.php
Создано системой
1.14.0