Bearsampp 2026.5.5
Loading...
Searching...
No Matches
Util Class Reference

Static Public Member Functions

static changePath ($filesToScan, $rootPath=null)
static clearFileScanCache ()
static clearFolder ($path, $exclude=array())
static clearFolders ($paths, $exclude=array())
static clearLoadingText ()
static convertEncoding ($data, $direction='to_cp1252')
static cp1252ToUtf8 ($data)
static deleteFolder ($path)
static disableLaunchStartup ()
static enableLaunchStartup ()
static findRepos ($initPath, $startPath, $checkFile, $maxDepth=1)
static getApiJson ($url)
static getAppBinsRegKey ($fromRegistry=true)
static getAppPathRegKey ()
static getChangelogUrl ($utmSource=true)
static getFileScanCacheDuration ()
static getFileScanStats ()
static getFilesToScan ($path=null, $useCache=true, $forceRefresh=false)
static getFolderList ($path)
static getGithubUrl ($type='user', $user=APP_GITHUB_USER, $repo=null, $branch=null, $path=null)
static getGithubUserUrl ()
static getHeaders ($host, $port, $ssl=false)
static getLatestVersion ($url)
static getMicrotime ()
static getPowerShellPath ()
static getProcessorRegKey ()
static getRemoteFilesize ($url, $humanFileSize=true)
static getStartupLnkPath ()
static getSysPathRegKey ()
static getVersionList ($path)
static getWebsiteUrl ($path='', $fragment='', $utmSource=true)
static getWebsiteUrlNoUtm ($path='', $fragment='')
static humanFileSize ($size, $unit='')
static imgToBase64 ($path)
static installService ($bin, $port, $syntaxCheckCmd, $showWindow=false)
static is32BitsOs ()
static isAdmin ()
static isLaunchStartup ()
static isPortInUse ($port)
static isValidDomainName ($domainName)
static isValidIp ($ip)
static isValidPort ($port)
static openFileContent ($caption, $content)
static removeService ($service, $name)
static replaceDefine ($path, $var, $value)
static replaceInFile ($path, $replaceList)
static setAppBinsRegKey ($value)
static setAppPathRegKey ($value)
static setFileScanCacheDuration ($seconds)
static setSysPathRegKey ($value)
static startLoading ()
static startService ($bin, $syntaxCheckCmd, $showWindow=false)
static stopLoading ()
static updateLoadingText ($text)
static utf8ToCp1252 ($data)

Static Private Member Functions

static findFile ($startPath, $findFile)
static findFiles ($startPath, $includes=array(''), $recursive=true)
static generateCacheHMAC ($data, $cacheKey)
static getCacheIntegrityKey ()
static getFileScanCache ($cacheKey)
static getPathsToScan ()
static setFileScanCache ($cacheKey, $data)
static verifyCacheIntegrity ($fileContents, $cacheKey)

Static Private Attributes

static $cacheIntegrityKey = null
static $fileScanCache = null
static $fileScanCacheDuration = 3600
static $fileScanStats

Detailed Description

Utility class providing a wide range of static methods for various purposes including:

  • Input cleaning and sanitization have been moved to UtilInput.
    See also
    UtilInput
  • String manipulation methods have been moved to UtilString.
    See also
    UtilString
  • File and directory management functions for deleting, clearing, or finding files and directories.
  • System utilities for handling registry operations, managing environment variables, and executing system commands.
  • Network utilities to validate IPs, domains, and manage HTTP requests.
  • Helper functions for encoding, decoding, and file operations.

Path formatting (formatWindowsPath / formatUnixPath) has been moved to UtilPath.

See also
UtilPath Logging is handled by the Log class.
Log

This class is designed to be used as a helper or utility class where methods are accessed statically. This means you do not need to instantiate it to use the methods, but can simply call them using the Util::methodName() syntax.

Usage Example:

$cleanedData = UtilInput::cleanGetVar('data', 'text');
$isAvailable = Util::isValidIp('192.168.1.1');
static isValidIp($ip)
static cleanGetVar($name, $type='text')

Each method is self-contained and provides specific functionality, making this class a central point for common utility operations needed across a PHP application, especially in environments like web servers or command-line interfaces.

Definition at line 35 of file class.util.php.

Member Function Documentation

◆ changePath()

changePath ( $filesToScan,
$rootPath = null )
static

Replaces old path references with new path references in the specified files.

Parameters
array$filesToScanArray of file paths to scan and modify.
string | null$rootPathThe new root path to replace the old one. If null, uses a default root path.
Returns
array Returns an array with the count of occurrences changed and the count of files changed.

Definition at line 1329 of file class.util.php.

1330 {
1332
1333 $result = array(
1334 'countChangedOcc' => 0,
1335 'countChangedFiles' => 0
1336 );
1337
1338 $rootPath = $rootPath != null ? $rootPath : $bearsamppRoot->getRootPath();
1339 $unixOldPath = UtilPath::formatUnixPath($bearsamppCore->getLastPathContent());
1340 $windowsOldPath = UtilPath::formatWindowsPath($bearsamppCore->getLastPathContent());
1341 $unixCurrentPath = UtilPath::formatUnixPath($rootPath);
1342 $windowsCurrentPath = UtilPath::formatWindowsPath($rootPath);
1343
1344 foreach ($filesToScan as $fileToScan) {
1345 $tmpCountChangedOcc = 0;
1346 $fileContentOr = file_get_contents($fileToScan);
1347 $fileContent = $fileContentOr;
1348
1349 // old path
1350 preg_match('#' . $unixOldPath . '#i', $fileContent, $unixMatches);
1351 if (!empty($unixMatches)) {
1352 $fileContent = str_replace($unixOldPath, $unixCurrentPath, $fileContent, $countChanged);
1353 $tmpCountChangedOcc += $countChanged;
1354 }
1355 preg_match('#' . str_replace('\\', '\\\\', $windowsOldPath) . '#i', $fileContent, $windowsMatches);
1356 if (!empty($windowsMatches)) {
1357 $fileContent = str_replace($windowsOldPath, $windowsCurrentPath, $fileContent, $countChanged);
1358 $tmpCountChangedOcc += $countChanged;
1359 }
1360
1361 // placeholders
1362 preg_match('#' . Core::PATH_LIN_PLACEHOLDER . '#i', $fileContent, $unixMatches);
1363 if (!empty($unixMatches)) {
1364 $fileContent = str_replace(Core::PATH_LIN_PLACEHOLDER, $unixCurrentPath, $fileContent, $countChanged);
1365 $tmpCountChangedOcc += $countChanged;
1366 }
1367 preg_match('#' . Core::PATH_WIN_PLACEHOLDER . '#i', $fileContent, $windowsMatches);
1368 if (!empty($windowsMatches)) {
1369 $fileContent = str_replace(Core::PATH_WIN_PLACEHOLDER, $windowsCurrentPath, $fileContent, $countChanged);
1370 $tmpCountChangedOcc += $countChanged;
1371 }
1372
1373 if ($fileContentOr != $fileContent) {
1374 $result['countChangedOcc'] += $tmpCountChangedOcc;
1375 $result['countChangedFiles'] += 1;
1376 file_put_contents($fileToScan, $fileContent);
1377 }
1378 }
1379
1380 Log::debug('changePath() completed: ' . $result['countChangedFiles'] . ' files changed, ' . $result['countChangedOcc'] . ' total occurrences');
1381
1382 return $result;
1383 }
$result
global $bearsamppRoot
global $bearsamppCore
const PATH_LIN_PLACEHOLDER
const PATH_WIN_PLACEHOLDER
static debug($data, $file=null)
static formatWindowsPath($path)
static formatUnixPath($path)

References $bearsamppCore, $bearsamppRoot, $result, Log\debug(), UtilPath\formatUnixPath(), UtilPath\formatWindowsPath(), Core\PATH_LIN_PLACEHOLDER, and Core\PATH_WIN_PLACEHOLDER.

Referenced by ActionStartup\changePath(), BinPostgresql\initData(), and ActionSwitchVersion\processWindow().

◆ clearFileScanCache()

clearFileScanCache ( )
static

Clears all file scan caches.

Returns
void

Definition at line 1031 of file class.util.php.

1032 {
1033 global $bearsamppRoot;
1034
1035 // Clear memory cache
1036 self::$fileScanCache = null;
1037
1038 // Clear file caches
1039 if (isset($bearsamppRoot)) {
1040 $tmpPath = $bearsamppRoot->getTmpPath();
1041 $cacheFiles = glob($tmpPath . '/filescan_cache_*.dat');
1042
1043 if ($cacheFiles !== false) {
1044 foreach ($cacheFiles as $cacheFile) {
1045 @unlink($cacheFile);
1046 }
1047 Log::info('Cleared ' . count($cacheFiles) . ' file scan cache files');
1048 }
1049 }
1050
1051 // Reset stats
1052 self::$fileScanStats = [
1053 'hits' => 0,
1054 'misses' => 0,
1055 'invalidations' => 0
1056 ];
1057 }
static info($data, $file=null)

References $bearsamppRoot, and Log\info().

◆ clearFolder()

clearFolder ( $path,
$exclude = array() )
static

Recursively clears all files and directories within a specified directory, excluding specified items.

Parameters
string$pathThe path of the directory to clear.
array$excludeAn array of filenames to exclude from deletion.
Returns
array|null Returns an array with the operation status and count of files deleted, or null if the directory cannot be opened.

Definition at line 92 of file class.util.php.

93 {
94 $result = array();
95 $result['return'] = true;
96 $result['nb_files'] = 0;
97
98 $handle = @opendir($path);
99 if (!$handle) {
100 return null;
101 }
102
103 while (false !== ($file = readdir($handle))) {
104 if ($file == '.' || $file == '..' || in_array($file, $exclude)) {
105 continue;
106 }
107 if (is_dir($path . '/' . $file)) {
108 $r = self::clearFolder($path . '/' . $file);
109 if (!$r) {
110 $result['return'] = false;
111
112 return $result;
113 }
114 } else {
115 $r = @unlink($path . '/' . $file);
116 if ($r) {
117 $result['nb_files']++;
118 } else {
119 $result['return'] = false;
120
121 return $result;
122 }
123 }
124 }
125
126 closedir($handle);
127
128 return $result;
129 }
static clearFolder($path, $exclude=array())

References $result, and clearFolder().

Referenced by ActionClearFolders\__construct(), ActionStartup\cleanTmpFolders(), clearFolder(), and clearFolders().

◆ clearFolders()

clearFolders ( $paths,
$exclude = array() )
static

Recursively deletes files from a specified directory while excluding certain files.

Parameters
string$pathThe path to the directory to clear.
array$excludeAn array of filenames to exclude from deletion.
Returns
array Returns an array with the status of the operation and the number of files deleted.

Definition at line 74 of file class.util.php.

75 {
76 $result = array();
77 foreach ($paths as $path) {
78 $result[$path] = self::clearFolder($path, $exclude);
79 }
80
81 return $result;
82 }

References $result, and clearFolder().

◆ clearLoadingText()

clearLoadingText ( )
static

Clears the loading status file

Definition at line 773 of file class.util.php.

774 {
775 global $bearsamppCore;
776
777 $statusFile = $bearsamppCore->getTmpPath() . '/loading_status.txt';
778 if (file_exists($statusFile)) {
779 @unlink($statusFile);
780 }
781 }

References $bearsamppCore.

Referenced by stopLoading().

◆ convertEncoding()

convertEncoding ( $data,
$direction = 'to_cp1252' )
static

Converts data between UTF-8 and Windows-1252 encodings.

Parameters
string$dataThe data to convert.
string$directionThe conversion direction: 'to_cp1252' or 'to_utf8'. Defaults to 'to_cp1252'.
Returns
string The converted data.

Definition at line 684 of file class.util.php.

685 {
686 if ($direction === 'to_utf8') {
687 return self::cp1252ToUtf8($data);
688 } else {
689 return self::utf8ToCp1252($data);
690 }
691 }
static cp1252ToUtf8($data)
static utf8ToCp1252($data)

References cp1252ToUtf8(), and utf8ToCp1252().

◆ cp1252ToUtf8()

cp1252ToUtf8 ( $data)
static

Converts Windows-1252 encoded data to UTF-8 encoding.

Parameters
string$dataThe Windows-1252 encoded data.
Returns
string Returns the data encoded in UTF-8.

Definition at line 712 of file class.util.php.

713 {
714 return iconv('WINDOWS-1252', 'UTF-8//IGNORE', $data);
715 }

Referenced by convertEncoding().

◆ deleteFolder()

deleteFolder ( $path)
static

Recursively deletes a directory and all its contents.

Parameters
string$pathThe path of the directory to delete.

Definition at line 136 of file class.util.php.

137 {
138 if (is_dir($path)) {
139 if (substr($path, strlen($path) - 1, 1) != '/') {
140 $path .= '/';
141 }
142 $files = glob($path . '*', GLOB_MARK);
143 foreach ($files as $file) {
144 if (is_dir($file)) {
145 self::deleteFolder($file);
146 } else {
147 unlink($file);
148 }
149 }
150 rmdir($path);
151 }
152 }
static deleteFolder($path)

References deleteFolder().

Referenced by deleteFolder(), and ActionStartup\rotationLogs().

◆ disableLaunchStartup()

disableLaunchStartup ( )
static

Disables launching the application at startup by removing the shortcut from the startup folder.

Returns
bool True on success, false on failure.

Definition at line 595 of file class.util.php.

596 {
597 $startupLnkPath = self::getStartupLnkPath();
598
599 // Check if file exists before attempting to delete
600 if (file_exists($startupLnkPath)) {
601 return @unlink($startupLnkPath);
602 }
603
604 // Return true if the file doesn't exist (already disabled)
605 return true;
606 }
static getStartupLnkPath()

References getStartupLnkPath().

Referenced by ActionLaunchStartup\__construct(), and ActionStartup\checkLaunchStartup().

◆ enableLaunchStartup()

enableLaunchStartup ( )
static

Enables launching the application at startup by creating a shortcut in the startup folder.

Returns
bool True on success, false on failure.

Definition at line 573 of file class.util.php.

574 {
576
577 $shortcutPath = self::getStartupLnkPath();
578 if (!$shortcutPath) {
579 return false;
580 }
581
582 $targetPath = $bearsamppRoot->getExeFilePath();
583 $workingDir = $bearsamppRoot->getRootPath();
584 $description = APP_TITLE . ' ' . $bearsamppCore->getAppVersion();
585 $iconPath = $bearsamppCore->getIconsPath() . '/app.ico';
586
587 return Win32Native::createShortcut($shortcutPath, $targetPath, $workingDir, $description, $iconPath);
588 }
static createShortcut($shortcutPath, $targetPath, $workingDir='', $description='', $iconPath='')
const APP_TITLE
Definition root.php:13

References $bearsamppCore, $bearsamppRoot, APP_TITLE, Win32Native\createShortcut(), and getStartupLnkPath().

Referenced by ActionLaunchStartup\__construct(), and ActionStartup\checkLaunchStartup().

◆ findFile()

findFile ( $startPath,
$findFile )
staticprivate

Recursively searches for a file starting from a specified directory.

Parameters
string$startPathThe directory path to start the search.
string$findFileThe filename to search for.
Returns
string|false Returns the path to the file if found, or false if not found.

Definition at line 162 of file class.util.php.

163 {
164 $result = false;
165
166 $handle = @opendir($startPath);
167 if (!$handle) {
168 return false;
169 }
170
171 while (false !== ($file = readdir($handle))) {
172 if ($file == '.' || $file == '..') {
173 continue;
174 }
175 if (is_dir($startPath . '/' . $file)) {
176 $result = self::findFile($startPath . '/' . $file, $findFile);
177 if ($result !== false) {
178 break;
179 }
180 } elseif ($file == $findFile) {
181 $result = UtilPath::formatUnixPath($startPath . '/' . $file);
182 break;
183 }
184 }
185
186 closedir($handle);
187
188 return $result;
189 }
static findFile($startPath, $findFile)

References $result, findFile(), and UtilPath\formatUnixPath().

Referenced by findFile(), and getPowerShellPath().

◆ findFiles()

findFiles ( $startPath,
$includes = array(''),
$recursive = true )
staticprivate

Recursively finds files in a directory that match a set of inclusion patterns.

Parameters
string$startPathThe directory path to start the search from.
array$includesAn array of file patterns to include in the search. Patterns starting with '!' are excluded.
bool$recursiveDetermines whether the search should be recursive.
Returns
array An array of files that match the inclusion patterns.

Definition at line 1282 of file class.util.php.

1283 {
1284 $result = array();
1285
1286 $handle = @opendir($startPath);
1287 if (!$handle) {
1288 return $result;
1289 }
1290
1291 while (false !== ($file = readdir($handle))) {
1292 if ($file == '.' || $file == '..') {
1293 continue;
1294 }
1295 if (is_dir($startPath . '/' . $file) && $recursive) {
1296 $tmpResults = self::findFiles($startPath . '/' . $file, $includes);
1297 foreach ($tmpResults as $tmpResult) {
1298 $result[] = $tmpResult;
1299 }
1300 } elseif (is_file($startPath . '/' . $file)) {
1301 foreach ($includes as $include) {
1302 if (UtilString::startWith($include, '!')) {
1303 $include = ltrim($include, '!');
1304 if (UtilString::startWith($file, '.') && !UtilString::endWith($file, $include)) {
1305 $result[] = UtilPath::formatUnixPath($startPath . '/' . $file);
1306 } elseif ($file != $include) {
1307 $result[] = UtilPath::formatUnixPath($startPath . '/' . $file);
1308 }
1309 } elseif (UtilString::endWith($file, $include) || $file == $include || empty($include)) {
1310 $result[] = UtilPath::formatUnixPath($startPath . '/' . $file);
1311 }
1312 }
1313 }
1314 }
1315
1316 closedir($handle);
1317
1318 return $result;
1319 }
static findFiles($startPath, $includes=array(''), $recursive=true)
static startWith($string, $search)
static endWith($string, $search)

References $result, UtilString\endWith(), findFiles(), UtilPath\formatUnixPath(), and UtilString\startWith().

Referenced by findFiles(), and getFilesToScan().

◆ findRepos()

findRepos ( $initPath,
$startPath,
$checkFile,
$maxDepth = 1 )
static

Recursively searches for repositories starting from a given path up to a specified depth.

Parameters
string$initPathThe initial path from where the search begins.
string$startPathThe current path from where to search.
string$checkFileThe file name to check for in the directory to consider it a repository.
int$maxDepthThe maximum depth of directories to search into.
Returns
array Returns an array of paths that contain the specified file.

Definition at line 632 of file class.util.php.

633 {
634 $depth = substr_count(str_replace($initPath, '', $startPath), '/');
635 $result = array();
636
637 $handle = @opendir($startPath);
638 if (!$handle) {
639 return $result;
640 }
641
642 while (false !== ($file = readdir($handle))) {
643 if ($file == '.' || $file == '..') {
644 continue;
645 }
646 if (is_dir($startPath . '/' . $file) && ($initPath == $startPath || $depth <= $maxDepth)) {
647 $tmpResults = self::findRepos($initPath, $startPath . '/' . $file, $checkFile, $maxDepth);
648 foreach ($tmpResults as $tmpResult) {
649 $result[] = $tmpResult;
650 }
651 } elseif (is_file($startPath . '/' . $checkFile) && !in_array($startPath, $result)) {
652 $result[] = UtilPath::formatUnixPath($startPath);
653 }
654 }
655
656 closedir($handle);
657
658 return $result;
659 }
static findRepos($initPath, $startPath, $checkFile, $maxDepth=1)

