1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
webnode.php
См. документацию.
1<?php
3
5{
6 public static $errno = 0;
7 public static $errstr = '';
8
9 public function Add($arFields)
10 {
11 global $DB;
12
13 if (!$this->CheckFields($arFields, 0))
14 {
15 return false;
16 }
17
18 $ID = $DB->Add('b_cluster_webnode', $arFields);
19
20 return $ID;
21 }
22
23 public static function Delete($ID)
24 {
25 global $DB;
26 $ID = intval($ID);
27
28 $res = $DB->Query('DELETE FROM b_cluster_webnode WHERE ID = ' . $ID, false, '', ['fixed_connection' => true]);
29
30 return $res;
31 }
32
33 public function Update($ID, $arFields)
34 {
35 global $DB;
36 $ID = intval($ID);
37
38 if ($ID <= 0)
39 {
40 return false;
41 }
42
43 if (!$this->CheckFields($arFields, $ID))
44 {
45 return false;
46 }
47
48 $strUpdate = $DB->PrepareUpdate('b_cluster_webnode', $arFields);
49 if ($strUpdate <> '')
50 {
51 $strSql = '
52 UPDATE b_cluster_webnode SET
53 ' . $strUpdate . '
54 WHERE ID = ' . $ID . '
55 ';
56 if (!$DB->Query($strSql, false, '', ['fixed_connection' => true]))
57 {
58 return false;
59 }
60 }
61
62 return true;
63 }
64
65 public function CheckFields(&$arFields, $ID)
66 {
67 global $APPLICATION;
68 $aMsg = [];
69
70 $bHost = false;
71 if (isset($arFields['HOST']))
72 {
73 if (preg_match('/^([0-9a-zA-Z-_.]+)$/', $arFields['HOST']))
74 {
75 $bHost = true;
76 }
77
78 if (!$bHost)
79 {
80 $aMsg[] = ['id' => 'HOST', 'text' => GetMessage('CLU_WEBNODE_WRONG_IP')];
81 }
82 }
83
84 $bStatus = true;
85 if ($bHost && isset($arFields['PORT']))
86 {
87 if ($arFields['STATUS_URL'] <> '')
88 {
89 $arStatus = static::GetStatus($arFields['HOST'], $arFields['PORT'], $arFields['STATUS_URL']);
90 $bStatus = is_array($arStatus);
91 }
92 }
93
94 if (!$bStatus)
95 {
96 //$aMsg[] = array("id" => "STATUS_URL", "text" => GetMessage("CLU_WEBNODE_WRONG_STATUS_URL"));
97 }
98
99 if (!empty($aMsg))
100 {
101 $e = new CAdminException($aMsg);
102 $APPLICATION->ThrowException($e);
103 return false;
104 }
105 return true;
106 }
107
108 public static function GetList($arOrder=false, $arFilter=false, $arSelect=false)
109 {
110 global $DB;
111
112 if (!is_array($arSelect))
113 {
114 $arSelect = [];
115 }
116 if (count($arSelect) < 1)
117 {
118 $arSelect = [
119 'ID',
120 'NAME',
121 'DESCRIPTION',
122 'HOST',
123 'PORT',
124 'STATUS_URL',
125 ];
126 }
127
128 if (!is_array($arOrder))
129 {
130 $arOrder = [];
131 }
132
133 $arQueryOrder = [];
134 foreach ($arOrder as $strColumn => $strDirection)
135 {
136 $strColumn = mb_strtoupper($strColumn);
137 $strDirection = mb_strtoupper($strDirection) === 'ASC' ? 'ASC' : 'DESC';
138 switch ($strColumn)
139 {
140 case 'ID':
141 case 'NAME':
142 $arSelect[] = $strColumn;
143 $arQueryOrder[$strColumn] = $strColumn . ' ' . $strDirection;
144 break;
145 }
146 }
147
148 $arQuerySelect = [];
149 foreach ($arSelect as $strColumn)
150 {
151 $strColumn = mb_strtoupper($strColumn);
152 switch ($strColumn)
153 {
154 case 'ID':
155 case 'NAME':
156 case 'DESCRIPTION':
157 case 'HOST':
158 case 'PORT':
159 case 'STATUS_URL':
160 $arQuerySelect[$strColumn] = 'w.' . $strColumn;
161 break;
162 }
163 }
164 if (count($arQuerySelect) < 1)
165 {
166 $arQuerySelect = ['ID' => 'w.ID'];
167 }
168
169 $obQueryWhere = new CSQLWhere;
170 $arFields = [
171 'ID' => [
172 'TABLE_ALIAS' => 'w',
173 'FIELD_NAME' => 'w.ID',
174 'FIELD_TYPE' => 'int',
175 'JOIN' => false,
176 ],
177 'GROUP_ID' => [
178 'TABLE_ALIAS' => 'w',
179 'FIELD_NAME' => 'w.GROUP_ID',
180 'FIELD_TYPE' => 'int',
181 'JOIN' => false,
182 ],
183 'NAME' => [
184 'TABLE_ALIAS' => 'w',
185 'FIELD_NAME' => 'w.NAME',
186 'FIELD_TYPE' => 'string',
187 'JOIN' => false,
188 ],
189 'HOST' => [
190 'TABLE_ALIAS' => 'w',
191 'FIELD_NAME' => 'w.HOST',
192 'FIELD_TYPE' => 'string',
193 'JOIN' => false,
194 ],
195 'PORT' => [
196 'TABLE_ALIAS' => 'w',
197 'FIELD_NAME' => 'w.PORT',
198 'FIELD_TYPE' => 'int',
199 'JOIN' => false,
200 ],
201 ];
202 $obQueryWhere->SetFields($arFields);
203
204 if (!is_array($arFilter))
205 {
206 $arFilter = [];
207 }
208 $strQueryWhere = $obQueryWhere->GetQuery($arFilter);
209
210 $bDistinct = $obQueryWhere->bDistinctReqired;
211
212 $strSql = '
213 SELECT ' . ($bDistinct ? 'DISTINCT' : '') . '
214 ' . implode(', ', $arQuerySelect) . '
215 FROM
216 b_cluster_webnode w
217 ' . $obQueryWhere->GetJoins() . '
218 ';
219
220 if ($strQueryWhere)
221 {
222 $strSql .= '
223 WHERE
224 ' . $strQueryWhere . '
225 ';
226 }
227
228 if (count($arQueryOrder) > 0)
229 {
230 $strSql .= '
231 ORDER BY
232 ' . implode(', ', $arQueryOrder) . '
233 ';
234 }
235
236 return $DB->Query($strSql, false, '', ['fixed_connection' => true]);
237 }
238
239 public static function GetStatus($host, $port, $url)
240 {
241 self::$errno = 0;
242 self::$errstr = '';
243 $protocol = ($port === '443') ? 'ssl://' : '';
244 $FP = @fsockopen($protocol . $host, $port, self::$errno, self::$errstr, 2);
245 if ($FP)
246 {
247 $strRequest = 'GET ' . $url . " HTTP/1.0\r\n";
248 $strRequest .= "User-Agent: BitrixSMCluster\r\n";
249 $strRequest .= "Accept: */*\r\n";
250 $strRequest .= 'Host: ' . $host . "\r\n";
251 $strRequest .= "Accept-Language: en\r\n";
252 $strRequest .= "\r\n";
253 fputs($FP, $strRequest);
254
255 $headers = '';
256 while (!feof($FP))
257 {
258 $line = fgets($FP, 4096);
259 if ($line == "\r\n")
260 {
261 break;
262 }
263 $headers .= $line;
264 }
265
266 $text = '';
267 while (!feof($FP))
268 {
269 $text .= fread($FP, 4096);
270 }
271
272 fclose($FP);
273
274 $match = [];
275 if (preg_match_all('#<dt>(.*?)\\s*:\\s*(.*?)</dt>#', $text, $match))
276 {
277 $arResult = [];
278 foreach ($match[0] as $i => $_)
279 {
280 $key = $match[1][$i];
281 $value = $match[2][$i];
282 if ($key === 'Total accesses')
283 {
284 $accessMatch = [];
285 if (preg_match('/^(.*) - (.*)\\s*:\\s*(.*)$/', $value, $accessMatch))
286 {
287 $value = $accessMatch[1];
288 $arResult[$accessMatch[2]] = $accessMatch[3];
289 }
290 }
291 $arResult[$key] = $value;
292 }
293 return $arResult;
294 }
295 }
296
297 return false;
298 }
299
300 public static function getServerList()
301 {
302 global $DB;
303 $result = [];
304 $rsData = $DB->Query('
305 SELECT ID, GROUP_ID, HOST
306 FROM b_cluster_webnode
307 ORDER BY GROUP_ID, ID
308 ');
309 while ($arData = $rsData->Fetch())
310 {
311 $host = $arData['HOST'] === '127.0.0.1' || $arData['HOST'] === 'localhost' ? '' : $arData['HOST'];
312 $result[] = [
313 'ID' => $arData['ID'],
314 'GROUP_ID' => $arData['GROUP_ID'],
315 'SERVER_TYPE' => 'web',
316 'ROLE_ID' => '',
317 'HOST' => $host,
318 'DEDICATED' => 'Y',
319 'EDIT_URL' => '/bitrix/admin/cluster_webnode_edit.php?lang=' . LANGUAGE_ID . '&group_id=' . $arData['GROUP_ID'] . '&ID=' . $arData['ID'],
320 ];
321 }
322 return $result;
323 }
324
325 public static function ParseDateTime($str)
326 {
327 static $search = false;
328 static $replace = false;
329 if ($search === false)
330 {
331 $search = [];
332 $replace = [];
333 for ($i = 1; $i <= 12; $i++)
334 {
335 $time = mktime(0, 0, 0, $i, 1, 2010);
336 $search[] = date('M', $time);
337 $replace[] = date('m', $time);
338 }
339 }
340
341 $str = str_replace($search, $replace, $str);
342 $dateMatch = [];
343 if (preg_match('/(\\d{2}-\\d{2}-\\d{4} \\d{2}:\\d{2}:\\d{2})/', $str, $dateMatch))
344 {
345 return MakeTimeStamp($dateMatch[1], 'DD-MM-YYYY HH:MI:SS');
346 }
347 else
348 {
349 return false;
350 }
351 }
352}
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
Определения webnode.php:5
static $errstr
Определения webnode.php:7
static $errno
Определения webnode.php:6
static Delete($ID)
Определения webnode.php:23
CheckFields(&$arFields, $ID)
Определения webnode.php:65
static ParseDateTime($str)
Определения webnode.php:325
static GetStatus($host, $port, $url)
Определения webnode.php:239
static GetList($arOrder=false, $arFilter=false, $arSelect=false)
Определения webnode.php:108
Add($arFields)
Определения webnode.php:9
static getServerList()
Определения webnode.php:300
Update($ID, $arFields)
Определения webnode.php:33
Определения sqlwhere.php:1359
$str
Определения commerceml2.php:63
$arFields
Определения dblapprove.php:5
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$protocol
Определения .description.php:9
$host
Определения .description.php:9
global $DB
Определения cron_frame.php:29
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
MakeTimeStamp($datetime, $format=false)
Определения tools.php:538
$time
Определения payment.php:61
if(empty($signedUserToken)) $key
Определения quickway.php:257
$text
Определения template_pdf.php:79
$i
Определения factura.php:643
</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
if(file_exists($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/updater.log") &&is_file($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/updater.log") &&is_readable($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/updater.log")) $rsData
Определения update_log.php:102
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7