From 884a0f5ca64f478f8ca1a2e4c7e8a175f11ae88b Mon Sep 17 00:00:00 2001 From: Sven van Ginkel Date: Wed, 2 Apr 2025 17:38:08 +0200 Subject: [PATCH 1/2] Add config option for the internet check --- app/Actions/CheckInternetConnection.php | 33 ++++++++++++++++++++++ app/Jobs/CheckForInternetConnectionJob.php | 4 +-- config/speedtest.php | 2 ++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 app/Actions/CheckInternetConnection.php diff --git a/app/Actions/CheckInternetConnection.php b/app/Actions/CheckInternetConnection.php new file mode 100644 index 000000000..85f641023 --- /dev/null +++ b/app/Actions/CheckInternetConnection.php @@ -0,0 +1,33 @@ +timeout(5) + ->get(config('speedtest.externalip_url')); + + if (! $response->ok()) { + return false; + } + + return Str::trim($response->body()); + } catch (Throwable $e) { + Log::error('Failed to check internet connection.', [$e->getMessage()]); + + return false; + } + } +} diff --git a/app/Jobs/CheckForInternetConnectionJob.php b/app/Jobs/CheckForInternetConnectionJob.php index 1e8f3cc08..24e769e3a 100644 --- a/app/Jobs/CheckForInternetConnectionJob.php +++ b/app/Jobs/CheckForInternetConnectionJob.php @@ -2,7 +2,7 @@ namespace App\Jobs; -use App\Actions\GetExternalIpAddress; +use App\Actions\CheckInternetConnection; use App\Enums\ResultStatus; use App\Events\SpeedtestChecking; use App\Events\SpeedtestFailed; @@ -44,7 +44,7 @@ public function handle(): void SpeedtestChecking::dispatch($this->result); - if (GetExternalIpAddress::run() !== false) { + if (CheckInternetConnection::run() !== false) { return; } diff --git a/config/speedtest.php b/config/speedtest.php index a94f4faba..c976e374d 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -28,6 +28,8 @@ 'interface' => env('SPEEDTEST_INTERFACE'), + 'externalip_url' => env('SPEEDTEST_EXTERNALIP_URL', 'https://icanhazip.com'), + /** * IP filtering settings. */ From 3b9092ca919ac1c0c7bc73c2926675dbb7535082 Mon Sep 17 00:00:00 2001 From: Sven van Ginkel Date: Wed, 2 Apr 2025 17:44:11 +0200 Subject: [PATCH 2/2] Change name --- app/Actions/CheckInternetConnection.php | 2 +- config/speedtest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Actions/CheckInternetConnection.php b/app/Actions/CheckInternetConnection.php index 85f641023..c1c2ccd2f 100644 --- a/app/Actions/CheckInternetConnection.php +++ b/app/Actions/CheckInternetConnection.php @@ -17,7 +17,7 @@ public function handle(): bool|string try { $response = Http::retry(3, 100) ->timeout(5) - ->get(config('speedtest.externalip_url')); + ->get(config('speedtest.checkinternet_url')); if (! $response->ok()) { return false; diff --git a/config/speedtest.php b/config/speedtest.php index c976e374d..eff8cf2fd 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -28,7 +28,7 @@ 'interface' => env('SPEEDTEST_INTERFACE'), - 'externalip_url' => env('SPEEDTEST_EXTERNALIP_URL', 'https://icanhazip.com'), + 'checkinternet_url' => env('SPEEDTEST_CHECKINTERNET_URL', 'https://icanhazip.com'), /** * IP filtering settings.