References $result, findRepos(), and UtilPath\formatUnixPath().

Referenced by ToolGit\findRepos(), and findRepos().

◆ generateCacheHMAC()

generateCacheHMAC ( $data,
$cacheKey )
staticprivate

Generates HMAC for cache data integrity verification.

Parameters
array$dataThe data to generate HMAC for
string$cacheKeyThe cache key
Returns
string The HMAC hash

Definition at line 997 of file class.util.php.

998 {
1000 $message = serialize($data) . $cacheKey;
1001 return hash_hmac('sha256', $message, $key);
1002 }
static getCacheIntegrityKey()

References getCacheIntegrityKey().

Referenced by setFileScanCache(), and verifyCacheIntegrity().

◆ getApiJson()

getApiJson ( $url)
static

Sends a GET request to the specified URL and returns the response as a JSON string.

Parameters
string$urlThe URL to send the GET request to.
Returns
string|null The response data as a JSON string from the URL, or null on failure.

Definition at line 1583 of file class.util.php.

1584 {
1586
1587 if (isset($result['error'])) {
1588 return null;
1589 }
1590
1591 return isset($result['data']) ? $result['data'] : null;
1592 }
static getApiJson($url, $headers=array())

References $result, and HttpClient\getApiJson().

Referenced by getLatestVersion().

◆ getAppBinsRegKey()

getAppBinsRegKey ( $fromRegistry = true)
static

Definition at line 384 of file class.util.php.

385 {
386 global $bearsamppRegistry;
387
388 if ($fromRegistry) {
389 $value = $bearsamppRegistry->getValue(
393 );
394 Log::debug('App reg key from registry: ' . $value);
395 } else {
396 global $bearsamppBins, $bearsamppTools;
397 $value = '';
398 if ($bearsamppBins->getApache()->isEnable()) {
399 $value .= $bearsamppBins->getApache()->getSymlinkPath() . '/bin;';
400 }
401 if ($bearsamppBins->getPhp()->isEnable()) {
402 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . ';';
403 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/pear;';
404 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/deps;';
405 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/imagick;';
406 }
407 if ($bearsamppBins->getNodejs()->isEnable()) {
408 $value .= $bearsamppBins->getNodejs()->getSymlinkPath() . ';';
409 }
410 if ($bearsamppTools->getComposer()->isEnable()) {
411 $value .= $bearsamppTools->getComposer()->getSymlinkPath() . ';';
412 $value .= $bearsamppTools->getComposer()->getSymlinkPath() . '/vendor/bin;';
413 }
414 if ($bearsamppTools->getGhostscript()->isEnable()) {
415 $value .= $bearsamppTools->getGhostscript()->getSymlinkPath() . '/bin;';
416 }
417 if ($bearsamppTools->getGit()->isEnable()) {
418 $value .= $bearsamppTools->getGit()->getSymlinkPath() . '/bin;';
419 }
420 if ($bearsamppTools->getNgrok()->isEnable()) {
421 $value .= $bearsamppTools->getNgrok()->getSymlinkPath() . ';';
422 }
423 if ($bearsamppTools->getPerl()->isEnable()) {
424 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/perl/site/bin;';
425 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/perl/bin;';
426 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/c/bin;';
427 }
428 if ($bearsamppTools->getPython()->isEnable()) {
429 $value .= $bearsamppTools->getPython()->getSymlinkPath() . '/bin;';
430 }
431 if ($bearsamppTools->getRuby()->isEnable()) {
432 $value .= $bearsamppTools->getRuby()->getSymlinkPath() . '/bin;';
433 }
434 $value = UtilPath::formatWindowsPath($value);
435 Log::debug('Generated app bins reg key: ' . $value);
436 }
437
438 return $value;
439 }
global $bearsamppBins
const HKEY_LOCAL_MACHINE
const APP_BINS_REG_ENTRY

References $bearsamppBins, Registry\APP_BINS_REG_ENTRY, Log\debug(), Registry\ENV_KEY, UtilPath\formatWindowsPath(), and Registry\HKEY_LOCAL_MACHINE.

Referenced by ActionStartup\checkBinsRegKey(), Win32Service\create(), and ActionSwitchVersion\processWindow().

◆ getAppPathRegKey()

getAppPathRegKey ( )
static

Retrieves the application path from the registry.

Returns
mixed The value of the application path registry key or false on error.

Definition at line 465 of file class.util.php.

466 {
467 global $bearsamppRegistry;
468
469 return $bearsamppRegistry->getValue(
473 );
474 }
const APP_PATH_REG_ENTRY

References Registry\APP_PATH_REG_ENTRY, Registry\ENV_KEY, and Registry\HKEY_LOCAL_MACHINE.

Referenced by ActionStartup\checkPathRegKey().

◆ getCacheIntegrityKey()

getCacheIntegrityKey ( )
staticprivate

Generates or retrieves the cache integrity key. This key is unique per session to prevent cross-session cache tampering.

Returns
string The cache integrity key

Definition at line 950 of file class.util.php.

951 {
952 if (self::$cacheIntegrityKey === null) {
953 global $bearsamppRoot;
954
955 // Try to load existing key from session file
956 if (isset($bearsamppRoot)) {
957 $keyFile = $bearsamppRoot->getTmpPath() . '/cache_integrity.key';
958
959 if (file_exists($keyFile)) {
960 $key = @file_get_contents($keyFile);
961 if ($key !== false && strlen($key) === 64) {
962 self::$cacheIntegrityKey = $key;
963 return self::$cacheIntegrityKey;
964 }
965 }
966
967 // Generate new key if none exists or invalid
968 try {
969 self::$cacheIntegrityKey = bin2hex(random_bytes(32));
970 @file_put_contents($keyFile, self::$cacheIntegrityKey, LOCK_EX);
971 } catch (Exception $e) {
972 Log::error('Failed to generate cache integrity key: ' . $e->getMessage());
973 // Fallback to a less secure but functional key
974 self::$cacheIntegrityKey = hash('sha256', uniqid('bearsampp_cache_', true));
975 }
976 } else {
977 // Fallback if bearsamppRoot not available
978 try {
979 self::$cacheIntegrityKey = bin2hex(random_bytes(32));
980 } catch (Exception $e) {
981 self::$cacheIntegrityKey = hash('sha256', uniqid('bearsampp_cache_', true));
982 }
983 }
984 }
985
986 return self::$cacheIntegrityKey;
987 }
static error($data, $file=null)

References $bearsamppRoot, and Log\error().

Referenced by generateCacheHMAC().

◆ getChangelogUrl()

getChangelogUrl ( $utmSource = true)
static

Constructs the URL to the changelog page, optionally including UTM parameters.

Parameters
bool$utmSourceWhether to include UTM source parameters.
Returns
string The URL to the changelog page.

Definition at line 1466 of file class.util.php.

1467 {
1468 return self::getWebsiteUrl('doc/changelog', null, $utmSource);
1469 }
static getWebsiteUrl($path='', $fragment='', $utmSource=true)

References getWebsiteUrl().

◆ getFileScanCache()

getFileScanCache ( $cacheKey)
staticprivate

Gets cached file scan results if valid. Includes integrity verification to prevent cache tampering.

Parameters
string$cacheKeyThe cache key to retrieve.
Returns
array|false Returns cached results or false if cache is invalid/missing.

Definition at line 844 of file class.util.php.

845 {
846 global $bearsamppRoot;
847
848 // Check if we have in-memory cache first
849 if (self::$fileScanCache !== null && isset(self::$fileScanCache[$cacheKey])) {
850 $cache = self::$fileScanCache[$cacheKey];
851
852 // Check if cache is still valid
853 if (time() - $cache['timestamp'] < self::$fileScanCacheDuration) {
854 return $cache['data'];
855 } else {
856 self::$fileScanStats['invalidations']++;
857 unset(self::$fileScanCache[$cacheKey]);
858 }
859 }
860
861 // Try to load from file cache
862 if (!isset($bearsamppRoot)) {
863 return false;
864 }
865
866 $cacheFile = $bearsamppRoot->getTmpPath() . '/filescan_cache_' . $cacheKey . '.dat';
867
868 if (file_exists($cacheFile)) {
869 $fileContents = @file_get_contents($cacheFile);
870
871 if ($fileContents === false) {
872 return false;
873 }
874
875 // Verify file integrity before unserializing
876 if (!self::verifyCacheIntegrity($fileContents, $cacheKey)) {
877 Log::warning('File scan cache integrity check failed for key: ' . $cacheKey . '. Possible tampering detected.');
878 @unlink($cacheFile);
879 return false;
880 }
881
882 $cacheData = @unserialize($fileContents);
883
884 if ($cacheData !== false && isset($cacheData['timestamp']) && isset($cacheData['data']) && isset($cacheData['hmac'])) {
885 // Check if file cache is still valid
886 if (time() - $cacheData['timestamp'] < self::$fileScanCacheDuration) {
887 // Store in memory cache for faster subsequent access
888 if (self::$fileScanCache === null) {
889 self::$fileScanCache = [];
890 }
891 self::$fileScanCache[$cacheKey] = $cacheData;
892
893 return $cacheData['data'];
894 } else {
895 // Cache expired, delete file
896 self::$fileScanStats['invalidations']++;
897 @unlink($cacheFile);
898 }
899 } else {
900 // Invalid cache structure, delete file
901 Log::warning('Invalid cache structure detected for key: ' . $cacheKey);
902 @unlink($cacheFile);
903 }
904 }
905
906 return false;
907 }
static warning($data, $file=null)

References $bearsamppRoot, and Log\warning().

Referenced by getFilesToScan().

◆ getFileScanCacheDuration()

getFileScanCacheDuration ( )
static

Gets the current file scan cache duration.

Returns
int Cache duration in seconds

Definition at line 1089 of file class.util.php.

1090 {
1091 return self::$fileScanCacheDuration;
1092 }

