1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
vendornotifier.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Security\Notifications;
4
5use Bitrix\Main\Application;
6use Bitrix\Main\Config\Option;
7use Bitrix\Main\Loader;
8use Bitrix\Main\ModuleManager;
9use Bitrix\Main\Web\HttpClient;
10use Bitrix\Main\Web\Json;
11use ReflectionExtension;
12use CSecuritySystemInformation;
13
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']];
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 {
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
130 }
131 }
132 }
133 }
134 catch (\Throwable $e)
135 {
136 \CEventLog::log(
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
Определения actionsdefinitions.php:38
static getInstance()
Определения application.php:98
static getConnection($name="")
Определения application.php:638
static includeModule($moduleName)
Определения loader.php:67
static getModulesFromDisk($withLocal=true, $withPartners=true, $withKernel=true)
Определения modulemanager.php:32
static cleanCache()
Определения datamanager.php:1983
const SEVERITY_SECURITY
Определения event_log.php:22
$modules
Определения bitrix.php:26
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
$response
Определения result.php:21