@@ -92,11 +92,11 @@ export default {
9292 return new Response ( JSON . stringify ( 检测代理响应 , null , 2 ) , { status : 200 , headers : { 'Content-Type' : 'application/json;charset=utf-8' } } ) ;
9393 }
9494
95- config_JSON = await 读取config_JSON ( env , host , userID , env . PATH ) ;
95+ config_JSON = await 读取config_JSON ( env , host , userID ) ;
9696
9797 if ( 访问路径 === 'admin/init' ) { // 重置配置为默认值
9898 try {
99- config_JSON = await 读取config_JSON ( env , host , userID , env . PATH , true ) ;
99+ config_JSON = await 读取config_JSON ( env , host , userID , true ) ;
100100 ctx . waitUntil ( 请求日志记录 ( env , request , 访问IP , 'Init_Config' , config_JSON ) ) ;
101101 config_JSON . init = '配置已重置为默认值' ;
102102 return new Response ( JSON . stringify ( config_JSON , null , 2 ) , { status : 200 , headers : { 'Content-Type' : 'application/json;charset=utf-8' } } ) ;
@@ -191,7 +191,7 @@ export default {
191191 } else if ( 访问路径 === 'sub' ) { //处理订阅请求
192192 const 订阅TOKEN = await MD5MD5 ( host + userID ) ;
193193 if ( url . searchParams . get ( 'token' ) === 订阅TOKEN ) {
194- config_JSON = await 读取config_JSON ( env , host , userID , env . PATH ) ;
194+ config_JSON = await 读取config_JSON ( env , host , userID ) ;
195195 ctx . waitUntil ( 请求日志记录 ( env , request , 访问IP , 'Get_SUB' , config_JSON ) ) ;
196196 const ua = UA . toLowerCase ( ) ;
197197 const expire = 4102329600 ; //2099-12-31 到期时间
@@ -233,7 +233,6 @@ export default {
233233 const 协议类型 = ( url . searchParams . has ( 'surge' ) || ua . includes ( 'surge' ) ) ? 'tro' + 'jan' : config_JSON . 协议类型 ;
234234 let 订阅内容 = '' ;
235235 if ( 订阅类型 === 'mixed' ) {
236- const 节点路径 = config_JSON . 启用0RTT ? config_JSON . PATH + '?ed=2560' : config_JSON . PATH ;
237236 const TLS分片参数 = config_JSON . TLS分片 == 'Shadowrocket' ? `&fragment=${ encodeURIComponent ( '1,40-60,30-50,tlshello' ) } ` : config_JSON . TLS分片 == 'Happ' ? `&fragment=${ encodeURIComponent ( '3,1,tlshello' ) } ` : '' ;
238237 let 完整优选IP = [ ] , 其他节点LINK = '' ;
239238
@@ -301,7 +300,7 @@ export default {
301300 return null ;
302301 }
303302
304- return `${ 协议类型 } ://00000000-0000-4000-8000-000000000000@${ 节点地址 } :${ 节点端口 } ?security=tls&type=${ config_JSON . 传输协议 + ECHLINK参数 } &host=example.com&fp=${ config_JSON . Fingerprint } &sni=example.com&path=${ encodeURIComponent ( config_JSON . 随机路径 ? 随机路径 ( ) + 节点路径 : 节点路径 ) + TLS分片参数 } &encryption=none${ config_JSON . 跳过证书验证 ? '&insecure=1&allowInsecure=1' : '' } #${ encodeURIComponent ( 节点备注 ) } ` ;
303+ return `${ 协议类型 } ://00000000-0000-4000-8000-000000000000@${ 节点地址 } :${ 节点端口 } ?security=tls&type=${ config_JSON . 传输协议 + ECHLINK参数 } &host=example.com&fp=${ config_JSON . Fingerprint } &sni=example.com&path=${ encodeURIComponent ( config_JSON . 随机路径 ? 随机路径 ( ) + config_JSON . 完整节点路径 : config_JSON . 完整节点路径 ) + TLS分片参数 } &encryption=none${ config_JSON . 跳过证书验证 ? '&insecure=1&allowInsecure=1' : '' } #${ encodeURIComponent ( 节点备注 ) } ` ;
305304 } ) . filter ( item => item !== null ) . join ( '\n' ) ;
306305 } else { // 订阅转换
307306 const 订阅转换URL = `${ config_JSON . 订阅转换配置 . SUBAPI } /sub?target=${ 订阅类型 } &url=${ encodeURIComponent ( url . protocol + '//' + url . host + '/sub?target=mixed&token=' + 订阅TOKEN + ( url . searchParams . has ( 'sub' ) && url . searchParams . get ( 'sub' ) != '' ? `&sub=${ url . searchParams . get ( 'sub' ) } ` : '' ) ) } &config=${ encodeURIComponent ( config_JSON . 订阅转换配置 . SUBCONFIG ) } &emoji=${ config_JSON . 订阅转换配置 . SUBEMOJI } &scv=${ config_JSON . 跳过证书验证 } ` ;
@@ -1188,12 +1187,11 @@ function Surge订阅配置文件热补丁(content, url, config_JSON) {
11881187 const 每行内容 = content . includes ( '\r\n' ) ? content . split ( '\r\n' ) : content . split ( '\n' ) ;
11891188
11901189 let 输出内容 = "" ;
1191- const realSurgePath = config_JSON . 启用0RTT ? config_JSON . PATH + '?ed=2560' : config_JSON . PATH ;
11921190 for ( let x of 每行内容 ) {
11931191 if ( x . includes ( '= tro' + 'jan,' ) && ! x . includes ( 'ws=true' ) && ! x . includes ( 'ws-path=' ) ) {
11941192 const host = x . split ( "sni=" ) [ 1 ] . split ( "," ) [ 0 ] ;
11951193 const 备改内容 = `sni=${ host } , skip-cert-verify=${ config_JSON . 跳过证书验证 } ` ;
1196- const 正确内容 = `sni=${ host } , skip-cert-verify=${ config_JSON . 跳过证书验证 } , ws=true, ws-path=${ realSurgePath } , ws-headers=Host:"${ host } "` ;
1194+ const 正确内容 = `sni=${ host } , skip-cert-verify=${ config_JSON . 跳过证书验证 } , ws=true, ws-path=${ config_JSON . 随机路径 ? 随机路径 ( ) + config_JSON . 完整节点路径 : config_JSON . 完整节点路径 } , ws-headers=Host:"${ host } "` ;
11971195 输出内容 += x . replace ( new RegExp ( 备改内容 , 'g' ) , 正确内容 ) . replace ( "[" , "" ) . replace ( "]" , "" ) + '\n' ;
11981196 } else {
11991197 输出内容 += x + '\n' ;
@@ -1351,7 +1349,7 @@ async function getECH(host) {
13511349 }
13521350}
13531351
1354- async function 读取config_JSON ( env , hostname , userID , path , 重置配置 = false ) {
1352+ async function 读取config_JSON ( env , hostname , userID , 重置配置 = false ) {
13551353 //const host = 随机替换通配符(hostname);
13561354 const host = hostname , CM_DoH = "https://doh.cmliussss.net/CMLiussss" ;
13571355 const 初始化开始时间 = performance . now ( ) ;
@@ -1360,6 +1358,7 @@ async function 读取config_JSON(env, hostname, userID, path, 重置配置 = fal
13601358 HOST : host ,
13611359 HOSTS : [ hostname ] ,
13621360 UUID : userID ,
1361+ PATH : "/" ,
13631362 协议类型 : "v" + "le" + "ss" ,
13641363 传输协议 : "ws" ,
13651364 跳过证书验证 : true ,
@@ -1438,14 +1437,24 @@ async function 读取config_JSON(env, hostname, userID, path, 重置配置 = fal
14381437 config_JSON . UUID = userID ;
14391438 if ( ! config_JSON . 随机路径 ) config_JSON . 随机路径 = false ;
14401439 if ( ! config_JSON . 启用0RTT ) config_JSON . 启用0RTT = false ;
1441- config_JSON . PATH = path ? ( path . startsWith ( '/' ) ? path : '/' + path ) : ( config_JSON . 反代 . SOCKS5 . 启用 ? ( '/' + config_JSON . 反代 . SOCKS5 . 启用 + ( config_JSON . 反代 . SOCKS5 . 全局 ? '://' : '=' ) + config_JSON . 反代 . SOCKS5 . 账号 ) : ( config_JSON . 反代 . PROXYIP === 'auto' ? '/' : `/proxyip=${ config_JSON . 反代 . PROXYIP } ` ) ) ;
1440+
1441+ if ( env . PATH ) config_JSON . PATH = env . PATH . startsWith ( '/' ) ? env . PATH : '/' + env . PATH ;
1442+ else if ( ! config_JSON . PATH ) config_JSON . PATH = '/' ;
1443+
1444+ const PATH反代参数 = config_JSON . 反代 . SOCKS5 . 启用 ? ( '/' + config_JSON . 反代 . SOCKS5 . 启用 + ( config_JSON . 反代 . SOCKS5 . 全局 ? '://' : '=' ) + config_JSON . 反代 . SOCKS5 . 账号 ) : ( config_JSON . 反代 . PROXYIP === 'auto' ? '/' : `/proxyip=${ config_JSON . 反代 . PROXYIP } ` ) ;
1445+ let PATH固定参数 = config_JSON . PATH ;
1446+ if ( PATH固定参数 === '/' ) PATH固定参数 = '' ;
1447+ else while ( PATH固定参数 . endsWith ( '/' ) ) PATH固定参数 = PATH固定参数 . slice ( 0 , - 1 ) ;
1448+
1449+ config_JSON . 完整节点路径 = config_JSON . 启用0RTT ? PATH固定参数 + PATH反代参数 + '?ed=2560' : PATH固定参数 + PATH反代参数 ;
1450+
14421451 if ( ! config_JSON . TLS分片 && config_JSON . TLS分片 !== null ) config_JSON . TLS分片 = null ;
14431452 const TLS分片参数 = config_JSON . TLS分片 == 'Shadowrocket' ? `&fragment=${ encodeURIComponent ( '1,40-60,30-50,tlshello' ) } ` : config_JSON . TLS分片 == 'Happ' ? `&fragment=${ encodeURIComponent ( '3,1,tlshello' ) } ` : '' ;
14441453 if ( ! config_JSON . Fingerprint ) config_JSON . Fingerprint = "chrome" ;
14451454 if ( ! config_JSON . ECH ) config_JSON . ECH = false ;
14461455 if ( ! config_JSON . ECHConfig ) config_JSON . ECHConfig = { DNS : CM_DoH , SNI : null } ;
14471456 const ECHLINK参数 = config_JSON . ECH ? `&ech=${ encodeURIComponent ( ( config_JSON . ECHConfig . SNI ? config_JSON . ECHConfig . SNI + '+' : '' ) + config_JSON . ECHConfig . DNS ) } ` : '' ;
1448- config_JSON . LINK = `${ config_JSON . 协议类型 } ://${ userID } @${ host } :443?security=tls&type=${ config_JSON . 传输协议 + ECHLINK参数 } &host=${ host } &fp=${ config_JSON . Fingerprint } &sni=${ host } &path=${ encodeURIComponent ( config_JSON . 启用0RTT ? config_JSON . PATH + '?ed=2560' : config_JSON . PATH ) + TLS分片参数 } &encryption=none${ config_JSON . 跳过证书验证 ? '&insecure=1&allowInsecure=1' : '' } #${ encodeURIComponent ( config_JSON . 优选订阅生成 . SUBNAME ) } ` ;
1457+ config_JSON . LINK = `${ config_JSON . 协议类型 } ://${ userID } @${ host } :443?security=tls&type=${ config_JSON . 传输协议 + ECHLINK参数 } &host=${ host } &fp=${ config_JSON . Fingerprint } &sni=${ host } &path=${ encodeURIComponent ( config_JSON . 随机路径 ? 随机路径 ( ) + config_JSON . 完整节点路径 : config_JSON . 完整节点路径 ) + TLS分片参数 } &encryption=none${ config_JSON . 跳过证书验证 ? '&insecure=1&allowInsecure=1' : '' } #${ encodeURIComponent ( config_JSON . 优选订阅生成 . SUBNAME ) } ` ;
14491458 config_JSON . 优选订阅生成 . TOKEN = await MD5MD5 ( hostname + userID ) ;
14501459
14511460 const 初始化TG_JSON = { BotToken : null , ChatID : null } ;
0 commit comments