Skip to content

Commit 6fcc829

Browse files
authored
Merge branch 'main' into feature/2146-implement-a-data-cap
2 parents 3a100bc + fd7a034 commit 6fcc829

File tree

87 files changed

+1066
-559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1066
-559
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/Notifications/SendAppriseTestNotification.php

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
namespace App\Actions\Notifications;
44

55
use App\Notifications\Apprise\TestNotification;
6+
use App\Settings\NotificationSettings;
67
use Filament\Notifications\Notification;
78
use Illuminate\Support\Facades\Notification as FacadesNotification;
89
use Lorisleiva\Actions\Concerns\AsAction;
10+
use Throwable;
911

1012
class SendAppriseTestNotification
1113
{
1214
use AsAction;
1315

14-
public function handle(array $channel_urls)
16+
public function handle(array $channel_urls): void
1517
{
1618
if (! count($channel_urls)) {
1719
Notification::make()
@@ -22,24 +24,77 @@ public function handle(array $channel_urls)
2224
return;
2325
}
2426

25-
foreach ($channel_urls as $row) {
26-
$channelUrl = $row['channel_url'] ?? null;
27-
if (! $channelUrl) {
28-
Notification::make()
29-
->title('Skipping missing channel URL!')
30-
->warning()
31-
->send();
27+
$settings = app(NotificationSettings::class);
28+
$appriseUrl = rtrim($settings->apprise_server_url ?? '', '/');
3229

33-
continue;
30+
if (empty($appriseUrl)) {
31+
Notification::make()
32+
->title('Apprise Server URL is not configured')
33+
->body('Please configure the Apprise Server URL in the settings above.')
34+
->danger()
35+
->send();
36+
37+
return;
38+
}
39+
40+
try {
41+
foreach ($channel_urls as $row) {
42+
$channelUrl = $row['channel_url'] ?? null;
43+
if (! $channelUrl) {
44+
continue;
45+
}
46+
47+
// Use notifyNow() to send synchronously even though notification implements ShouldQueue
48+
// This allows us to catch exceptions and show them in the UI immediately
49+
FacadesNotification::route('apprise_urls', $channelUrl)
50+
->notifyNow(new TestNotification);
3451
}
52+
} catch (Throwable $e) {
53+
$errorMessage = $this->cleanErrorMessage($e);
54+
55+
Notification::make()
56+
->title('Failed to send Apprise test notification')
57+
->body($errorMessage)
58+
->danger()
59+
->send();
3560

36-
FacadesNotification::route('apprise_urls', $channelUrl)
37-
->notify(new TestNotification);
61+
return;
3862
}
3963

4064
Notification::make()
4165
->title('Test Apprise notification sent.')
4266
->success()
4367
->send();
4468
}
69+
70+
/**
71+
* Clean up error message for display in UI.
72+
*/
73+
protected function cleanErrorMessage(Throwable $e): string
74+
{
75+
$message = $e->getMessage();
76+
77+
// Get the full Apprise server URL for error messages
78+
$settings = app(NotificationSettings::class);
79+
$appriseUrl = rtrim($settings->apprise_server_url ?? '', '/');
80+
81+
// Handle connection errors - extract just the important part
82+
if (str_contains($message, 'cURL error')) {
83+
if (str_contains($message, 'Could not resolve host')) {
84+
return "Could not connect to Apprise server at {$appriseUrl}";
85+
}
86+
87+
if (str_contains($message, 'Connection refused')) {
88+
return "Connection refused by Apprise server at {$appriseUrl}";
89+
}
90+
91+
if (str_contains($message, 'Operation timed out')) {
92+
return "Connection to Apprise server at {$appriseUrl} timed out";
93+
}
94+
95+
return "Failed to connect to Apprise server at {$appriseUrl}";
96+
}
97+
98+
return $message;
99+
}
45100
}

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+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Foundation\Events\Dispatchable;
77
use Illuminate\Queue\SerializesModels;
88

9-
class SpeedtestBenchmarkFailed
9+
class SpeedtestBenchmarkHealthy
1010
{
1111
use Dispatchable, SerializesModels;
1212

app/Events/SpeedtestBenchmarkPassed.php renamed to app/Events/SpeedtestBenchmarkUnhealthy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Illuminate\Foundation\Events\Dispatchable;
77
use Illuminate\Queue\SerializesModels;
88

9-
class SpeedtestBenchmarkPassed
9+
class SpeedtestBenchmarkUnhealthy
1010
{
1111
use Dispatchable, SerializesModels;
1212

app/Filament/Pages/Settings/Notification.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Actions\Notifications\SendTelegramTestNotification;
1515
use App\Actions\Notifications\SendWebhookTestNotification;
1616
use App\Rules\AppriseScheme;
17+
use App\Rules\ContainsString;
1718
use App\Settings\NotificationSettings;
1819
use CodeWithDennis\SimpleAlert\Components\SimpleAlert;
1920
use Filament\Actions\Action;
@@ -233,10 +234,12 @@ public function form(Schema $schema): Schema
233234
->schema([
234235
TextInput::make('apprise_server_url')
235236
->label(__('settings/notifications.apprise_server_url'))
236-
->placeholder('http://localhost:8000')
237+
->placeholder('http://localhost:8000/notify')
238+
->helperText(__('settings/notifications.apprise_server_url_helper'))
237239
->maxLength(2000)
238240
->required()
239241
->url()
242+
->rule(new ContainsString('/notify'))
240243
->columnSpanFull(),
241244
Checkbox::make('apprise_verify_ssl')
242245
->label(__('settings/notifications.apprise_verify_ssl'))

app/Filament/Pages/Tools/ListOoklaServers.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use Filament\Forms\Components\Textarea;
88
use Filament\Forms\Concerns\InteractsWithForms;
99
use Filament\Forms\Contracts\HasForms;
10-
use Filament\Forms\Form;
1110
use Filament\Notifications\Notification;
1211
use Filament\Pages\Page;
12+
use Filament\Schemas\Schema;
1313

1414
class ListOoklaServers extends Page implements HasForms
1515
{
@@ -69,10 +69,10 @@ public function fetchServers(): void
6969
}
7070
}
7171

72-
public function form(Form $form): Form
72+
public function form(Schema $schema): Schema
7373
{
74-
return $form
75-
->schema([
74+
return $schema
75+
->components([
7676
Textarea::make('servers')
7777
->label(false)
7878
->rows(20)

0 commit comments

Comments
 (0)