diff --git a/app/Actions/CheckInternetConnection.php b/app/Actions/CheckInternetConnection.php new file mode 100644 index 000000000..c1c2ccd2f --- /dev/null +++ b/app/Actions/CheckInternetConnection.php @@ -0,0 +1,33 @@ +timeout(5) + ->get(config('speedtest.checkinternet_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..eff8cf2fd 100644 --- a/config/speedtest.php +++ b/config/speedtest.php @@ -28,6 +28,8 @@ 'interface' => env('SPEEDTEST_INTERFACE'), + 'checkinternet_url' => env('SPEEDTEST_CHECKINTERNET_URL', 'https://icanhazip.com'), + /** * IP filtering settings. */