◆ getFileScanStats()

getFileScanStats ( )
static

Gets file scan cache statistics.

Returns
array Array containing hits, misses, and invalidations counts

Definition at line 1064 of file class.util.php.

1065 {
1066 return self::$fileScanStats;
1067 }

◆ getFilesToScan()

getFilesToScan ( $path = null,
$useCache = true,
$forceRefresh = false )
static

Retrieves a list of files to scan from specified paths or default paths. Implements caching to avoid repeated expensive file system scans.

Parameters
string | null$pathOptional. The path to start scanning from. If null, uses default paths.
bool$useCacheWhether to use cached results (default: true).
bool$forceRefreshForce refresh the cache even if valid (default: false).
Returns
array Returns an array of files found during the scan.

Definition at line 793 of file class.util.php.

794 {
795 // Generate cache key based on path parameter
796 $cacheKey = md5(serialize($path));
797
798 // Try to get from cache if enabled and not forcing refresh
799 if ($useCache && !$forceRefresh) {
800 $cachedResult = self::getFileScanCache($cacheKey);
801 if ($cachedResult !== false) {
802 self::$fileScanStats['hits']++;
803 Log::debug('File scan cache HIT (saved expensive scan operation)');
804 return $cachedResult;
805 }
806 }
807
808 self::$fileScanStats['misses']++;
809 Log::debug('File scan cache MISS (performing full scan)');
810
811 // Perform the actual scan
812 $startTime = self::getMicrotime();
813 $result = array();
814 $pathsToScan = !empty($path) ? $path : self::getPathsToScan();
815
816 foreach ($pathsToScan as $pathToScan) {
817 $pathStartTime = self::getMicrotime();
818 $findFiles = self::findFiles($pathToScan['path'], $pathToScan['includes'], $pathToScan['recursive']);
819 foreach ($findFiles as $findFile) {
820 $result[] = $findFile;
821 }
822 Log::debug($pathToScan['path'] . ' scanned in ' . round(self::getMicrotime() - $pathStartTime, 3) . 's');
823 }
824
825 $totalTime = round(self::getMicrotime() - $startTime, 3);
826 Log::info('Full file scan completed in ' . $totalTime . 's (' . count($result) . ' files found)');
827
828 // Store in cache if enabled
829 if ($useCache) {
831 }
832
833 return $result;
834 }
static getMicrotime()
static getPathsToScan()
static setFileScanCache($cacheKey, $data)
static getFileScanCache($cacheKey)

References $result, Log\debug(), findFiles(), getFileScanCache(), getMicrotime(), getPathsToScan(), Log\info(), and setFileScanCache().

Referenced by BinPostgresql\initData(), ActionSwitchVersion\processWindow(), and ActionStartup\scanFolders().

◆ getFolderList()

getFolderList ( $path)
static

Gets the list of folders in the specified path.

Parameters
string$pathThe directory path to scan for folders.
Returns
array|false Returns a sorted array of folder names, or false if the directory cannot be opened.

Definition at line 1867 of file class.util.php.

1868 {
1869 $result = array();
1870
1871 $handle = @opendir($path);
1872 if (!$handle) {
1873 return false;
1874 }
1875
1876 while (false !== ($file = readdir($handle))) {
1877 $filePath = $path . '/' . $file;
1878 if ($file != '.' && $file != '..' && is_dir($filePath) && $file != 'current') {
1879 $result[] = $file;
1880 }
1881 }
1882
1883 closedir($handle);
1884 natcasesort($result);
1885
1886 return $result;
1887 }

References $result.

Referenced by ActionSwitchVersion\__construct(), and getPathsToScan().

◆ getGithubUrl()

getGithubUrl ( $type = 'user',
$user = APP_GITHUB_USER,
$repo = null,
$branch = null,
$path = null )
static

Generates various GitHub URLs based on the specified type.

Parameters
string$typeThe type of URL ('user', 'repo', 'raw'). Defaults to 'user'.
string$userThe GitHub username. Defaults to 'Bearsampp'.
string | null$repoThe repository name (required for 'repo' and 'raw' types).
string | null$branchThe branch name (required for 'raw' type).
string | null$pathThe file path (required for 'raw' type).
Returns
string|false The generated URL or false on invalid input.

Definition at line 1813 of file class.util.php.

1813 {
1814 if (empty($user) || !is_string($user)) {
1815 return false;
1816 }
1817
1818 // Encode as URL path segment (not query encoding)
1819 $user = rawurlencode($user);
1820
1821 switch ($type) {
1822 case 'user':
1823 return "https://github.com/{$user}";
1824
1825 case 'repo':
1826 if (empty($repo) || !is_string($repo)) {
1827 return false;
1828 }
1829 $repo = rawurlencode($repo);
1830 return "https://github.com/{$user}/{$repo}";
1831
1832 case 'raw':
1833 if (empty($repo) || empty($branch) || empty($path) || !is_string($repo) || !is_string($branch) || !is_string($path)) {
1834 return false;
1835 }
1836 $repo = rawurlencode($repo);
1837 $branch = rawurlencode($branch);
1838
1839 $path = ltrim($path, '/');
1840 $segments = array_map('rawurlencode', explode('/', $path));
1841 $pathEncoded = implode('/', $segments);
1842
1843 return "https://raw.githubusercontent.com/{$user}/{$repo}/{$branch}/{$pathEncoded}";
1844
1845 default:
1846 return false;
1847 }
1848 }

References APP_GITHUB_USER.

Referenced by getGithubUserUrl().

◆ getGithubUserUrl()

getGithubUserUrl ( )
static

Gets the GitHub user URL for Bearsampp.

Returns
string The GitHub user URL.

Definition at line 1855 of file class.util.php.

1856 {
1857 return self::getGithubUrl('user', APP_GITHUB_USER);
1858 }
static getGithubUrl($type='user', $user=APP_GITHUB_USER, $repo=null, $branch=null, $path=null)
const APP_GITHUB_USER
Definition root.php:16

References APP_GITHUB_USER, and getGithubUrl().

Referenced by ActionAbout\__construct(), and ActionAbout\processWindow().

◆ getHeaders()

getHeaders ( $host,
$port,
$ssl = false )
static

Retrieves the initial response line from a specified host and port using a socket connection.

This method optionally uses SSL and creates a stream context with SSL verification enabled for security. It attempts to connect to the host and port, reads the first line of the response, and parses it. Detailed debug information is logged for each header line received.

Parameters
string$hostThe host name or IP address to connect to.
int$portThe port number to connect to.
bool$sslWhether to use SSL (defaults to false).
Returns
array An array containing the first line of the response, split into parts, or an empty array if unsuccessful.

Definition at line 1539 of file class.util.php.

1540 {
1541 $result = array();
1542 $context = stream_context_create(array(
1543 'ssl' => array(
1544 'verify_peer' => true,
1545 'verify_peer_name' => true,
1546 'allow_self_signed' => false,
1547 )
1548 ));
1549
1550 $fp = @stream_socket_client(($ssl ? 'ssl://' : '') . $host . ':' . $port, $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context);
1551 if ($fp) {
1552 $out = fgets($fp);
1553 $result = explode(PHP_EOL, $out);
1554 @fclose($fp);
1555 }
1556
1557 if (!empty($result)) {
1558 $rebuildResult = array();
1559 foreach ($result as $row) {
1560 $row = trim($row);
1561 if (!empty($row)) {
1562 $rebuildResult[] = $row;
1563 }
1564 }
1565 $result = $rebuildResult;
1566
1567 Log::debug('getHeaders:');
1568 foreach ($result as $header) {
1569 Log::debug('-> ' . $header);
1570 }
1571 }
1572
1573 return $result;
1574 }
$port

References $port, $result, and Log\debug().

Referenced by BinMailpit\checkPort(), and BinXlight\checkPort().

◆ getLatestVersion()

getLatestVersion ( $url)
static

Fetches the latest version information from a given url.

Parameters
string$urlThe URL to fetch version information from.
Returns
array|null Returns an array with 'version', 'html_url', and 'name' if successful, null otherwise.

Definition at line 1392 of file class.util.php.

1393 {
1394 $responseData = self::getApiJson($url);
1395
1396 if (empty($responseData)) {
1397 Log::error('Cannot retrieve latest github info: empty result or error');
1398 return null;
1399 }
1400
1401 // Now decode the JSON string
1402 $resultArray = json_decode($responseData, true);
1403
1404 if (isset($resultArray['tag_name']) && isset($resultArray['assets'][0]['browser_download_url'])) {
1405 $tagName = $resultArray['tag_name'];
1406 $downloadUrl = $resultArray['assets'][0]['browser_download_url'];
1407 $name = $resultArray['name'];
1408 Log::debug('Latest version tag name: ' . $tagName);
1409 Log::debug('Download URL: ' . $downloadUrl);
1410 Log::debug('Name: ' . $name);
1411
1412 return ['version' => $tagName, 'html_url' => $downloadUrl, 'name' => $name];
1413 } else {
1414 Log::error('Tag name, download URL, or name not found in the response');
1415 return null;
1416 }
1417 }
static getApiJson($url)

References Log\debug(), Log\error(), and getApiJson().

Referenced by ActionCheckVersion\__construct().

◆ getMicrotime()

getMicrotime ( )
static

Gets the current Unix timestamp with microseconds.

Returns
float Returns the current Unix timestamp combined with microseconds.

Definition at line 377 of file class.util.php.

378 {
379 list($usec, $sec) = explode(' ', microtime());
380
381 return ((float)$usec + (float)$sec);
382 }

Referenced by ActionStartup\__construct(), getFilesToScan(), ActionStartup\installServicesSequential(), ActionStartup\prepareService(), ActionStartup\processWindow(), and ActionStartup\scanFolders().

◆ getPathsToScan()

getPathsToScan ( )
staticprivate

Retrieves a list of directories and file types to scan within the BEARSAMPP environment.

