From 2d94504aa31f966718b30e7361570c1f2cb532b2 Mon Sep 17 00:00:00 2001 From: mercury Date: Wed, 8 May 2024 00:40:31 +0400 Subject: [PATCH] outbounds auto fill --- app/bot.php | 95 ++++++++++++++++++++++++++++++++++++++++++------ config/sing.json | 39 +------------------- 2 files changed, 84 insertions(+), 50 deletions(-) diff --git a/app/bot.php b/app/bot.php index 66b8d33..f4700b1 100644 --- a/app/bot.php +++ b/app/bot.php @@ -539,7 +539,8 @@ class Bot "method" => "2022-blake3-aes-128-gcm", "password" => $p['xray']['sspwd'], "multiplex" => [ - "enabled" => true + "enabled" => true, + "padding" => true, ] ] ]; @@ -3780,10 +3781,14 @@ DNS-over-HTTPS with IP: $this->templates($type); } - public function downloadTemplate($type, $name) + public function downloadTemplate($type, $name = false) { $pac = $this->getPacConf(); - $f = new \CURLStringFile(json_encode($pac["{$type}templates"][base64_decode($name)], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), base64_decode($name) . '.json', 'application/json'); + if (!empty($name)) { + $f = new \CURLStringFile(json_encode($pac["{$type}templates"][base64_decode($name)], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), base64_decode($name) . '.json', 'application/json'); + } else { + $f = new \CURLFile("/config/{$type}.json", 'application/json', "$type.json"); + } $this->sendFile($this->input['chat'], $f); } @@ -3818,6 +3823,10 @@ DNS-over-HTTPS with IP: 'text' => "origin", 'web_app' => ['url' => "https://$domain/pac?h=$hash&t=te&ty=$type"], ], + [ + 'text' => $this->i18n('download'), + 'callback_data' => "/downloadTemplate $type", + ], [ 'text' => $this->i18n($pac["default{$type}template"] && !empty($pac["{$type}templates"][base64_decode($pac["default{$type}template"])]) ? 'off' : 'on'), 'callback_data' => "/defaultTemplate $type", @@ -4283,22 +4292,84 @@ DNS-over-HTTPS with IP: switch ($pac['xtlsmode']) { case 'shadow': - $c['outbounds'][0]['server'] = $domain; - $c['outbounds'][0]['password'] = $uid; - $c['outbounds'][0]['tls']['server_name'] = $pac['xray']['domain']; - $c['outbounds'][1]['password'] = $pac['xray']['sspwd']; + $o = [ + [ + "type" => "shadowtls", + "tag" => "ss-tls-out", + "server" => $domain, + "server_port" => 443, + "version" => 3, + "password" => $uid, + "tls" => [ + "enabled" => true, + "server_name" => $pac['xray']['domain'], + "utls" => [ + "enabled" => true, + "fingerprint" => "randomized" + ] + ] + ], + [ + "type" => "shadowsocks", + "tag" => "proxy", + "detour" => "ss-tls-out", + "method" => "2022-blake3-aes-128-gcm", + "password" => $pac['xray']['sspwd'], + "network" => "tcp", + "udp_over_tcp" => true, + "multiplex" => [ + "enabled" => true, + "padding" => true + ] + ] + ]; break; case 'trojan': break; default: - $c['outbounds'][0]['server'] = $domain; - $c['outbounds'][0]['uuid'] = $uid; - $c['outbounds'][0]['tls']['reality']['public_key'] = $pac['xray']['public']; - $c['outbounds'][0]['tls']['server_name'] = $pac['xray']['domain']; - $c['outbounds'][0]['tls']['reality']['short_id'] = $pac['xray']['shortid']; + $o = [ + [ + "flow" => "xtls-rprx-vision", + "packet_encoding" => "", + "server" => $domain, + "server_port" => 443, + "tls" => [ + "enabled" => true, + "insecure" => false, + "reality" => [ + "enabled" => true, + "public_key" => $pac['xray']['public'], + "short_id" => $pac['xray']['shortid'] + ], + "server_name" => $pac['xray']['domain'], + "utls" => [ + "enabled" => true, + "fingerprint" => "chrome" + ] + ], + "uuid" => $uid, + "type" => "vless", + "domain_strategy" => "ipv4_only", + "tag" => "proxy" + ] + ]; break; } + $c['outbounds'] = array_merge($o, [ + [ + "type" => "direct", + "tag" => "direct" + ], + [ + "type" => "block", + "tag" => "block" + ], + [ + "type" => "dns", + "tag" => "dns-out" + ] + ]); foreach ($c['route']['rules'] as $k => $v) { if (array_key_exists('domain_suffix', $v) && $v['domain_suffix'] == '~pac~') { $c['route']['rules'][$k]['domain_suffix'] = array_keys(array_filter($pac['includelist'] ?: [])); diff --git a/config/sing.json b/config/sing.json index 0df1cc9..075f1d3 100644 --- a/config/sing.json +++ b/config/sing.json @@ -57,44 +57,7 @@ "strategy": "ipv4_only", "independent_cache": true }, - "outbounds": [ - { - "flow": "xtls-rprx-vision", - "packet_encoding": "", - "server": "", - "server_port": 443, - "tls": { - "enabled": true, - "insecure": false, - "reality": { - "enabled": true, - "public_key": "", - "short_id": "" - }, - "server_name": "", - "utls": { - "enabled": true, - "fingerprint": "chrome" - } - }, - "uuid": "", - "type": "vless", - "domain_strategy": "ipv4_only", - "tag": "proxy" - }, - { - "type": "direct", - "tag": "direct" - }, - { - "type": "block", - "tag": "block" - }, - { - "type": "dns", - "tag": "dns-out" - } - ], + "outbounds": [], "route": { "auto_detect_interface": true, "override_android_vpn": true,