Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

1.8 KB
Raw Blame
<?php

namespace App\Livewire\Server\Proxy;

use App\Models\Server;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;

class DynamicConfigurationNavbar extends Component
{
    use AuthorizesRequests;

    public $server_id;

    public Server $server;

    public $fileName = '';

    public $value = '';

    public $newFile = false;

    public function delete(string $fileName)
    {
        try {
            $this->authorize('update', $this->server);
            $proxy_path = $this->server->proxyPath();
            $proxy_type = $this->server->proxyType();

            // Decode filename: pipes are used to encode dots for Livewire property binding
            // (e.g., 'my|service.yaml' -> 'my.service.yaml')
            // This must happen BEFORE validation because validateFilenameSafe()
            // rejects pipe characters through validateShellSafePath().
            $file = str_replace('|', '.', $fileName);

            validateFilenameSafe($file, 'proxy configuration filename');

            if ($proxy_type === 'CADDY' && $file === 'Caddyfile') {
                $this->dispatch('error', 'Cannot delete Caddyfile.');

                return;
            }

            $fullPath = "{$proxy_path}/dynamic/{$file}";
            $escapedPath = escapeshellarg($fullPath);
            instant_remote_process(["rm -f {$escapedPath}"], $this->server);
            if ($proxy_type === 'CADDY') {
                $this->server->reloadCaddy();
            }
            $this->dispatch('success', 'File deleted.');
            $this->dispatch('loadDynamicConfigurations');
            $this->dispatch('refresh');
        } catch (\Throwable $e) {
            return handleError($e, $this);
        }
    }

    public function render()
    {
        return view('livewire.server.proxy.dynamic-configuration-navbar');
    }
}