From 4434b13361be7e5e29d4ca0f8d08efcc38dbaac4 Mon Sep 17 00:00:00 2001 From: v2board Date: Thu, 28 Sep 2023 13:34:58 +0800 Subject: [PATCH] update: hysteria2 --- .../V1/Admin/Server/HysteriaController.php | 4 +- .../V1/Server/UniProxyController.php | 4 +- app/Protocols/ClashMeta.php | 76 +++++++++++++++++++ database/install.sql | 4 +- database/update.sql | 4 + 5 files changed, 89 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/V1/Admin/Server/HysteriaController.php b/app/Http/Controllers/V1/Admin/Server/HysteriaController.php index 814eaedd..1e7a2907 100644 --- a/app/Http/Controllers/V1/Admin/Server/HysteriaController.php +++ b/app/Http/Controllers/V1/Admin/Server/HysteriaController.php @@ -24,7 +24,9 @@ class HysteriaController extends Controller 'up_mbps' => 'required|numeric|min:1', 'down_mbps' => 'required|numeric|min:1', 'server_name' => 'nullable', - 'insecure' => 'required|in:0,1' + 'insecure' => 'required|in:0,1', + 'obfs_type' => 'nullable|in:salamander', + 'ignore_client_bandwidth' => 'required|in:0,1' ]); if ($request->input('id')) { diff --git a/app/Http/Controllers/V1/Server/UniProxyController.php b/app/Http/Controllers/V1/Server/UniProxyController.php index 5723d4f4..42c3046f 100644 --- a/app/Http/Controllers/V1/Server/UniProxyController.php +++ b/app/Http/Controllers/V1/Server/UniProxyController.php @@ -108,7 +108,9 @@ class UniProxyController extends Controller 'server_name' => $this->nodeInfo->server_name, 'up_mbps' => $this->nodeInfo->up_mbps, 'down_mbps' => $this->nodeInfo->down_mbps, - 'obfs' => Helper::getServerKey($this->nodeInfo->created_at, 16) + 'obfs' => Helper::getServerKey($this->nodeInfo->created_at, 16), + 'obfs_type' => $this->nodeInfo->obfs_type, + 'ignore_client_bandwidth' => !!$this->nodeInfo->ignore_client_bandwidth ]; break; case "vless": diff --git a/app/Protocols/ClashMeta.php b/app/Protocols/ClashMeta.php index 33946664..6d2b2d59 100644 --- a/app/Protocols/ClashMeta.php +++ b/app/Protocols/ClashMeta.php @@ -48,6 +48,10 @@ class ClashMeta array_push($proxy, self::buildTrojan($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']); + } } $config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy); @@ -160,6 +164,78 @@ class ClashMeta 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['udp'] = true; + + if ($server['tls'] === 1) { + $array['tls'] = true; + if ($server['tls_settings']) { + $tlsSettings = $server['tls_settings']; + if (isset($tlsSettings['allow_insecure']) && !empty($tlsSettings['allow_insecure'])) + $array['skip-cert-verify'] = ($tlsSettings['allow_insecure'] ? true : false); + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) + $array['servername'] = $tlsSettings['server_name']; + } + } + + if (isset($server['flow']) && $server['flow']) { + $array['flow'] = $server['flow']; + $array['client-fingerprint'] = 'chrome'; + } + + if ($server['tls'] === 2) { + $array['client-fingerprint'] = 'chrome'; + $array['tls'] = true; + $array['reality-opts'] = []; + if ($server['tls_settings']) { + $tlsSettings = $server['tls_settings']; + if (isset($tlsSettings['allow_insecure']) && !empty($tlsSettings['allow_insecure'])) + $array['skip-cert-verify'] = ($tlsSettings['allow_insecure'] ? true : false); + if (isset($tlsSettings['server_name']) && !empty($tlsSettings['server_name'])) + $array['servername'] = $tlsSettings['server_name']; + if (isset($tlsSettings['public_key'])) $array['reality-opts']['public-key'] = $tlsSettings['public_key']; + } + } + + if ($server['network'] === 'tcp') { + $tcpSettings = $server['network_settings']; + if (isset($tcpSettings['header']['type'])) $array['network'] = $tcpSettings['header']['type']; + if (isset($tcpSettings['header']['request']['path'][0])) $array['http-opts']['path'] = $tcpSettings['header']['request']['path'][0]; + } + 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/database/install.sql b/database/install.sql index 35f69c30..7a04c13c 100644 --- a/database/install.sql +++ b/database/install.sql @@ -231,6 +231,8 @@ CREATE TABLE `v2_server_hysteria` ( `down_mbps` int(11) NOT NULL, `server_name` varchar(64) DEFAULT NULL, `insecure` tinyint(1) NOT NULL DEFAULT '0', + `ignore_client_bandwidth` tinyint(1) NOT NULL DEFAULT '0', + `obfs_type` varchar(11) DEFAULT NULL, `created_at` int(11) NOT NULL, `updated_at` int(11) NOT NULL, PRIMARY KEY (`id`) @@ -470,4 +472,4 @@ CREATE TABLE `v2_user` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- 2023-09-06 07:17:40 +-- 2023-09-24 19:19:32 diff --git a/database/update.sql b/database/update.sql index f83c5340..bafa43cd 100644 --- a/database/update.sql +++ b/database/update.sql @@ -720,3 +720,7 @@ ADD `transfer_unit_price` int(11) NULL AFTER `daily_unit_price`; ALTER TABLE `v2_order` DROP `surplus_order_ids`; + +ALTER TABLE `v2_server_hysteria` + ADD `ignore_client_bandwidth` tinyint(1) NOT NULL DEFAULT '0' AFTER `insecure`, +ADD `obfs_type` varchar(11) NULL AFTER `ignore_client_bandwidth`;