mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-22 07:30:25 +00:00
update
This commit is contained in:
parent
d1a1bfbfff
commit
96bc319cb7
2 changed files with 16 additions and 22 deletions
|
@ -4,6 +4,17 @@ namespace App;
|
||||||
|
|
||||||
class ShellApi
|
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 = [])
|
public static function exec($command, $argsArray = [])
|
||||||
{
|
{
|
||||||
$args = '';
|
$args = '';
|
||||||
|
@ -15,27 +26,9 @@ class ShellApi
|
||||||
|
|
||||||
$fullCommand = $command.' '.$args;
|
$fullCommand = $command.' '.$args;
|
||||||
|
|
||||||
// Run the command as sudo "/usr/bin/sudo "
|
$execOutput = shell_exec($fullCommand);
|
||||||
$execOutput = shell_exec('/usr/bin/sudo '.$fullCommand);
|
|
||||||
$execOutput = str_replace(PHP_EOL, '', $execOutput);
|
|
||||||
|
|
||||||
return $execOutput;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ use App\Models\HostingPlan;
|
||||||
use App\Models\HostingSubscription;
|
use App\Models\HostingSubscription;
|
||||||
use Faker\Factory;
|
use Faker\Factory;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Tests\Feature\Api\ActionTestCase;
|
use Tests\Feature\Api\ActionTestCase;
|
||||||
|
|
||||||
class BackupTest extends ActionTestCase
|
class BackupTest extends ActionTestCase
|
||||||
|
@ -40,7 +41,7 @@ class BackupTest extends ActionTestCase
|
||||||
$this->assertTrue($backupFinished);
|
$this->assertTrue($backupFinished);
|
||||||
$this->assertSame($findLastBackup->status, BackupStatus::Completed);
|
$this->assertSame($findLastBackup->status, BackupStatus::Completed);
|
||||||
$this->assertNotEmpty($findLastBackup->filepath);
|
$this->assertNotEmpty($findLastBackup->filepath);
|
||||||
$this->assertTrue(file_exists($findLastBackup->filepath));
|
$this->assertTrue(file_exists(Storage::disk('backups')->path($findLastBackup->filepath)));
|
||||||
|
|
||||||
$backup = new Backup();
|
$backup = new Backup();
|
||||||
$checkCronJob = $backup->checkCronJob();
|
$checkCronJob = $backup->checkCronJob();
|
||||||
|
@ -91,13 +92,13 @@ class BackupTest extends ActionTestCase
|
||||||
|
|
||||||
$this->assertTrue($backupCompleted);
|
$this->assertTrue($backupCompleted);
|
||||||
$this->assertNotEmpty($findBackup->filepath);
|
$this->assertNotEmpty($findBackup->filepath);
|
||||||
$this->assertTrue(file_exists($findBackup->filepath));
|
$this->assertTrue(file_exists(Storage::disk('backups')->path($findBackup->filepath)));
|
||||||
|
|
||||||
$getFilesize = filesize($findBackup->filepath);
|
$getFilesize = filesize($findBackup->filepath);
|
||||||
$this->assertGreaterThan(0, $getFilesize);
|
$this->assertGreaterThan(0, $getFilesize);
|
||||||
$this->assertSame(Helpers::checkPathSize($findBackup->path), $findBackup->size);
|
$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');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue