This commit is contained in:
Bozhidar 2024-05-01 01:55:07 +03:00
parent d1a1bfbfff
commit 96bc319cb7
2 changed files with 16 additions and 22 deletions

View file

@ -4,6 +4,17 @@ namespace App;
class ShellApi
{
public function safeRmRf($pathOrFile, $whiteListedPaths = [])
{
if (in_array($pathOrFile, $whiteListedPaths)) {
return false;
}
$exec = shell_exec('rm -rf ' . $pathOrFile);
return $exec;
}
public static function exec($command, $argsArray = [])
{
$args = '';
@ -15,27 +26,9 @@ class ShellApi
$fullCommand = $command.' '.$args;
// Run the command as sudo "/usr/bin/sudo "
$execOutput = shell_exec('/usr/bin/sudo '.$fullCommand);
$execOutput = str_replace(PHP_EOL, '', $execOutput);
$execOutput = shell_exec($fullCommand);
return $execOutput;
}
public static function callBin($command, $argsArray = [])
{
$args = '';
if (! empty($argsArray)) {
foreach ($argsArray as $arg) {
$args .= escapeshellarg($arg).' ';
}
}
$fullCommand = escapeshellarg('/usr/local/phyre/bin/'.$command.'.sh').' '.$args;
$commandAsSudo = '/usr/bin/sudo '.$fullCommand;
$execOutput = shell_exec($commandAsSudo);
return $execOutput;
}
}

View file

@ -10,6 +10,7 @@ use App\Models\HostingPlan;
use App\Models\HostingSubscription;
use Faker\Factory;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
use Tests\Feature\Api\ActionTestCase;
class BackupTest extends ActionTestCase
@ -40,7 +41,7 @@ class BackupTest extends ActionTestCase
$this->assertTrue($backupFinished);
$this->assertSame($findLastBackup->status, BackupStatus::Completed);
$this->assertNotEmpty($findLastBackup->filepath);
$this->assertTrue(file_exists($findLastBackup->filepath));
$this->assertTrue(file_exists(Storage::disk('backups')->path($findLastBackup->filepath)));
$backup = new Backup();
$checkCronJob = $backup->checkCronJob();
@ -91,13 +92,13 @@ class BackupTest extends ActionTestCase
$this->assertTrue($backupCompleted);
$this->assertNotEmpty($findBackup->filepath);
$this->assertTrue(file_exists($findBackup->filepath));
$this->assertTrue(file_exists(Storage::disk('backups')->path($findBackup->filepath)));
$getFilesize = filesize($findBackup->filepath);
$this->assertGreaterThan(0, $getFilesize);
$this->assertSame(Helpers::checkPathSize($findBackup->path), $findBackup->size);
Helpers::extractTar($findBackup->filepath, $findBackup->path . '/unit-test');
Helpers::extractTar(Storage::disk('backups')->path($findBackup->filepath), $findBackup->path . '/unit-test');
}