forked from pelican-dev/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d87a13b
commit f44eb21
Showing
3 changed files
with
53 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Services\Helpers; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\GuzzleException; | ||
|
||
class TrustedProxyService | ||
{ | ||
/** | ||
* TrustedProxyService constructor. | ||
*/ | ||
public function __construct( | ||
protected Client $client | ||
) { | ||
} | ||
|
||
/** | ||
* Get provider ips list from given url | ||
*/ | ||
public function handle(): array | ||
{ | ||
$ips = collect(); | ||
try { | ||
$response = $this->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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters