gen_config.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. #!/usr/bin/lua
  2. local ucursor = require "luci.model.uci".cursor()
  3. local json = require "luci.jsonc"
  4. local server_section = arg[1]
  5. local proto = arg[2]
  6. local local_port = arg[3] or "0"
  7. local socks_port = arg[4] or "0"
  8. local chain = arg[5] or "0"
  9. local chain_local_port = string.split(chain, "/")[2] or "0"
  10. local server = ucursor:get_all("shadowsocksr", server_section)
  11. local xray_fragment = ucursor:get_all("shadowsocksr", "@global_xray_fragment[0]") or {}
  12. local xray_noise = ucursor:get_all("shadowsocksr", "@xray_noise_packets[0]") or {}
  13. local outbound_settings = nil
  14. function vmess_vless()
  15. outbound_settings = {
  16. vnext = {
  17. {
  18. address = server.server,
  19. port = tonumber(server.server_port),
  20. users = {
  21. {
  22. id = server.vmess_id,
  23. alterId = (server.v2ray_protocol == "vmess" or not server.v2ray_protocol) and tonumber(server.alter_id) or nil,
  24. security = (server.v2ray_protocol == "vmess" or not server.v2ray_protocol) and server.security or nil,
  25. encryption = (server.v2ray_protocol == "vless") and server.vless_encryption or nil,
  26. flow = ((server.xtls == '1') or (server.tls == '1') or (server.reality == '1')) and server.tls_flow or nil
  27. }
  28. }
  29. }
  30. }
  31. }
  32. end
  33. function trojan_shadowsocks()
  34. outbound_settings = {
  35. servers = {
  36. {
  37. address = server.server,
  38. port = tonumber(server.server_port),
  39. password = server.password,
  40. method = ((server.v2ray_protocol == "shadowsocks") and server.encrypt_method_ss) or nil,
  41. uot = (server.v2ray_protocol == "shadowsocks") and (server.uot == '1') or nil,
  42. ivCheck = (server.v2ray_protocol == "shadowsocks") and (server.ivCheck == '1') or nil,
  43. }
  44. }
  45. }
  46. end
  47. function socks_http()
  48. outbound_settings = {
  49. version = server.socks_ver or nil,
  50. servers = {
  51. {
  52. address = server.server,
  53. port = tonumber(server.server_port),
  54. users = (server.auth_enable == "1") and {
  55. {
  56. user = server.username,
  57. pass = server.password
  58. }
  59. } or nil
  60. }
  61. }
  62. }
  63. end
  64. function wireguard()
  65. outbound_settings = {
  66. secretKey = server.private_key,
  67. address = server.local_addresses,
  68. peers = {
  69. {
  70. publicKey = server.peer_pubkey,
  71. preSharedKey = server.preshared_key,
  72. endpoint = server.server .. ":" .. server.server_port,
  73. keepAlive = tonumber(server.keepaliveperiod),
  74. allowedIPs = (server.allowedips) or nil,
  75. }
  76. },
  77. noKernelTun = (server.kernelmode == "1") and true or false,
  78. reserved = {server.reserved} or nil,
  79. mtu = tonumber(server.mtu)
  80. }
  81. end
  82. local outbound = {}
  83. function outbound:new(o)
  84. o = o or {}
  85. setmetatable(o, self)
  86. self.__index = self
  87. return o
  88. end
  89. function outbound:handleIndex(index)
  90. local switch = {
  91. vmess = function()
  92. vmess_vless()
  93. end,
  94. vless = function()
  95. vmess_vless()
  96. end,
  97. trojan = function()
  98. trojan_shadowsocks()
  99. end,
  100. shadowsocks = function()
  101. trojan_shadowsocks()
  102. end,
  103. socks = function()
  104. socks_http()
  105. end,
  106. http = function()
  107. socks_http()
  108. end,
  109. wireguard = function()
  110. wireguard()
  111. end
  112. }
  113. if switch[index] then
  114. switch[index]()
  115. end
  116. end
  117. local settings = outbound:new()
  118. settings:handleIndex(server.v2ray_protocol)
  119. local Xray = {
  120. log = {
  121. -- error = "/var/ssrplus.log",
  122. loglevel = "warning"
  123. },
  124. -- 初始化 inbounds 表
  125. inbounds = {},
  126. -- 初始化 outbounds 表
  127. outbounds = {},
  128. }
  129. -- 传入连接
  130. -- 添加 dokodemo-door 配置,如果 local_port 不为 0
  131. if local_port ~= "0" then
  132. table.insert(Xray.inbounds, {
  133. -- listening
  134. port = tonumber(local_port),
  135. protocol = "dokodemo-door",
  136. settings = {network = proto, followRedirect = true},
  137. sniffing = {
  138. enabled = true,
  139. destOverride = {"http", "tls", "quic"},
  140. metadataOnly = false,
  141. domainsExcluded = {
  142. "courier.push.apple.com",
  143. "rbsxbxp-mim.vivox.com",
  144. "rbsxbxp.www.vivox.com",
  145. "rbsxbxp-ws.vivox.com",
  146. "rbspsxp.www.vivox.com",
  147. "rbspsxp-mim.vivox.com",
  148. "rbspsxp-ws.vivox.com",
  149. "rbswxp.www.vivox.com",
  150. "rbswxp-mim.vivox.com",
  151. "disp-rbspsp-5-1.vivox.com",
  152. "disp-rbsxbp-5-1.vivox.com",
  153. "proxy.rbsxbp.vivox.com",
  154. "proxy.rbspsp.vivox.com",
  155. "proxy.rbswp.vivox.com",
  156. "rbswp.vivox.com",
  157. "rbsxbp.vivox.com",
  158. "rbspsp.vivox.com",
  159. "rbspsp.www.vivox.com",
  160. "rbswp.www.vivox.com",
  161. "rbsxbp.www.vivox.com",
  162. "rbsxbxp.vivox.com",
  163. "rbspsxp.vivox.com",
  164. "rbswxp.vivox.com",
  165. "Mijia Cloud",
  166. "dlg.io.mi.com"
  167. }
  168. }
  169. })
  170. end
  171. -- 开启 socks 代理
  172. -- 检查是否启用 socks 代理
  173. if proto:find("tcp") and socks_port ~= "0" then
  174. table.insert(Xray.inbounds, {
  175. -- socks
  176. protocol = "socks",
  177. port = tonumber(socks_port),
  178. settings = {auth = "noauth", udp = true}
  179. })
  180. end
  181. -- 传出连接
  182. Xray.outbounds = {
  183. {
  184. protocol = server.v2ray_protocol,
  185. settings = outbound_settings,
  186. -- 底层传输配置
  187. streamSettings = (server.v2ray_protocol ~= "wireguard") and {
  188. network = server.transport or "tcp",
  189. security = (server.xtls == '1') and "xtls" or (server.tls == '1') and "tls" or (server.reality == '1') and "reality" or nil,
  190. tlsSettings = (server.tls == '1') and {
  191. -- tls
  192. alpn = server.tls_alpn,
  193. fingerprint = server.fingerprint,
  194. allowInsecure = (server.insecure == "1"),
  195. serverName = server.tls_host,
  196. certificates = server.certificate and {
  197. usage = "verify",
  198. certificateFile = server.certpath
  199. } or nil,
  200. } or nil,
  201. xtlsSettings = (server.xtls == '1') and server.tls_host and {
  202. -- xtls
  203. allowInsecure = (server.insecure == "1") and true or nil,
  204. serverName = server.tls_host,
  205. minVersion = "1.3"
  206. } or nil,
  207. realitySettings = (server.reality == '1') and {
  208. publicKey = server.reality_publickey,
  209. shortId = server.reality_shortid,
  210. spiderX = server.reality_spiderx,
  211. fingerprint = server.fingerprint,
  212. serverName = server.tls_host
  213. } or nil,
  214. tcpSettings = (server.transport == "tcp" and server.tcp_guise == "http") and {
  215. -- tcp
  216. header = {
  217. type = server.tcp_guise,
  218. request = {
  219. -- request
  220. path = {server.http_path} or {"/"},
  221. headers = {Host = {server.http_host} or {}}
  222. }
  223. }
  224. } or nil,
  225. rawSettings = (server.transport == "raw" and server.raw_guise == "http") and {
  226. -- raw
  227. header = {
  228. type = server.raw_guise,
  229. request = {
  230. -- request
  231. path = {server.http_path} or {"/"},
  232. headers = {Host = {server.http_host} or {}}
  233. }
  234. }
  235. } or nil,
  236. kcpSettings = (server.transport == "kcp") and {
  237. -- kcp
  238. mtu = tonumber(server.mtu),
  239. tti = tonumber(server.tti),
  240. uplinkCapacity = tonumber(server.uplink_capacity),
  241. downlinkCapacity = tonumber(server.downlink_capacity),
  242. congestion = (server.congestion == "1") and true or false,
  243. readBufferSize = tonumber(server.read_buffer_size),
  244. writeBufferSize = tonumber(server.write_buffer_size),
  245. header = {type = server.kcp_guise},
  246. seed = server.seed or nil
  247. } or nil,
  248. wsSettings = (server.transport == "ws") and (server.ws_path or server.ws_host or server.tls_host) and {
  249. -- ws
  250. headers = (server.ws_host or server.tls_host) and {
  251. -- headers
  252. Host = server.ws_host or server.tls_host
  253. } or nil,
  254. path = server.ws_path,
  255. maxEarlyData = tonumber(server.ws_ed) or nil,
  256. earlyDataHeaderName = server.ws_ed_header or nil
  257. } or nil,
  258. httpupgradeSettings = (server.transport == "httpupgrade") and {
  259. -- httpupgrade
  260. host = (server.httpupgrade_host or server.tls_host) or nil,
  261. path = server.httpupgrade_path or ""
  262. } or nil,
  263. splithttpSettings = (server.transport == "splithttp") and {
  264. -- splithttp
  265. host = (server.splithttp_host or server.tls_host) or nil,
  266. path = server.splithttp_path or "/"
  267. } or nil,
  268. httpSettings = (server.transport == "h2") and {
  269. -- h2
  270. path = server.h2_path or "",
  271. host = {server.h2_host} or nil,
  272. read_idle_timeout = tonumber(server.read_idle_timeout) or nil,
  273. health_check_timeout = tonumber(server.health_check_timeout) or nil
  274. } or nil,
  275. quicSettings = (server.transport == "quic") and {
  276. -- quic
  277. security = server.quic_security,
  278. key = server.quic_key,
  279. header = {type = server.quic_guise}
  280. } or nil,
  281. grpcSettings = (server.transport == "grpc") and {
  282. -- grpc
  283. serviceName = server.serviceName or "",
  284. multiMode = (server.grpc_mode == "multi") and true or false,
  285. idle_timeout = tonumber(server.idle_timeout) or nil,
  286. health_check_timeout = tonumber(server.health_check_timeout) or nil,
  287. permit_without_stream = (server.permit_without_stream == "1") and true or nil,
  288. initial_windows_size = tonumber(server.initial_windows_size) or nil
  289. } or nil,
  290. sockopt = {
  291. tcpMptcp = (server.mptcp == "1") and true or false, -- MPTCP
  292. tcpNoDelay = (server.mptcp == "1") and true or false, -- MPTCP
  293. tcpcongestion = server.custom_tcpcongestion, -- 连接服务器节点的 TCP 拥塞控制算法
  294. dialerProxy = (xray_fragment.fragment == "1" or xray_fragment.noise == "1") and "dialerproxy" or nil
  295. }
  296. } or nil,
  297. mux = (server.v2ray_protocol ~= "wireguard") and {
  298. -- mux
  299. enabled = (server.mux == "1") and true or false, -- Mux
  300. concurrency = tonumber(server.concurrency), -- TCP 最大并发连接数
  301. xudpConcurrency = tonumber(server.xudpConcurrency), -- UDP 最大并发连接数
  302. xudpProxyUDP443 = server.xudpProxyUDP443 -- 对被代理的 UDP/443 流量处理方式
  303. } or nil
  304. }
  305. }
  306. -- 添加带有 fragment 设置的 dialerproxy 配置
  307. if xray_fragment.fragment ~= "0" or (xray_fragment.noise ~= "0" and xray_noise.enabled ~= "0") then
  308. table.insert(Xray.outbounds, {
  309. protocol = "freedom",
  310. tag = "dialerproxy",
  311. settings = {
  312. domainStrategy = (xray_fragment.noise == "1" and xray_noise.enabled == "1") and xray_noise.domainStrategy,
  313. fragment = (xray_fragment.fragment == "1") and {
  314. packets = (xray_fragment.fragment_packets ~= "") and xray_fragment.fragment_packets or nil,
  315. length = (xray_fragment.fragment_length ~= "") and xray_fragment.fragment_length or nil,
  316. interval = (xray_fragment.fragment_interval ~= "") and xray_fragment.fragment_interval or nil
  317. } or nil,
  318. noises = (xray_fragment.noise == "1" and xray_noise.enabled == "1") and {
  319. {
  320. type = xray_noise.type,
  321. packet = xray_noise.packet,
  322. delay = xray_noise.delay:find("-") and xray_noise.delay or tonumber(xray_noise.delay)
  323. }
  324. } or nil
  325. },
  326. streamSettings = {
  327. sockopt = {
  328. tcpMptcp = (server.mptcp == "1") and true or false, -- MPTCP
  329. tcpNoDelay = (server.mptcp == "1") and true or false -- MPTCP
  330. }
  331. }
  332. })
  333. end
  334. local cipher = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA"
  335. local cipher13 = "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384"
  336. local trojan = {
  337. log_level = 3,
  338. run_type = (proto == "nat" or proto == "tcp") and "nat" or "client",
  339. local_addr = "0.0.0.0",
  340. local_port = tonumber(local_port),
  341. remote_addr = server.server,
  342. remote_port = tonumber(server.server_port),
  343. udp_timeout = 60,
  344. -- 传入连接
  345. password = {server.password},
  346. -- 传出连接
  347. ssl = {
  348. verify = (server.insecure == "0") and true or false,
  349. verify_hostname = (server.tls == "1") and true or false,
  350. cert = (server.certificate) and server.certpath or nil,
  351. cipher = cipher,
  352. cipher_tls13 = cipher13,
  353. sni = server.tls_host,
  354. alpn = server.tls_alpn or {"h2", "http/1.1"},
  355. curve = "",
  356. reuse_session = true,
  357. session_ticket = (server.tls_sessionTicket == "1") and true or false
  358. },
  359. udp_timeout = 60,
  360. tcp = {
  361. -- tcp
  362. no_delay = true,
  363. keep_alive = true,
  364. reuse_port = true,
  365. fast_open = (server.fast_open == "1") and true or false,
  366. fast_open_qlen = 20
  367. }
  368. }
  369. local naiveproxy = {
  370. proxy = (server.username and server.password and server.server and server.server_port) and "https://" .. server.username .. ":" .. server.password .. "@" .. server.server .. ":" .. server.server_port,
  371. listen = (proto == "redir") and "redir" .. "://0.0.0.0:" .. tonumber(local_port) or "socks" .. "://0.0.0.0:" .. tonumber(local_port),
  372. ["insecure-concurrency"] = tonumber(server.concurrency) or 1
  373. }
  374. local ss = {
  375. server = (server.kcp_enable == "1") and "127.0.0.1" or server.server,
  376. server_port = tonumber(server.server_port),
  377. local_address = "0.0.0.0",
  378. local_port = tonumber(local_port),
  379. mode = (proto == "tcp,udp") and "tcp_and_udp" or proto .. "_only",
  380. password = server.password,
  381. method = server.encrypt_method_ss,
  382. timeout = tonumber(server.timeout),
  383. fast_open = (server.fast_open == "1") and true or false,
  384. reuse_port = true
  385. }
  386. local hysteria = {
  387. server = (server.server_port and (server.port_range and (server.server .. ":" .. server.server_port .. "," .. server.port_range) or server.server .. ":" .. server.server_port) or (server.port_range and server.server .. ":" .. server.port_range or server.server .. ":443")),
  388. bandwidth = (server.uplink_capacity or server.downlink_capacity) and {
  389. up = tonumber(server.uplink_capacity) and tonumber(server.uplink_capacity) .. " mbps" or nil,
  390. down = tonumber(server.downlink_capacity) and tonumber(server.downlink_capacity) .. " mbps" or nil
  391. },
  392. socks5 = (proto:find("tcp") and tonumber(socks_port) and tonumber(socks_port) ~= 0) and {
  393. listen = "0.0.0.0:" .. tonumber(socks_port),
  394. disable_udp = false
  395. } or nil,
  396. transport = (server.transport_protocol) and {
  397. type = (server.transport_protocol) or udp,
  398. udp = (server.port_range and (server.hopinterval) and {
  399. hopInterval = (server.port_range and (tonumber(server.hopinterval) .. "s") or nil)
  400. } or nil)
  401. } or nil,
  402. --[[
  403. tcpTProxy = (proto:find("tcp") and local_port ~= "0") and {
  404. listen = "0.0.0.0:" .. tonumber(local_port)
  405. } or nil,
  406. ]]--
  407. tcpRedirect = (proto:find("tcp") and local_port ~= "0") and {
  408. listen = "0.0.0.0:" .. tonumber(local_port)
  409. } or nil,
  410. udpTProxy = (proto:find("udp") and local_port ~= "0") and {
  411. listen = "0.0.0.0:" .. tonumber(local_port)
  412. } or nil,
  413. obfs = (server.flag_obfs == "1") and {
  414. type = server.obfs_type,
  415. salamander = { password = server.salamander }
  416. } or nil,
  417. quic = (server.flag_quicparam == "1" ) and {
  418. initStreamReceiveWindow = (server.initstreamreceivewindow and server.initstreamreceivewindow or nil),
  419. maxStreamReceiveWindow = (server.maxstreamseceivewindow and server.maxstreamseceivewindow or nil),
  420. initConnReceiveWindow = (server.initconnreceivewindow and server.initconnreceivewindow or nil),
  421. maxConnReceiveWindow = (server.maxconnreceivewindow and server.maxconnreceivewindow or nil),
  422. maxIdleTimeout = (tonumber(server.maxidletimeout) and tonumber(server.maxidletimeout) .. "s" or nil),
  423. keepAlivePeriod = (tonumber(server.keepaliveperiod) and tonumber(server.keepaliveperiod) .. "s" or nil),
  424. disablePathMTUDiscovery = (server.disablepathmtudiscovery == "1") and true or false
  425. } or nil,
  426. auth = server.hy2_auth,
  427. tls = (server.tls_host) and {
  428. sni = server.tls_host,
  429. --alpn = server.tls_alpn or nil,
  430. insecure = (server.insecure == "1") and true or false,
  431. pinSHA256 = (server.insecure == "1") and server.pinsha256 or nil
  432. } or {
  433. sni = server.server,
  434. insecure = (server.insecure == "1") and true or false
  435. },
  436. fast_open = (server.fast_open == "1") and true or false,
  437. lazy = (server.lazy_mode == "1") and true or false
  438. }
  439. local shadowtls = {
  440. client = {
  441. server_addr = server.server_port and server.server .. ":" .. server.server_port or nil,
  442. listen = "127.0.0.1:" .. tonumber(local_port),
  443. tls_names = server.shadowtls_sni,
  444. password = server.password
  445. },
  446. v3 = (server.shadowtls_protocol == "v3") and true or false,
  447. disable_nodelay = (server.disable_nodelay == "1") and true or false,
  448. fastopen = (server.fastopen == "1") and true or false,
  449. strict = (server.strict == "1") and true or false
  450. }
  451. local chain_sslocal = {
  452. locals = local_port ~= "0" and {
  453. {
  454. local_address = "0.0.0.0",
  455. local_port = (chain_local_port == "0" and tonumber(server.local_port) or tonumber(chain_local_port)),
  456. mode = (proto:find("tcp,udp") and "tcp_and_udp") or proto .. "_only",
  457. protocol = "redir",
  458. tcp_redir = "redirect",
  459. --tcp_redir = "tproxy",
  460. udp_redir = "tproxy"
  461. },
  462. socks_port ~= "0" and {
  463. protocol = "socks",
  464. local_address = "0.0.0.0",
  465. local_port = tonumber(socks_port)
  466. } or nil
  467. } or {{
  468. protocol = "socks",
  469. local_address = "0.0.0.0",
  470. ocal_port = tonumber(socks_port)
  471. }},
  472. servers = {
  473. {
  474. server = "127.0.0.1",
  475. server_port = (tonumber(local_port) == 0 and tonumber(chain_local_port) or tonumber(local_port)),
  476. method = server.sslocal_method,
  477. password = server.sslocal_password
  478. }
  479. }
  480. }
  481. local chain_vmess = {
  482. inbounds = (local_port ~= "0") and {
  483. {
  484. port = (chain_local_port == "0" and tonumber(server.local_port) or tonumber(chain_local_port)),
  485. protocol = "dokodemo-door",
  486. settings = {
  487. network = proto,
  488. followRedirect = true
  489. },
  490. streamSettings = {
  491. sockopt = {tproxy = "redirect"}
  492. },
  493. sniffing = {
  494. enable = true,
  495. destOverride = {"http","tls"}
  496. }
  497. },
  498. (proto:find("tcp") and socks_port ~= "0") and {
  499. protocol = "socks",
  500. port = tonumber(socks_port)
  501. } or nil
  502. } or { protocol = "socks",port = tonumber(socks_port) },
  503. outbound = {
  504. protocol = "vmess",
  505. settings = {
  506. vnext = {{
  507. address = "127.0.0.1",
  508. port = (tonumber(local_port) == 0 and tonumber(chain_local_port) or tonumber(local_port)),
  509. users = {{
  510. id = (server.vmess_uuid),
  511. security = server.vmess_method,
  512. level = 0
  513. }}
  514. }}
  515. }
  516. }
  517. }
  518. local tuic = {
  519. relay = {
  520. server = server.server_port and server.server .. ":" .. server.server_port,
  521. ip = server.tuic_ip,
  522. uuid = server.tuic_uuid,
  523. password = server.tuic_passwd,
  524. certificates = server.certificate and { server.certpath } or nil,
  525. udp_relay_mode = server.udp_relay_mode,
  526. congestion_control = server.congestion_control,
  527. heartbeat = server.heartbeat and server.heartbeat .. "s" or nil,
  528. timeout = server.timeout and server.timeout .. "s" or nil,
  529. gc_interval = server.gc_interval and server.gc_interval .. "s" or nil,
  530. gc_lifetime = server.gc_lifetime and server.gc_lifetime .. "s" or nil,
  531. alpn = server.tls_alpn,
  532. disable_sni = (server.disable_sni == "1") and true or false,
  533. zero_rtt_handshake = (server.zero_rtt_handshake == "1") and true or false,
  534. send_window = tonumber(server.send_window),
  535. receive_window = tonumber(server.receive_window)
  536. },
  537. ["local"] = {
  538. server = tonumber(socks_port) and "[::]:" .. (socks_port == "0" and local_port or tonumber(socks_port)),
  539. dual_stack = (server.tuic_dual_stack == "1") and true or nil,
  540. max_packet_size = tonumber(server.tuic_max_package_size)
  541. }
  542. }
  543. local config = {}
  544. function config:new(o)
  545. o = o or {}
  546. setmetatable(o, self)
  547. self.__index = self
  548. return o
  549. end
  550. function config:handleIndex(index)
  551. local switch = {
  552. ss = function()
  553. ss.protocol = socks_port
  554. if server.plugin and server.plugin ~= "none" then
  555. ss.plugin = server.plugin
  556. ss.plugin_opts = server.plugin_opts or nil
  557. end
  558. print(json.stringify(ss, 1))
  559. end,
  560. ssr = function()
  561. ss.protocol = server.protocol
  562. ss.protocol_param = server.protocol_param
  563. ss.method = server.encrypt_method
  564. ss.obfs = server.obfs
  565. ss.obfs_param = server.obfs_param
  566. print(json.stringify(ss, 1))
  567. end,
  568. v2ray = function()
  569. print(json.stringify(Xray, 1))
  570. end,
  571. trojan = function()
  572. print(json.stringify(trojan, 1))
  573. end,
  574. naiveproxy = function()
  575. print(json.stringify(naiveproxy, 1))
  576. end,
  577. hysteria = function()
  578. print(json.stringify(hysteria, 1))
  579. end,
  580. shadowtls = function()
  581. local chain_switch = {
  582. sslocal = function()
  583. if (chain:find("chain")) then
  584. print(json.stringify(chain_sslocal, 1))
  585. else
  586. print(json.stringify(shadowtls, 1))
  587. end
  588. end,
  589. vmess = function()
  590. if (chain:find("chain")) then
  591. print(json.stringify(chain_vmess, 1))
  592. else
  593. print(json.stringify(shadowtls, 1))
  594. end
  595. end
  596. }
  597. local ChainType = server.chain_type
  598. if chain_switch[ChainType] then
  599. chain_switch[ChainType]()
  600. end
  601. end,
  602. tuic = function()
  603. print(json.stringify(tuic, 1))
  604. end
  605. }
  606. if switch[index] then
  607. switch[index]()
  608. end
  609. end
  610. local f = config:new()
  611. f:handleIndex(server.type)