From 911e29f2ea0781d14401b712f27f3e257ef64d91 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 25 Apr 2024 13:52:52 +0200 Subject: [PATCH] fix: refresh public ips on start --- app/Console/Commands/Init.php | 2 ++ bootstrap/helpers/shared.php | 36 +++++++++++++++++++++++++++ database/seeders/ProductionSeeder.php | 22 +--------------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index acdff5b35..06414f715 100644 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -20,6 +20,7 @@ class Init extends Command public function handle() { $this->alive(); + get_public_ips(); $full_cleanup = $this->option('full-cleanup'); $cleanup_deployments = $this->option('cleanup-deployments'); if ($cleanup_deployments) { @@ -56,6 +57,7 @@ public function handle() $this->cleanup_stucked_helper_containers(); $this->call('cleanup:stucked-resources'); } + private function restore_coolify_db_backup() { try { diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 25c8cfb81..597ecbd29 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -29,11 +29,13 @@ use Illuminate\Database\UniqueConstraintViolationException; use Illuminate\Mail\Message; use Illuminate\Notifications\Messages\MailMessage; +use Illuminate\Process\Pool; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\Process; use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; @@ -2011,3 +2013,37 @@ function parseLineForSudo(string $command, Server $server): string return $command; } + +function get_public_ips() +{ + try { + echo "Refreshing public ips!\n"; + $settings = InstanceSettings::get(); + [$first, $second] = Process::concurrently(function (Pool $pool) { + $pool->path(__DIR__)->command('curl -4s https://ifconfig.io'); + $pool->path(__DIR__)->command('curl -6s https://ifconfig.io'); + }); + $ipv4 = $first->output(); + if ($ipv4) { + $ipv4 = trim($ipv4); + $validate_ipv4 = filter_var($ipv4, FILTER_VALIDATE_IP); + if ($validate_ipv4 == false) { + echo "Invalid ipv4: $ipv4\n"; + return; + } + $settings->update(['public_ipv4' => $ipv4]); + } + $ipv6 = $second->output(); + if ($ipv6) { + $ipv6 = trim($ipv6); + $validate_ipv6 = filter_var($ipv6, FILTER_VALIDATE_IP); + if ($validate_ipv6 == false) { + echo "Invalid ipv6: $ipv6\n"; + return; + } + $settings->update(['public_ipv6' => $ipv6]); + } + } catch (\Throwable $e) { + echo "Error: {$e->getMessage()}\n"; + } +} diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index 206e92f76..16dc3583e 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -177,27 +177,7 @@ public function run(): void } } - try { - $settings = InstanceSettings::get(); - if (is_null($settings->public_ipv4)) { - $ipv4 = Process::run('curl -4s https://ifconfig.io')->output(); - if ($ipv4) { - $ipv4 = trim($ipv4); - $ipv4 = filter_var($ipv4, FILTER_VALIDATE_IP); - $settings->update(['public_ipv4' => $ipv4]); - } - } - if (is_null($settings->public_ipv6)) { - $ipv6 = Process::run('curl -6s https://ifconfig.io')->output(); - if ($ipv6) { - $ipv6 = trim($ipv6); - $ipv6 = filter_var($ipv6, FILTER_VALIDATE_IP); - $settings->update(['public_ipv6' => $ipv6]); - } - } - } catch (\Throwable $e) { - echo "Error: {$e->getMessage()}\n"; - } + get_public_ips(); $oauth_settings_seeder = new OauthSettingSeeder(); $oauth_settings_seeder->run();