Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.util.php
Go to the documentation of this file.
1<?php
2/*
3 *
4 * * Copyright (c) 2022-2025 Bearsampp
5 * * License: GNU General Public License version 3 or later; see LICENSE.txt
6 * * Website: https://bearsampp.com
7 * * Github: https://github.com/Bearsampp
8 *
9 */
10
34class Util
35{
39 const LOG_ERROR = 'ERROR';
40 const LOG_WARNING = 'WARNING';
41 const LOG_INFO = 'INFO';
42 const LOG_DEBUG = 'DEBUG';
43 const LOG_TRACE = 'TRACE';
44
53 public static function cleanArgv($name, $type = 'text')
54 {
55 if (isset($_SERVER['argv'])) {
56 if ($type == 'text') {
57 return (isset($_SERVER['argv'][$name]) && !empty($_SERVER['argv'][$name])) ? trim($_SERVER['argv'][$name]) : '';
58 } elseif ($type == 'numeric') {
59 return (isset($_SERVER['argv'][$name]) && is_numeric($_SERVER['argv'][$name])) ? intval($_SERVER['argv'][$name]) : '';
60 } elseif ($type == 'boolean') {
61 return (isset($_SERVER['argv'][$name])) ? true : false;
62 } elseif ($type == 'array') {
63 return (isset($_SERVER['argv'][$name]) && is_array($_SERVER['argv'][$name])) ? $_SERVER['argv'][$name] : array();
64 }
65 }
66
67 return false;
68 }
69
78 public static function cleanGetVar($name, $type = 'text')
79 {
80 if (is_string($name)) {
81 if ($type == 'text') {
82 return (isset($_GET[$name]) && !empty($_GET[$name])) ? stripslashes($_GET[$name]) : '';
83 } elseif ($type == 'numeric') {
84 return (isset($_GET[$name]) && is_numeric($_GET[$name])) ? intval($_GET[$name]) : '';
85 } elseif ($type == 'boolean') {
86 return (isset($_GET[$name])) ? true : false;
87 } elseif ($type == 'array') {
88 return (isset($_GET[$name]) && is_array($_GET[$name])) ? $_GET[$name] : array();
89 }
90 }
91
92 return false;
93 }
94
103 public static function cleanPostVar($name, $type = 'text')
104 {
105 if (is_string($name)) {
106 if ($type == 'text') {
107 return (isset($_POST[$name]) && !empty($_POST[$name])) ? stripslashes(trim($_POST[$name])) : '';
108 } elseif ($type == 'number') {
109 return (isset($_POST[$name]) && is_numeric($_POST[$name])) ? intval($_POST[$name]) : '';
110 } elseif ($type == 'float') {
111 return (isset($_POST[$name]) && is_numeric($_POST[$name])) ? floatval($_POST[$name]) : '';
112 } elseif ($type == 'boolean') {
113 return (isset($_POST[$name])) ? true : false;
114 } elseif ($type == 'array') {
115 return (isset($_POST[$name]) && is_array($_POST[$name])) ? $_POST[$name] : array();
116 } elseif ($type == 'content') {
117 return (isset($_POST[$name]) && !empty($_POST[$name])) ? trim($_POST[$name]) : '';
118 }
119 }
120
121 return false;
122 }
123
132 public static function contains($string, $search)
133 {
134 if (!empty($string) && !empty($search)) {
135 $result = stripos($string, $search);
136 if ($result !== false) {
137 return true;
138 } else {
139 return false;
140 }
141 } else {
142 return false;
143 }
144 }
145
154 public static function startWith($string, $search)
155 {
156 // Return false if string is NULL or empty
157 if ($string === null || $string === '') {
158 return false;
159 }
160
161 $length = strlen($search);
162
163 return (substr($string, 0, $length) === $search);
164 }
165
177 public static function endWith($string, $search)
178 {
179 $length = strlen($search);
180 $start = $length * -1;
181
182 return (substr($string, $start) === $search);
183 }
184
193 public static function random($length = 32, $withNumeric = true)
194 {
195 $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
196 if ($withNumeric) {
197 $characters .= '0123456789';
198 }
199
200 $randomString = '';
201 for ($i = 0; $i < $length; $i++) {
202 $randomString .= $characters[rand(0, strlen($characters) - 1)];
203 }
204
205 return $randomString;
206 }
207
216 public static function clearFolders($paths, $exclude = array())
217 {
218 $result = array();
219 foreach ($paths as $path) {
220 $result[$path] = self::clearFolder($path, $exclude);
221 }
222
223 return $result;
224 }
225
234 public static function clearFolder($path, $exclude = array())
235 {
236 $result = array();
237 $result['return'] = true;
238 $result['nb_files'] = 0;
239
240 $handle = @opendir($path);
241 if (!$handle) {
242 return null;
243 }
244
245 while (false !== ($file = readdir($handle))) {
246 if ($file == '.' || $file == '..' || in_array($file, $exclude)) {
247 continue;
248 }
249 if (is_dir($path . '/' . $file)) {
250 $r = self::clearFolder($path . '/' . $file);
251 if (!$r) {
252 $result['return'] = false;
253
254 return $result;
255 }
256 } else {
257 $r = @unlink($path . '/' . $file);
258 if ($r) {
259 $result['nb_files']++;
260 } else {
261 $result['return'] = false;
262
263 return $result;
264 }
265 }
266 }
267
268 closedir($handle);
269
270 return $result;
271 }
272
278 public static function deleteFolder($path)
279 {
280 if (is_dir($path)) {
281 if (substr($path, strlen($path) - 1, 1) != '/') {
282 $path .= '/';
283 }
284 $files = glob($path . '*', GLOB_MARK);
285 foreach ($files as $file) {
286 if (is_dir($file)) {
287 self::deleteFolder($file);
288 } else {
289 unlink($file);
290 }
291 }
292 rmdir($path);
293 }
294 }
295
304 private static function findFile($startPath, $findFile)
305 {
306 $result = false;
307
308 $handle = @opendir($startPath);
309 if (!$handle) {
310 return false;
311 }
312
313 while (false !== ($file = readdir($handle))) {
314 if ($file == '.' || $file == '..') {
315 continue;
316 }
317 if (is_dir($startPath . '/' . $file)) {
318 $result = self::findFile($startPath . '/' . $file, $findFile);
319 if ($result !== false) {
320 break;
321 }
322 } elseif ($file == $findFile) {
323 $result = self::formatUnixPath($startPath . '/' . $file);
324 break;
325 }
326 }
327
328 closedir($handle);
329
330 return $result;
331 }
332
340 public static function isValidIp($ip)
341 {
342 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)
343 || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
344 }
345
353 public static function isValidPort($port)
354 {
355 return is_numeric($port) && ($port > 0 && $port <= 65535);
356 }
357
365 public static function replaceDefine($path, $var, $value)
366 {
367 self::replaceInFile($path, array(
368 '/^define\‍((.*?)' . $var . '(.*?),/' => 'define(\'' . $var . '\', ' . (is_int($value) ? $value : '\'' . $value . '\'') . ');'
369 ));
370 }
371
378 public static function replaceInFile($path, $replaceList)
379 {
380 if (file_exists($path)) {
381 $lines = file($path);
382 $fp = fopen($path, 'w');
383 foreach ($lines as $nb => $line) {
384 $replaceDone = false;
385 foreach ($replaceList as $regex => $replace) {
386 if (preg_match($regex, $line, $matches)) {
387 $countParams = preg_match_all('/{{(\d+)}}/', $replace, $paramsMatches);
388 if ($countParams > 0 && $countParams <= count($matches)) {
389 foreach ($paramsMatches[1] as $paramsMatch) {
390 $replace = str_replace('{{' . $paramsMatch . '}}', $matches[$paramsMatch], $replace);
391 }
392 }
393 self::logTrace('Replace in file ' . $path . ' :');
394 self::logTrace('## line_num: ' . trim($nb));
395 self::logTrace('## old: ' . trim($line));
396 self::logTrace('## new: ' . trim($replace));
397 fwrite($fp, $replace . PHP_EOL);
398
399 $replaceDone = true;
400 break;
401 }
402 }
403 if (!$replaceDone) {
404 fwrite($fp, $line);
405 }
406 }
407 fclose($fp);
408 }
409 }
410
418 public static function getVersionList($path)
419 {
420 $result = array();
421
422 $handle = @opendir($path);
423 if (!$handle) {
424 return false;
425 }
426
427 while (false !== ($file = readdir($handle))) {
428 $filePath = $path . '/' . $file;
429 if ($file != '.' && $file != '..' && is_dir($filePath) && $file != 'current') {
430 $result[] = str_replace(basename($path), '', $file);
431 }
432 }
433
434 closedir($handle);
435 natcasesort($result);
436
437 return $result;
438 }
439
445 public static function getMicrotime()
446 {
447 list($usec, $sec) = explode(' ', microtime());
448
449 return ((float)$usec + (float)$sec);
450 }
451
452 public static function getAppBinsRegKey($fromRegistry = true)
453 {
454 global $bearsamppRegistry;
455
456 if ($fromRegistry) {
457 $value = $bearsamppRegistry->getValue(
461 );
462 self::logDebug('App reg key from registry: ' . $value);
463 } else {
464 global $bearsamppBins, $bearsamppTools;
465 $value = '';
466 if ($bearsamppBins->getApache()->isEnable()) {
467 $value .= $bearsamppBins->getApache()->getSymlinkPath() . '/bin;';
468 }
469 if ($bearsamppBins->getPhp()->isEnable()) {
470 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . ';';
471 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/pear;';
472 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/deps;';
473 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/imagick;';
474 }
475 if ($bearsamppBins->getNodejs()->isEnable()) {
476 $value .= $bearsamppBins->getNodejs()->getSymlinkPath() . ';';
477 }
478 if ($bearsamppTools->getComposer()->isEnable()) {
479 $value .= $bearsamppTools->getComposer()->getSymlinkPath() . ';';
480 $value .= $bearsamppTools->getComposer()->getSymlinkPath() . '/vendor/bin;';
481 }
482 if ($bearsamppTools->getGhostscript()->isEnable()) {
483 $value .= $bearsamppTools->getGhostscript()->getSymlinkPath() . '/bin;';
484 }
485 if ($bearsamppTools->getGit()->isEnable()) {
486 $value .= $bearsamppTools->getGit()->getSymlinkPath() . '/bin;';
487 }
488 if ($bearsamppTools->getNgrok()->isEnable()) {
489 $value .= $bearsamppTools->getNgrok()->getSymlinkPath() . ';';
490 }
491 if ($bearsamppTools->getPerl()->isEnable()) {
492 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/perl/site/bin;';
493 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/perl/bin;';
494 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/c/bin;';
495 }
496 if ($bearsamppTools->getPython()->isEnable()) {
497 $value .= $bearsamppTools->getPython()->getSymlinkPath() . '/bin;';
498 }
499 if ($bearsamppTools->getRuby()->isEnable()) {
500 $value .= $bearsamppTools->getRuby()->getSymlinkPath() . '/bin;';
501 }
502 $value = self::formatWindowsPath($value);
503 self::logDebug('Generated app bins reg key: ' . $value);
504 }
505
506 return $value;
507 }
508
516 public static function setAppBinsRegKey($value)
517 {
518 global $bearsamppRegistry;
519
520 return $bearsamppRegistry->setStringValue(
524 $value
525 );
526 }
527
533 public static function getAppPathRegKey()
534 {
535 global $bearsamppRegistry;
536
537 return $bearsamppRegistry->getValue(
541 );
542 }
543
551 public static function setAppPathRegKey($value)
552 {
553 global $bearsamppRegistry;
554
555 return $bearsamppRegistry->setStringValue(
559 $value
560 );
561 }
562
568 public static function getSysPathRegKey()
569 {
570 global $bearsamppRegistry;
571
572 return $bearsamppRegistry->getValue(
576 );
577 }
578
586 public static function setSysPathRegKey($value)
587 {
588 global $bearsamppRegistry;
589
590 return $bearsamppRegistry->setExpandStringValue(
594 $value
595 );
596 }
597
603 public static function getProcessorRegKey()
604 {
605 global $bearsamppRegistry;
606
607 return $bearsamppRegistry->getValue(
611 );
612 }
613
619 public static function getStartupLnkPath()
620 {
621 return Vbs::getStartupPath(APP_TITLE . '.lnk');
622 }
623
629 public static function isLaunchStartup()
630 {
631 return file_exists(self::getStartupLnkPath());
632 }
633
639 public static function enableLaunchStartup()
640 {
641 return Vbs::createShortcut(self::getStartupLnkPath());
642 }
643
649 public static function disableLaunchStartup()
650 {
651 $startupLnkPath = self::getStartupLnkPath();
652
653 // Check if file exists before attempting to delete
654 if (file_exists($startupLnkPath)) {
655 return @unlink($startupLnkPath);
656 }
657
658 // Return true if the file doesn't exist (already disabled)
659 return true;
660 }
661
669 private static function log($data, $type, $file = null)
670 {
672 $file = $file == null ? ($type == self::LOG_ERROR ? $bearsamppRoot->getErrorLogFilePath() : $bearsamppRoot->getLogFilePath()) : $file;
673 if (!$bearsamppRoot->isRoot()) {
674 $file = $bearsamppRoot->getHomepageLogFilePath();
675 }
676
677 $verbose = array();
678 $verbose[Config::VERBOSE_SIMPLE] = $type == self::LOG_ERROR || $type == self::LOG_WARNING;
679 $verbose[Config::VERBOSE_REPORT] = $verbose[Config::VERBOSE_SIMPLE] || $type == self::LOG_INFO;
680 $verbose[Config::VERBOSE_DEBUG] = $verbose[Config::VERBOSE_REPORT] || $type == self::LOG_DEBUG;
681 $verbose[Config::VERBOSE_TRACE] = $verbose[Config::VERBOSE_DEBUG] || $type == self::LOG_TRACE;
682
683 $writeLog = false;
684 if ($bearsamppConfig->getLogsVerbose() == Config::VERBOSE_SIMPLE && $verbose[Config::VERBOSE_SIMPLE]) {
685 $writeLog = true;
686 } elseif ($bearsamppConfig->getLogsVerbose() == Config::VERBOSE_REPORT && $verbose[Config::VERBOSE_REPORT]) {
687 $writeLog = true;
688 } elseif ($bearsamppConfig->getLogsVerbose() == Config::VERBOSE_DEBUG && $verbose[Config::VERBOSE_DEBUG]) {
689 $writeLog = true;
690 } elseif ($bearsamppConfig->getLogsVerbose() == Config::VERBOSE_TRACE && $verbose[Config::VERBOSE_TRACE]) {
691 $writeLog = true;
692 }
693
694 if ($writeLog) {
695 file_put_contents(
696 $file,
697 '[' . date('Y-m-d H:i:s', time()) . '] # ' . APP_TITLE . ' ' . $bearsamppCore->getAppVersion() . ' # ' . $type . ': ' . $data . PHP_EOL,
698 FILE_APPEND
699 );
700 }
701 }
702
709 public static function logSeparator()
710 {
711 global $bearsamppRoot;
712
713 $logs = array(
714 $bearsamppRoot->getLogFilePath(),
715 $bearsamppRoot->getErrorLogFilePath(),
716 $bearsamppRoot->getServicesLogFilePath(),
717 $bearsamppRoot->getRegistryLogFilePath(),
718 $bearsamppRoot->getStartupLogFilePath(),
719 $bearsamppRoot->getBatchLogFilePath(),
720 $bearsamppRoot->getVbsLogFilePath(),
721 $bearsamppRoot->getWinbinderLogFilePath(),
722 );
723
724 $separator = '========================================================================================' . PHP_EOL;
725 foreach ($logs as $log) {
726 if (!file_exists($log)) {
727 continue; // Skip to the next iteration if the file does not exist
728 }
729 $logContent = @file_get_contents($log);
730 if ($logContent !== false && !self::endWith($logContent, $separator)) {
731 file_put_contents($log, $separator, FILE_APPEND);
732 }
733 }
734 }
735
743 public static function logTrace($data, $file = null)
744 {
745 self::log($data, self::LOG_TRACE, $file);
746 }
747
755 public static function logDebug($data, $file = null)
756 {
757 self::log($data, self::LOG_DEBUG, $file);
758 }
759
767 public static function logInfo($data, $file = null)
768 {
769 self::log($data, self::LOG_INFO, $file);
770 }
771
779 public static function logWarning($data, $file = null)
780 {
781 self::log($data, self::LOG_WARNING, $file);
782 }
783
791 public static function logError($data, $file = null)
792 {
793 self::log($data, self::LOG_ERROR, $file);
794 }
795
801 public static function logInitClass($classInstance)
802 {
803 self::logTrace('Init ' . get_class($classInstance));
804 }
805
811 public static function logReloadClass($classInstance)
812 {
813 self::logTrace('Reload ' . get_class($classInstance));
814 }
815
821 public static function getPowerShellPath()
822 {
823 if (is_dir('C:\Windows\System32\WindowsPowerShell')) {
824 return self::findFile('C:\Windows\System32\WindowsPowerShell', 'powershell.exe');
825 }
826
827 return false;
828 }
829
840 public static function findRepos($initPath, $startPath, $checkFile, $maxDepth = 1)
841 {
842 $depth = substr_count(str_replace($initPath, '', $startPath), '/');
843 $result = array();
844
845 $handle = @opendir($startPath);
846 if (!$handle) {
847 return $result;
848 }
849
850 while (false !== ($file = readdir($handle))) {
851 if ($file == '.' || $file == '..') {
852 continue;
853 }
854 if (is_dir($startPath . '/' . $file) && ($initPath == $startPath || $depth <= $maxDepth)) {
855 $tmpResults = self::findRepos($initPath, $startPath . '/' . $file, $checkFile, $maxDepth);
856 foreach ($tmpResults as $tmpResult) {
857 $result[] = $tmpResult;
858 }
859 } elseif (is_file($startPath . '/' . $checkFile) && !in_array($startPath, $result)) {
860 $result[] = self::formatUnixPath($startPath);
861 }
862 }
863
864 closedir($handle);
865
866 return $result;
867 }
868
876 public static function formatWindowsPath($path)
877 {
878 return str_replace('/', '\\', $path);
879 }
880
888 public static function formatUnixPath($path)
889 {
890 return str_replace('\\', '/', $path);
891 }
892
900 public static function imgToBase64($path)
901 {
902 $type = pathinfo($path, PATHINFO_EXTENSION);
903 $data = file_get_contents($path);
904
905 return 'data:image/' . $type . ';base64,' . base64_encode($data);
906 }
907
915 public static function utf8ToCp1252($data)
916 {
917 return iconv('UTF-8', 'WINDOWS-1252//IGNORE', $data);
918 }
919
927 public static function cp1252ToUtf8($data)
928 {
929 return iconv('WINDOWS-1252', 'UTF-8//IGNORE', $data);
930 }
931
935 public static function startLoading()
936 {
937 global $bearsamppCore, $bearsamppWinbinder;
938 $bearsamppWinbinder->exec($bearsamppCore->getPhpExe(), Core::isRoot_FILE . ' ' . Action::LOADING);
939 }
940
944 public static function stopLoading()
945 {
946 global $bearsamppCore;
947 if (file_exists($bearsamppCore->getLoadingPid())) {
948 $pids = file($bearsamppCore->getLoadingPid());
949 foreach ($pids as $pid) {
950 Win32Ps::kill($pid);
951 }
952 @unlink($bearsamppCore->getLoadingPid());
953 }
954 }
955
963 public static function getFilesToScan($path = null)
964 {
965 $result = array();
966 $pathsToScan = !empty($path) ? $path : self::getPathsToScan();
967 foreach ($pathsToScan as $pathToScan) {
968 $startTime = self::getMicrotime();
969 $findFiles = self::findFiles($pathToScan['path'], $pathToScan['includes'], $pathToScan['recursive']);
970 foreach ($findFiles as $findFile) {
971 $result[] = $findFile;
972 }
973 self::logDebug($pathToScan['path'] . ' scanned in ' . round(self::getMicrotime() - $startTime, 3) . 's');
974 }
975
976 return $result;
977 }
978
1003 private static function getPathsToScan()
1004 {
1005 global $bearsamppRoot, $bearsamppCore, $bearsamppBins, $bearsamppApps, $bearsamppTools;
1006 $paths = array();
1007
1008 // Alias
1009 $paths[] = array(
1010 'path' => $bearsamppRoot->getAliasPath(),
1011 'includes' => array(''),
1012 'recursive' => false
1013 );
1014
1015 // Vhosts
1016 $paths[] = array(
1017 'path' => $bearsamppRoot->getVhostsPath(),
1018 'includes' => array(''),
1019 'recursive' => false
1020 );
1021
1022 // OpenSSL
1023 $paths[] = array(
1024 'path' => $bearsamppCore->getOpenSslPath(),
1025 'includes' => array('openssl.cfg'),
1026 'recursive' => false
1027 );
1028
1029 // Homepage
1030 $paths[] = array(
1031 'path' => $bearsamppCore->getResourcesPath() . '/homepage',
1032 'includes' => array('alias.conf'),
1033 'recursive' => false
1034 );
1035
1036 // Apache
1037 $folderList = self::getFolderList($bearsamppBins->getApache()->getRootPath());
1038 foreach ($folderList as $folder) {
1039 $paths[] = array(
1040 'path' => $bearsamppBins->getApache()->getRootPath() . '/' . $folder,
1041 'includes' => array('.ini', '.conf'),
1042 'recursive' => true
1043 );
1044 }
1045
1046 // PHP
1047 $folderList = self::getFolderList($bearsamppBins->getPhp()->getRootPath());
1048 foreach ($folderList as $folder) {
1049 $paths[] = array(
1050 'path' => $bearsamppBins->getPhp()->getRootPath() . '/' . $folder,
1051 'includes' => array('.php', '.bat', '.ini', '.reg', '.inc'),
1052 'recursive' => true
1053 );
1054 }
1055
1056 // MySQL
1057 $folderList = self::getFolderList($bearsamppBins->getMysql()->getRootPath());
1058 foreach ($folderList as $folder) {
1059 $paths[] = array(
1060 'path' => $bearsamppBins->getMysql()->getRootPath() . '/' . $folder,
1061 'includes' => array('my.ini'),
1062 'recursive' => false
1063 );
1064 }
1065
1066 // MariaDB
1067 $folderList = self::getFolderList($bearsamppBins->getMariadb()->getRootPath());
1068 foreach ($folderList as $folder) {
1069 $paths[] = array(
1070 'path' => $bearsamppBins->getMariadb()->getRootPath() . '/' . $folder,
1071 'includes' => array('my.ini'),
1072 'recursive' => false
1073 );
1074 }
1075
1076 // PostgreSQL
1077 $folderList = self::getFolderList($bearsamppBins->getPostgresql()->getRootPath());
1078 foreach ($folderList as $folder) {
1079 $paths[] = array(
1080 'path' => $bearsamppBins->getPostgresql()->getRootPath() . '/' . $folder,
1081 'includes' => array('.ber', '.conf', '.bat'),
1082 'recursive' => true
1083 );
1084 }
1085
1086 // Node.js
1087 $folderList = self::getFolderList($bearsamppBins->getNodejs()->getRootPath());
1088 foreach ($folderList as $folder) {
1089 $paths[] = array(
1090 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/etc',
1091 'includes' => array('npmrc'),
1092 'recursive' => true
1093 );
1094 $paths[] = array(
1095 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/node_modules/npm',
1096 'includes' => array('npmrc'),
1097 'recursive' => false
1098 );
1099 }
1100
1101 // Composer
1102 $folderList = self::getFolderList($bearsamppTools->getComposer()->getRootPath());
1103 foreach ($folderList as $folder) {
1104 $paths[] = array(
1105 'path' => $bearsamppTools->getComposer()->getRootPath() . '/' . $folder,
1106 'includes' => array('giscus.json'),
1107 'recursive' => false
1108 );
1109 }
1110
1111 // ConsoleZ
1112 $folderList = self::getFolderList($bearsamppTools->getConsoleZ()->getRootPath());
1113 foreach ($folderList as $folder) {
1114 $paths[] = array(
1115 'path' => $bearsamppTools->getConsoleZ()->getRootPath() . '/' . $folder,
1116 'includes' => array('console.xml', '.ini', '.btm'),
1117 'recursive' => true
1118 );
1119 }
1120
1121 // Python
1122 $folderList = self::getFolderList($bearsamppTools->getPython()->getRootPath());
1123 foreach ($folderList as $folder) {
1124 $paths[] = array(
1125 'path' => $bearsamppTools->getPython()->getRootPath() . '/' . $folder . '/bin',
1126 'includes' => array('.bat'),
1127 'recursive' => false
1128 );
1129 $paths[] = array(
1130 'path' => $bearsamppTools->getPython()->getRootPath() . '/' . $folder . '/settings',
1131 'includes' => array('winpython.ini'),
1132 'recursive' => false
1133 );
1134 }
1135
1136 // Ruby
1137 $folderList = self::getFolderList($bearsamppTools->getRuby()->getRootPath());
1138 foreach ($folderList as $folder) {
1139 $paths[] = array(
1140 'path' => $bearsamppTools->getRuby()->getRootPath() . '/' . $folder . '/bin',
1141 'includes' => array('!.dll', '!.exe'),
1142 'recursive' => false
1143 );
1144 }
1145
1146 return $paths;
1147 }
1148
1158 private static function findFiles($startPath, $includes = array(''), $recursive = true)
1159 {
1160 $result = array();
1161
1162 $handle = @opendir($startPath);
1163 if (!$handle) {
1164 return $result;
1165 }
1166
1167 while (false !== ($file = readdir($handle))) {
1168 if ($file == '.' || $file == '..') {
1169 continue;
1170 }
1171 if (is_dir($startPath . '/' . $file) && $recursive) {
1172 $tmpResults = self::findFiles($startPath . '/' . $file, $includes);
1173 foreach ($tmpResults as $tmpResult) {
1174 $result[] = $tmpResult;
1175 }
1176 } elseif (is_file($startPath . '/' . $file)) {
1177 foreach ($includes as $include) {
1178 if (self::startWith($include, '!')) {
1179 $include = ltrim($include, '!');
1180 if (self::startWith($file, '.') && !self::endWith($file, $include)) {
1181 $result[] = self::formatUnixPath($startPath . '/' . $file);
1182 } elseif ($file != $include) {
1183 $result[] = self::formatUnixPath($startPath . '/' . $file);
1184 }
1185 } elseif (self::endWith($file, $include) || $file == $include || empty($include)) {
1186 $result[] = self::formatUnixPath($startPath . '/' . $file);
1187 }
1188 }
1189 }
1190 }
1191
1192 closedir($handle);
1193
1194 return $result;
1195 }
1196
1205 public static function changePath($filesToScan, $rootPath = null)
1206 {
1208
1209 $result = array(
1210 'countChangedOcc' => 0,
1211 'countChangedFiles' => 0
1212 );
1213
1214 $rootPath = $rootPath != null ? $rootPath : $bearsamppRoot->getRootPath();
1215 $unixOldPath = self::formatUnixPath($bearsamppCore->getLastPathContent());
1216 $windowsOldPath = self::formatWindowsPath($bearsamppCore->getLastPathContent());
1217 $unixCurrentPath = self::formatUnixPath($rootPath);
1218 $windowsCurrentPath = self::formatWindowsPath($rootPath);
1219
1220 foreach ($filesToScan as $fileToScan) {
1221 $tmpCountChangedOcc = 0;
1222 $fileContentOr = file_get_contents($fileToScan);
1223 $fileContent = $fileContentOr;
1224
1225 // old path
1226 preg_match('#' . $unixOldPath . '#i', $fileContent, $unixMatches);
1227 if (!empty($unixMatches)) {
1228 $fileContent = str_replace($unixOldPath, $unixCurrentPath, $fileContent, $countChanged);
1229 $tmpCountChangedOcc += $countChanged;
1230 }
1231 preg_match('#' . str_replace('\\', '\\\\', $windowsOldPath) . '#i', $fileContent, $windowsMatches);
1232 if (!empty($windowsMatches)) {
1233 $fileContent = str_replace($windowsOldPath, $windowsCurrentPath, $fileContent, $countChanged);
1234 $tmpCountChangedOcc += $countChanged;
1235 }
1236
1237 // placeholders
1238 preg_match('#' . Core::PATH_LIN_PLACEHOLDER . '#i', $fileContent, $unixMatches);
1239 if (!empty($unixMatches)) {
1240 $fileContent = str_replace(Core::PATH_LIN_PLACEHOLDER, $unixCurrentPath, $fileContent, $countChanged);
1241 $tmpCountChangedOcc += $countChanged;
1242 }
1243 preg_match('#' . Core::PATH_WIN_PLACEHOLDER . '#i', $fileContent, $windowsMatches);
1244 if (!empty($windowsMatches)) {
1245 $fileContent = str_replace(Core::PATH_WIN_PLACEHOLDER, $windowsCurrentPath, $fileContent, $countChanged);
1246 $tmpCountChangedOcc += $countChanged;
1247 }
1248
1249 if ($fileContentOr != $fileContent) {
1250 $result['countChangedOcc'] += $tmpCountChangedOcc;
1251 $result['countChangedFiles'] += 1;
1252 file_put_contents($fileToScan, $fileContent);
1253 }
1254 }
1255
1256 return $result;
1257 }
1258
1266 public static function getLatestVersion($url)
1267 {
1268 $result = self::getApiJson($url);
1269 if (empty($result)) {
1270 self::logError('Cannot retrieve latest github info for: ' . $result . ' RESULT');
1271
1272 return null;
1273 }
1274
1275 $resultArray = json_decode($result, true);
1276 if (isset($resultArray['tag_name']) && isset($resultArray['assets'][0]['browser_download_url'])) {
1277 $tagName = $resultArray['tag_name'];
1278 $downloadUrl = $resultArray['assets'][0]['browser_download_url'];
1279 $name = $resultArray['name'];
1280 self::logDebug('Latest version tag name: ' . $tagName);
1281 self::logDebug('Download URL: ' . $downloadUrl);
1282 self::logDebug('Name: ' . $name);
1283
1284 return ['version' => $tagName, 'html_url' => $downloadUrl, 'name' => $name];
1285 } else {
1286 self::logError('Tag name, download URL, or name not found in the response: ' . $result);
1287
1288 return null;
1289 }
1290 }
1291
1300 public static function getWebsiteUrlNoUtm($path = '', $fragment = '')
1301 {
1302 return self::getWebsiteUrl($path, $fragment, false);
1303 }
1304
1314 public static function getWebsiteUrl($path = '', $fragment = '', $utmSource = true)
1315 {
1316 global $bearsamppCore;
1317
1318 $url = APP_WEBSITE;
1319 if (!empty($path)) {
1320 $url .= '/' . ltrim($path, '/');
1321 }
1322 if ($utmSource) {
1323 $url = rtrim($url, '/') . '/?utm_source=bearsampp-' . $bearsamppCore->getAppVersion();
1324 }
1325 if (!empty($fragment)) {
1326 $url .= $fragment;
1327 }
1328
1329 return $url;
1330 }
1331
1339 public static function getChangelogUrl($utmSource = true)
1340 {
1341 return self::getWebsiteUrl('doc/changelog', null, $utmSource);
1342 }
1343
1352 public static function getRemoteFilesize($url, $humanFileSize = true)
1353 {
1354 $size = 0;
1355
1356 $data = get_headers($url, true);
1357 if (isset($data['Content-Length'])) {
1358 $size = intval($data['Content-Length']);
1359 }
1360
1361 return $humanFileSize ? self::humanFileSize($size) : $size;
1362 }
1363
1372 public static function humanFileSize($size, $unit = '')
1373 {
1374 if ((!$unit && $size >= 1 << 30) || $unit == 'GB') {
1375 return number_format($size / (1 << 30), 2) . 'GB';
1376 }
1377 if ((!$unit && $size >= 1 << 20) || $unit == 'MB') {
1378 return number_format($size / (1 << 20), 2) . 'MB';
1379 }
1380 if ((!$unit && $size >= 1 << 10) || $unit == 'KB') {
1381 return number_format($size / (1 << 10), 2) . 'KB';
1382 }
1383
1384 return number_format($size) . ' bytes';
1385 }
1386
1392 public static function is32BitsOs()
1393 {
1394 $processor = self::getProcessorRegKey();
1395
1396 return self::contains($processor, 'x86');
1397 }
1398
1406 public static function getHttpHeaders($pingUrl)
1407 {
1408 if (function_exists('curl_version')) {
1410 } else {
1412 }
1413
1414 if (!empty($result)) {
1415 $rebuildResult = array();
1416 foreach ($result as $row) {
1417 $row = trim($row);
1418 if (!empty($row)) {
1419 $rebuildResult[] = $row;
1420 }
1421 }
1422 $result = $rebuildResult;
1423
1424 self::logDebug('getHttpHeaders:');
1425 foreach ($result as $header) {
1426 self::logDebug('-> ' . $header);
1427 }
1428 }
1429
1430 return $result;
1431 }
1432
1444 public static function getFopenHttpHeaders($url)
1445 {
1446 $result = array();
1447
1448 $context = stream_context_create(array(
1449 'ssl' => array(
1450 'verify_peer' => false,
1451 'verify_peer_name' => false,
1452 'allow_self_signed' => true,
1453 )
1454 ));
1455
1456 $fp = @fopen($url, 'r', false, $context);
1457 if ($fp) {
1458 $meta = stream_get_meta_data($fp);
1459 $result = isset($meta['wrapper_data']) ? $meta['wrapper_data'] : $result;
1460 fclose($fp);
1461 }
1462
1463 return $result;
1464 }
1465
1477 public static function getCurlHttpHeaders($url)
1478 {
1479 $result = array();
1480
1481 $ch = curl_init();
1482 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1483 curl_setopt($ch, CURLOPT_VERBOSE, true);
1484 curl_setopt($ch, CURLOPT_HEADER, true);
1485 curl_setopt($ch, CURLOPT_URL, $url);
1486 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1487
1488 $response = @curl_exec($ch);
1489 if (empty($response)) {
1490 return $result;
1491 }
1492
1493 self::logTrace('getCurlHttpHeaders:' . $response);
1494 $responseHeaders = explode("\r\n\r\n", $response, 2);
1495 if (!isset($responseHeaders[0]) || empty($responseHeaders[0])) {
1496 return $result;
1497 }
1498
1499 return explode("\n", $responseHeaders[0]);
1500 }
1501
1515 public static function getHeaders($host, $port, $ssl = false)
1516 {
1517 $result = array();
1518 $context = stream_context_create(array(
1519 'ssl' => array(
1520 'verify_peer' => false,
1521 'verify_peer_name' => false,
1522 'allow_self_signed' => true,
1523 )
1524 ));
1525
1526 $fp = @stream_socket_client(($ssl ? 'ssl://' : '') . $host . ':' . $port, $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context);
1527 if ($fp) {
1528 $out = fgets($fp);
1529 $result = explode(PHP_EOL, $out);
1530 @fclose($fp);
1531 }
1532
1533 if (!empty($result)) {
1534 $rebuildResult = array();
1535 foreach ($result as $row) {
1536 $row = trim($row);
1537 if (!empty($row)) {
1538 $rebuildResult[] = $row;
1539 }
1540 }
1541 $result = $rebuildResult;
1542
1543 self::logDebug('getHeaders:');
1544 foreach ($result as $header) {
1545 self::logDebug('-> ' . $header);
1546 }
1547 }
1548
1549 return $result;
1550 }
1551
1559 public static function getApiJson($url)
1560 {
1562
1563 $ch = curl_init();
1564 curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
1565 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1566 curl_setopt($ch, CURLOPT_VERBOSE, true);
1567 curl_setopt($ch, CURLOPT_URL, $url);
1568 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1569 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
1570 $data = curl_exec($ch);
1571 if (curl_errno($ch)) {
1572 Util::logError('CURL Error: ' . curl_error($ch));
1573 }
1574 curl_close($ch);
1575
1576 return trim($data);
1577 }
1578
1586 public static function isPortInUse($port)
1587 {
1588 // Set localIP statically
1589 $localIP = '127.0.0.1';
1590
1591 // Save current error reporting level
1592 $errorReporting = error_reporting();
1593
1594 // Disable error reporting temporarily
1595 error_reporting(0);
1596
1597 $connection = @fsockopen($localIP, $port);
1598
1599 // Restore original error reporting level
1600 error_reporting($errorReporting);
1601
1602 if (is_resource($connection)) {
1603 fclose($connection);
1605
1606 return $process != null ? $process : 'N/A';
1607 }
1608
1609 return false;
1610 }
1611
1619 public static function isValidDomainName($domainName)
1620 {
1621 return preg_match('/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i', $domainName)
1622 && preg_match('/^.{1,253}$/', $domainName)
1623 && preg_match('/^[^\.]{1,63}(\.[^\.]{1,63})*$/', $domainName);
1624 }
1625
1633 public static function isAlphanumeric($string)
1634 {
1635 return ctype_alnum($string);
1636 }
1637
1648 public static function installService($bin, $port, $syntaxCheckCmd, $showWindow = false)
1649 {
1650 global $bearsamppLang, $bearsamppWinbinder;
1651 $name = $bin->getName();
1652 $service = $bin->getService();
1653 $boxTitle = sprintf($bearsamppLang->getValue(Lang::INSTALL_SERVICE_TITLE), $name);
1654
1655 $isPortInUse = self::isPortInUse($port);
1656 if ($isPortInUse === false) {
1657 if (!$service->isInstalled()) {
1658 $service->create();
1659 if ($service->start()) {
1660 self::logInfo(sprintf('%s service successfully installed. (name: %s ; port: %s)', $name, $service->getName(), $port));
1661 if ($showWindow) {
1662 $bearsamppWinbinder->messageBoxInfo(
1663 sprintf($bearsamppLang->getValue(Lang::SERVICE_INSTALLED), $name, $service->getName(), $port),
1664 $boxTitle
1665 );
1666 }
1667
1668 return true;
1669 } else {
1670 $serviceError = sprintf($bearsamppLang->getValue(Lang::SERVICE_INSTALL_ERROR), $name);
1671 $serviceErrorLog = sprintf('Error during the installation of %s service', $name);
1672 if (!empty($syntaxCheckCmd)) {
1673 $cmdSyntaxCheck = $bin->getCmdLineOutput($syntaxCheckCmd);
1674 if (!$cmdSyntaxCheck['syntaxOk']) {
1675 $serviceError .= PHP_EOL . sprintf($bearsamppLang->getValue(Lang::STARTUP_SERVICE_SYNTAX_ERROR), $cmdSyntaxCheck['content']);
1676 $serviceErrorLog .= sprintf(' (conf errors detected : %s)', $cmdSyntaxCheck['content']);
1677 }
1678 }
1679 self::logError($serviceErrorLog);
1680 if ($showWindow) {
1681 $bearsamppWinbinder->messageBoxError($serviceError, $boxTitle);
1682 }
1683 }
1684 } else {
1685 self::logWarning(sprintf('%s service already installed', $name));
1686 if ($showWindow) {
1687 $bearsamppWinbinder->messageBoxWarning(
1688 sprintf($bearsamppLang->getValue(Lang::SERVICE_ALREADY_INSTALLED), $name),
1689 $boxTitle
1690 );
1691 }
1692
1693 return true;
1694 }
1695 } elseif ($service->isRunning()) {
1696 self::logWarning(sprintf('%s service already installed and running', $name));
1697 if ($showWindow) {
1698 $bearsamppWinbinder->messageBoxWarning(
1699 sprintf($bearsamppLang->getValue(Lang::SERVICE_ALREADY_INSTALLED), $name),
1700 $boxTitle
1701 );
1702 }
1703
1704 return true;
1705 } else {
1706 self::logError(sprintf('Port %s is used by an other application : %s', $name));
1707 if ($showWindow) {
1708 $bearsamppWinbinder->messageBoxError(
1709 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED_BY), $port, $isPortInUse),
1710 $boxTitle
1711 );
1712 }
1713 }
1714
1715 return false;
1716 }
1717
1726 public static function removeService($service, $name)
1727 {
1728 if (!($service instanceof Win32Service)) {
1729 self::logError('$service not an instance of Win32Service');
1730
1731 return false;
1732 }
1733
1734 if ($service->isInstalled()) {
1735 if ($service->delete()) {
1736 self::logInfo(sprintf('%s service successfully removed', $name));
1737
1738 return true;
1739 } else {
1740 self::logError(sprintf('Error during the uninstallation of %s service', $name));
1741
1742 return false;
1743 }
1744 } else {
1745 self::logWarning(sprintf('%s service does not exist', $name));
1746 }
1747
1748 return true;
1749 }
1750
1760 public static function startService($bin, $syntaxCheckCmd, $showWindow = false)
1761 {
1762 global $bearsamppLang, $bearsamppWinbinder;
1763 $name = $bin->getName();
1764 $service = $bin->getService();
1765 $boxTitle = sprintf($bearsamppLang->getValue(Lang::START_SERVICE_TITLE), $name);
1766
1767 if (!$service->start()) {
1768 $serviceError = sprintf($bearsamppLang->getValue(Lang::START_SERVICE_ERROR), $name);
1769 $serviceErrorLog = sprintf('Error while starting the %s service', $name);
1770 if (!empty($syntaxCheckCmd)) {
1771 $cmdSyntaxCheck = $bin->getCmdLineOutput($syntaxCheckCmd);
1772 if (!$cmdSyntaxCheck['syntaxOk']) {
1773 $serviceError .= PHP_EOL . sprintf($bearsamppLang->getValue(Lang::STARTUP_SERVICE_SYNTAX_ERROR), $cmdSyntaxCheck['content']);
1774 $serviceErrorLog .= sprintf(' (conf errors detected : %s)', $cmdSyntaxCheck['content']);
1775 }
1776 }
1777 self::logError($serviceErrorLog);
1778 if ($showWindow) {
1779 $bearsamppWinbinder->messageBoxError($serviceError, $boxTitle);
1780 }
1781
1782 return false;
1783 }
1784
1785 return true;
1786 }
1787
1795 public static function getGithubUserUrl($part = null)
1796 {
1797 $part = !empty($part) ? '/' . $part : null;
1798
1799 return 'https://github.com/' . APP_GITHUB_USER . $part;
1800 }
1801
1809 public static function getGithubUrl($part = null)
1810 {
1811 $part = !empty($part) ? '/' . $part : null;
1812
1814 }
1815
1823 public static function getGithubRawUrl($file)
1824 {
1825 $file = !empty($file) ? '/' . $file : null;
1826
1827 return 'https://raw.githubusercontent.com/' . APP_GITHUB_USER . '/' . APP_GITHUB_REPO . '/main' . $file;
1828 }
1829
1837 public static function getFolderList($path)
1838 {
1839 $result = array();
1840
1841 $handle = @opendir($path);
1842 if (!$handle) {
1843 return false;
1844 }
1845
1846 while (false !== ($file = readdir($handle))) {
1847 $filePath = $path . '/' . $file;
1848 if ($file != '.' && $file != '..' && is_dir($filePath) && $file != 'current') {
1849 $result[] = $file;
1850 }
1851 }
1852
1853 closedir($handle);
1854
1855 return $result;
1856 }
1857
1866 public static function getNssmEnvPaths()
1867 {
1868 global $bearsamppRoot;
1869
1870 $result = '';
1871 $nssmEnvPathsFile = $bearsamppRoot->getRootPath() . '/nssmEnvPaths.dat';
1872
1873 if (is_file($nssmEnvPathsFile)) {
1874 $paths = explode(PHP_EOL, file_get_contents($nssmEnvPathsFile));
1875 foreach ($paths as $path) {
1876 $path = trim($path);
1877 if (stripos($path, ':') === false) {
1878 $path = $bearsamppRoot->getRootPath() . '/' . $path;
1879 }
1880 if (is_dir($path)) {
1881 $result .= self::formatUnixPath($path) . ';';
1882 } else {
1883 self::logWarning('Path not found in nssmEnvPaths.dat: ' . $path);
1884 }
1885 }
1886 }
1887
1888 return $result;
1889 }
1890
1902 public static function openFileContent($caption, $content)
1903 {
1904 global $bearsamppRoot, $bearsamppConfig, $bearsamppWinbinder;
1905
1906 $folderPath = $bearsamppRoot->getTmpPath() . '/openFileContent-' . self::random();
1907 if (!is_dir($folderPath)) {
1908 mkdir($folderPath, 0777, true);
1909 }
1910
1911 $filepath = self::formatWindowsPath($folderPath . '/' . $caption);
1912 file_put_contents($filepath, $content);
1913
1914 $bearsamppWinbinder->exec($bearsamppConfig->getNotepad(), '"' . $filepath . '"');
1915 }
1916
1922 public static function decryptFile()
1923 {
1925
1926 $stringfile = $bearsamppCore->getResourcesPath() . '/string.dat';
1927 $encryptedFile = $bearsamppCore->getResourcesPath() . '/github.dat';
1928 $method = 'AES-256-CBC'; // The same encryption method used
1929
1930 // Get key string
1931 $stringPhrase = @file_get_contents($stringfile);
1932 if ($stringPhrase === false) {
1933 Util::logDebug("Failed to read the file at path: {$stringfile}");
1934
1935 return false;
1936 }
1937
1938 $stringKey = convert_uudecode($stringPhrase);
1939
1940 // Read the encrypted data from the file
1941 $encryptedData = file_get_contents($encryptedFile);
1942 if ($encryptedData === false) {
1943 Util::logDebug("Failed to read the file at path: {$encryptedFile}");
1944
1945 return false;
1946 }
1947
1948 // Decode the base64 encoded data
1949 $data = base64_decode($encryptedData);
1950 if ($data === false) {
1951 Util::logDebug("Failed to decode the data from path: {$encryptedFile}");
1952
1953 return false;
1954 }
1955
1956 // Extract the IV which was prepended to the encrypted data
1957 $ivLength = openssl_cipher_iv_length($method);
1958 $iv = substr($data, 0, $ivLength);
1959 $encrypted = substr($data, $ivLength);
1960
1961 // Decrypt the data
1962 $decrypted = openssl_decrypt($encrypted, $method, $stringKey, 0, $iv);
1963 if ($decrypted === false) {
1964 Util::logDebug("Decryption failed for data from path: {$encryptedFile}");
1965
1966 return false;
1967 }
1968
1969 return $decrypted;
1970 }
1971
1977 public static function setupCurlHeaderWithToken()
1978 {
1979 // Usage
1981 $Token = self::decryptFile();
1982
1983 return [
1984 'Accept: application/vnd.github+json',
1985 'Authorization: Token ' . $Token,
1986 'User-Agent: ' . APP_GITHUB_USERAGENT,
1987 'X-GitHub-Api-Version: 2022-11-28'
1988 ];
1989 }
1990
1999 public static function checkInternetState()
2000 {
2001 $connected = @fsockopen('www.google.com', 80);
2002 if ($connected) {
2003 fclose($connected);
2004
2005 return true; // Internet connection is active
2006 } else {
2007 return false; // Internet connection is not active
2008 }
2009 }
2010}
$result
global $bearsamppBins
global $bearsamppLang
global $bearsamppRoot
$port
global $bearsamppCore
$response
const LOADING
static getProcessUsingPort($port)
const VERBOSE_REPORT
const VERBOSE_SIMPLE
const VERBOSE_TRACE
const VERBOSE_DEBUG
const isRoot_FILE
const PATH_LIN_PLACEHOLDER
const PATH_WIN_PLACEHOLDER
const START_SERVICE_ERROR
const START_SERVICE_TITLE
const SERVICE_INSTALLED
const INSTALL_SERVICE_TITLE
const STARTUP_SERVICE_SYNTAX_ERROR
const SERVICE_INSTALL_ERROR
const SERVICE_ALREADY_INSTALLED
const PORT_NOT_USED_BY
const SYSPATH_REG_ENTRY
const PROCESSOR_REG_SUBKEY
const HKEY_LOCAL_MACHINE
const PROCESSOR_REG_ENTRY
const APP_PATH_REG_ENTRY
const APP_BINS_REG_ENTRY
static logError($data, $file=null)
static findRepos($initPath, $startPath, $checkFile, $maxDepth=1)
static isLaunchStartup()
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static getWebsiteUrlNoUtm($path='', $fragment='')
static disableLaunchStartup()
static getRemoteFilesize($url, $humanFileSize=true)
static getMicrotime()
static getGithubUrl($part=null)
static deleteFolder($path)
static logInitClass($classInstance)
static getHeaders($host, $port, $ssl=false)
static removeService($service, $name)
static logTrace($data, $file=null)
static isValidPort($port)
static cleanArgv($name, $type='text')
static cp1252ToUtf8($data)
static setAppPathRegKey($value)
static logInfo($data, $file=null)
static imgToBase64($path)
static contains($string, $search)
const LOG_ERROR
static getVersionList($path)
static getHttpHeaders($pingUrl)
static utf8ToCp1252($data)
static isValidDomainName($domainName)
static getLatestVersion($url)
static getFolderList($path)
static getAppBinsRegKey($fromRegistry=true)
static getAppPathRegKey()
static getGithubRawUrl($file)
static getChangelogUrl($utmSource=true)
static getFilesToScan($path=null)
static openFileContent($caption, $content)
static logDebug($data, $file=null)
static isAlphanumeric($string)
static logReloadClass($classInstance)
static logSeparator()
static startWith($string, $search)
static getGithubUserUrl($part=null)
static humanFileSize($size, $unit='')
static getPathsToScan()
const LOG_TRACE
static random($length=32, $withNumeric=true)
static startLoading()
static endWith($string, $search)
static getNssmEnvPaths()
static formatWindowsPath($path)
static changePath($filesToScan, $rootPath=null)
const LOG_INFO
static getWebsiteUrl($path='', $fragment='', $utmSource=true)
static formatUnixPath($path)
static isPortInUse($port)
static cleanGetVar($name, $type='text')
static getApiJson($url)
static decryptFile()
const LOG_DEBUG
static findFiles($startPath, $includes=array(''), $recursive=true)
static replaceDefine($path, $var, $value)
static clearFolder($path, $exclude=array())
static isValidIp($ip)
static setupCurlHeaderWithToken()
static stopLoading()
static is32BitsOs()
static clearFolders($paths, $exclude=array())
static getFopenHttpHeaders($url)
static startService($bin, $syntaxCheckCmd, $showWindow=false)
const LOG_WARNING
static cleanPostVar($name, $type='text')
static findFile($startPath, $findFile)
static getCurlHttpHeaders($url)
static log($data, $type, $file=null)
static enableLaunchStartup()
static getStartupLnkPath()
static setSysPathRegKey($value)
static replaceInFile($path, $replaceList)
static getSysPathRegKey()
static getPowerShellPath()
static getProcessorRegKey()
static checkInternetState()
static setAppBinsRegKey($value)
static logWarning($data, $file=null)
static createShortcut($savePath)
static getStartupPath($file=null)
static kill($pid)
global $bearsamppConfig
Definition homepage.php:27
const APP_GITHUB_USERAGENT
Definition root.php:18
const APP_WEBSITE
Definition root.php:14
const APP_GITHUB_USER
Definition root.php:16
const APP_GITHUB_REPO
Definition root.php:17
const APP_TITLE
Definition root.php:13