This method compiles an array of paths from various components of the BEARSAMPP stack, including Apache, PHP, MySQL, MariaDB, PostgreSQL, Node.js, Composer, PowerShell, Python and Ruby. Each path entry includes the directory path, file types to include in the scan, and whether the scan should be recursive.

The method uses global variables to access the root paths of each component. It then dynamically fetches specific subdirectories using the getFolderList method (which is assumed to be defined elsewhere in this class or in the global scope) and constructs an array of path specifications.

Each path specification is an associative array with the following keys:

  • 'path': The full directory path to scan.
  • 'includes': An array of file extensions or filenames to include in the scan.
  • 'recursive': A boolean indicating whether the scan should include subdirectories.

The method is designed to be used for setting up scans of configuration files and other important files within the BEARSAMPP environment, possibly for purposes like configuration management, backup, or security auditing.

Returns
array An array of associative arrays, each containing 'path', 'includes', and 'recursive' keys.

Definition at line 1118 of file class.util.php.

1119 {
1120 global $bearsamppRoot, $bearsamppCore, $bearsamppBins, $bearsamppApps, $bearsamppTools;
1121 $paths = array();
1122
1123 // Alias
1124 $paths[] = array(
1125 'path' => $bearsamppRoot->getAliasPath(),
1126 'includes' => array(''),
1127 'recursive' => false
1128 );
1129
1130 // Vhosts
1131 $paths[] = array(
1132 'path' => $bearsamppRoot->getVhostsPath(),
1133 'includes' => array(''),
1134 'recursive' => false
1135 );
1136
1137 // OpenSSL
1138 $paths[] = array(
1139 'path' => $bearsamppCore->getOpenSslPath(),
1140 'includes' => array('openssl.cfg'),
1141 'recursive' => false
1142 );
1143
1144 // Homepage
1145 $paths[] = array(
1146 'path' => $bearsamppCore->getResourcesPath() . '/homepage',
1147 'includes' => array('alias.conf'),
1148 'recursive' => false
1149 );
1150
1151 // Apache
1152 $folderList = self::getFolderList($bearsamppBins->getApache()->getRootPath());
1153 foreach ($folderList as $folder) {
1154 $paths[] = array(
1155 'path' => $bearsamppBins->getApache()->getRootPath() . '/' . $folder,
1156 'includes' => array('.ini', '.conf'),
1157 'recursive' => true
1158 );
1159 }
1160
1161 // PHP
1162 $folderList = self::getFolderList($bearsamppBins->getPhp()->getRootPath());
1163 foreach ($folderList as $folder) {
1164 $paths[] = array(
1165 'path' => $bearsamppBins->getPhp()->getRootPath() . '/' . $folder,
1166 'includes' => array('.php', '.bat', '.ini', '.reg', '.inc'),
1167 'recursive' => true
1168 );
1169 }
1170
1171 // MySQL
1172 $folderList = self::getFolderList($bearsamppBins->getMysql()->getRootPath());
1173 foreach ($folderList as $folder) {
1174 $paths[] = array(
1175 'path' => $bearsamppBins->getMysql()->getRootPath() . '/' . $folder,
1176 'includes' => array('my.ini'),
1177 'recursive' => false
1178 );
1179 }
1180
1181 // MariaDB
1182 $folderList = self::getFolderList($bearsamppBins->getMariadb()->getRootPath());
1183 foreach ($folderList as $folder) {
1184 $paths[] = array(
1185 'path' => $bearsamppBins->getMariadb()->getRootPath() . '/' . $folder,
1186 'includes' => array('my.ini'),
1187 'recursive' => false
1188 );
1189 // Also scan data directory for my.ini (created during initialization)
1190 $dataPath = $bearsamppBins->getMariadb()->getRootPath() . '/' . $folder . '/data';
1191 if (is_dir($dataPath)) {
1192 $paths[] = array(
1193 'path' => $dataPath,
1194 'includes' => array('my.ini'),
1195 'recursive' => false
1196 );
1197 }
1198 }
1199
1200 // PostgreSQL
1201 $folderList = self::getFolderList($bearsamppBins->getPostgresql()->getRootPath());
1202 foreach ($folderList as $folder) {
1203 $paths[] = array(
1204 'path' => $bearsamppBins->getPostgresql()->getRootPath() . '/' . $folder,
1205 'includes' => array( '.conf', '.bat', '.ber'),
1206 'recursive' => true
1207 );
1208 }
1209
1210 // Node.js
1211 $folderList = self::getFolderList($bearsamppBins->getNodejs()->getRootPath());
1212 foreach ($folderList as $folder) {
1213 $paths[] = array(
1214 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/etc',
1215 'includes' => array('npmrc'),
1216 'recursive' => true
1217 );
1218 $paths[] = array(
1219 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/node_modules/npm',
1220 'includes' => array('npmrc'),
1221 'recursive' => false
1222 );
1223 }
1224
1225 // Composer
1226 $folderList = self::getFolderList($bearsamppTools->getComposer()->getRootPath());
1227 foreach ($folderList as $folder) {
1228 $paths[] = array(
1229 'path' => $bearsamppTools->getComposer()->getRootPath() . '/' . $folder,
1230 'includes' => array('giscus.json'),
1231 'recursive' => false
1232 );
1233 }
1234
1235 // PowerShell
1236 $folderList = self::getFolderList($bearsamppTools->getPowerShell()->getRootPath());
1237 foreach ($folderList as $folder) {
1238 $paths[] = array(
1239 'path' => $bearsamppTools->getPowerShell()->getRootPath() . '/' . $folder,
1240 'includes' => array('console.xml', '.ini', '.btm'),
1241 'recursive' => true
1242 );
1243 }
1244
1245 // Python
1246 $folderList = self::getFolderList($bearsamppTools->getPython()->getRootPath());
1247 foreach ($folderList as $folder) {
1248 $paths[] = array(
1249 'path' => $bearsamppTools->getPython()->getRootPath() . '/' . $folder . '/bin',
1250 'includes' => array('.bat'),
1251 'recursive' => false
1252 );
1253 $paths[] = array(
1254 'path' => $bearsamppTools->getPython()->getRootPath() . '/' . $folder . '/settings',
1255 'includes' => array('winpython.ini'),
1256 'recursive' => false
1257 );
1258 }
1259
1260 // Ruby
1261 $folderList = self::getFolderList($bearsamppTools->getRuby()->getRootPath());
1262 foreach ($folderList as $folder) {
1263 $paths[] = array(
1264 'path' => $bearsamppTools->getRuby()->getRootPath() . '/' . $folder . '/bin',
1265 'includes' => array('!.dll', '!.exe'),
1266 'recursive' => false
1267 );
1268 }
1269
1270 return $paths;
1271 }
static getFolderList($path)

References $bearsamppBins, $bearsamppCore, $bearsamppRoot, and getFolderList().

Referenced by getFilesToScan().

◆ getPowerShellPath()

getPowerShellPath ( )
static

Finds the path to the PowerShell executable in the Windows System32 directory.

Returns
string|false Returns the path to powershell.exe if found, otherwise false.

Definition at line 613 of file class.util.php.

614 {
615 if (is_dir('C:\Windows\System32\WindowsPowerShell')) {
616 return self::findFile('C:\Windows\System32\WindowsPowerShell', 'powershell.exe');
617 }
618
619 return false;
620 }

References findFile().

Referenced by TplPowerShell\getTabPowerShellSection().

◆ getProcessorRegKey()

getProcessorRegKey ( )
static

Retrieves the processor identifier from the registry.

Returns
mixed The value of the processor identifier registry key or false on error.

Definition at line 535 of file class.util.php.

536 {
537 global $bearsamppRegistry;
538
539 return $bearsamppRegistry->getValue(
543 );
544 }
const PROCESSOR_REG_SUBKEY
const PROCESSOR_REG_ENTRY

References Registry\HKEY_LOCAL_MACHINE, Registry\PROCESSOR_REG_ENTRY, and Registry\PROCESSOR_REG_SUBKEY.

Referenced by is32BitsOs().

◆ getRemoteFilesize()

getRemoteFilesize ( $url,
$humanFileSize = true )
static

Retrieves the file size of a remote file.

Parameters
string$urlThe URL of the remote file.
bool$humanFileSizeWhether to return the size in a human-readable format.
Returns
mixed The file size, either in bytes or as a formatted string.

Definition at line 1479 of file class.util.php.

1480 {
1481 $size = 0;
1482
1483 $data = get_headers($url, true);
1484 if (isset($data['Content-Length'])) {
1485 $size = intval($data['Content-Length']);
1486 }
1487
1488 return $humanFileSize ? self::humanFileSize($size) : $size;
1489 }
static humanFileSize($size, $unit='')

References humanFileSize().

◆ getStartupLnkPath()

getStartupLnkPath ( )
static

Retrieves the path for the startup link file.

Returns
string The full path to the startup link file.

Definition at line 551 of file class.util.php.

552 {
553 $startupPath = Win32Native::getSpecialFolderPath('Startup');
554 return $startupPath ? $startupPath . '/' . APP_TITLE . '.lnk' : false;
555 }
static getSpecialFolderPath($folderName)

References APP_TITLE, and Win32Native\getSpecialFolderPath().

Referenced by disableLaunchStartup(), enableLaunchStartup(), and isLaunchStartup().

◆ getSysPathRegKey()

getSysPathRegKey ( )
static

Retrieves the system path from the registry.

Returns
mixed The value of the system path registry key or false on error.

Definition at line 500 of file class.util.php.

501 {
502 global $bearsamppRegistry;
503
504 return $bearsamppRegistry->getValue(
508 );
509 }
const SYSPATH_REG_ENTRY

References Registry\ENV_KEY, Registry\HKEY_LOCAL_MACHINE, and Registry\SYSPATH_REG_ENTRY.

Referenced by ActionStartup\checkSystemPathRegKey().

◆ getVersionList()

getVersionList ( $path)
static

