mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			86 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Utils;
 | |
| 
 | |
| 
 | |
| class QuantumultX
 | |
| {
 | |
|     public static function buildShadowsocks($password, $server)
 | |
|     {
 | |
|         $config = [
 | |
|             "shadowsocks={$server['host']}:{$server['port']}",
 | |
|             "method={$server['cipher']}",
 | |
|             "password={$password}",
 | |
|             'fast-open=true',
 | |
|             'udp-relay=true',
 | |
|             "tag={$server['name']}"
 | |
|         ];
 | |
|         $config = array_filter($config);
 | |
|         $uri = implode(',', $config);
 | |
|         $uri .= "\r\n";
 | |
|         return $uri;
 | |
|     }
 | |
| 
 | |
|     public static function buildVmess($uuid, $server)
 | |
|     {
 | |
|         $config = [
 | |
|             "vmess={$server['host']}:{$server['port']}",
 | |
|             'method=chacha20-poly1305',
 | |
|             "password={$uuid}",
 | |
|             'fast-open=true',
 | |
|             'udp-relay=true',
 | |
|             "tag={$server['name']}"
 | |
|         ];
 | |
| 
 | |
|         if ($server['tls']) {
 | |
|             if ($server['network'] === 'tcp') {
 | |
|                 array_push($config, 'obfs=over-tls');
 | |
|             } else {
 | |
|                 array_push($config, 'obfs=wss');
 | |
|             }
 | |
|         } else if ($server['network'] === 'ws') {
 | |
|             array_push($config, 'obfs=ws');
 | |
|         }
 | |
| 
 | |
|         if ($server['tls']) {
 | |
|             if ($server['tlsSettings']) {
 | |
|                 $tlsSettings = json_decode($server['tlsSettings'], true);
 | |
|                 if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
 | |
|                     array_push($config, 'tls-verification=' . ($tlsSettings['allowInsecure'] ? 'false' : 'true'));
 | |
|             }
 | |
|         }
 | |
|         if ($server['network'] === 'ws') {
 | |
|             if ($server['networkSettings']) {
 | |
|                 $wsSettings = json_decode($server['networkSettings'], true);
 | |
|                 if (isset($wsSettings['path']) && !empty($wsSettings['path']))
 | |
|                     array_push($config, "obfs-uri={$wsSettings['path']}");
 | |
|                 if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
 | |
|                     array_push($config, "obfs-host={$wsSettings['headers']['Host']}");
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         $uri = implode(',', $config);
 | |
|         $uri .= "\r\n";
 | |
|         return $uri;
 | |
|     }
 | |
| 
 | |
|     public static function buildTrojan($password, $server)
 | |
|     {
 | |
|         $config = [
 | |
|             "trojan={$server['host']}:{$server['port']}",
 | |
|             "password={$password}",
 | |
|             'over-tls=true',
 | |
|             $server['server_name'] ? "tls-host={$server['server_name']}" : "",
 | |
|             // Tips: allowInsecure=false = tls-verification=true
 | |
|             $server['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
 | |
|             'fast-open=true',
 | |
|             'udp-relay=true',
 | |
|             "tag={$server['name']}"
 | |
|         ];
 | |
|         $config = array_filter($config);
 | |
|         $uri = implode(',', $config);
 | |
|         $uri .= "\r\n";
 | |
|         return $uri;
 | |
|     }
 | |
| }
 |