2023-03-20 12:04:22 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 19:06:32 +01:00
|
|
|
namespace App\Livewire;
|
2023-03-20 12:04:22 +00:00
|
|
|
|
2023-03-24 22:15:36 +01:00
|
|
|
use App\Models\Server;
|
2023-03-20 12:04:22 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class RunCommand extends Component
|
|
|
|
{
|
2023-05-12 15:39:07 +02:00
|
|
|
public string $command;
|
2023-03-28 15:47:37 +02:00
|
|
|
public $server;
|
2023-03-24 22:15:36 +01:00
|
|
|
public $servers = [];
|
|
|
|
|
2023-03-29 12:27:02 +02:00
|
|
|
protected $rules = [
|
|
|
|
'server' => 'required',
|
2023-05-04 10:00:08 +02:00
|
|
|
'command' => 'required',
|
2023-03-29 12:27:02 +02:00
|
|
|
];
|
2023-06-16 12:35:40 +02:00
|
|
|
protected $validationAttributes = [
|
|
|
|
'server' => 'server',
|
|
|
|
'command' => 'command',
|
|
|
|
];
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-05-12 15:39:07 +02:00
|
|
|
public function mount($servers)
|
2023-03-24 22:15:36 +01:00
|
|
|
{
|
2023-05-12 15:39:07 +02:00
|
|
|
$this->servers = $servers;
|
|
|
|
$this->server = $servers[0]->uuid;
|
2023-03-24 22:15:36 +01:00
|
|
|
}
|
2023-03-20 12:04:22 +00:00
|
|
|
|
|
|
|
public function runCommand()
|
|
|
|
{
|
2023-06-19 11:02:01 +02:00
|
|
|
$this->validate();
|
2023-05-12 15:39:07 +02:00
|
|
|
try {
|
2023-06-07 15:39:08 +02:00
|
|
|
$activity = remote_process([$this->command], Server::where('uuid', $this->server)->first(), ignore_errors: true);
|
2024-02-05 14:40:54 +01:00
|
|
|
$this->dispatch('activityMonitor', $activity->id);
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 15:34:25 +02:00
|
|
|
return handleError($e, $this);
|
2023-05-12 15:39:07 +02:00
|
|
|
}
|
2023-03-20 12:04:22 +00:00
|
|
|
}
|
|
|
|
}
|