diff --git a/app/Protocols/General.php b/app/Protocols/General.php index b74b18cc..63a89471 100644 --- a/app/Protocols/General.php +++ b/app/Protocols/General.php @@ -104,7 +104,7 @@ class General { $config = [ "v" => "2", - "ps" => $server['name'], + "ps" => Helper::encodeURIComponent($server['name']), "add" => $server['host'], "port" => (string)$server['port'], "id" => $uuid, @@ -132,12 +132,12 @@ class General if ((string)$server['network'] === 'tcp') { $tcpSettings = $server['network_settings']; 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') { $wsSettings = $server['network_settings']; - if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; - if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; + if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); + if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); } if ((string)$server['network'] === 'grpc') { $grpcSettings = $server['network_settings']; @@ -146,7 +146,6 @@ class General //grpc需要继续修 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']}#${config['ps']}" . "\r\n"; } diff --git a/app/Protocols/Shadowrocket.php b/app/Protocols/Shadowrocket.php index e5414297..feaad8b8 100644 --- a/app/Protocols/Shadowrocket.php +++ b/app/Protocols/Shadowrocket.php @@ -126,7 +126,7 @@ class Shadowrocket { $config = [ "v" => "2", - "ps" => $server['name'], + "ps" => Helper::encodeURIComponent($server['name']), "add" => $server['host'], "port" => (string)$server['port'], "id" => $uuid, @@ -154,12 +154,12 @@ class Shadowrocket if ((string)$server['network'] === 'tcp') { $tcpSettings = $server['network_settings']; 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') { $wsSettings = $server['network_settings']; - if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; - if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; + if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); + if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); } if ((string)$server['network'] === 'grpc') { $grpcSettings = $server['network_settings']; @@ -168,7 +168,6 @@ class Shadowrocket //grpc需要继续修 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']}#${config['ps']}" . "\r\n"; } diff --git a/app/Protocols/V2rayN.php b/app/Protocols/V2rayN.php index b428de2d..d77e6c1a 100644 --- a/app/Protocols/V2rayN.php +++ b/app/Protocols/V2rayN.php @@ -104,7 +104,7 @@ class V2rayN { $config = [ "v" => "2", - "ps" => $server['name'], + "ps" => Helper::encodeURIComponent($server['name']), "add" => $server['host'], "port" => (string)$server['port'], "id" => $uuid, @@ -132,12 +132,12 @@ class V2rayN if ((string)$server['network'] === 'tcp') { $tcpSettings = $server['network_settings']; 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') { $wsSettings = $server['network_settings']; - if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; - if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; + if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); + if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); } if ((string)$server['network'] === 'grpc') { $grpcSettings = $server['network_settings']; @@ -146,7 +146,6 @@ class V2rayN //grpc需要继续修 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']}#${config['ps']}" . "\r\n"; } diff --git a/app/Protocols/V2rayNG.php b/app/Protocols/V2rayNG.php index 790681dc..96353630 100644 --- a/app/Protocols/V2rayNG.php +++ b/app/Protocols/V2rayNG.php @@ -2,6 +2,7 @@ namespace App\Protocols; +use App\Utils\Helper; class V2rayNG { @@ -92,7 +93,7 @@ class V2rayNG { $config = [ "v" => "2", - "ps" => $server['name'], + "ps" => Helper::encodeURIComponent($server['name']), "add" => $server['host'], "port" => (string)$server['port'], "id" => $uuid, @@ -120,12 +121,12 @@ class V2rayNG if ((string)$server['network'] === 'tcp') { $tcpSettings = $server['network_settings']; 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') { $wsSettings = $server['network_settings']; - if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; - if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; + if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); + if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); } if ((string)$server['network'] === 'grpc') { $grpcSettings = $server['network_settings']; @@ -134,7 +135,6 @@ class V2rayNG //grpc需要继续修 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']}#${config['ps']}" . "\r\n"; } diff --git a/app/Utils/Helper.php b/app/Utils/Helper.php index 196b4769..207b6d60 100644 --- a/app/Utils/Helper.php +++ b/app/Utils/Helper.php @@ -126,4 +126,8 @@ class Helper $encoded = base64_encode($data); return str_replace(['+', '/', '='], ['-', '_', ''], $encoded); } + public static function encodeURIComponent($str) { + $revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')'); + return strtr(rawurlencode($str), $revert); + } }