1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
helper.php
См. документацию.
1<?
2namespace Bitrix\Scale;
3
4use \Bitrix\Main\Localization\Loc;
5Loc::loadMessages(__FILE__);
6
11class Helper
12{
13 const BX_ENV_MIN_VERSION = "7.2.0";
14
15 public static function checkBxEnvVersion($version = false)
16 {
17 if(!$version)
18 $version = getenv('BITRIX_VA_VER');
19
20 return version_compare($version, self::BX_ENV_MIN_VERSION , '>=');
21 }
22
23 public static function nbsp($str)
24 {
25 return str_replace(" ", "&nbsp;",$str);
26 }
27
28 public static function getAvailabilityPage($minutes)
29 {
30 if(intval($minutes) <= 0)
31 throw new \Bitrix\Main\ArgumentNullException("minutes");
32
33 $now = time();
34
35 $contents = file_get_contents(\Bitrix\Main\Application::getDocumentRoot().'/bitrix/modules/scale/server_off.html');
36
37 $contents = str_replace(
38 "##SITE_NAME##",
39 \CUtil::JSEscape(\COption::GetOptionString("main","site_name", $_SERVER["SERVER_NAME"])),
41 );
42
43 $contents = str_replace(
44 "##CHARSET##",
47 );
48
49 $contents = str_replace(
50 "##AVAILABLE_MESSAGE##",
51 Loc::getMessage("SCALE_HLP_AV_MESSAGE"),
53 );
54
55 $contents = str_replace(
56 "##AVAILABLE_DATETIME##",
57 ($now+60*$minutes)*1000,
59 );
60
61 $contents = str_replace(
62 "##SERVER_NOW##",
63 $now*1000,
65 );
66
67 $contents = str_replace(
68 "##HOURS##",
69 Loc::getMessage("SCALE_HLP_AV_HOURS")." ",
71 );
72
73 $contents = str_replace(
74 "##MINS##",
75 Loc::getMessage("SCALE_HLP_AV_MINS")." ",
77 );
78
79 $contents = str_replace(
80 "##SECS##",
81 Loc::getMessage("SCALE_HLP_AV_SECS")." ",
83 );
84
85 return $contents;
86 }
87
88 public static function modifyDbconn($DBHost, $DBName, $DBLogin, $DBPassword)
89 {
90 if($DBHost == '')
91 throw new \Bitrix\Main\ArgumentNullException("DBHost");
92 if($DBName == '')
93 throw new \Bitrix\Main\ArgumentNullException("DBName");
94 if($DBLogin == '')
95 throw new \Bitrix\Main\ArgumentNullException("DBLogin");
96
97 $filename = \Bitrix\Main\Application::getDocumentRoot()."/bitrix/php_interface/dbconn.php";
98 $file = new \Bitrix\Main\IO\File($filename);
99
100 if(!$file->isExists())
101 return false;
102
103 $content = file_get_contents($filename);
104
105 if($content == '')
106 return false;
107
108 file_put_contents(\Bitrix\Main\Application::getDocumentRoot()."/bitrix/php_interface/dbconn.php.bak", $content);
109
110 $content = preg_replace('/(\$DBHost\s*=\s*(\"|\')+)(.*)((\"|\')+;)/','${1}'.$DBHost.'${4}',$content);
111 $content = preg_replace('/(\$DBName\s*=\s*(\"|\')+)(.*)((\"|\')+;)/','${1}'.$DBName.'${4}',$content);
112 $content = preg_replace('/(\$DBLogin\s*=\s*(\"|\')+)(.*)((\"|\')+;)/','${1}'.$DBLogin.'${4}',$content);
113 $content = preg_replace('/(\$DBPassword\s*=\s*(\"|\')+)(.*)((\"|\')+;)/','${1}'.$DBPassword.'${4}',$content);
114
115 return file_put_contents($filename, $content);
116 }
117
119 {
120 $filename = $_SERVER['DOCUMENT_ROOT']."/bitrix/.settings-test.php";
121
122 if (!file_exists($filename))
123 return true;
124
125 ob_start();
126 $settings = include($filename);
127 ob_end_clean();
128
129 if (!is_array($settings))
130 return false;
131
132 if(!isset($settings['connections']['value']['default']) || !is_array($settings['connections']['value']['default']))
133 return true;
134
135 $settings['connections']['value']['default']['host'] = $DBHost;
136 $settings['connections']['value']['default']['database'] = $DBName;
137 $settings['connections']['value']['default']['login'] = $DBLogin;
138 $settings['connections']['value']['default']['password'] = $DBPassword;
139
140 $data = var_export($settings, true);
141
142 rename($filename, $_SERVER['DOCUMENT_ROOT']."/bitrix/.settings-test.php.bak");
143 file_put_contents($filename, "<"."?php\nreturn ".$data.";\n");
144
145 return true;
146 }
147
148 public static function generatePass($length = 20)
149 {
150 $chars="abcdefghiknrstyzABCDEFGHKNQRSTYZ1234567890";
151 $charsCount = mb_strlen($chars);
152 $result="";
153
154 for($i=0; $i<$length; $i++)
155 $result .= mb_substr($chars, rand(1, $charsCount) - 1, 1);
156
157 return $result;
158 }
159
160 public static function isExtraDbExist($hostname)
161 {
162 $dbList = ServersData::getDbList($hostname);
164 $currentDb = $connection->getDbName();
165 $dbCount = count($dbList);
166 if($dbCount > 1
167 ||($dbCount == 1
168 && !in_array($currentDb, $dbList)
169 )
170 )
171 {
172 $result = true;
173 }
174 else
175 {
176 $result = false;
177 }
178
179 return $result;
180 }
181
182 public static function getNetworkInterfaces()
183 {
184 $result = array();
185 $shellAdapter = new ShellAdapter();
186 $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-node -o json");
187 $jsonData = $shellAdapter->getLastOutput();
188
189 if($execRes)
190 {
191 $arData = json_decode($jsonData, true);
192
193 if(isset($arData["params"]["pool_interfaces"]))
194 $result = $arData["params"]["pool_interfaces"];
195
196 if(is_array($result))
197 {
198 foreach($result as $iface => $ip)
199 $result[$iface] = $iface." (".$ip.")";
200 }
201 }
202
203 return $result;
204 }
205
206 public static function isScaleCanBeUsed()
207 {
208 global $DB;
209
210 return getenv('BITRIX_VA_VER')
211 && mb_stristr(php_uname('s'), 'linux')
212 && $DB->type == 'MYSQL'
214 }
215
216 public static function getTmpDir()
217 {
218 $path = '/home/bitrix/.webdir';
219 $permissionsForOwnerOnly = 0700;
220 $res = true;
221
222 if(!file_exists($path))
223 $res = mkdir($path, $permissionsForOwnerOnly, true);
224
225 return $res ? $path : '';
226 }
227}
$path
Определения access_edit.php:21
$connection
Определения actionsdefinitions.php:38
static getDocumentRoot()
Определения application.php:736
static getConnection($name="")
Определения application.php:638
Определения helper.php:12
static nbsp($str)
Определения helper.php:23
static isScaleCanBeUsed()
Определения helper.php:206
static getNetworkInterfaces()
Определения helper.php:182
static getAvailabilityPage($minutes)
Определения helper.php:28
static modifySettings($DBHost, $DBName, $DBLogin, $DBPassword)
Определения helper.php:118
static getTmpDir()
Определения helper.php:216
static generatePass($length=20)
Определения helper.php:148
static isExtraDbExist($hostname)
Определения helper.php:160
static checkBxEnvVersion($version=false)
Определения helper.php:15
const BX_ENV_MIN_VERSION
Определения helper.php:13
static modifyDbconn($DBHost, $DBName, $DBLogin, $DBPassword)
Определения helper.php:88
static getDbList($hostname)
Определения serversdata.php:102
$str
Определения commerceml2.php:63
$contents
Определения commerceml2.php:57
$content
Определения commerceml.php:144
$data['IS_AVAILABLE']
Определения .description.php:13
$filename
Определения file_edit.php:47
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $DB
Определения cron_frame.php:29
const LANG_CHARSET
Определения include.php:65
global $DBHost
Определения start.php:35
global $DBName
Определения start.php:35
global $DBPassword
Определения start.php:35
global $DBLogin
Определения start.php:35
$settings
Определения product_settings.php:43
$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