diff --git a/app/Http/Livewire/Settings/Form.php b/app/Http/Livewire/Settings/Form.php index 02f04c999..3d34b4ddc 100644 --- a/app/Http/Livewire/Settings/Form.php +++ b/app/Http/Livewire/Settings/Form.php @@ -14,12 +14,15 @@ class Form extends Component public $do_not_track; public $is_auto_update_enabled; public $is_registration_enabled; + protected string $dynamic_config_path; + protected Server $server; protected $rules = [ 'settings.fqdn' => 'nullable', 'settings.wildcard_domain' => 'nullable', 'settings.public_port_min' => 'required', 'settings.public_port_max' => 'required', + 'settings.default_redirect_404' => 'nullable', ]; public function mount() { @@ -35,27 +38,13 @@ public function instantSave() $this->settings->save(); $this->emit('saved', 'Settings updated!'); } - public function submit() + private function setup_instance_fqdn() { - $this->resetErrorBag(); - if ($this->settings->public_port_min > $this->settings->public_port_max) { - $this->addError('settings.public_port_min', 'The minimum port must be lower than the maximum port.'); - return; - } - $this->validate(); - $this->settings->save(); - - $dynamic_config_path = '/data/coolify/proxy/dynamic'; - if (config('app.env') == 'local') { - $server = Server::findOrFail(1); - } else { - $server = Server::findOrFail(0); - } - + $file = "$this->dynamic_config_path/coolify.yaml"; if (empty($this->settings->fqdn)) { remote_process([ - "rm -f $dynamic_config_path/coolify.yaml", - ], $server); + "rm -f $file", + ], $this->server); } else { $url = Url::fromString($this->settings->fqdn); $host = $url->getHost(); @@ -108,19 +97,108 @@ public function submit() ], ]; } - $yaml = Yaml::dump($traefik_dynamic_conf, 12, 2); - $yaml = - "# This file is automatically generated by Coolify.\n" . - "# Do not edit it manually (only if you know what are you doing).\n\n" . - $yaml; - if (config('app.env') == 'local') { - dump($yaml); - } - $base64 = base64_encode($yaml); - remote_process([ - "mkdir -p $dynamic_config_path", - "echo '$base64' | base64 -d > $dynamic_config_path/coolify.yaml", - ], $server); + $this->save_configuration_to_disk($traefik_dynamic_conf, $file); } } + private function setup_default_redirect_404() + { + $file = "$this->dynamic_config_path/default_redirect_404.yaml"; + + if (empty($this->settings->default_redirect_404)) { + remote_process([ + "rm -f $file", + ], $this->server); + } else { + $url = Url::fromString($this->settings->default_redirect_404); + $host = $url->getHost(); + $schema = $url->getScheme(); + $traefik_dynamic_conf = [ + 'http' => + [ + 'routers' => + [ + 'catchall' => + [ + 'entryPoints' => [ + 0 => 'http', + 1 => 'https', + ], + 'service' => 'noop', + 'rule' => "HostRegexp(`{catchall:.*}`)", + 'priority' => 1, + 'middlewares' => [ + 0 => 'redirect-regexp@file', + ], + ], + ], + 'services' => + [ + 'noop' => + [ + 'loadBalancer' => + [ + 'servers' => + [ + 0 => + [ + 'url' => '', + ], + ], + ], + ], + ], + 'middlewares' => + [ + 'redirect-regexp' => + [ + 'redirectRegex' => + [ + 'regex' => '(.*)', + 'replacement' => $this->settings->default_redirect_404, + 'permanent' => false, + ], + ], + ], + ], + ]; + $this->save_configuration_to_disk($traefik_dynamic_conf, $file); + } + } + private function save_configuration_to_disk(array $traefik_dynamic_conf, string $file) + { + $yaml = Yaml::dump($traefik_dynamic_conf, 12, 2); + $yaml = + "# This file is automatically generated by Coolify.\n" . + "# Do not edit it manually (only if you know what are you doing).\n\n" . + $yaml; + + $base64 = base64_encode($yaml); + remote_process([ + "mkdir -p $this->dynamic_config_path", + "echo '$base64' | base64 -d > $file", + ], $this->server); + + if (config('app.env') == 'local') { + ray($yaml); + } + } + public function submit() + { + $this->resetErrorBag(); + if ($this->settings->public_port_min > $this->settings->public_port_max) { + $this->addError('settings.public_port_min', 'The minimum port must be lower than the maximum port.'); + return; + } + $this->validate(); + $this->settings->save(); + + $this->dynamic_config_path = '/data/coolify/proxy/dynamic'; + if (config('app.env') == 'local') { + $this->server = Server::findOrFail(1); + } else { + $this->server = Server::findOrFail(0); + } + $this->setup_instance_fqdn(); + $this->setup_default_redirect_404(); + } } diff --git a/database/migrations/2023_03_20_112813_create_instance_settings_table.php b/database/migrations/2023_03_20_112813_create_instance_settings_table.php index a6e241bb0..e8396b036 100644 --- a/database/migrations/2023_03_20_112813_create_instance_settings_table.php +++ b/database/migrations/2023_03_20_112813_create_instance_settings_table.php @@ -15,17 +15,15 @@ public function up(): void $table->id(); $table->string('fqdn')->nullable(); $table->string('wildcard_domain')->nullable(); - $table->string('redirect_url')->nullable(); - // $table->string('preview_domain_separator')->default('.'); + $table->string('default_redirect_404')->nullable(); $table->integer('public_port_min')->default(9000); $table->integer('public_port_max')->default(9100); - // $table->string('custom_dns_servers')->default('1.1.1.1,8.8.8.8'); - $table->boolean('do_not_track')->default(false); - $table->boolean('is_auto_update_enabled')->default(true); - // $table->boolean('is_dns_check_enabled')->default(true); $table->boolean('is_registration_enabled')->default(true); + // $table->string('preview_domain_separator')->default('.'); + // $table->string('custom_dns_servers')->default('1.1.1.1,8.8.8.8'); + // $table->boolean('is_dns_check_enabled')->default(true); $table->timestamps(); }); } diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index edf7729fa..475f4e7c0 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -66,6 +66,6 @@ services: image: ghcr.io/buggregator/server:latest container_name: coolify-debug ports: - - 8001:8000 + - 23517:8000 networks: - coolify diff --git a/examples/traefik-dynamic-catch-all.yaml b/examples/traefik-dynamic-catch-all.yaml new file mode 100644 index 000000000..54f7b1fb9 --- /dev/null +++ b/examples/traefik-dynamic-catch-all.yaml @@ -0,0 +1,23 @@ +# This is an example dynamic configuration. +http: + routers: + catchall: + entryPoints: + - http + - https + service: noop + rule: HostRegexp(`{catchall:.*}`) + priority: 1 + middlewares: + - redirect-regexp + services: + noop: + loadBalancer: + servers: + - url: '' + middlewares: + redirect-regexp: + redirectRegex: + regex: '(.*)' + replacement: 'https://coolify.io' + permanent: false \ No newline at end of file diff --git a/examples/traefik-dynamic-coolify.yaml b/examples/traefik-dynamic-coolify.yaml new file mode 100644 index 000000000..0c5f7e311 --- /dev/null +++ b/examples/traefik-dynamic-coolify.yaml @@ -0,0 +1,14 @@ +# This is an example dynamic configuration. +http: + routers: + coolify-http: + entryPoints: + - http + service: coolify + rule: Host(`coolify.io`) + services: + coolify: + loadBalancer: + servers: + - + url: 'http://coolify:80' \ No newline at end of file diff --git a/resources/css/app.css b/resources/css/app.css index f617da219..31f2eb8b4 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -127,6 +127,6 @@ @keyframes lds-heart { .bg-coollabs-gradient { @apply text-transparent bg-clip-text bg-gradient-to-r from-purple-500 via-pink-500 to-red-500; } -.bold-helper { +.text-helper { @apply inline-block font-bold text-warning } \ No newline at end of file diff --git a/resources/views/livewire/force-upgrade.blade.php b/resources/views/livewire/force-upgrade.blade.php index 3aa54fc7d..ef5472369 100644 --- a/resources/views/livewire/force-upgrade.blade.php +++ b/resources/views/livewire/force-upgrade.blade.php @@ -1,6 +1,7 @@