From 451cfd341c236a5e791de78750f242312db4eaf9 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 20 Aug 2023 20:28:44 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=AF=E6=8C=81vless?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE=E7=9A=84=E5=AE=A2=E6=88=B7=E7=AB=AF=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Protocols/Clash.php | 62 +++++++++++++++++++++++ app/Protocols/ClashMeta.php | 2 +- app/Protocols/General.php | 70 +++++++++++++++++++------- app/Protocols/Passwall.php | 88 +++++++++++++++++++++++++++++++++ app/Protocols/SSRPlus.php | 86 ++++++++++++++++++++++++++++++++ app/Protocols/SagerNet.php | 90 ++++++++++++++++++++++++++++++++++ app/Protocols/Shadowrocket.php | 71 ++++++++++++++++++++------- app/Protocols/Stash.php | 61 +++++++++++++++++++++++ app/Protocols/V2rayN.php | 70 +++++++++++++++++++------- app/Protocols/V2rayNG.php | 72 +++++++++++++++++++-------- 10 files changed, 597 insertions(+), 75 deletions(-) diff --git a/app/Protocols/Clash.php b/app/Protocols/Clash.php index 4d6c4631..cc2f2874 100644 --- a/app/Protocols/Clash.php +++ b/app/Protocols/Clash.php @@ -52,6 +52,10 @@ class Clash array_push($proxy, self::buildVmess($user['uuid'], $item)); array_push($proxies, $item['name']); } + if ($item['type'] === 'vless') { + array_push($proxy, self::buildVless($user['uuid'], $item)); + array_push($proxies, $item['name']); + } if ($item['type'] === 'trojan') { array_push($proxy, self::buildTrojan($user['uuid'], $item)); array_push($proxies, $item['name']); @@ -159,6 +163,64 @@ class Clash return $array; } + public static function buildVless($uuid, $server) + { + $array = []; + $array['name'] = $server['name']; + $array['type'] = 'vless'; + $array['server'] = $server['host']; + $array['port'] = $server['port']; + $array['uuid'] = $uuid; + $array['flow'] = !empty($server['flow']) ? $server['flow']: ""; + $array['client-fingerprint'] = 'chrome'; + $array['udp'] = true; + + if ($server['tls']) { + $array['tls'] = true; + if ($server['tls_settings']) { + $tlsSettings = $server['tls_settings']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) + $array['servername'] = $tlsSettings['server_name']; + if ($server['tls'] == 2) { + $array['reality-opts'] = []; + $array['reality-opts']['public-key'] = $tlsSettings['public_key']; + $array['reality-opts']['short-id'] = $tlsSettings['shortId']; + } + } + } + + if ($server['network'] === 'tcp') { + $tcpSettings = $server['network_settings']; + } + + if ($server['network'] === 'ws') { + $array['network'] = 'ws'; + if ($server['network_settings']) { + $wsSettings = $server['network_settings']; + $array['ws-opts'] = []; + if (isset($wsSettings['path']) && !empty($wsSettings['path'])) + $array['ws-opts']['path'] = $wsSettings['path']; + if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host'])) + $array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']]; + if (isset($wsSettings['path']) && !empty($wsSettings['path'])) + $array['ws-path'] = $wsSettings['path']; + if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host'])) + $array['ws-headers'] = ['Host' => $wsSettings['headers']['Host']]; + } + } + if ($server['network'] === 'grpc') { + $array['network'] = 'grpc'; + if ($server['network_settings']) { + $grpcSettings = $server['network_settings']; + $array['grpc-opts'] = []; + if (isset($grpcSettings['serviceName'])) $array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName']; + } + } + + return $array; + } + + public static function buildTrojan($password, $server) { $array = []; diff --git a/app/Protocols/ClashMeta.php b/app/Protocols/ClashMeta.php index c6362793..a6f3535d 100644 --- a/app/Protocols/ClashMeta.php +++ b/app/Protocols/ClashMeta.php @@ -172,7 +172,7 @@ class ClashMeta $array['server'] = $server['host']; $array['port'] = $server['port']; $array['uuid'] = $uuid; - $array['flow'] = $server['flow']; + $array['flow'] = !empty($server['flow']) ? $server['flow']: ""; $array['client-fingerprint'] = 'chrome'; $array['udp'] = true; diff --git a/app/Protocols/General.php b/app/Protocols/General.php index 63a89471..48ebe8b7 100644 --- a/app/Protocols/General.php +++ b/app/Protocols/General.php @@ -103,51 +103,85 @@ class General public static function buildVless($uuid, $server) { $config = [ - "v" => "2", - "ps" => Helper::encodeURIComponent($server['name']), + "name" => Helper::encodeURIComponent($server['name']), "add" => $server['host'], "port" => (string)$server['port'], - "id" => $uuid, - "net" => $server['network'], - "type" => "none", + "type" => $server['network'], + "encryption" => "none", "host" => "", "path" => "", - "tls" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", + "headerType" => "none", + "quicSecurity" => "none", + "serviceName" => "", + "mode" => "gun", + "security" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", "flow" => $server['flow'], "sni" => "", "pbk" => "", "sid" =>"", ]; + + $output = "vless://" . $uuid . "@" . $config['add'] . ":" . $config['port']; + $output .= "?" . "type={$config['type']}" . "&encryption={$config['encryption']}" . "&security={$config['security']}"; + if ($server['tls']) { if ($server['tls_settings']) { $tlsSettings = $server['tls_settings']; - if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) - $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['flow']) && !empty($tlsSettings['flow'])) $config['flow'] = $tlsSettings['flow']; + + $output .= "&sni={$config['sni']}" . "&flow={$config['flow']}"; + if ($server['tls'] == 2) { - $config['pbk'] = $tlsSettings['public_key']; - $config['sid'] = $tlsSettings['shortId']; + $config['pbk'] = $tlsSettings['public_key']; + $config['sid'] = $tlsSettings['shortId']; + $output .= "&pbk={$config['pbk']}" . "&sid={$config['sid']}"; } } } 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'] = Helper::encodeURIComponent($tcpSettings['header']['request']['path'][0]); + if (isset($tcpSettings['header']['type'])) $config['headerType'] = $tcpSettings['header']['type']; + $output .= "&headerType={$config['headerType']}"; } + if ((string)$server['network'] === 'kcp') { + $kcpSettings = $server['network_settings']; + if (isset($kcpSettings['header']['type'])) $config['headerType'] = $kcpSettings['header']['type']; + if (isset($kcpSettings['seed'])) $config['path'] = Helper::encodeURIComponent($kcpSettings['seed']); + $output .= "&headerType={$config['headerType']}" . "&seed={$config['path']}"; + } if ((string)$server['network'] === 'ws') { $wsSettings = $server['network_settings']; if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'h2') { + $h2Settings = $server['network_settings']; + if (isset($h2Settings['path'])) $config['path'] = Helper::encodeURIComponent($h2Settings['path']); + if (isset($h2Settings['host'])) $config['host'] = Helper::encodeURIComponent($h2Settings['host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'quic') { + $quicSettings = $server['network_settings']; + if (isset($quicSettings['security'])) $config['quicSecurity'] = $quicSettings['security']; + if (isset($quicSettings['header']['type'])) $config['headerType'] = $quicSettings['header']['type']; + + $output .= "&quicSecurity={$config['quicSecurity']}" . "&headerType={$config['headerType']}"; + + if ((string)$quicSettings['security'] !== 'none' && isset($quicSettings['key'])) $config['path'] = Helper::encodeURIComponent($quicSettings['key']); + + $output .= "&key={$config['path']}"; } if ((string)$server['network'] === 'grpc') { $grpcSettings = $server['network_settings']; - if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['serviceName'])) $config['serviceName'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['multiMode'])) $config['mode'] = $grpcSettings['multiMode'] ? "multi" : "gun"; + $output .= "&serviceName={$config['serviceName']}" . "&mode={$config['mode']}"; } -//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"; + $output .= "&fp=chrome" . "#" . $config['name']; + + return $output . "\r\n"; } public static function buildTrojan($password, $server) diff --git a/app/Protocols/Passwall.php b/app/Protocols/Passwall.php index 0731bda9..ffa10a25 100644 --- a/app/Protocols/Passwall.php +++ b/app/Protocols/Passwall.php @@ -2,6 +2,7 @@ namespace App\Protocols; +use App\Utils\Helper; class Passwall { @@ -25,6 +26,9 @@ class Passwall if ($item['type'] === 'vmess') { $uri .= self::buildVmess($user['uuid'], $item); } + if ($item['type'] === 'vless') { + $uri .= self::buildVless($user['uuid'], $item); + } if ($item['type'] === 'shadowsocks') { $uri .= self::buildShadowsocks($user['uuid'], $item); } @@ -85,6 +89,90 @@ class Passwall return "vmess://" . base64_encode(json_encode($config)) . "\r\n"; } + public static function buildVless($uuid, $server) + { + $config = [ + "name" => Helper::encodeURIComponent($server['name']), + "add" => $server['host'], + "port" => (string)$server['port'], + "type" => $server['network'], + "encryption" => "none", + "host" => "", + "path" => "", + "headerType" => "none", + "quicSecurity" => "none", + "serviceName" => "", + "mode" => "gun", + "security" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", + "flow" => $server['flow'], + "sni" => "", + "pbk" => "", + "sid" =>"", + ]; + + $output = "vless://" . $uuid . "@" . $config['add'] . ":" . $config['port']; + $output .= "?" . "type={$config['type']}" . "&encryption={$config['encryption']}" . "&security={$config['security']}"; + + if ($server['tls']) { + if ($server['tls_settings']) { + $tlsSettings = $server['tls_settings']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['flow']) && !empty($tlsSettings['flow'])) $config['flow'] = $tlsSettings['flow']; + + $output .= "&sni={$config['sni']}" . "&flow={$config['flow']}"; + + if ($server['tls'] == 2) { + $config['pbk'] = $tlsSettings['public_key']; + $config['sid'] = $tlsSettings['shortId']; + $output .= "&pbk={$config['pbk']}" . "&sid={$config['sid']}"; + } + } + } + if ((string)$server['network'] === 'tcp') { + $tcpSettings = $server['network_settings']; + if (isset($tcpSettings['header']['type'])) $config['headerType'] = $tcpSettings['header']['type']; + $output .= "&headerType={$config['headerType']}"; + } + if ((string)$server['network'] === 'kcp') { + $kcpSettings = $server['network_settings']; + if (isset($kcpSettings['header']['type'])) $config['headerType'] = $kcpSettings['header']['type']; + if (isset($kcpSettings['seed'])) $config['path'] = Helper::encodeURIComponent($kcpSettings['seed']); + $output .= "&headerType={$config['headerType']}" . "&seed={$config['path']}"; + } + if ((string)$server['network'] === 'ws') { + $wsSettings = $server['network_settings']; + if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); + if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'h2') { + $h2Settings = $server['network_settings']; + if (isset($h2Settings['path'])) $config['path'] = Helper::encodeURIComponent($h2Settings['path']); + if (isset($h2Settings['host'])) $config['host'] = Helper::encodeURIComponent($h2Settings['host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'quic') { + $quicSettings = $server['network_settings']; + if (isset($quicSettings['security'])) $config['quicSecurity'] = $quicSettings['security']; + if (isset($quicSettings['header']['type'])) $config['headerType'] = $quicSettings['header']['type']; + + $output .= "&quicSecurity={$config['quicSecurity']}" . "&headerType={$config['headerType']}"; + + if ((string)$quicSettings['security'] !== 'none' && isset($quicSettings['key'])) $config['path'] = Helper::encodeURIComponent($quicSettings['key']); + + $output .= "&key={$config['path']}"; + } + if ((string)$server['network'] === 'grpc') { + $grpcSettings = $server['network_settings']; + if (isset($grpcSettings['serviceName'])) $config['serviceName'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['multiMode'])) $config['mode'] = $grpcSettings['multiMode'] ? "multi" : "gun"; + $output .= "&serviceName={$config['serviceName']}" . "&mode={$config['mode']}"; + } + $output .= "&fp=chrome" . "#" . $config['name']; + + return $output . "\r\n"; + } + public static function buildTrojan($password, $server) { $name = rawurlencode($server['name']); diff --git a/app/Protocols/SSRPlus.php b/app/Protocols/SSRPlus.php index 8622b8f2..7c04c3d3 100644 --- a/app/Protocols/SSRPlus.php +++ b/app/Protocols/SSRPlus.php @@ -25,6 +25,9 @@ class SSRPlus if ($item['type'] === 'vmess') { $uri .= self::buildVmess($user['uuid'], $item); } + if ($item['type'] === 'vless') { + $uri .= self::buildVless($user['uuid'], $item); + } if ($item['type'] === 'shadowsocks') { $uri .= self::buildShadowsocks($user['uuid'], $item); } @@ -80,6 +83,89 @@ class SSRPlus return "vmess://" . base64_encode(json_encode($config)) . "\r\n"; } + public static function buildVless($uuid, $server) + { + $config = [ + "name" => Helper::encodeURIComponent($server['name']), + "add" => $server['host'], + "port" => (string)$server['port'], + "type" => $server['network'], + "encryption" => "none", + "host" => "", + "path" => "", + "headerType" => "none", + "quicSecurity" => "none", + "serviceName" => "", + "mode" => "gun", + "security" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", + "flow" => $server['flow'], + "sni" => "", + "pbk" => "", + "sid" =>"", + ]; + + $output = "vless://" . $uuid . "@" . $config['add'] . ":" . $config['port']; + $output .= "?" . "type={$config['type']}" . "&encryption={$config['encryption']}" . "&security={$config['security']}"; + + if ($server['tls']) { + if ($server['tls_settings']) { + $tlsSettings = $server['tls_settings']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) { + $config['sni'] = $tlsSettings['server_name']; + $output .= "&sni={$config['sni']}"; + } + if ($server['tls'] == 2) { + $config['pbk'] = $tlsSettings['public_key']; + $config['sid'] = $tlsSettings['shortId']; + $output .= "&pbk={$config['pbk']}" . "&sid={$config['sid']}"; + } + } + } + if ((string)$server['network'] === 'tcp') { + $tcpSettings = $server['network_settings']; + if (isset($tcpSettings['header']['type'])) $config['headerType'] = $tcpSettings['header']['type']; + $output .= "&headerType={$config['headerType']}"; + } + if ((string)$server['network'] === 'kcp') { + $kcpSettings = $server['network_settings']; + if (isset($kcpSettings['header']['type'])) $config['headerType'] = $kcpSettings['header']['type']; + if (isset($kcpSettings['seed'])) $config['path'] = Helper::encodeURIComponent($kcpSettings['seed']); + $output .= "&headerType={$config['headerType']}" . "&seed={$config['path']}"; + } + if ((string)$server['network'] === 'ws') { + $wsSettings = $server['network_settings']; + if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); + if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'h2') { + $h2Settings = $server['network_settings']; + if (isset($h2Settings['path'])) $config['path'] = Helper::encodeURIComponent($h2Settings['path']); + if (isset($h2Settings['host'])) $config['host'] = Helper::encodeURIComponent($h2Settings['host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'quic') { + $quicSettings = $server['network_settings']; + if (isset($quicSettings['security'])) $config['quicSecurity'] = $quicSettings['security']; + if (isset($quicSettings['header']['type'])) $config['headerType'] = $quicSettings['header']['type']; + + $output .= "&quicSecurity={$config['quicSecurity']}" . "&headerType={$config['headerType']}"; + + if ((string)$quicSettings['security'] !== 'none' && isset($quicSettings['key'])) $config['path'] = Helper::encodeURIComponent($quicSettings['key']); + + $output .= "&key={$config['path']}"; + } + if ((string)$server['network'] === 'grpc') { + $grpcSettings = $server['network_settings']; + if (isset($grpcSettings['serviceName'])) $config['serviceName'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['multiMode'])) $config['mode'] = $grpcSettings['multiMode'] ? "multi" : "gun"; + $output .= "&serviceName={$config['serviceName']}" . "&mode={$config['mode']}"; + } + $output .= "&fp=chrome" . "#" . $config['name']; + + return $output . "\r\n"; + } + public static function buildTrojan($password, $server) { $name = rawurlencode($server['name']); diff --git a/app/Protocols/SagerNet.php b/app/Protocols/SagerNet.php index 781e8114..0f5b030d 100644 --- a/app/Protocols/SagerNet.php +++ b/app/Protocols/SagerNet.php @@ -2,6 +2,9 @@ namespace App\Protocols; + +use App\Utils\Helper; + class SagerNet { public $flag = 'sagernet'; @@ -24,6 +27,9 @@ class SagerNet if ($item['type'] === 'vmess') { $uri .= self::buildVmess($user['uuid'], $item); } + if ($item['type'] === 'vless') { + $uri .= self::buildVless($user['uuid'], $item); + } if ($item['type'] === 'shadowsocks') { $uri .= self::buildShadowsocks($user['uuid'], $item); } @@ -89,6 +95,90 @@ class SagerNet return "vmess://" . $uuid . "@" . $server['host'] . ":" . $server['port'] . "?" . http_build_query($config) . "#" . urlencode($server['name']) . "\r\n"; } + public static function buildVless($uuid, $server) + { + $config = [ + "name" => Helper::encodeURIComponent($server['name']), + "add" => $server['host'], + "port" => (string)$server['port'], + "type" => $server['network'], + "encryption" => "none", + "host" => "", + "path" => "", + "headerType" => "none", + "quicSecurity" => "none", + "serviceName" => "", + "mode" => "gun", + "security" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", + "flow" => $server['flow'], + "sni" => "", + "pbk" => "", + "sid" =>"", + ]; + + $output = "vless://" . $uuid . "@" . $config['add'] . ":" . $config['port']; + $output .= "?" . "type={$config['type']}" . "&encryption={$config['encryption']}" . "&security={$config['security']}"; + + if ($server['tls']) { + if ($server['tls_settings']) { + $tlsSettings = $server['tls_settings']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['flow']) && !empty($tlsSettings['flow'])) $config['flow'] = $tlsSettings['flow']; + + $output .= "&sni={$config['sni']}" . "&flow={$config['flow']}"; + + if ($server['tls'] == 2) { + $config['pbk'] = $tlsSettings['public_key']; + $config['sid'] = $tlsSettings['shortId']; + $output .= "&pbk={$config['pbk']}" . "&sid={$config['sid']}"; + } + } + } + if ((string)$server['network'] === 'tcp') { + $tcpSettings = $server['network_settings']; + if (isset($tcpSettings['header']['type'])) $config['headerType'] = $tcpSettings['header']['type']; + $output .= "&headerType={$config['headerType']}"; + } + if ((string)$server['network'] === 'kcp') { + $kcpSettings = $server['network_settings']; + if (isset($kcpSettings['header']['type'])) $config['headerType'] = $kcpSettings['header']['type']; + if (isset($kcpSettings['seed'])) $config['path'] = Helper::encodeURIComponent($kcpSettings['seed']); + $output .= "&headerType={$config['headerType']}" . "&seed={$config['path']}"; + } + if ((string)$server['network'] === 'ws') { + $wsSettings = $server['network_settings']; + if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); + if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'h2') { + $h2Settings = $server['network_settings']; + if (isset($h2Settings['path'])) $config['path'] = Helper::encodeURIComponent($h2Settings['path']); + if (isset($h2Settings['host'])) $config['host'] = Helper::encodeURIComponent($h2Settings['host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'quic') { + $quicSettings = $server['network_settings']; + if (isset($quicSettings['security'])) $config['quicSecurity'] = $quicSettings['security']; + if (isset($quicSettings['header']['type'])) $config['headerType'] = $quicSettings['header']['type']; + + $output .= "&quicSecurity={$config['quicSecurity']}" . "&headerType={$config['headerType']}"; + + if ((string)$quicSettings['security'] !== 'none' && isset($quicSettings['key'])) $config['path'] = Helper::encodeURIComponent($quicSettings['key']); + + $output .= "&key={$config['path']}"; + } + if ((string)$server['network'] === 'grpc') { + $grpcSettings = $server['network_settings']; + if (isset($grpcSettings['serviceName'])) $config['serviceName'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['multiMode'])) $config['mode'] = $grpcSettings['multiMode'] ? "multi" : "gun"; + $output .= "&serviceName={$config['serviceName']}" . "&mode={$config['mode']}"; + } + $output .= "&fp=chrome" . "#" . $config['name']; + + return $output . "\r\n"; + } + public static function buildTrojan($uuid, $server) { $name = rawurlencode($server['name']); diff --git a/app/Protocols/Shadowrocket.php b/app/Protocols/Shadowrocket.php index feaad8b8..64164c39 100644 --- a/app/Protocols/Shadowrocket.php +++ b/app/Protocols/Shadowrocket.php @@ -122,54 +122,89 @@ class Shadowrocket $uri .= "\r\n"; return $uri; } + public static function buildVless($uuid, $server) { $config = [ - "v" => "2", - "ps" => Helper::encodeURIComponent($server['name']), + "name" => Helper::encodeURIComponent($server['name']), "add" => $server['host'], "port" => (string)$server['port'], - "id" => $uuid, - "net" => $server['network'], - "type" => "none", + "type" => $server['network'], + "encryption" => "none", "host" => "", "path" => "", - "tls" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", + "headerType" => "none", + "quicSecurity" => "none", + "serviceName" => "", + "mode" => "gun", + "security" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", "flow" => $server['flow'], "sni" => "", "pbk" => "", "sid" =>"", ]; + + $output = "vless://" . $uuid . "@" . $config['add'] . ":" . $config['port']; + $output .= "?" . "type={$config['type']}" . "&encryption={$config['encryption']}" . "&security={$config['security']}"; + if ($server['tls']) { if ($server['tls_settings']) { $tlsSettings = $server['tls_settings']; - if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) - $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['flow']) && !empty($tlsSettings['flow'])) $config['flow'] = $tlsSettings['flow']; + + $output .= "&sni={$config['sni']}" . "&flow={$config['flow']}"; + if ($server['tls'] == 2) { - $config['pbk'] = $tlsSettings['public_key']; - $config['sid'] = $tlsSettings['shortId']; + $config['pbk'] = $tlsSettings['public_key']; + $config['sid'] = $tlsSettings['shortId']; + $output .= "&pbk={$config['pbk']}" . "&sid={$config['sid']}"; } } } 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'] = Helper::encodeURIComponent($tcpSettings['header']['request']['path'][0]); + if (isset($tcpSettings['header']['type'])) $config['headerType'] = $tcpSettings['header']['type']; + $output .= "&headerType={$config['headerType']}"; } + if ((string)$server['network'] === 'kcp') { + $kcpSettings = $server['network_settings']; + if (isset($kcpSettings['header']['type'])) $config['headerType'] = $kcpSettings['header']['type']; + if (isset($kcpSettings['seed'])) $config['path'] = Helper::encodeURIComponent($kcpSettings['seed']); + $output .= "&headerType={$config['headerType']}" . "&seed={$config['path']}"; + } if ((string)$server['network'] === 'ws') { $wsSettings = $server['network_settings']; if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'h2') { + $h2Settings = $server['network_settings']; + if (isset($h2Settings['path'])) $config['path'] = Helper::encodeURIComponent($h2Settings['path']); + if (isset($h2Settings['host'])) $config['host'] = Helper::encodeURIComponent($h2Settings['host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'quic') { + $quicSettings = $server['network_settings']; + if (isset($quicSettings['security'])) $config['quicSecurity'] = $quicSettings['security']; + if (isset($quicSettings['header']['type'])) $config['headerType'] = $quicSettings['header']['type']; + + $output .= "&quicSecurity={$config['quicSecurity']}" . "&headerType={$config['headerType']}"; + + if ((string)$quicSettings['security'] !== 'none' && isset($quicSettings['key'])) $config['path'] = Helper::encodeURIComponent($quicSettings['key']); + + $output .= "&key={$config['path']}"; } if ((string)$server['network'] === 'grpc') { $grpcSettings = $server['network_settings']; - if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['serviceName'])) $config['serviceName'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['multiMode'])) $config['mode'] = $grpcSettings['multiMode'] ? "multi" : "gun"; + $output .= "&serviceName={$config['serviceName']}" . "&mode={$config['mode']}"; } -//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"; + $output .= "&fp=chrome" . "#" . $config['name']; + + return $output . "\r\n"; } public static function buildTrojan($password, $server) diff --git a/app/Protocols/Stash.php b/app/Protocols/Stash.php index 8f916e8d..5892f741 100644 --- a/app/Protocols/Stash.php +++ b/app/Protocols/Stash.php @@ -51,6 +51,10 @@ class Stash array_push($proxy, self::buildVmess($user['uuid'], $item)); array_push($proxies, $item['name']); } + if ($item['type'] === 'vless') { + array_push($proxy, self::buildVless($user['uuid'], $item)); + array_push($proxies, $item['name']); + } if ($item['type'] === 'trojan') { array_push($proxy, self::buildTrojan($user['uuid'], $item)); array_push($proxies, $item['name']); @@ -157,6 +161,63 @@ class Stash return $array; } + public static function buildVless($uuid, $server) + { + $array = []; + $array['name'] = $server['name']; + $array['type'] = 'vless'; + $array['server'] = $server['host']; + $array['port'] = $server['port']; + $array['uuid'] = $uuid; + $array['flow'] = !empty($server['flow']) ? $server['flow']: ""; + $array['client-fingerprint'] = 'chrome'; + $array['udp'] = true; + + if ($server['tls']) { + $array['tls'] = true; + if ($server['tls_settings']) { + $tlsSettings = $server['tls_settings']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) + $array['servername'] = $tlsSettings['server_name']; + if ($server['tls'] == 2) { + $array['reality-opts'] = []; + $array['reality-opts']['public-key'] = $tlsSettings['public_key']; + $array['reality-opts']['short-id'] = $tlsSettings['shortId']; + } + } + } + + if ($server['network'] === 'tcp') { + $tcpSettings = $server['network_settings']; + } + + if ($server['network'] === 'ws') { + $array['network'] = 'ws'; + if ($server['network_settings']) { + $wsSettings = $server['network_settings']; + $array['ws-opts'] = []; + if (isset($wsSettings['path']) && !empty($wsSettings['path'])) + $array['ws-opts']['path'] = $wsSettings['path']; + if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host'])) + $array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']]; + if (isset($wsSettings['path']) && !empty($wsSettings['path'])) + $array['ws-path'] = $wsSettings['path']; + if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host'])) + $array['ws-headers'] = ['Host' => $wsSettings['headers']['Host']]; + } + } + if ($server['network'] === 'grpc') { + $array['network'] = 'grpc'; + if ($server['network_settings']) { + $grpcSettings = $server['network_settings']; + $array['grpc-opts'] = []; + if (isset($grpcSettings['serviceName'])) $array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName']; + } + } + + return $array; + } + public static function buildTrojan($password, $server) { $array = []; diff --git a/app/Protocols/V2rayN.php b/app/Protocols/V2rayN.php index d77e6c1a..64bead92 100644 --- a/app/Protocols/V2rayN.php +++ b/app/Protocols/V2rayN.php @@ -103,51 +103,85 @@ class V2rayN public static function buildVless($uuid, $server) { $config = [ - "v" => "2", - "ps" => Helper::encodeURIComponent($server['name']), + "name" => Helper::encodeURIComponent($server['name']), "add" => $server['host'], "port" => (string)$server['port'], - "id" => $uuid, - "net" => $server['network'], - "type" => "none", + "type" => $server['network'], + "encryption" => "none", "host" => "", "path" => "", - "tls" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", + "headerType" => "none", + "quicSecurity" => "none", + "serviceName" => "", + "mode" => "gun", + "security" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", "flow" => $server['flow'], "sni" => "", "pbk" => "", "sid" =>"", ]; + + $output = "vless://" . $uuid . "@" . $config['add'] . ":" . $config['port']; + $output .= "?" . "type={$config['type']}" . "&encryption={$config['encryption']}" . "&security={$config['security']}"; + if ($server['tls']) { if ($server['tls_settings']) { $tlsSettings = $server['tls_settings']; - if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) - $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['flow']) && !empty($tlsSettings['flow'])) $config['flow'] = $tlsSettings['flow']; + + $output .= "&sni={$config['sni']}" . "&flow={$config['flow']}"; + if ($server['tls'] == 2) { - $config['pbk'] = $tlsSettings['public_key']; - $config['sid'] = $tlsSettings['shortId']; + $config['pbk'] = $tlsSettings['public_key']; + $config['sid'] = $tlsSettings['shortId']; + $output .= "&pbk={$config['pbk']}" . "&sid={$config['sid']}"; } } } 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'] = Helper::encodeURIComponent($tcpSettings['header']['request']['path'][0]); + if (isset($tcpSettings['header']['type'])) $config['headerType'] = $tcpSettings['header']['type']; + $output .= "&headerType={$config['headerType']}"; } + if ((string)$server['network'] === 'kcp') { + $kcpSettings = $server['network_settings']; + if (isset($kcpSettings['header']['type'])) $config['headerType'] = $kcpSettings['header']['type']; + if (isset($kcpSettings['seed'])) $config['path'] = Helper::encodeURIComponent($kcpSettings['seed']); + $output .= "&headerType={$config['headerType']}" . "&seed={$config['path']}"; + } if ((string)$server['network'] === 'ws') { $wsSettings = $server['network_settings']; if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'h2') { + $h2Settings = $server['network_settings']; + if (isset($h2Settings['path'])) $config['path'] = Helper::encodeURIComponent($h2Settings['path']); + if (isset($h2Settings['host'])) $config['host'] = Helper::encodeURIComponent($h2Settings['host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'quic') { + $quicSettings = $server['network_settings']; + if (isset($quicSettings['security'])) $config['quicSecurity'] = $quicSettings['security']; + if (isset($quicSettings['header']['type'])) $config['headerType'] = $quicSettings['header']['type']; + + $output .= "&quicSecurity={$config['quicSecurity']}" . "&headerType={$config['headerType']}"; + + if ((string)$quicSettings['security'] !== 'none' && isset($quicSettings['key'])) $config['path'] = Helper::encodeURIComponent($quicSettings['key']); + + $output .= "&key={$config['path']}"; } if ((string)$server['network'] === 'grpc') { $grpcSettings = $server['network_settings']; - if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['serviceName'])) $config['serviceName'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['multiMode'])) $config['mode'] = $grpcSettings['multiMode'] ? "multi" : "gun"; + $output .= "&serviceName={$config['serviceName']}" . "&mode={$config['mode']}"; } -//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"; + $output .= "&fp=chrome" . "#" . $config['name']; + + return $output . "\r\n"; } public static function buildTrojan($password, $server) diff --git a/app/Protocols/V2rayNG.php b/app/Protocols/V2rayNG.php index 96353630..06501c79 100644 --- a/app/Protocols/V2rayNG.php +++ b/app/Protocols/V2rayNG.php @@ -92,51 +92,85 @@ class V2rayNG public static function buildVless($uuid, $server) { $config = [ - "v" => "2", - "ps" => Helper::encodeURIComponent($server['name']), + "name" => Helper::encodeURIComponent($server['name']), "add" => $server['host'], "port" => (string)$server['port'], - "id" => $uuid, - "net" => $server['network'], - "type" => "none", + "type" => $server['network'], + "encryption" => "none", "host" => "", "path" => "", - "tls" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", + "headerType" => "none", + "quicSecurity" => "none", + "serviceName" => "", + "mode" => "gun", + "security" => $server['tls'] !=0 ? ($server['tls'] == 2 ? "reality":"tls") : "", "flow" => $server['flow'], "sni" => "", "pbk" => "", "sid" =>"", ]; + + $output = "vless://" . $uuid . "@" . $config['add'] . ":" . $config['port']; + $output .= "?" . "type={$config['type']}" . "&encryption={$config['encryption']}" . "&security={$config['security']}"; + if ($server['tls']) { if ($server['tls_settings']) { $tlsSettings = $server['tls_settings']; - if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) - $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) $config['sni'] = $tlsSettings['server_name']; + if (isset($tlsSettings['flow']) && !empty($tlsSettings['flow'])) $config['flow'] = $tlsSettings['flow']; + + $output .= "&sni={$config['sni']}" . "&flow={$config['flow']}"; + if ($server['tls'] == 2) { - $config['pbk'] = $tlsSettings['public_key']; - $config['sid'] = $tlsSettings['shortId']; + $config['pbk'] = $tlsSettings['public_key']; + $config['sid'] = $tlsSettings['shortId']; + $output .= "&pbk={$config['pbk']}" . "&sid={$config['sid']}"; } } } 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'] = Helper::encodeURIComponent($tcpSettings['header']['request']['path'][0]); + if (isset($tcpSettings['header']['type'])) $config['headerType'] = $tcpSettings['header']['type']; + $output .= "&headerType={$config['headerType']}"; } + if ((string)$server['network'] === 'kcp') { + $kcpSettings = $server['network_settings']; + if (isset($kcpSettings['header']['type'])) $config['headerType'] = $kcpSettings['header']['type']; + if (isset($kcpSettings['seed'])) $config['path'] = Helper::encodeURIComponent($kcpSettings['seed']); + $output .= "&headerType={$config['headerType']}" . "&seed={$config['path']}"; + } if ((string)$server['network'] === 'ws') { $wsSettings = $server['network_settings']; if (isset($wsSettings['path'])) $config['path'] = Helper::encodeURIComponent($wsSettings['path']); if (isset($wsSettings['headers']['Host'])) $config['host'] = Helper::encodeURIComponent($wsSettings['headers']['Host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'h2') { + $h2Settings = $server['network_settings']; + if (isset($h2Settings['path'])) $config['path'] = Helper::encodeURIComponent($h2Settings['path']); + if (isset($h2Settings['host'])) $config['host'] = Helper::encodeURIComponent($h2Settings['host']); + $output .= "&path={$config['path']}" . "&host={$config['host']}"; + } + if ((string)$server['network'] === 'quic') { + $quicSettings = $server['network_settings']; + if (isset($quicSettings['security'])) $config['quicSecurity'] = $quicSettings['security']; + if (isset($quicSettings['header']['type'])) $config['headerType'] = $quicSettings['header']['type']; + + $output .= "&quicSecurity={$config['quicSecurity']}" . "&headerType={$config['headerType']}"; + + if ((string)$quicSettings['security'] !== 'none' && isset($quicSettings['key'])) $config['path'] = Helper::encodeURIComponent($quicSettings['key']); + + $output .= "&key={$config['path']}"; } if ((string)$server['network'] === 'grpc') { $grpcSettings = $server['network_settings']; - if (isset($grpcSettings['serviceName'])) $config['path'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['serviceName'])) $config['serviceName'] = $grpcSettings['serviceName']; + if (isset($grpcSettings['multiMode'])) $config['mode'] = $grpcSettings['multiMode'] ? "multi" : "gun"; + $output .= "&serviceName={$config['serviceName']}" . "&mode={$config['mode']}"; } -//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"; + $output .= "&fp=chrome" . "#" . $config['name']; + + return $output . "\r\n"; } public static function buildTrojan($password, $server) @@ -151,6 +185,4 @@ class V2rayNG $uri .= "\r\n"; return $uri; } - - }