update: support grpc for clash & shadowrocket

This commit is contained in:
tokumeikoi 2021-06-12 15:42:44 +09:00
parent c5e2ec1d12
commit d510064732
4 changed files with 24 additions and 4 deletions

View File

@ -25,7 +25,7 @@ class ServerV2raySave extends FormRequest
'tags' => 'nullable|array', 'tags' => 'nullable|array',
'rate' => 'required|numeric', 'rate' => 'required|numeric',
'alter_id' => 'required|integer', 'alter_id' => 'required|integer',
'network' => 'required|in:tcp,kcp,ws,http,domainsocket,quic', 'network' => 'required|in:tcp,kcp,ws,http,domainsocket,quic,grpc',
'networkSettings' => '', 'networkSettings' => '',
'ruleSettings' => '', 'ruleSettings' => '',
'tlsSettings' => '', 'tlsSettings' => '',

View File

@ -32,7 +32,7 @@ class Clash
if ($server['tls']) { if ($server['tls']) {
$array['tls'] = true; $array['tls'] = true;
if ($server['tlsSettings']) { if (isset($server['tlsSettings'])) {
$tlsSettings = json_decode($server['tlsSettings'], true); $tlsSettings = json_decode($server['tlsSettings'], true);
if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure'])) if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
$array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false); $array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false);
@ -42,7 +42,7 @@ class Clash
} }
if ($server['network'] === 'ws') { if ($server['network'] === 'ws') {
$array['network'] = 'ws'; $array['network'] = 'ws';
if ($server['networkSettings']) { if (isset($server['networkSettings'])) {
$wsSettings = json_decode($server['networkSettings'], true); $wsSettings = json_decode($server['networkSettings'], true);
if (isset($wsSettings['path']) && !empty($wsSettings['path'])) if (isset($wsSettings['path']) && !empty($wsSettings['path']))
$array['ws-path'] = $wsSettings['path']; $array['ws-path'] = $wsSettings['path'];
@ -50,6 +50,14 @@ class Clash
$array['ws-headers'] = ['Host' => $wsSettings['headers']['Host']]; $array['ws-headers'] = ['Host' => $wsSettings['headers']['Host']];
} }
} }
if ($server['network'] === 'grpc') {
$array['network'] = 'grpc';
if (isset($server['networkSettings'])) {
$grpcObject = json_decode($server['networkSettings'], true);
$array['grpc-opts'] = [];
$array['grpc-opts']['grpc-service-name'] = $grpcObject['serviceName'];
}
}
return $array; return $array;
} }

View File

@ -44,6 +44,18 @@ class Shadowrocket
$config['obfsParam'] = $wsSettings['headers']['Host']; $config['obfsParam'] = $wsSettings['headers']['Host'];
} }
} }
if ($server['network'] === 'grpc') {
$config['obfs'] = "grpc";
if (isset($server['networkSettings'])) {
$grpcObject = json_decode($server['networkSettings'], true);
if (isset($grpcObject['serviceName'])) {
$config['obfsParam'] = json_decode([
'Host' => $grpcObject['serviceName']
]);
$config['path'] = '/';
}
}
}
$query = http_build_query($config, '', '&', PHP_QUERY_RFC3986); $query = http_build_query($config, '', '&', PHP_QUERY_RFC3986);
$uri = "vmess://{$userinfo}?{$query}"; $uri = "vmess://{$userinfo}?{$query}";
$uri .= "\r\n"; $uri .= "\r\n";

File diff suppressed because one or more lines are too long