Skip to content

Commit

Permalink
Remove Service
Browse files Browse the repository at this point in the history
  • Loading branch information
RMartinOscar committed Nov 1, 2024
1 parent f44eb21 commit a627892
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 55 deletions.
24 changes: 22 additions & 2 deletions app/Filament/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\Backup;
use App\Notifications\MailTested;
use App\Services\Helpers\TrustedProxyService;
use App\Traits\EnvironmentWriterTrait;
use Exception;
use Filament\Actions\Action;
Expand All @@ -25,6 +24,8 @@
use Filament\Pages\Concerns\HasUnsavedDataChangesAlert;
use Filament\Pages\Concerns\InteractsWithHeaderActions;
use Filament\Pages\Page;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Notification as MailNotification;

Expand Down Expand Up @@ -160,7 +161,26 @@ private function generalSettings(): array
->label('Set to Cloudflare IPs')
->icon('tabler-brand-cloudflare')
->authorize(fn () => auth()->user()->can('update settings'))
->action(fn (Set $set, TrustedProxyService $service) => $set('TRUSTED_PROXIES', $service->handle())),
->action(function (Client $client, Set $set) {
$ips = collect();
try {
$response = $client->request(
'GET',
'https://api.cloudflare.com/client/v4/ips',
config('panel.guzzle')
);
if ($response->getStatusCode() === 200) {
$result = json_decode($response->getBody(), true)['result'];
foreach (['ipv4_cidrs', 'ipv6_cidrs'] as $value) {
$ips->push(...data_get($result, $value));
}
$ips->unique();
}
} catch (GuzzleException $e) {
}

$set('TRUSTED_PROXIES', $ips->values()->all());
}),
]),
];
}
Expand Down
42 changes: 0 additions & 42 deletions app/Services/Helpers/TrustedProxyService.php

This file was deleted.

11 changes: 0 additions & 11 deletions config/trustedproxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,4 @@
*/
'proxies' => in_array(env('TRUSTED_PROXIES', []), ['*', '**']) ?
env('TRUSTED_PROXIES') : explode(',', env('TRUSTED_PROXIES') ?? ''),

/*
* Automatically pull ips from url
*/
'auto' => [
'url' => 'https://api.cloudflare.com/client/v4/ips',
'keys' => [
'result.ipv4_cidrs',
'result.ipv6_cidrs',
],
],
];

0 comments on commit a627892

Please sign in to comment.