From a627892c0bac6f673046c761d1a91c58adfa6c5b Mon Sep 17 00:00:00 2001 From: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com> Date: Fri, 1 Nov 2024 00:37:22 +0000 Subject: [PATCH] Remove Service --- app/Filament/Pages/Settings.php | 24 ++++++++++- app/Services/Helpers/TrustedProxyService.php | 42 -------------------- config/trustedproxy.php | 11 ----- 3 files changed, 22 insertions(+), 55 deletions(-) delete mode 100644 app/Services/Helpers/TrustedProxyService.php diff --git a/app/Filament/Pages/Settings.php b/app/Filament/Pages/Settings.php index 993bd2be1a..c9f3f9dcf0 100644 --- a/app/Filament/Pages/Settings.php +++ b/app/Filament/Pages/Settings.php @@ -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; @@ -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; @@ -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()); + }), ]), ]; } diff --git a/app/Services/Helpers/TrustedProxyService.php b/app/Services/Helpers/TrustedProxyService.php deleted file mode 100644 index c915ade040..0000000000 --- a/app/Services/Helpers/TrustedProxyService.php +++ /dev/null @@ -1,42 +0,0 @@ -client->request( - 'GET', - config('trustedproxy.auto.url'), - config('panel.guzzle') - ); - if ($response->getStatusCode() === 200) { - $result = json_decode($response->getBody(), true); - foreach (config('trustedproxy.auto.keys') as $value) { - $ips->push(...data_get($result, $value)); - } - $ips->unique(); - } - } catch (GuzzleException $e) { - } - - return $ips->values()->all(); - } -} diff --git a/config/trustedproxy.php b/config/trustedproxy.php index d30ca531d0..7e0166af8e 100644 --- a/config/trustedproxy.php +++ b/config/trustedproxy.php @@ -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', - ], - ], ];