-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
76 lines (66 loc) · 1.76 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace JoelESvensson\OcTrustedProxy;
use Fideloper\Proxy\TrustProxies;
use Illuminate\Contracts\Http\Kernel;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
/**
* This plugin always needs to run
*/
public $elevated = true;
public function pluginDetails()
{
return array(
'name' => 'Trusted Proxy',
'description' => '',
'author' => 'Joel E. Svensson',
'icon' => 'icon-server',
'homepage' => ''
);
}
/**
* @param string $ips
* @return string|array
*/
protected static function buildIpList($ips)
{
$ips = trim($ips);
if ($ips === '*') {
return '*';
}
/**
* Create array of IP:s from comma separated string
*/
return collect(explode(',', $ips))
->map(function ($ip) {
return trim($ip);
})
->toArray()
;
}
public function register()
{
$this->app->singleton(
TrustProxies::class,
function ($app) {
$config = $app->make('config');
$proxies = env('TRUSTED_PROXIES');
if ($proxies) {
$proxies = static::buildIpList($proxies);
} else {
/**
* Empty array means no trusted proxies
*/
$proxies = [];
}
$config->set('trustedproxy.proxies', $proxies);
return new TrustProxies($config);
}
);
}
public function boot()
{
$this->app->make(Kernel::class)->prependMiddleware(TrustProxies::class);
}
}