coolify/app/Livewire/Server/Proxy/DynamicConfigurations.php

66 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace App\Livewire\Server\Proxy;
use App\Models\Server;
use Illuminate\Support\Collection;
use Livewire\Component;
class DynamicConfigurations extends Component
{
public ?Server $server = null;
2024-06-10 22:43:34 +02:00
public $parameters = [];
2024-06-10 22:43:34 +02:00
public Collection $contents;
2024-06-10 22:43:34 +02:00
2024-03-12 12:30:40 +01:00
public function getListeners()
{
$teamId = auth()->user()->currentTeam()->id;
2024-06-10 22:43:34 +02:00
2024-03-12 12:30:40 +01:00
return [
"echo-private:team.{$teamId},ProxyStatusChanged" => 'loadDynamicConfigurations',
'loadDynamicConfigurations',
2024-06-10 22:43:34 +02:00
'refresh' => '$refresh',
2024-03-12 12:30:40 +01:00
];
}
2024-06-10 22:43:34 +02:00
protected $rules = [
'contents.*' => 'nullable|string',
];
2024-06-10 22:43:34 +02:00
public function loadDynamicConfigurations()
{
2024-03-11 15:08:05 +01:00
$proxy_path = $this->server->proxyPath();
$files = instant_remote_process(["mkdir -p $proxy_path/dynamic && ls -1 {$proxy_path}/dynamic"], $this->server);
2024-06-10 22:43:34 +02:00
$files = collect(explode("\n", $files))->filter(fn ($file) => ! empty($file));
$files = $files->map(fn ($file) => trim($file));
$files = $files->sort();
$contents = collect([]);
foreach ($files as $file) {
$without_extension = str_replace('.', '|', $file);
$contents[$without_extension] = instant_remote_process(["cat {$proxy_path}/dynamic/{$file}"], $this->server);
}
$this->contents = $contents;
2024-03-12 12:30:40 +01:00
$this->dispatch('refresh');
}
2024-06-10 22:43:34 +02:00
public function mount()
{
$this->parameters = get_route_parameters();
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->first();
if (is_null($this->server)) {
return redirect()->route('server.index');
}
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
2024-06-10 22:43:34 +02:00
public function render()
{
return view('livewire.server.proxy.dynamic-configurations');
}
}