46 if ( extension_loaded(
'winbinder' ) ) {
47 require_once $this->
getLibsPath() .
'/winbinder/winbinder.php';
180 return $bearsamppRoot->getCorePath( $aetrayPath ) .
'/' . self::isRoot_FILE;
193 if ( !is_file( $filePath ) ) {
199 return trim( file_get_contents( $filePath ) );
232 if (file_exists($file)) {
233 return trim(file_get_contents($file));
247 return $this->
getTmpPath( $aetrayPath ) .
'/' . self::EXEC;
257 file_put_contents( $this->
getExec(), $action );
279 file_put_contents( $this->
getLoadingPid(), $pid . PHP_EOL, FILE_APPEND );
303 return $this->
getPhpPath( $aetrayPath ) .
'/' . self::PHP_EXE;
315 return $this->
getLibsPath( $aetrayPath ) .
'/setenv';
327 return $this->
getSetEnvPath( $aetrayPath ) .
'/' . self::SETENV_EXE;
339 return $this->
getLibsPath( $aetrayPath ) .
'/nssm';
351 return $this->
getNssmPath( $aetrayPath ) .
'/' . self::NSSM_EXE;
363 return $this->
getLibsPath( $aetrayPath ) .
'/openssl';
375 return $this->
getOpenSslPath( $aetrayPath ) .
'/' . self::OPENSSL_EXE;
387 return $this->
getOpenSslPath( $aetrayPath ) .
'/' . self::OPENSSL_CONF;
399 return $this->
getLibsPath( $aetrayPath ) .
'/hostseditor';
435 return $this->
getLnPath( $aetrayPath ) .
'/' . self::LN_EXE;
447 return $this->
getLibsPath( $aetrayPath ) .
'/pwgen';
459 return $this->
getPwgenPath( $aetrayPath ) .
'/' . self::PWGEN_EXE;
469 return 'core object';
492 public function unzipFile($filePath, $destination, $progressCallback =
null)
496 $sevenZipPath = $this->
getLibsPath() .
'/7zip/7za.exe';
498 if ( !file_exists( $sevenZipPath ) ) {
499 Log::error(
'7za.exe not found at: ' . $sevenZipPath );
506 preg_match(
'/Files: (\d+)/', $testOutput !==
false ? $testOutput :
'', $matches);
507 $numFiles = isset($matches[1]) ? (int) $matches[1] : 0;
508 Log::trace(
'Number of files to be extracted: ' . $numFiles);
513 [
'x', $filePath,
'-y',
'-bsp1',
'-bb0',
'-o' . $destination],
514 function (
string $line) use ($progressCallback) {
516 if ($line ===
'Everything is Ok') {
517 if ($progressCallback) {
519 call_user_func($progressCallback, 100);
521 } elseif ($progressCallback && preg_match(
'/(?:^|\s)(\d+)%/', $line, $matches)) {
522 $currentPercentage = intval($matches[1]);
523 Log::trace(
"Extraction progress: $currentPercentage%");
524 call_user_func($progressCallback, $currentPercentage);
526 Log::trace(
"Line did not match pattern: $line");
531 if ($returnVar ===
false) {
532 Log::error(
'Failed to open process for: ' . $sevenZipPath);
533 return [
'error' =>
'Failed to open process',
'numFiles' => $numFiles];
536 Log::trace(
'Command return value: ' . $returnVar);
538 if ($returnVar === 0 && $progressCallback) {
539 Log::trace(
'Extraction completed successfully. Setting progress to 100%');
540 call_user_func($progressCallback, 100);
544 if ($returnVar === 0) {
545 Log::debug(
'Successfully unzipped file to: ' . $destination);
546 return [
'success' =>
true,
'numFiles' => $numFiles];
549 Log::error(
'Failed to unzip file. Command return value: ' . $returnVar);
550 return [
'error' =>
'Failed to unzip file',
'numFiles' => $numFiles];
567 public function getFileFromUrl(
string $moduleUrl,
string $filePath, $progressBar =
false)
570 $inputStream = @fopen( $moduleUrl,
'rb' );
571 if ( $inputStream ===
false ) {
572 Log::error(
'Error fetching content from URL: ' . $moduleUrl );
574 return [
'error' =>
'Error fetching module'];
578 $outputStream = @fopen( $filePath,
'wb' );
579 if ( $outputStream ===
false ) {
580 Log::error(
'Error opening file for writing: ' . $filePath );
581 fclose( $inputStream );
583 return [
'error' =>
'Error saving module'];
590 while ( !feof( $inputStream ) ) {
591 $buffer = fread( $inputStream, $bufferSize );
592 fwrite( $outputStream, $buffer );
596 if ( $progressBar ) {
597 $progress = $chunksRead;
598 echo json_encode( [
'progress' => $progress] );
601 if ( ob_get_length() !==
false ) {
608 fclose( $inputStream );
609 fclose( $outputStream );
611 return [
'success' =>
true];
static stream(string $executable, array $args, callable $lineCallback)
static exec(string $executable, array $args=[], string &$stderr='')
getAjaxPath($aetrayPath=false)
unzipFile($filePath, $destination, $progressCallback=null)
getLibsPath($aetrayPath=false)
getLnPath($aetrayPath=false)
getLastPath($aetrayPath=false)
getPwgenExe($aetrayPath=false)
getNssmPath($aetrayPath=false)
getSetEnvExe($aetrayPath=false)
getLnExe($aetrayPath=false)
getHomepagePath($aetrayPath=false)
getOpenSslPath($aetrayPath=false)
getPhpPath($aetrayPath=false)
getResourcesPath($aetrayPath=false)
getSetEnvPath($aetrayPath=false)
getExec($aetrayPath=false)
getIconsPath($aetrayPath=false)
getisRootFilePath($aetrayPath=false)
getFileFromUrl(string $moduleUrl, string $filePath, $progressBar=false)
const PATH_LIN_PLACEHOLDER
getLangsPath($aetrayPath=false)
getPhpExe($aetrayPath=false)
getNssmExe($aetrayPath=false)
getLoadingPid($aetrayPath=false)
getPwgenPath($aetrayPath=false)
getOpenSslConf($aetrayPath=false)
getTmpPath($aetrayPath=false)
getImagesPath($aetrayPath=false)
const PATH_WIN_PLACEHOLDER
getScriptsPath($aetrayPath=false)
getOpenSslExe($aetrayPath=false)
getHostsEditorExe($aetrayPath=false)
getHostsEditorPath($aetrayPath=false)
const ERROR_CONF_NOT_FOUND
static debug($data, $file=null)
static trace($data, $file=null)
static error($data, $file=null)