为vless订阅链接增加转义。

This commit is contained in:
root 2023-08-15 01:27:36 +09:00
parent 8259f40175
commit 29c1691086
5 changed files with 21 additions and 20 deletions

View File

@ -104,7 +104,7 @@ class General
{ {
$config = [ $config = [
"v" => "2", "v" => "2",
"ps" => $server['name'], "ps" => Helper::encodeURIComponent($server['name']),
"add" => $server['host'], "add" => $server['host'],
"port" => (string)$server['port'], "port" => (string)$server['port'],
"id" => $uuid, "id" => $uuid,
@ -132,12 +132,12 @@ class General
if ((string)$server['network'] === 'tcp') { if ((string)$server['network'] === 'tcp') {
$tcpSettings = $server['network_settings']; $tcpSettings = $server['network_settings'];
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type']; if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0]; if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = Helper::encodeURIComponent($tcpSettings['header']['request']['path'][0]);
} }
if ((string)$server['network'] === 'ws') { if ((string)$server['network'] === 'ws') {
$wsSettings = $server['network_settings']; $wsSettings = $server['network_settings'];
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']);
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']);
} }
if ((string)$server['network'] === 'grpc') { if ((string)$server['network'] === 'grpc') {
$grpcSettings = $server['network_settings']; $grpcSettings = $server['network_settings'];
@ -146,7 +146,6 @@ class General
//grpc需要继续修 //grpc需要继续修
if ($server['tls'] == 2) { if ($server['tls'] == 2) {
return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}&pbk={$config['pbk']}&sid={$config['sid']}#${config['ps']}" . "\r\n"; return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}&pbk={$config['pbk']}&sid={$config['sid']}#${config['ps']}" . "\r\n";
} }
return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}#${config['ps']}" . "\r\n"; return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}#${config['ps']}" . "\r\n";
} }

View File

@ -126,7 +126,7 @@ class Shadowrocket
{ {
$config = [ $config = [
"v" => "2", "v" => "2",
"ps" => $server['name'], "ps" => Helper::encodeURIComponent($server['name']),
"add" => $server['host'], "add" => $server['host'],
"port" => (string)$server['port'], "port" => (string)$server['port'],
"id" => $uuid, "id" => $uuid,
@ -154,12 +154,12 @@ class Shadowrocket
if ((string)$server['network'] === 'tcp') { if ((string)$server['network'] === 'tcp') {
$tcpSettings = $server['network_settings']; $tcpSettings = $server['network_settings'];
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type']; if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0]; if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = Helper::encodeURIComponent($tcpSettings['header']['request']['path'][0]);
} }
if ((string)$server['network'] === 'ws') { if ((string)$server['network'] === 'ws') {
$wsSettings = $server['network_settings']; $wsSettings = $server['network_settings'];
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']);
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']);
} }
if ((string)$server['network'] === 'grpc') { if ((string)$server['network'] === 'grpc') {
$grpcSettings = $server['network_settings']; $grpcSettings = $server['network_settings'];
@ -168,7 +168,6 @@ class Shadowrocket
//grpc需要继续修 //grpc需要继续修
if ($server['tls'] == 2) { if ($server['tls'] == 2) {
return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}&pbk={$config['pbk']}&sid={$config['sid']}#${config['ps']}" . "\r\n"; return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}&pbk={$config['pbk']}&sid={$config['sid']}#${config['ps']}" . "\r\n";
} }
return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}#${config['ps']}" . "\r\n"; return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}#${config['ps']}" . "\r\n";
} }

View File

@ -104,7 +104,7 @@ class V2rayN
{ {
$config = [ $config = [
"v" => "2", "v" => "2",
"ps" => $server['name'], "ps" => Helper::encodeURIComponent($server['name']),
"add" => $server['host'], "add" => $server['host'],
"port" => (string)$server['port'], "port" => (string)$server['port'],
"id" => $uuid, "id" => $uuid,
@ -132,12 +132,12 @@ class V2rayN
if ((string)$server['network'] === 'tcp') { if ((string)$server['network'] === 'tcp') {
$tcpSettings = $server['network_settings']; $tcpSettings = $server['network_settings'];
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type']; if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0]; if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = Helper::encodeURIComponent($tcpSettings['header']['request']['path'][0]);
} }
if ((string)$server['network'] === 'ws') { if ((string)$server['network'] === 'ws') {
$wsSettings = $server['network_settings']; $wsSettings = $server['network_settings'];
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']);
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']);
} }
if ((string)$server['network'] === 'grpc') { if ((string)$server['network'] === 'grpc') {
$grpcSettings = $server['network_settings']; $grpcSettings = $server['network_settings'];
@ -146,7 +146,6 @@ class V2rayN
//grpc需要继续修 //grpc需要继续修
if ($server['tls'] == 2) { if ($server['tls'] == 2) {
return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}&pbk={$config['pbk']}&sid={$config['sid']}#${config['ps']}" . "\r\n"; return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}&pbk={$config['pbk']}&sid={$config['sid']}#${config['ps']}" . "\r\n";
} }
return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}#${config['ps']}" . "\r\n"; return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}#${config['ps']}" . "\r\n";
} }

View File

@ -2,6 +2,7 @@
namespace App\Protocols; namespace App\Protocols;
use App\Utils\Helper;
class V2rayNG class V2rayNG
{ {
@ -92,7 +93,7 @@ class V2rayNG
{ {
$config = [ $config = [
"v" => "2", "v" => "2",
"ps" => $server['name'], "ps" => Helper::encodeURIComponent($server['name']),
"add" => $server['host'], "add" => $server['host'],
"port" => (string)$server['port'], "port" => (string)$server['port'],
"id" => $uuid, "id" => $uuid,
@ -120,12 +121,12 @@ class V2rayNG
if ((string)$server['network'] === 'tcp') { if ((string)$server['network'] === 'tcp') {
$tcpSettings = $server['network_settings']; $tcpSettings = $server['network_settings'];
if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type']; if (isset($tcpSettings['header']['type'])) $config['type'] = $tcpSettings['header']['type'];
if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = $tcpSettings['header']['request']['path'][0]; if (isset($tcpSettings['header']['request']['path'][0])) $config['path'] = Helper::encodeURIComponent($tcpSettings['header']['request']['path'][0]);
} }
if ((string)$server['network'] === 'ws') { if ((string)$server['network'] === 'ws') {
$wsSettings = $server['network_settings']; $wsSettings = $server['network_settings'];
if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']);
if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']);
} }
if ((string)$server['network'] === 'grpc') { if ((string)$server['network'] === 'grpc') {
$grpcSettings = $server['network_settings']; $grpcSettings = $server['network_settings'];
@ -134,7 +135,6 @@ class V2rayNG
//grpc需要继续修 //grpc需要继续修
if ($server['tls'] == 2) { if ($server['tls'] == 2) {
return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}&pbk={$config['pbk']}&sid={$config['sid']}#${config['ps']}" . "\r\n"; return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}&pbk={$config['pbk']}&sid={$config['sid']}#${config['ps']}" . "\r\n";
} }
return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}#${config['ps']}" . "\r\n"; return "vless://{$uuid}@{$config['add']}:{$server['port']}?type={$config['net']}&encryption=none&security={$config['tls']}&path={$config['path']}&host={$config['host']}&headerType={$config['type']}&flow={$server['flow']}&fp=chrome&sni={$config['sni']}#${config['ps']}" . "\r\n";
} }

View File

@ -126,4 +126,8 @@ class Helper
$encoded = base64_encode($data); $encoded = base64_encode($data);
return str_replace(['+', '/', '='], ['-', '_', ''], $encoded); return str_replace(['+', '/', '='], ['-', '_', ''], $encoded);
} }
public static function encodeURIComponent($str) {
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);
}
} }