add docker ip

This commit is contained in:
dongwei 2019-02-28 14:20:42 +08:00
parent 436a084581
commit 445f9dd037
2 changed files with 92 additions and 65 deletions

View File

@ -15,12 +15,21 @@ class InternalApi
app()->configure('internal_api');
}
private function isClientIPPermitted ($ip) {
private function isClientIPPermitted($ip)
{
if (!app()->environment('production', 'staging')) {
return true;
}
if (Str::startsWith($ip, [
'127.0.0.', '192.168.', '10.0.',
'127.0.0.1',
//局域网
'192.168.',
//vpc
'10.0.',
//pod network
'172.20.',
//北京办公区
'172.16.'
])) {
return true;
}
@ -51,7 +60,7 @@ class InternalApi
if (empty($params['timestamp'])) {
$data = ['error' => 'require time',];
return new JsonResponse($data, 403);
} elseif (intval($params['timestamp']) + 60 < time()) {
} else if (intval($params['timestamp']) + 60 < time()) {
$data = ['error' => 'sign expired',];
return new JsonResponse($data, 403);
}

View File

@ -2,8 +2,26 @@
namespace PdInternalApi;
use Illuminate\Http\Request;
class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function boot(){
Request::setTrustedProxies([
//pod network
'172.20.0.0/16',
//vpc
'10.0.0.0/16',
//local
'127.0.0.1',
//北京办公区
'172.16.0.0/16',
//aliyun slb
'100.116.0.0/16',
], Request::HEADER_X_FORWARDED_ALL);
}
/**
* Register any application services.
*