lasthourcloud/app/Http/Livewire/RunCommand.php

36 lines
826 B
PHP
Raw Normal View History

2023-03-20 12:04:22 +00:00
<?php
namespace App\Http\Livewire;
2023-05-03 06:24:34 +00:00
use App\Enums\ActivityTypes;
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;
public $servers = [];
protected $rules = [
'server' => 'required',
2023-05-04 08:00:08 +00:00
'command' => 'required',
];
2023-05-12 13:39:07 +00:00
public function mount($servers)
{
2023-05-12 13:39:07 +00:00
$this->servers = $servers;
$this->server = $servers[0]->uuid;
}
2023-03-20 12:04:22 +00:00
public function runCommand()
{
2023-05-12 13:39:07 +00:00
try {
$this->validate();
$activity = remoteProcess([$this->command], Server::where('uuid', $this->server)->first(), ActivityTypes::INLINE->value);
$this->emit('newMonitorActivity', $activity->id);
} catch (\Exception $e) {
return generalErrorHandler($e);
}
2023-03-20 12:04:22 +00:00
}
}