mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 17:31:49 +08:00 
			
		
		
		
	Merge branch 'dev' of https://github.com/v2board/v2board into dev
This commit is contained in:
		| @@ -6,6 +6,7 @@ use App\Http\Controllers\Controller; | |||||||
| use App\Services\ServerService; | use App\Services\ServerService; | ||||||
| use App\Utils\Clash; | use App\Utils\Clash; | ||||||
| use App\Utils\QuantumultX; | use App\Utils\QuantumultX; | ||||||
|  | use App\Utils\Shadowrocket; | ||||||
| use App\Utils\Surge; | use App\Utils\Surge; | ||||||
| use Illuminate\Http\Request; | use Illuminate\Http\Request; | ||||||
| use App\Models\Server; | use App\Models\Server; | ||||||
| @@ -41,6 +42,9 @@ class ClientController extends Controller | |||||||
|                 if (strpos($_SERVER['HTTP_USER_AGENT'], 'surge') !== false) { |                 if (strpos($_SERVER['HTTP_USER_AGENT'], 'surge') !== false) { | ||||||
|                     die($this->surge($user, $servers['vmess'], $servers['trojan'])); |                     die($this->surge($user, $servers['vmess'], $servers['trojan'])); | ||||||
|                 } |                 } | ||||||
|  |                 if (strpos($_SERVER['HTTP_USER_AGENT'], 'shadowrocket') !== false) { | ||||||
|  |                     die($this->shadowrocket($user, $servers['vmess'], $servers['trojan'])); | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|             die($this->origin($user, $servers['vmess'], $servers['trojan'])); |             die($this->origin($user, $servers['vmess'], $servers['trojan'])); | ||||||
|         } |         } | ||||||
| @@ -66,6 +70,20 @@ class ClientController extends Controller | |||||||
|         return base64_encode($uri); |         return base64_encode($uri); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private function shadowrocket($user, $vmess = [], $trojan = []) | ||||||
|  |     { | ||||||
|  |         $uri = ''; | ||||||
|  |         //TODO: display remaining traffic and expire date | ||||||
|  |         //$uri .= 'STATUS=' . 'Traffic:' . 'Expiry:' . '\r\n'; | ||||||
|  |         foreach ($vmess as $item) { | ||||||
|  |             $uri .= Shadowrocket::buildVmess($user->uuid, $item); | ||||||
|  |         } | ||||||
|  |         foreach ($trojan as $item) { | ||||||
|  |             $uri .= Shadowrocket::buildTrojan($user->uuid, $item); | ||||||
|  |         } | ||||||
|  |         return base64_encode($uri); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private function quantumultX($user, $vmess = [], $trojan = []) |     private function quantumultX($user, $vmess = [], $trojan = []) | ||||||
|     { |     { | ||||||
|         $uri = ''; |         $uri = ''; | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ class Clash | |||||||
|         $array['uuid'] = $uuid; |         $array['uuid'] = $uuid; | ||||||
|         $array['alterId'] = 2; |         $array['alterId'] = 2; | ||||||
|         $array['cipher'] = 'auto'; |         $array['cipher'] = 'auto'; | ||||||
|  |         $array['udp'] = true; | ||||||
|         if ($server->tls) { |         if ($server->tls) { | ||||||
|             $tlsSettings = json_decode($server->tlsSettings); |             $tlsSettings = json_decode($server->tlsSettings); | ||||||
|             $array['tls'] = true; |             $array['tls'] = true; | ||||||
| @@ -42,6 +43,7 @@ class Clash | |||||||
|         $array['server'] = $server->host; |         $array['server'] = $server->host; | ||||||
|         $array['port'] = $server->port; |         $array['port'] = $server->port; | ||||||
|         $array['password'] = $password; |         $array['password'] = $password; | ||||||
|  |         $array['udp'] = true; | ||||||
|         $array['sni'] = $server->server_name; |         $array['sni'] = $server->server_name; | ||||||
|         if ($server->allow_insecure) { |         if ($server->allow_insecure) { | ||||||
|             $array['skip-cert-verify'] = true; |             $array['skip-cert-verify'] = true; | ||||||
|   | |||||||
							
								
								
									
										43
									
								
								app/Utils/Shadowrocket.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								app/Utils/Shadowrocket.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace App\Utils; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Shadowrocket | ||||||
|  | { | ||||||
|  |     public static function buildVmess($uuid, $server) | ||||||
|  |     { | ||||||
|  |         $userinfo = base64_encode('auto:' . $uuid . '@' . $server->host . ':' . $server->port); | ||||||
|  |         $config = [ | ||||||
|  |             'remark' => $server->name | ||||||
|  |         ]; | ||||||
|  |         if ($server->tls) { | ||||||
|  |             $tlsSettings = json_decode($server->tlsSettings); | ||||||
|  |             $config['tls'] = 1; | ||||||
|  |             if (isset($tlsSettings->serverName)) $config['peer'] = $tlsSettings->serverName; | ||||||
|  |             if (isset($tlsSettings->allowInsecure)) $config['allowInsecure'] = 1; | ||||||
|  |         } | ||||||
|  |         if ($server->network === 'ws') { | ||||||
|  |             $wsSettings = json_decode($server->networkSettings); | ||||||
|  |             $config['obfs'] = "websocket"; | ||||||
|  |             if (isset($wsSettings->path)) $config['path'] = $wsSettings->path; | ||||||
|  |             if (isset($wsSettings->headers->Host)) $config['obfsParam'] = $wsSettings->headers->Host; | ||||||
|  |         } | ||||||
|  |         $query = http_build_query($config); | ||||||
|  |         $uri = "vmess://{$userinfo}?{$query}&tfo=1"; | ||||||
|  |         $uri .= "\r\n"; | ||||||
|  |         return $uri; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static function buildTrojan($password, $server) | ||||||
|  |     { | ||||||
|  |         $server->name = rawurlencode($server->name); | ||||||
|  |         $query = http_build_query([ | ||||||
|  |             'allowInsecure' => $server->allow_insecure, | ||||||
|  |             'peer' => $server->server_name | ||||||
|  |         ]); | ||||||
|  |         $uri = "trojan://{$password}@{$server->host}:{$server->port}?{$query}&tfo=1#{$server->name}"; | ||||||
|  |         $uri .= "\r\n"; | ||||||
|  |         return $uri; | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user