coolify/app/Http/Livewire/RunCommand.php

40 lines
934 B
PHP
Raw Normal View History

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