Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions app/Actions/CheckInternetConnection.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/Actions/GetExternalIpAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GetExternalIpAddress

public function handle(?string $url = null): array
{
$url = $url ?? config('speedtest.preflight.get_external_ip_url');
$url = $url ?? config('speedtest.preflight.external_ip_url');

try {
$response = Http::retry(3, 100)
Expand Down
27 changes: 27 additions & 0 deletions app/Actions/PingHostname.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Actions;

use Lorisleiva\Actions\Concerns\AsAction;
use Spatie\Ping\Ping;
use Spatie\Ping\PingResult;

class PingHostname
{
use AsAction;

public function handle(?string $hostname = null, int $count = 1): PingResult
{
$hostname = $hostname ?? config('speedtest.preflight.internet_check_hostname');

// Remove protocol if present
$hostname = preg_replace('#^https?://#', '', $hostname);

$ping = (new Ping(
hostname: $hostname,
count: $count,
))->run();

return $ping;
}
}
10 changes: 7 additions & 3 deletions app/Jobs/CheckForInternetConnectionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Jobs;

use App\Actions\CheckInternetConnection;
use App\Actions\PingHostname;
use App\Enums\ResultStatus;
use App\Events\SpeedtestChecking;
use App\Events\SpeedtestFailed;
Expand Down Expand Up @@ -44,14 +44,18 @@ public function handle(): void

SpeedtestChecking::dispatch($this->result);

if (CheckInternetConnection::run() !== false) {
$ping = PingHostname::run();

if ($ping->isSuccess()) {
return;
}

$message = sprintf('Failed to connected to hostname "%s". Error received "%s".', $ping->getHost(), $ping->error()?->value);

$this->result->update([
'data->type' => 'log',
'data->level' => 'error',
'data->message' => 'Failed to connect to the internet.',
'data->message' => $message,
'status' => ResultStatus::Failed,
]);

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"dragonmantank/cron-expression": "^3.6.0",
"filament/filament": "4.1.0",
"filament/spatie-laravel-settings-plugin": "^4.1",
"geerlingguy/ping": "^1.2.1",
"influxdata/influxdb-client-php": "^3.8",
"laravel-notification-channels/telegram": "^6.0",
"laravel/framework": "^12.41.1",
Expand All @@ -36,6 +35,7 @@
"spatie/laravel-query-builder": "^6.3.6",
"spatie/laravel-settings": "^3.6.0",
"spatie/laravel-webhook-server": "^3.8.3",
"spatie/ping": "^1.1.1",
"zircote/swagger-php": "^5.7.6"
},
"require-dev": {
Expand Down
98 changes: 60 additions & 38 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions config/speedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
'interface' => env('SPEEDTEST_INTERFACE'),

'preflight' => [
'get_external_ip_url' => env('SPEEDTEST_CHECKINTERNET_URL') ?? env('SPEEDTEST_GET_EXTERNAL_IP_URL', 'https://icanhazip.com'),
'external_ip_url' => env('SPEEDTEST_CHECKINTERNET_URL') ?? env('SPEEDTEST_EXTERNAL_IP_URL', 'https://icanhazip.com'),
'internet_check_hostname' => env('SPEEDTEST_CHECKINTERNET_URL') ?? env('SPEEDTEST_INTERNET_CHECK_HOSTNAME', 'icanhazip.com'),
],

'checkinternet_url' => env('SPEEDTEST_CHECKINTERNET_URL'), // ! DEPRECATED, use preflight.get_external_ip_url instead

/**
* IP filtering settings.
*/
Expand Down