2023-03-20 12:04:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
2023-03-24 21:15:36 +00:00
|
|
|
use App\Models\Server;
|
2023-03-20 12:04:22 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class RunCommand extends Component
|
|
|
|
{
|
2023-05-12 13:39:07 +00:00
|
|
|
public string $command;
|
2023-03-28 13:47:37 +00:00
|
|
|
public $server;
|
2023-03-24 21:15:36 +00:00
|
|
|
public $servers = [];
|
|
|
|
|
2023-03-29 10:27:02 +00:00
|
|
|
protected $rules = [
|
|
|
|
'server' => 'required',
|
2023-05-04 08:00:08 +00:00
|
|
|
'command' => 'required',
|
2023-03-29 10:27:02 +00:00
|
|
|
];
|
2023-06-16 10:35:40 +00:00
|
|
|
protected $validationAttributes = [
|
|
|
|
'server' => 'server',
|
|
|
|
'command' => 'command',
|
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-12 13:39:07 +00:00
|
|
|
public function mount($servers)
|
2023-03-24 21:15:36 +00:00
|
|
|
{
|
2023-05-12 13:39:07 +00:00
|
|
|
$this->servers = $servers;
|
|
|
|
$this->server = $servers[0]->uuid;
|
2023-03-24 21:15:36 +00:00
|
|
|
}
|
2023-03-20 12:04:22 +00:00
|
|
|
|
|
|
|
public function runCommand()
|
|
|
|
{
|
2023-06-19 09:02:01 +00:00
|
|
|
$this->validate();
|
2023-05-12 13:39:07 +00:00
|
|
|
try {
|
2023-06-07 13:39:08 +00:00
|
|
|
$activity = remote_process([$this->command], Server::where('uuid', $this->server)->first(), ignore_errors: true);
|
2023-05-12 13:39:07 +00:00
|
|
|
$this->emit('newMonitorActivity', $activity->id);
|
|
|
|
} catch (\Exception $e) {
|
2023-06-09 13:55:21 +00:00
|
|
|
return general_error_handler(err: $e);
|
2023-05-12 13:39:07 +00:00
|
|
|
}
|
2023-03-20 12:04:22 +00:00
|
|
|
}
|
|
|
|
}
|