diff --git a/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php b/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php new file mode 100644 index 000000000..acff38ccb --- /dev/null +++ b/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php @@ -0,0 +1,28 @@ +whereId($this->server_id)->first(); + $proxy_path = get_proxy_path(); + $file = str_replace('|', '.', $fileName); + instant_remote_process(["rm -f {$proxy_path}/dynamic/{$file}"], $server); + $this->dispatch('success', 'Success', 'File deleted.'); + $this->dispatch('loadDynamicConfigurations'); + $this->dispatch('refresh'); + } + public function render() + { + return view('livewire.server.proxy.dynamic-configuration-navbar'); + } +} diff --git a/app/Livewire/Server/Proxy/DynamicConfigurations.php b/app/Livewire/Server/Proxy/DynamicConfigurations.php new file mode 100644 index 000000000..9e7a89780 --- /dev/null +++ b/app/Livewire/Server/Proxy/DynamicConfigurations.php @@ -0,0 +1,49 @@ + '$refresh']; + protected $rules = [ + 'contents.*' => 'nullable|string', + ]; + public function loadDynamicConfigurations() + { + $proxy_path = get_proxy_path(); + $files = instant_remote_process(["mkdir -p $proxy_path/dynamic && ls -1 {$proxy_path}/dynamic"], $this->server); + $files = collect(explode("\n", $files))->filter(fn ($file) => !empty($file)); + $files = $files->map(fn ($file) => trim($file)); + $files = $files->sort(); + $files = $files->filter(fn ($file) => $file !== 'coolify.yaml')->prepend('coolify.yaml'); + $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; + } + 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); + } + } + public function render() + { + return view('livewire.server.proxy.dynamic-configurations'); + } +} diff --git a/app/Livewire/Server/Proxy/NewDynamicConfiguration.php b/app/Livewire/Server/Proxy/NewDynamicConfiguration.php new file mode 100644 index 000000000..cf9c88160 --- /dev/null +++ b/app/Livewire/Server/Proxy/NewDynamicConfiguration.php @@ -0,0 +1,73 @@ +parameters = get_route_parameters(); + if ($this->fileName !== '') { + $this->fileName = str_replace('|', '.', $this->fileName); + } + } + public function addDynamicConfiguration() + { + try { + $this->validate([ + 'fileName' => 'required', + 'value' => 'required', + ]); + + if (data_get($this->parameters, 'server_uuid')) { + $this->server = Server::ownedByCurrentTeam()->whereUuid(data_get($this->parameters, 'server_uuid'))->first(); + } + if (!is_null($this->server_id)) { + $this->server = Server::ownedByCurrentTeam()->whereId($this->server_id)->first(); + } + if (is_null($this->server)) { + return redirect()->route('server.index'); + } + if (!str($this->fileName)->endsWith('.yaml') && !str($this->fileName)->endsWith('.yml')) { + $this->fileName = "{$this->fileName}.yaml"; + } + if ($this->fileName === 'coolify.yaml') { + $this->dispatch('error', 'Error', 'File name is reserved.'); + return; + } + $proxy_path = get_proxy_path(); + $file = "{$proxy_path}/dynamic/{$this->fileName}"; + if ($this->newFile) { + $exists = instant_remote_process(["test -f $file && echo 1 || echo 0"], $this->server); + if ($exists == 1) { + $this->dispatch('error', 'Error', 'File already exists'); + return; + } + } + $yaml = Yaml::parse($this->value); + $yaml = Yaml::dump($yaml, 10, 2); + $this->value = $yaml; + $base64_value = base64_encode($this->value); + instant_remote_process(["echo '{$base64_value}' | base64 -d > {$file}"], $this->server); + $this->dispatch('loadDynamicConfigurations'); + $this->dispatch('dynamic-configuration-added'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function render() + { + return view('livewire.server.proxy.new-dynamic-configuration'); + } +} diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 094973a6a..ed5819494 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -104,13 +104,13 @@ function handleError(?Throwable $error = null, ?Livewire\Component $livewire = n ray($error); if ($error instanceof TooManyRequestsException) { if (isset($livewire)) { - return $livewire->dispatch('error', "Too many requests.", "Please try again in {$error->secondsUntilAvailable} seconds."); + return $livewire->dispatch('error', "Error", "Too many requests. Please try again in {$error->secondsUntilAvailable} seconds."); } return "Too many requests. Please try again in {$error->secondsUntilAvailable} seconds."; } if ($error instanceof UniqueConstraintViolationException) { if (isset($livewire)) { - return $livewire->dispatch('error', "Duplicate entry found.", "Please use a different name."); + return $livewire->dispatch('error', "Error", "Duplicate entry found. Please use a different name."); } return "Duplicate entry found. Please use a different name."; } @@ -126,7 +126,7 @@ function handleError(?Throwable $error = null, ?Livewire\Component $livewire = n if (isset($livewire)) { if (str($message)->length() > 20) { - return $livewire->dispatch('error', 'Error occured', $message); + return $livewire->dispatch('error', 'Error', $message); } return $livewire->dispatch('error', $message); } diff --git a/resources/views/components/proxy/options.blade.php b/resources/views/components/proxy/options.blade.php deleted file mode 100644 index 04a6f04ba..000000000 --- a/resources/views/components/proxy/options.blade.php +++ /dev/null @@ -1,47 +0,0 @@ -@props(['proxy_settings']) -