diff --git a/app/Http/Controllers/frontend/ServiceController.php b/app/Http/Controllers/frontend/ServiceController.php index 7256cfd..71cf384 100644 --- a/app/Http/Controllers/frontend/ServiceController.php +++ b/app/Http/Controllers/frontend/ServiceController.php @@ -402,9 +402,7 @@ class ServiceController extends Controller \App\Jobs\VirtualMachine\Snapshot\CreateSnapshot::dispatch( $snapshot->id - ) - ->onQueue('snapshots') - ->delay(now()->addSeconds(3)); + )->delay(now()->addSeconds(3)); return redirect()->back()->with( 'success', diff --git a/app/Http/Services/vCenter.php b/app/Http/Services/vCenter.php index 527adf7..07a674e 100644 --- a/app/Http/Services/vCenter.php +++ b/app/Http/Services/vCenter.php @@ -300,11 +300,7 @@ class vCenter $action = "powershell.exe; Connect-viserver -Server '$this->apiUri' -User '$this->username' -Password \"'$this->password'\" -SaveCredentials; $cmd"; //Run action - $stream = ssh2_exec($auth, $action); - - stream_set_blocking($stream, true); - - return stream_get_contents($stream); + return $auth->exec($action); } catch (Exception $error) { return $error->getCode(); } @@ -314,9 +310,10 @@ class vCenter { try { - $connection = ssh2_connect('10.10.10.173', 22); + $connection = new SSH2('10.10.10.173', 22); - if (ssh2_auth_password($connection, 'administrator', 'Thegioiso@123**$$8899TgTk2')) { + if ($connection->login('administrator', 'Thegioiso@123**$$8899TgTk2')) { + $connection->setTimeout(0); // No timeout return $connection; } return false; @@ -351,14 +348,8 @@ class vCenter . '-Command "' . str_replace('"', '\"', $psCommand) . '"'; try { - $stream = ssh2_exec($auth, $action); - if (!$stream) - throw new \RuntimeException("ssh2_exec failed"); - $err = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR); - stream_set_blocking($stream, true); - stream_set_blocking($err, true); - $out = stream_get_contents($stream) ?: ''; - $errOut = stream_get_contents($err) ?: ''; + $out = $auth->exec($action); + $errOut = $auth->getStdError(); return $out . ($errOut ? "\n[STDERR]\n" . $errOut : ''); } catch (\Throwable $e) { return "Error: " . $e->getMessage(); @@ -412,14 +403,8 @@ PS; $action = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded"; try { - $stream = ssh2_exec($auth, $action); - if (!$stream) - return "ssh2_exec failed"; - $err = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR); - stream_set_blocking($stream, true); - stream_set_blocking($err, true); - $out = stream_get_contents($stream) ?: ''; - $errOut = stream_get_contents($err) ?: ''; + $out = $auth->exec($action); + $errOut = $auth->getStdError(); return $out . ($errOut ? "\n[STDERR]\n" . $errOut : ''); } catch (\Throwable $e) { return "Error: " . $e->getMessage(); @@ -467,15 +452,8 @@ PS; $action = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded"; try { - $stream = ssh2_exec($auth, $action); - if (!$stream) - return "ssh2_exec failed"; - $err = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR); - stream_set_blocking($stream, true); - stream_set_blocking($err, true); - - $out = stream_get_contents($stream) ?: ''; - $errOut = stream_get_contents($err) ?: ''; + $out = $auth->exec($action); + $errOut = $auth->getStdError(); if ($expectJson) { // CẮT JSON cuối: {...} hoặc [...] diff --git a/resources/views/frontend/layouts/topbar.blade.php b/resources/views/frontend/layouts/topbar.blade.php index e5edc1c..c922085 100644 --- a/resources/views/frontend/layouts/topbar.blade.php +++ b/resources/views/frontend/layouts/topbar.blade.php @@ -54,12 +54,13 @@