Gets the list of version directories in the specified path. Returns version suffixes by stripping the common prefix (basename of path) if present.

Parameters
string$pathThe directory path to scan for version directories.
Returns
array|false Returns a sorted array of version suffixes, or false if the directory cannot be opened.

Definition at line 343 of file class.util.php.

344 {
345 $result = array();
346
347 $handle = @opendir($path);
348 if (!$handle) {
349 return false;
350 }
351
352 $prefix = basename($path);
353
354 while (false !== ($file = readdir($handle))) {
355 $filePath = $path . '/' . $file;
356 if ($file != '.' && $file != '..' && is_dir($filePath) && $file != 'current') {
357 if (strpos($file, $prefix) === 0) {
358 $version = substr($file, strlen($prefix));
359 } else {
360 $version = $file;
361 }
362 $result[] = $version;
363 }
364 }
365
366 closedir($handle);
367 natcasesort($result);
368
369 return $result;
370 }

References $result.

Referenced by Module\getVersionList().

◆ getWebsiteUrl()

getWebsiteUrl ( $path = '',
$fragment = '',
$utmSource = true )
static

Constructs a complete website URL with optional path, fragment, and UTM source parameters.

Parameters
string$pathOptional path to append to the base URL.
string$fragmentOptional fragment to append to the URL.
bool$utmSourceWhether to include UTM source parameters. Defaults to true.
Returns
string The constructed URL.

Definition at line 1428 of file class.util.php.

1429 {
1430 global $bearsamppCore;
1431
1432 $url = APP_WEBSITE;
1433 if (!empty($path)) {
1434 $url .= '/' . ltrim($path, '/');
1435 }
1436 if ($utmSource) {
1437 $url = rtrim($url, '/') . '/?utm_source=bearsampp-' . $bearsamppCore->getAppVersion();
1438 }
1439 if (!empty($fragment)) {
1440 $url .= $fragment;
1441 }
1442
1443 return $url;
1444 }
const APP_WEBSITE
Definition root.php:14

References $bearsamppCore, and APP_WEBSITE.

Referenced by getChangelogUrl(), TplAppApache\getMenuApache(), TplAppMailpit\getMenuMailpit(), TplAppMariadb\getMenuMariadb(), TplAppMemcached\getMenuMemcached(), TplAppMysql\getMenuMysql(), TplAppNodejs\getMenuNodejs(), TplAppPhp\getMenuPhp(), TplAppPostgresql\getMenuPostgresql(), TplAppXlight\getMenuXlight(), QuickPick\getQuickpickMenu(), TplApp\getSectionMenuRight(), getWebsiteUrlNoUtm(), and ActionAbout\processWindow().

◆ getWebsiteUrlNoUtm()

getWebsiteUrlNoUtm ( $path = '',
$fragment = '' )
static

Constructs a website URL without UTM parameters.

Parameters
string$pathOptional path to append to the base URL.
string$fragmentOptional fragment to append to the URL.
Returns
string The constructed URL without UTM parameters.

Definition at line 1454 of file class.util.php.

1455 {
1456 return self::getWebsiteUrl($path, $fragment, false);
1457 }

References getWebsiteUrl().

Referenced by ActionAbout\__construct().

◆ humanFileSize()

humanFileSize ( $size,
$unit = '' )
static

Converts a file size in bytes to a human-readable format.

Parameters
int$sizeThe file size in bytes.
string$unitThe unit to convert to ('GB', 'MB', 'KB', or ''). If empty, auto-selects the unit.
Returns
string The formatted file size.

Definition at line 1499 of file class.util.php.

1500 {
1501 if ((!$unit && $size >= 1 << 30) || $unit == 'GB') {
1502 return number_format($size / (1 << 30), 2) . 'GB';
1503 }
1504 if ((!$unit && $size >= 1 << 20) || $unit == 'MB') {
1505 return number_format($size / (1 << 20), 2) . 'MB';
1506 }
1507 if ((!$unit && $size >= 1 << 10) || $unit == 'KB') {
1508 return number_format($size / (1 << 10), 2) . 'KB';
1509 }
1510
1511 return number_format($size) . ' bytes';
1512 }

Referenced by getRemoteFilesize().

◆ imgToBase64()

imgToBase64 ( $path)
static

Converts an image file to a base64 encoded string.

Parameters
string$pathThe path to the image file.
Returns
string Returns the base64 encoded string of the image.

Definition at line 668 of file class.util.php.

669 {
670 $type = pathinfo($path, PATHINFO_EXTENSION);
671 $data = file_get_contents($path);
672
673 return 'data:image/' . $type . ';base64,' . base64_encode($data);
674 }

◆ installService()

installService ( $bin,
$port,
$syntaxCheckCmd,
$showWindow = false )
static

Attempts to install and start a service on a specific port, with optional syntax checking and user notifications.

Parameters
object$binAn object containing the binary information and methods related to the service.
int$portThe port number on which the service should run.
string$syntaxCheckCmdThe command to execute for syntax checking of the service configuration.
bool$showWindowOptional. Whether to show message boxes for information, warnings, and errors. Defaults to false.
Returns
bool Returns true if the service is successfully installed and started, false otherwise.

Definition at line 1653 of file class.util.php.

1654 {
1655 global $bearsamppLang, $bearsamppWinbinder;
1656
1657 if (method_exists($bin, 'initData')) {
1658 $bin->initData();
1659 }
1660
1661 $name = $bin->getName();
1662 $service = $bin->getService();
1663 $boxTitle = sprintf($bearsamppLang->getValue(Lang::INSTALL_SERVICE_TITLE), $name);
1664
1665 $isPortInUse = self::isPortInUse($port);
1666 if ($isPortInUse === false) {
1667 if (!$service->isInstalled()) {
1668 $service->create();
1669 if ($service->start()) {
1670 Log::info(sprintf('%s service successfully installed. (name: %s ; port: %s)', $name, $service->getName(), $port));
1671 if ($showWindow) {
1672 $bearsamppWinbinder->messageBoxInfo(
1673 sprintf($bearsamppLang->getValue(Lang::SERVICE_INSTALLED), $name, $service->getName(), $port),
1674 $boxTitle
1675 );
1676 }
1677
1678 return true;
1679 } else {
1680 $serviceError = sprintf($bearsamppLang->getValue(Lang::SERVICE_INSTALL_ERROR), $name);
1681 $serviceErrorLog = sprintf('Error during the installation of %s service', $name);
1682 if (!empty($syntaxCheckCmd)) {
1683 $cmdSyntaxCheck = $bin->getCmdLineOutput($syntaxCheckCmd);
1684 if (!$cmdSyntaxCheck['syntaxOk']) {
1685 $serviceError .= PHP_EOL . sprintf($bearsamppLang->getValue(Lang::STARTUP_SERVICE_SYNTAX_ERROR), $cmdSyntaxCheck['content']);
1686 $serviceErrorLog .= sprintf(' (conf errors detected : %s)', $cmdSyntaxCheck['content']);
1687 }
1688 }
1689 Log::error($serviceErrorLog);
1690 if ($showWindow) {
1691 $bearsamppWinbinder->messageBoxError($serviceError, $boxTitle);
1692 }
1693 }
1694 } else {
1695 Log::warning(sprintf('%s service already installed', $name));
1696 if ($showWindow) {
1697 $bearsamppWinbinder->messageBoxWarning(
1698 sprintf($bearsamppLang->getValue(Lang::SERVICE_ALREADY_INSTALLED), $name),
1699 $boxTitle
1700 );
1701 }
1702
1703 return true;
1704 }
1705 } elseif ($service->isRunning()) {
1706 Log::warning(sprintf('%s service already installed and running', $name));
1707 if ($showWindow) {
1708 $bearsamppWinbinder->messageBoxWarning(
1709 sprintf($bearsamppLang->getValue(Lang::SERVICE_ALREADY_INSTALLED), $name),
1710 $boxTitle
1711 );
1712 }
1713
1714 return true;
1715 } else {
1716 Log::error(sprintf('Port %s is used by an other application : %s', $port, $isPortInUse));
1717 if ($showWindow) {
1718 $bearsamppWinbinder->messageBoxError(
1719 sprintf($bearsamppLang->getValue(Lang::PORT_NOT_USED_BY), $port, $isPortInUse),
1720 $boxTitle
1721 );
1722 }
1723 }
1724
1725 return false;
1726 }
global $bearsamppLang
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
static isPortInUse($port)

References $bearsamppLang, $port, Log\error(), Log\info(), Lang\INSTALL_SERVICE_TITLE, isPortInUse(), Lang\PORT_NOT_USED_BY, Lang\SERVICE_ALREADY_INSTALLED, Lang\SERVICE_INSTALL_ERROR, Lang\SERVICE_INSTALLED, Lang\STARTUP_SERVICE_SYNTAX_ERROR, and Log\warning().

Referenced by ActionService\install(), BinApache\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinPostgresql\setEnable(), and BinXlight\setEnable().

◆ is32BitsOs()

is32BitsOs ( )
static

Checks if the operating system is 32-bit.

Returns
bool True if the OS is 32-bit, false otherwise.

Definition at line 1519 of file class.util.php.

1520 {
1521 $processor = self::getProcessorRegKey();
1522
1523 return UtilString::contains($processor, 'x86');
1524 }
static getProcessorRegKey()
static contains($string, $search)

References UtilString\contains(), and getProcessorRegKey().

◆ isAdmin()

isAdmin ( )
static

Checks if the current process is running with administrator/elevated privileges. This is essential for operations that require admin rights, such as installing Windows services.

Returns
bool True if running as administrator, false otherwise.

Definition at line 222 of file class.util.php.

223 {
224 // Only applicable on Windows
225 if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
226 // On non-Windows systems, check if running as root
227 if (function_exists('posix_geteuid')) {
228 return posix_geteuid() === 0;
229 }
230 // If we can't determine on non-Windows, assume true to avoid blocking
231 return true;
232 }
233
234 // Method 1: Try using shell_exec with 'net session' command
235 // This command only succeeds when run with admin privileges
236 $output = CommandRunner::shellExec('net session 2>&1');
237 if ($output !== null) {
238 // Check for access denied errors
239 if (stripos($output, 'Access is denied') !== false ||
240 stripos($output, 'System error 5') !== false ||
241 stripos($output, 'Zugriff verweigert') !== false) { // German
242 // Explicitly denied - not admin
243 return false;
244 }
245
246 // If we got output without errors, we likely have admin rights
247 if (stripos($output, 'There are no entries') !== false ||
248 stripos($output, 'These workstations') !== false ||
249 preg_match('/\\\\\\\\/', $output)) {
250 return true;
251 }
252 }
253
254 // Method 2: Check using whoami command (Windows Vista and later)
255 $output = CommandRunner::shellExec('whoami /groups 2>&1');
256 if ($output !== null && !empty($output)) {
257 // Look for the Administrators group or High Mandatory Level
258 if (stripos($output, 'S-1-16-12288') !== false || // High Mandatory Level
259 stripos($output, 'S-1-5-32-544') !== false) { // Administrators group
260 return true;
261 }
262
263 // If we got output but no admin indicators, we're not admin
264 if (stripos($output, 'S-1-16-8192') !== false) { // Medium Mandatory Level (not admin)
265 return false;
266 }
267 }
268
269 // Method 3: Try to write to a system directory
270 // This is a fallback method that checks if we can write to Windows directory
271 $testFile = getenv('SystemRoot') . '\\Temp\\bearsampp_admin_test_' . uniqid() . '.tmp';
272 $result = @file_put_contents($testFile, 'test');
273 if ($result !== false) {
274 @unlink($testFile);
275 return true;
276 }
277
278 // If all methods fail or indicate no admin, return false
279 return false;
280 }
static shellExec(string $command)

References $result, and CommandRunner\shellExec().

◆ isLaunchStartup()

isLaunchStartup ( )
static

Checks if the application is set to launch at startup.

Returns
bool True if the startup link exists, false otherwise.

Definition at line 562 of file class.util.php.

563 {
565 return $lnk ? file_exists($lnk) : false;
566 }

References getStartupLnkPath().

Referenced by ActionReload\__construct(), and TplAppLaunchStartup\process().

◆ isPortInUse()

isPortInUse ( $port)
static

Checks if a specific port is in use.

Parameters
int$portThe port number to check
Returns
mixed False if the port is not in use, otherwise returns the process using the port

Definition at line 1601 of file class.util.php.

1602 {
1603 // Set localIP statically
1604 $localIP = '127.0.0.1';
1605
1606 // Save current error reporting level
1607 $errorReporting = error_reporting();
1608
1609 // Disable error reporting temporarily
1610 error_reporting(0);
1611
1612 $connection = @fsockopen($localIP, $port);
1613
1614 // Restore original error reporting level
1615 error_reporting($errorReporting);
1616
1617 if (is_resource($connection)) {
1618 fclose($connection);
1620
1621 return $process != null ? $process : 'N/A';
1622 }
1623
1624 return false;
1625 }
static getProcessUsingPort($port)

References $port, and Batch\getProcessUsingPort().

Referenced by BinApache\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), BinPostgresql\handleNonPostgresUsage(), installService(), and ActionStartup\prepareService().

◆ isValidDomainName()

isValidDomainName ( $domainName)
static

Validates a domain name based on specific criteria.

Parameters
string$domainNameThe domain name to validate.
Returns
bool Returns true if the domain name is valid, false otherwise.

Definition at line 1634 of file class.util.php.

1635 {
1636 // This will return the string if valid, or FALSE if not.
1637 // It checks syntax rules (RFC 1034/1035) but doesn't check if the domain is "real."
1638 $isValidSyntax = filter_var($domainName, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
1639
1640 return $isValidSyntax;
1641 }

Referenced by ActionAddVhost\validateInput(), and ActionEditVhost\validateInput().

◆ isValidIp()

isValidIp ( $ip)
static

Validates an IP address.

Parameters
string$ipThe IP address to validate.
Returns
bool Returns true if the IP address is valid, otherwise false.

Definition at line 198 of file class.util.php.

199 {
200 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)
201 || filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
202 }

◆ isValidPort()

isValidPort ( $port)
static

Validates a port number.

Parameters
int$portThe port number to validate.
Returns
bool Returns true if the port number is valid and within the range of 1 to 65535, otherwise false.

Definition at line 211 of file class.util.php.

212 {
213 return is_numeric($port) && ($port > 0 && $port <= 65535);
214 }

References $port.

Referenced by BinApache\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), BinApache\checkPort(), BinMailpit\checkPort(), BinMariadb\checkPort(), BinMemcached\checkPort(), BinMysql\checkPort(), BinPostgresql\checkPort(), and BinXlight\checkPort().

◆ openFileContent()

openFileContent ( $caption,
$content )
static

Opens the given content in a temporary file using the editor configured in bearsampp.conf.

Parameters
string$captionThe caption/title for the temporary file.
string$contentThe content to write to the temporary file.
Returns
void

Definition at line 1897 of file class.util.php.

1898 {
1900
1901 $tmpFile = $bearsamppCore->getTmpPath() . '/' . $caption . '.txt';
1902 file_put_contents($tmpFile, $content);
1903
1904 // Open the file with the configured editor from bearsampp.conf
1905 $editor = $bearsamppConfig->getNotepad();
1906 $bearsamppCore->getWinbinder()->exec($editor, '"' . $tmpFile . '"');
1907 }
global $bearsamppConfig
Definition homepage.php:41

References $bearsamppConfig, and $bearsamppCore.

Referenced by ActionDebugBase\__construct().

◆ removeService()

removeService ( $service,
$name )
static

Removes a service if it is installed.

Parameters
Win32Service$serviceThe service object to be removed.
string$nameThe name of the service.
Returns
bool Returns true if the service is successfully removed, false otherwise.

Definition at line 1736 of file class.util.php.

1737 {
1738 if (!($service instanceof Win32Service)) {
1739 Log::error('$service not an instance of Win32Service');
1740
1741 return false;
1742 }
1743
1744 if ($service->isInstalled()) {
1745 if ($service->delete()) {
1746 Log::info(sprintf('%s service successfully removed', $name));
1747
1748 return true;
1749 } else {
1750 Log::error(sprintf('Error during the uninstallation of %s service', $name));
1751
1752 return false;
1753 }
1754 } else {
1755 Log::warning(sprintf('%s service does not exist', $name));
1756 }
1757
1758 return true;
1759 }

References Log\error(), Log\info(), and Log\warning().

Referenced by ActionService\remove(), BinApache\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinPostgresql\setEnable(), and BinXlight\setEnable().

◆ replaceDefine()

replaceDefine ( $path,
$var,
$value )
static

Replaces a defined constant in a file with a new value.

Parameters
string$pathThe file path where the constant is defined.
string$varThe name of the constant.
mixed$valueThe new value for the constant.

Definition at line 289 of file class.util.php.

290 {
291 self::replaceInFile($path, array(
292 '/^define\‍((.*?)' . $var . '(.*?),/' => 'define(\'' . $var . '\', ' . (is_int($value) ? $value : '\'' . $value . '\'') . ');'
293 ));
294 }
static replaceInFile($path, $replaceList)

References replaceInFile().

◆ replaceInFile()

replaceInFile ( $path,
$replaceList )
static

Performs replacements in a file based on a list of regular expression patterns.

Parameters
string$pathThe path to the file where replacements are to be made.
array$replaceListAn associative array where keys are regex patterns and values are replacement strings.

Definition at line 302 of file class.util.php.

303 {
304 if (file_exists($path)) {
305 $lines = file($path);
306 $fp = fopen($path, 'w');
307 foreach ($lines as $nb => $line) {
308 $replaceDone = false;
309 foreach ($replaceList as $regex => $replace) {
310 if (preg_match($regex, $line, $matches)) {
311 $countParams = preg_match_all('/{{(\d+)}}/', $replace, $paramsMatches);
312 if ($countParams > 0 && $countParams <= count($matches)) {
313 foreach ($paramsMatches[1] as $paramsMatch) {
314 $replace = str_replace('{{' . $paramsMatch . '}}', $matches[$paramsMatch], $replace);
315 }
316 }
317 Log::trace('Replace in file ' . $path . ' :');
318 Log::trace('## line_num: ' . trim($nb));
319 Log::trace('## old: ' . trim($line));
320 Log::trace('## new: ' . trim($replace));
321 fwrite($fp, $replace . PHP_EOL);
322
323 $replaceDone = true;
324 break;
325 }
326 }
327 if (!$replaceDone) {
328 fwrite($fp, $line);
329 }
330 }
331 fclose($fp);
332 }
333 }
static trace($data, $file=null)

References Log\trace().

Referenced by BinPostgresql\rebuildConf(), Homepage\refreshCommonsJsContent(), replaceDefine(), ToolGit\setScanStartup(), AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), BinApache\updateConfig(), BinMariadb\updateConfig(), BinMysql\updateConfig(), BinPhp\updateConfig(), and BinPostgresql\updateConfig().

◆ setAppBinsRegKey()

setAppBinsRegKey ( $value)
static

Retrieves or generates the application binaries registry key.

Parameters
bool$fromRegistryDetermines whether to retrieve the key from the registry or generate it.
Returns
string Returns the application binaries registry key.

Definition at line 448 of file class.util.php.

449 {
450 global $bearsamppRegistry;
451
452 return $bearsamppRegistry->setStringValue(
456 $value
457 );
458 }

References Registry\APP_BINS_REG_ENTRY, Registry\ENV_KEY, and Registry\HKEY_LOCAL_MACHINE.

Referenced by ActionStartup\checkBinsRegKey(), and ActionSwitchVersion\processWindow().

