1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
config.php
См. документацию.
1<?php
2namespace Bitrix\Pull;
3
4use Bitrix\Main\ArgumentException;
5use Bitrix\Main\Config\Option;
6use Bitrix\Main\Security\Random;
7use Bitrix\Pull\SharedServer\Client;
8
9
10class Config
11{
12 public const ONE_YEAR = 31536000; //60 * 60 * 24 * 365;
13
14 public static function get(array $params = [])
15 {
16 if (!\CPullOptions::GetQueueServerStatus())
17 return false;
18
19 $userId = (int)($params['USER_ID'] ?? 0);
20 if (isset($params['CHANNEL']) && !($params['CHANNEL'] instanceof \Bitrix\Pull\Model\Channel))
21 {
22 throw new ArgumentException('$params["CHANNEL"] should be instance of \Bitrix\Pull\Model\Channel');
23 }
24
25 if ($userId === 0 && !isset($params['CHANNEL']))
26 {
27 global $USER;
28 $userId = (int)$USER->GetID();
29 if ($userId === 0)
30 {
31 return false;
32 }
33 }
34
35 $params['CACHE'] = (bool)($params['CACHE'] ?? true);
36 $params['REOPEN'] = (bool)($params['REOPEN'] ?? false);
37
38 $cache = $params['CACHE'] !== false;
39 $reopen = $params['REOPEN'] !== false;
40
41 if ($userId !== 0)
42 {
43 $privateChannelType = $params['CUSTOM_TYPE'] ?? \CPullChannel::TYPE_PRIVATE;
44 $privateChannel = \CPullChannel::Get($userId, $cache, $reopen, $privateChannelType);
45 $sharedChannelType = $params['CUSTOM_TYPE'] ?? \CPullChannel::TYPE_SHARED;
46 $sharedChannel = \CPullChannel::GetShared($cache, $reopen, $sharedChannelType);
47 }
48 else // isset($params['CHANNEL'])
49 {
50 $privateChannel = [
51 'CHANNEL_ID' => $params['CHANNEL']->getPrivateId(),
52 'CHANNEL_PUBLIC_ID' => $params['CHANNEL']->getPublicId(),
53 'CHANNEL_DT' => $params['CHANNEL']->getDateCreate()->getTimestamp(),
54 'CHANNEL_DT_END' => $params['CHANNEL']->getDateCreate()->getTimestamp() + static::ONE_YEAR,
55 ];
56 $sharedChannel = null;
57 }
58
59 $domain = defined('BX24_HOST_NAME')? BX24_HOST_NAME: $_SERVER['SERVER_NAME'];
60
61 $isSharedMode = \CPullOptions::IsServerShared();
62 $serverConfig = [
63 'VERSION' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getServerVersion(): \CPullOptions::GetQueueServerVersion(),
64 'SERVER_ENABLED' => \CPullOptions::GetQueueServerStatus(),
65 'MODE' => \CPullOptions::GetQueueServerMode(),
66 'HOSTNAME' => Config::getHostname(),
67 'LONG_POLLING' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getLongPollingUrl(): \CPullOptions::GetListenUrl(),
68 'LONG_POOLING_SECURE' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getLongPollingUrl() : \CPullOptions::GetListenSecureUrl(),
69 'WEBSOCKET_ENABLED' => $isSharedMode ? true : \CPullOptions::GetWebSocket(),
70 'WEBSOCKET' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getWebSocketUrl() : \CPullOptions::GetWebSocketUrl(),
71 'WEBSOCKET_SECURE' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getWebSocketUrl() : \CPullOptions::GetWebSocketSecureUrl(),
72 'PUBLISH_ENABLED' => $isSharedMode ? true : \CPullOptions::GetPublishWebEnabled(),
73 'PUBLISH' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getWebPublishUrl() : \CPullOptions::GetPublishWebUrl(),
74 'PUBLISH_SECURE' => $isSharedMode ? \Bitrix\Pull\SharedServer\Config::getWebPublishUrl() : \CPullOptions::GetPublishWebSecureUrl(),
75 'CONFIG_TIMESTAMP' => \CPullOptions::GetConfigTimestamp(),
76 ];
77 foreach ($serverConfig as $key => $value)
78 {
79 if(is_string($value) && mb_strpos($value, '#DOMAIN#') !== false)
80 {
81 $serverConfig[$key] = str_replace('#DOMAIN#', $domain, $value);
82 }
83 }
84 $config['SERVER'] = $serverConfig;
85 if($isSharedMode)
86 {
88 }
89
90 $config['API'] = Array(
91 'REVISION_WEB' => PULL_REVISION_WEB,
92 'REVISION_MOBILE' => PULL_REVISION_MOBILE,
93 );
94
95 $config['CHANNELS'] = [];
96 if ($sharedChannel)
97 {
98 $config['CHANNELS']['SHARED'] = [
99 'ID' => \CPullChannel::SignChannel($sharedChannel["CHANNEL_ID"]),
100 'START' => $sharedChannel['CHANNEL_DT'],
101 'END' => $sharedChannel['CHANNEL_DT']+\CPullChannel::CHANNEL_TTL,
102 ];
103 }
104 if ($privateChannel)
105 {
106 if (\CPullOptions::GetQueueServerVersion() > 3)
107 {
108 $privateId = $privateChannel['CHANNEL_PUBLIC_ID']
109 ? "{$privateChannel['CHANNEL_ID']}:{$privateChannel['CHANNEL_PUBLIC_ID']}"
110 : $privateChannel['CHANNEL_ID']
111 ;
112 $privateId = \CPullChannel::SignChannel($privateId);
113
114 $publicId = \CPullChannel::SignPublicChannel($privateChannel['CHANNEL_PUBLIC_ID']);
115 }
116 else
117 {
118 $privateId = \CPullChannel::SignChannel($privateChannel['CHANNEL_ID']);
119 $publicId = '';
120 }
121
122 $config['CHANNELS']['PRIVATE'] = [
123 'ID' => $privateId,
124 'PUBLIC_ID' => $publicId,
125 'START' => $privateChannel['CHANNEL_DT'],
126 'END' => $privateChannel['CHANNEL_DT_END'] ?? $privateChannel['CHANNEL_DT']+\CPullChannel::CHANNEL_TTL,
127 ];
128 }
129
130 $params['JSON'] = (bool)($params['JSON'] ?? false);
131
132 $config['PUBLIC_CHANNELS'] = \Bitrix\Pull\Channel::getPublicIds(['JSON' => $params['JSON']]);
133 if (\CPullOptions::GetQueueServerVersion() >= 5)
134 {
135 $channelsForToken = [];
136 if ($sharedChannel)
137 {
138 $channelsForToken[] = $sharedChannel['CHANNEL_ID'];
139 }
140 if ($privateChannel && $userId == 0)
141 {
142 $channelsForToken[] = $privateChannel['CHANNEL_ID'];
143 if ($privateChannel['CHANNEL_PUBLIC_ID'] != '')
144 {
145 $channelsForToken[] = $privateChannel['CHANNEL_PUBLIC_ID'];
146 }
147 }
148 [$config['JWT'], $config['EXP']] = \Bitrix\Pull\Auth\Jwt::create($channelsForToken, $userId, [
149 'ttl' => \CPullOptions::GetConfigTtl()
150 ]);
151 }
152 if (\CPullOptions::GetConfigTtl() > 0 && !isset($config['EXP']))
153 {
154 $config['EXP'] = time() + \CPullOptions::GetConfigTtl();
155 }
156
157 if ($params['JSON'])
158 {
159 $result['server'] = array_change_key_case($config['SERVER'], CASE_LOWER);
160 $result['api'] = array_change_key_case($config['API'], CASE_LOWER);
161
162 foreach ($config['CHANNELS'] as $type => $channel)
163 {
164 $type = mb_strtolower($type);
165 $result['channels'][$type] = array_change_key_case($channel, CASE_LOWER);
166 $result['channels'][$type]['type'] = $type;
167 $result['channels'][$type]['start'] = date('c', $channel['START']);
168 $result['channels'][$type]['end'] = date('c', $channel['END']);
169 }
170
171 if($isSharedMode)
172 {
173 $result['clientId'] = $config['CLIENT_ID'];
174 }
175 if (isset($config['JWT']))
176 {
177 $result['jwt'] = $config['JWT'];
178 }
179 if (isset($config['EXP']))
180 {
181 $result['exp'] = $config['EXP'];
182 }
183
184 $result['publicChannels'] = $config['PUBLIC_CHANNELS'];
185
187 }
188
189 return $config;
190
191 }
192
197 public static function getPublishUrl($channelId = "")
198 {
199 $params = [];
200 if(\CPullOptions::IsServerShared())
201 {
204 }
205 else
206 {
207 $result = \CPullOptions::GetPublishUrl();
208 }
209
210 if($channelId != "")
211 {
212 $params["CHANNEL_ID"] = $channelId;
213 }
214
215 return \CHTTP::urlAddParams($result, $params);
216 }
217
218 public static function getJsonRpcUrl()
219 {
220 $params = [];
221 if(\CPullOptions::IsServerShared())
222 {
225 }
226 else
227 {
228 $result = \CPullOptions::GetJsonRpcUrl();
229 }
230
231 return \CHTTP::urlAddParams($result, $params);
232 }
233
234 public static function getHostname(): string
235 {
236 if (defined('BX24_HOST_NAME'))
237 {
238 return BX24_HOST_NAME;
239 }
240 else if (defined('SITE_SERVER_NAME') && SITE_SERVER_NAME)
241 {
242 return SITE_SERVER_NAME;
243 }
244
245 return Option::get('main', 'server_name', '');
246 }
247
248 public static function getHostId()
249 {
250 static $hostId = null;
251
252 if ($hostId === null)
253 {
254 $hostId = Option::get("pull", "host_id", "");
255 }
256 if ($hostId == '')
257 {
258 $hostId = Random::getString(32);
259 Option::set("pull", "host_id", $hostId);
260 }
261
262 return $hostId;
263 }
264
265 public static function getSignatureKey()
266 {
267 if(\CPullOptions::IsServerShared())
268 {
269 return \Bitrix\Pull\SharedServer\Config::getSignatureKey();
270 }
271 else
272 {
273 return \CPullOptions::GetSignatureKey();
274 }
275 }
276
277 public static function isProtobufUsed()
278 {
279 $result =
280 \CPullOptions::IsServerShared() ||
281 (
282 \CPullOptions::GetQueueServerVersion() == 4 &&
283 \CPullOptions::IsProtobufSupported() &&
284 \CPullOptions::IsProtobufEnabled()
285 );
286
287 return $result;
288 }
289
290 public static function isJsonRpcUsed(): bool
291 {
292 return \CPullOptions::GetQueueServerVersion() >= 5;
293 }
294}
$type
Определения options.php:106
if(empty( $fields)) foreach($fields as $field) $channelId
Определения push.php:23
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
static set($moduleId, $name, $value="", $siteId="")
Определения option.php:261
static create(array $channels=[], int $userId=0, array $options=[])
Определения jwt.php:15
Определения channel.php:6
static getPublicIds($params=[])
Определения channel.php:25
static getPublishUrl($channelId="")
Определения config.php:197
static isProtobufUsed()
Определения config.php:277
const ONE_YEAR
Определения config.php:12
static getHostId()
Определения config.php:248
static getHostname()
Определения config.php:234
static getJsonRpcUrl()
Определения config.php:218
static getSignatureKey()
Определения config.php:265
static isJsonRpcUsed()
Определения config.php:290
static getPublicLicenseCode()
Определения client.php:184
static getWebPublishUrl()
Определения config.php:99
static getLongPollingUrl()
Определения config.php:80
static getPublishUrl()
Определения config.php:60
static getJsonRpcUrl()
Определения config.php:70
static getWebSocketUrl()
Определения config.php:90
static getServerVersion()
Определения config.php:23
static Get(int $userId, $cache=true, $reOpen=false, $channelType=self::TYPE_PRIVATE)
Определения pull_channel.php:46
static SignChannel($channelId)
Определения pull_channel.php:179
const TYPE_PRIVATE
Определения pull_channel.php:9
const TYPE_SHARED
Определения pull_channel.php:10
const CHANNEL_TTL
Определения pull_channel.php:12
static SignPublicChannel($channelId)
Определения pull_channel.php:196
static GetShared($cache=true, $reOpen=false, $channelType=self::TYPE_SHARED)
Определения pull_channel.php:36
</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
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $USER
Определения csv_new_run.php:40
Определения channel.php:3
const PULL_REVISION_MOBILE
Определения include.php:4
const PULL_REVISION_WEB
Определения include.php:3
$config
Определения quickway.php:69
if(empty($signedUserToken)) $key
Определения quickway.php:257
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799