mirror of
				https://github.com/v2board/v2board.git
				synced 2025-11-04 19:31:45 +08:00 
			
		
		
		
	修复支持vless协议的客户端订阅链接
This commit is contained in:
		@@ -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']);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user