◆ setAppPathRegKey()

setAppPathRegKey ( $value)
static

Sets the application path in the registry.

Parameters
string$valueThe new value for the application path.
Returns
bool True on success, false on failure.

Definition at line 483 of file class.util.php.

484 {
485 global $bearsamppRegistry;
486
487 return $bearsamppRegistry->setStringValue(
491 $value
492 );
493 }

References Registry\APP_PATH_REG_ENTRY, Registry\ENV_KEY, and Registry\HKEY_LOCAL_MACHINE.

Referenced by ActionStartup\checkPathRegKey().

◆ setFileScanCache()

setFileScanCache ( $cacheKey,
$data )
staticprivate

Stores file scan results in cache with integrity protection.

Parameters
string$cacheKeyThe cache key to store under.
array$dataThe scan results to cache.
Returns
void

Definition at line 917 of file class.util.php.

918 {
919 global $bearsamppRoot;
920
921 // Generate HMAC for integrity verification
922 $hmac = self::generateCacheHMAC($data, $cacheKey);
923
924 $cacheData = [
925 'timestamp' => time(),
926 'data' => $data,
927 'hmac' => $hmac
928 ];
929
930 // Store in memory cache
931 if (self::$fileScanCache === null) {
932 self::$fileScanCache = [];
933 }
934 self::$fileScanCache[$cacheKey] = $cacheData;
935
936 // Store in file cache
937 if (isset($bearsamppRoot)) {
938 $cacheFile = $bearsamppRoot->getTmpPath() . '/filescan_cache_' . $cacheKey . '.dat';
939 @file_put_contents($cacheFile, serialize($cacheData), LOCK_EX);
940 Log::debug('File scan results cached to: ' . $cacheFile);
941 }
942 }
static generateCacheHMAC($data, $cacheKey)

References $bearsamppRoot, Log\debug(), and generateCacheHMAC().

Referenced by getFilesToScan().

◆ setFileScanCacheDuration()

setFileScanCacheDuration ( $seconds)
static

Sets the file scan cache duration.

Parameters
int$secondsCache duration in seconds (default: 3600 = 1 hour).
Returns
void

Definition at line 1076 of file class.util.php.

1077 {
1078 if ($seconds > 0 && $seconds <= 86400) { // Max 24 hours
1079 self::$fileScanCacheDuration = $seconds;
1080 Log::debug('File scan cache duration set to ' . $seconds . ' seconds');
1081 }
1082 }

References Log\debug().

◆ setSysPathRegKey()

setSysPathRegKey ( $value)
static

Sets the system path in the registry.

Parameters
string$valueThe new value for the system path.
Returns
bool True on success, false on failure.

Definition at line 518 of file class.util.php.

519 {
520 global $bearsamppRegistry;
521
522 return $bearsamppRegistry->setExpandStringValue(
526 $value
527 );
528 }

References Registry\ENV_KEY, Registry\HKEY_LOCAL_MACHINE, and Registry\SYSPATH_REG_ENTRY.

Referenced by ActionStartup\checkSystemPathRegKey().

◆ startLoading()

startLoading ( )
static

Initiates a loading process using external components.

Definition at line 720 of file class.util.php.

721 {
722 global $bearsamppCore, $bearsamppWinbinder;
723
724 Log::trace('startLoading() called');
725 Log::trace('PHP executable: ' . $bearsamppCore->getPhpExe());
726 Log::trace('Root file: ' . Core::isRoot_FILE);
727 Log::trace('Action: ' . Action::LOADING);
728
729 $command = Core::isRoot_FILE . ' ' . Action::LOADING;
730 Log::trace('Executing command: ' . $bearsamppCore->getPhpExe() . ' ' . $command);
731
732 $result = $bearsamppWinbinder->exec($bearsamppCore->getPhpExe(), $command);
733 Log::trace('exec() returned: ' . var_export($result, true));
734
735 Log::trace('startLoading() completed');
736 }
const LOADING
const isRoot_FILE

References $bearsamppCore, $result, Core\isRoot_FILE, Action\LOADING, and Log\trace().

Referenced by ActionCheckVersion\__construct(), ActionEnable\__construct(), ActionLaunchStartup\__construct(), ActionManualRestart\__construct(), ActionRefreshRepos\__construct(), ActionReload\__construct(), ActionService\__construct(), ActionSwitchOnline\__construct(), and ActionStartup\processWindow().

◆ startService()

startService ( $bin,
$syntaxCheckCmd,
$showWindow = false )
static

Attempts to start a service and performs a syntax check if required.

Parameters
object$binAn object containing service details.
string$syntaxCheckCmdCommand to check syntax errors.
bool$showWindowWhether to show error messages in a window.
Returns
bool Returns true if the service starts successfully, false otherwise.

Definition at line 1770 of file class.util.php.

1771 {
1772 global $bearsamppLang, $bearsamppWinbinder;
1773
1774 if (method_exists($bin, 'initData')) {
1775 $bin->initData();
1776 }
1777
1778 $name = $bin->getName();
1779 $service = $bin->getService();
1780 $boxTitle = sprintf($bearsamppLang->getValue(Lang::START_SERVICE_TITLE), $name);
1781
1782 if (!$service->start()) {
1783 $serviceError = sprintf($bearsamppLang->getValue(Lang::START_SERVICE_ERROR), $name);
1784 $serviceErrorLog = sprintf('Error while starting the %s service', $name);
1785 if (!empty($syntaxCheckCmd)) {
1786 $cmdSyntaxCheck = $bin->getCmdLineOutput($syntaxCheckCmd);
1787 if (!$cmdSyntaxCheck['syntaxOk']) {
1788 $serviceError .= PHP_EOL . sprintf($bearsamppLang->getValue(Lang::STARTUP_SERVICE_SYNTAX_ERROR), $cmdSyntaxCheck['content']);
1789 $serviceErrorLog .= sprintf(' (conf errors detected : %s)', $cmdSyntaxCheck['content']);
1790 }
1791 }
1792 Log::error($serviceErrorLog);
1793 if ($showWindow) {
1794 $bearsamppWinbinder->messageBoxError($serviceError, $boxTitle);
1795 }
1796
1797 return false;
1798 }
1799
1800 return true;
1801 }
const START_SERVICE_ERROR
const START_SERVICE_TITLE

References $bearsamppLang, Log\error(), Lang\START_SERVICE_ERROR, Lang\START_SERVICE_TITLE, and Lang\STARTUP_SERVICE_SYNTAX_ERROR.

Referenced by BinPhp\setEnable(), ActionService\start(), and ServiceHelper\startService().

◆ stopLoading()

stopLoading ( )
static

Stops a previously started loading process and cleans up related resources.

Definition at line 741 of file class.util.php.

742 {
743 global $bearsamppCore;
744 if (file_exists($bearsamppCore->getLoadingPid())) {
745 $pids = file($bearsamppCore->getLoadingPid());
746 foreach ($pids as $pid) {
747 Win32Ps::kill($pid);
748 }
749 @unlink($bearsamppCore->getLoadingPid());
750 }
751
752 // Clean up status file
754 }
static clearLoadingText()
static kill($pid)

References $bearsamppCore, clearLoadingText(), and Win32Ps\kill().

Referenced by ActionManualRestart\__construct(), ActionService\__construct(), ActionCheckVersion\showVersionOkMessageBox(), and ActionCheckVersion\showVersionUpdateWindow().

◆ updateLoadingText()

updateLoadingText ( $text)
static

Updates the loading screen text (if loading screen is active) This allows dynamic updates to show which service is being processed

Parameters
string$textThe text to display on the loading screen

Definition at line 762 of file class.util.php.

763 {
764 global $bearsamppCore;
765
766 $statusFile = $bearsamppCore->getTmpPath() . '/loading_status.txt';
767 file_put_contents($statusFile, json_encode(['text' => $text]));
768 }

References $bearsamppCore.

Referenced by ActionChangePort\processWindow(), ActionService\restart(), ActionService\start(), and ActionService\stop().

◆ utf8ToCp1252()

utf8ToCp1252 ( $data)
static

Converts UTF-8 encoded data to Windows-1252 encoding.

Parameters
string$dataThe UTF-8 encoded data.
Returns
string Returns the data encoded in Windows-1252.

Definition at line 700 of file class.util.php.

701 {
702 return iconv('UTF-8', 'WINDOWS-1252//IGNORE', $data);
703 }

Referenced by ActionReload\__construct(), and convertEncoding().

◆ verifyCacheIntegrity()

verifyCacheIntegrity ( $fileContents,
$cacheKey )
staticprivate

Verifies cache file integrity using HMAC.

Parameters
string$fileContentsThe serialized cache file contents
string$cacheKeyThe cache key
Returns
bool True if integrity check passes, false otherwise

Definition at line 1012 of file class.util.php.

1013 {
1014 $cacheData = @unserialize($fileContents);
1015
1016 if ($cacheData === false || !isset($cacheData['hmac']) || !isset($cacheData['data'])) {
1017 return false;
1018 }
1019
1020 $expectedHmac = self::generateCacheHMAC($cacheData['data'], $cacheKey);
1021
1022 // Use hash_equals to prevent timing attacks
1023 return hash_equals($expectedHmac, $cacheData['hmac']);
1024 }

References generateCacheHMAC().

Field Documentation

◆ $cacheIntegrityKey

$cacheIntegrityKey = null
staticprivate

Definition at line 64 of file class.util.php.

◆ $fileScanCache

$fileScanCache = null
staticprivate

Definition at line 41 of file class.util.php.

◆ $fileScanCacheDuration

$fileScanCacheDuration = 3600
staticprivate

Definition at line 47 of file class.util.php.

◆ $fileScanStats

$fileScanStats
staticprivate
Initial value:
= [
'hits' => 0,
'misses' => 0,
'invalidations' => 0
]

Definition at line 53 of file class.util.php.


The documentation for this class was generated from the following file: