Skip to content

Commit 2359cab

Browse files
authored
Merge branch 'main' into feat/schedule-ui
2 parents fb5a9ad + 43a88f5 commit 2359cab

File tree

12 files changed

+153
-95
lines changed

12 files changed

+153
-95
lines changed

app/Actions/CheckInternetConnection.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/Actions/GetExternalIpAddress.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,28 @@ class GetExternalIpAddress
1212
{
1313
use AsAction;
1414

15-
public function handle(): bool|string
15+
public function handle(?string $url = null): array
1616
{
17+
$url = $url ?? config('speedtest.preflight.external_ip_url');
18+
1719
try {
1820
$response = Http::retry(3, 100)
1921
->timeout(5)
20-
->get(url: 'https://icanhazip.com/');
22+
->get(url: $url);
2123
} catch (Throwable $e) {
22-
Log::error('Failed to fetch external IP address.', [$e->getMessage()]);
24+
$message = sprintf('Failed to fetch external IP address from "%s". See the logs for more details.', $url);
25+
26+
Log::error($message, [$e->getMessage()]);
2327

24-
return false;
28+
return [
29+
'ok' => false,
30+
'body' => $message,
31+
];
2532
}
2633

27-
return Str::trim($response->body());
34+
return [
35+
'ok' => $response->ok(),
36+
'body' => Str::of($response->body())->trim()->toString(),
37+
];
2838
}
2939
}

app/Actions/PingHostname.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Actions;
4+
5+
use Illuminate\Support\Facades\Log;
6+
use Lorisleiva\Actions\Concerns\AsAction;
7+
use Spatie\Ping\Ping;
8+
use Spatie\Ping\PingResult;
9+
10+
class PingHostname
11+
{
12+
use AsAction;
13+
14+
public function handle(?string $hostname = null, int $count = 1): PingResult
15+
{
16+
$hostname = $hostname ?? config('speedtest.preflight.internet_check_hostname');
17+
18+
// Remove protocol if present
19+
$hostname = preg_replace('#^https?://#', '', $hostname);
20+
21+
$ping = (new Ping(
22+
hostname: $hostname,
23+
count: $count,
24+
))->run();
25+
26+
Log::info('Pinged hostname', [
27+
'host' => $hostname,
28+
'data' => $ping->toArray(),
29+
]);
30+
31+
return $ping;
32+
}
33+
}

app/Jobs/CheckForInternetConnectionJob.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace App\Jobs;
44

5-
use App\Actions\CheckInternetConnection;
5+
use App\Actions\PingHostname;
66
use App\Enums\ResultStatus;
77
use App\Events\SpeedtestChecking;
88
use App\Events\SpeedtestFailed;
@@ -44,14 +44,18 @@ public function handle(): void
4444

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

47-
if (CheckInternetConnection::run() !== false) {
47+
$ping = PingHostname::run();
48+
49+
if ($ping->isSuccess()) {
4850
return;
4951
}
5052

53+
$message = sprintf('Failed to connected to hostname "%s". Error received "%s".', $ping->getHost(), $ping->error()?->value);
54+
5155
$this->result->update([
5256
'data->type' => 'log',
5357
'data->level' => 'error',
54-
'data->message' => 'Failed to connect to the internet.',
58+
'data->message' => $message,
5559
'status' => ResultStatus::Failed,
5660
]);
5761

app/Jobs/Ookla/RunSpeedtestJob.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function handle(): void
6060
'speedtest',
6161
'--accept-license',
6262
'--accept-gdpr',
63+
'--selection-details',
6364
'--format=json',
6465
$this->result->server_id ? '--server-id='.$this->result->server_id : null,
6566
config('speedtest.interface') ? '--interface='.config('speedtest.interface') : null,

app/Jobs/Ookla/SkipSpeedtestJob.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Actions\GetExternalIpAddress;
66
use App\Enums\ResultStatus;
7+
use App\Events\SpeedtestFailed;
78
use App\Events\SpeedtestSkipped;
89
use App\Helpers\Network;
910
use App\Models\Result;
@@ -47,8 +48,23 @@ public function handle(): void
4748

4849
$externalIp = GetExternalIpAddress::run();
4950

51+
if ($externalIp['ok'] === false) {
52+
$this->result->update([
53+
'data->type' => 'log',
54+
'data->level' => 'error',
55+
'data->message' => $externalIp['body'],
56+
'status' => ResultStatus::Failed,
57+
]);
58+
59+
SpeedtestFailed::dispatch($this->result);
60+
61+
$this->batch()->cancel();
62+
63+
return;
64+
}
65+
5066
$shouldSkip = $this->shouldSkip(
51-
externalIp: $externalIp,
67+
externalIp: $externalIp['body'],
5268
);
5369

5470
if ($shouldSkip === false) {
@@ -76,11 +92,11 @@ private function shouldSkip(string $externalIp): bool|string
7692
$skipIPs = array_filter(
7793
array_map(
7894
'trim',
79-
explode(',', config('speedtest.skip_ips')),
95+
explode(',', config('speedtest.preflight.skip_ips')),
8096
),
8197
);
8298

83-
if (count($skipIPs) < 1) {
99+
if (empty($skipIPs)) {
84100
return false;
85101
}
86102

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"dragonmantank/cron-expression": "^3.6.0",
2121
"filament/filament": "4.1.0",
2222
"filament/spatie-laravel-settings-plugin": "^4.1",
23-
"geerlingguy/ping": "^1.2.1",
2423
"influxdata/influxdb-client-php": "^3.8",
2524
"laravel-notification-channels/telegram": "^6.0",
2625
"laravel/framework": "^12.41.1",
@@ -37,6 +36,7 @@
3736
"spatie/laravel-query-builder": "^6.3.6",
3837
"spatie/laravel-settings": "^3.6.0",
3938
"spatie/laravel-webhook-server": "^3.8.3",
39+
"spatie/ping": "^1.1.1",
4040
"zircote/swagger-php": "^5.7.6"
4141
},
4242
"require-dev": {

composer.lock

Lines changed: 60 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/speedtest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
/**
77
* General settings.
88
*/
9-
'build_date' => Carbon::parse('2025-12-15'),
9+
'build_date' => Carbon::parse('2025-12-16'),
1010

11-
'build_version' => 'v1.12.4',
11+
'build_version' => 'v1.13.0',
1212

1313
'content_width' => env('CONTENT_WIDTH', '7xl'),
1414

@@ -29,15 +29,17 @@
2929

3030
'interface' => env('SPEEDTEST_INTERFACE'),
3131

32-
'checkinternet_url' => env('SPEEDTEST_CHECKINTERNET_URL', 'https://icanhazip.com'),
32+
'preflight' => [
33+
'external_ip_url' => env('SPEEDTEST_CHECKINTERNET_URL') ?? env('SPEEDTEST_EXTERNAL_IP_URL', 'https://icanhazip.com'),
34+
'internet_check_hostname' => env('SPEEDTEST_CHECKINTERNET_URL') ?? env('SPEEDTEST_INTERNET_CHECK_HOSTNAME', 'icanhazip.com'),
35+
'skip_ips' => env('SPEEDTEST_SKIP_IPS'),
36+
],
3337

3438
/**
3539
* IP filtering settings.
3640
*/
3741
'allowed_ips' => env('ALLOWED_IPS'),
3842

39-
'skip_ips' => env('SPEEDTEST_SKIP_IPS', ''),
40-
4143
/**
4244
* Threshold settings.
4345
*/

resources/views/filament/pages/dashboard.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class="col-span-1"
1212
icon="tabler-book"
1313
icon-size="md"
14+
:compact="true"
1415
>
1516
<x-slot name="heading">
1617
{{ __('general.documentation') }}
@@ -35,6 +36,7 @@ class="col-span-1"
3536
class="col-span-1"
3637
icon="tabler-cash-banknote-heart"
3738
icon-size="md"
39+
:compact="true"
3840
>
3941
<x-slot name="heading">
4042
{{ __('general.donations') }}
@@ -59,6 +61,7 @@ class="col-span-1"
5961
class="col-span-1"
6062
icon="tabler-brand-github"
6163
icon-size="md"
64+
:compact="true"
6265
>
6366
<x-slot name="heading">
6467
{{ __('general.speedtest_tracker') }}

0 commit comments

Comments
 (0)