gen_config.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. local ucursor = require"luci.model.uci".cursor()
  2. local json = require "luci.jsonc"
  3. local server_section = arg[1]
  4. local proto = arg[2]
  5. local local_port = arg[3] or "0"
  6. local socks_port = arg[4] or "0"
  7. local server = ucursor:get_all("shadowsocksr", server_section)
  8. local Xray = {
  9. log = {
  10. -- error = "/var/ssrplus.log",
  11. loglevel = "warning"
  12. },
  13. -- 传入连接
  14. inbound = (local_port ~= "0") and {
  15. port = tonumber(local_port),
  16. protocol = "dokodemo-door",
  17. settings = {network = proto, followRedirect = true},
  18. sniffing = {enabled = true, destOverride = {"http", "tls"}}
  19. } or nil,
  20. -- 开启 socks 代理
  21. inboundDetour = (proto == "tcp" and socks_port ~= "0") and {
  22. {
  23. protocol = "socks",
  24. port = tonumber(socks_port),
  25. settings = {auth = "noauth", udp = true}
  26. }
  27. } or nil,
  28. -- 传出连接
  29. outbound = {
  30. protocol = server.type,
  31. settings = {
  32. vnext = {
  33. {
  34. address = server.server,
  35. port = tonumber(server.server_port),
  36. users = {
  37. {
  38. id = server.vmess_id,
  39. alterId = (server.type == "vmess") and tonumber(server.alter_id) or nil,
  40. security = (server.type == "vmess") and server.security or nil,
  41. encryption = (server.type == "vless") and server.vless_encryption or nil,
  42. flow = (server.xtls == '1') and (server.vless_flow and server.vless_flow or "xtls-rprx-splice") or nil
  43. }
  44. }
  45. }
  46. }
  47. },
  48. -- 底层传输配置
  49. streamSettings = {
  50. network = server.transport,
  51. security = (server.xtls == '1') and "xtls" or (server.tls == '1') and "tls" or "none",
  52. tlsSettings = (server.tls == '1' and (server.insecure == "1" or server.tls_host)) and {
  53. allowInsecure = (server.insecure == "1") and true or nil,
  54. serverName = server.tls_host
  55. } or nil,
  56. xtlsSettings = (server.xtls == '1' and (server.insecure == "1" or server.tls_host)) and {
  57. allowInsecure = (server.insecure == "1") and true or nil,
  58. serverName = server.tls_host
  59. } or nil,
  60. tcpSettings = (server.transport == "tcp" and server.tcp_guise == "http") and {
  61. header = {
  62. type = server.tcp_guise,
  63. request = {
  64. path = {server.http_path} or {"/"},
  65. headers = {Host = {server.http_host} or {}}
  66. }
  67. }
  68. } or nil,
  69. kcpSettings = (server.transport == "kcp") and {
  70. mtu = tonumber(server.mtu),
  71. tti = tonumber(server.tti),
  72. uplinkCapacity = tonumber(server.uplink_capacity),
  73. downlinkCapacity = tonumber(server.downlink_capacity),
  74. congestion = (server.congestion == "1") and true or false,
  75. readBufferSize = tonumber(server.read_buffer_size),
  76. writeBufferSize = tonumber(server.write_buffer_size),
  77. header = {type = server.kcp_guise},
  78. seed = server.seed or nil
  79. } or nil,
  80. wsSettings = (server.transport == "ws") and (server.ws_path or server.ws_host or server.tls_host) and {
  81. path = server.ws_path,
  82. headers = (server.ws_host or server.tls_host) and {
  83. Host = server.ws_host or server.tls_host
  84. } or nil
  85. } or nil,
  86. httpSettings = (server.transport == "h2") and {
  87. path = server.h2_path or "",
  88. host = {server.h2_host} or nil
  89. } or nil,
  90. quicSettings = (server.transport == "quic") and {
  91. security = server.quic_security,
  92. key = server.quic_key,
  93. header = {type = server.quic_guise}
  94. } or nil
  95. },
  96. mux = (server.mux == "1" and server.xtls ~= "1") and {
  97. enabled = true,
  98. concurrency = tonumber(server.concurrency)
  99. } or nil
  100. } or nil
  101. }
  102. local trojan = {
  103. log_level = 3,
  104. run_type = (proto == "nat" or proto == "tcp") and "nat" or "client",
  105. local_addr = "0.0.0.0",
  106. local_port = tonumber(local_port),
  107. remote_addr = server.server,
  108. remote_port = tonumber(server.server_port),
  109. udp_timeout = 60,
  110. -- 传入连接
  111. password = {server.password},
  112. -- 传出连接
  113. ssl = {
  114. verify = (server.insecure == "0") and true or false,
  115. verify_hostname = (server.tls == "1") and true or false,
  116. cert = "",
  117. 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",
  118. cipher_tls13 = "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384",
  119. sni = server.tls_host,
  120. alpn = {"h2", "http/1.1"},
  121. curve = "",
  122. reuse_session = true,
  123. session_ticket = false
  124. },
  125. tcp = {
  126. no_delay = true,
  127. keep_alive = true,
  128. reuse_port = true,
  129. fast_open = (server.fast_open == "1") and true or false,
  130. fast_open_qlen = 20
  131. }
  132. }
  133. local naiveproxy = {
  134. proxy = (server.username and server.password and server.server and server.server_port) and "https://" .. server.username .. ":" .. server.password .. "@" .. server.server .. ":" .. server.server_port,
  135. listen = (proto == "redir") and "redir" .. "://0.0.0.0:" .. tonumber(local_port) or "socks" .. "://0.0.0.0:" .. tonumber(local_port),
  136. concurrency = (socks_port ~= "0") and tonumber(socks_port) or "1"
  137. }
  138. local ss = {
  139. server = (server.kcp_enable == "1") and "127.0.0.1" or server.server,
  140. server_port = tonumber(server.server_port),
  141. local_address = "0.0.0.0",
  142. local_port = tonumber(local_port),
  143. password = server.password,
  144. method = server.encrypt_method,
  145. timeout = tonumber(server.timeout) or 60,
  146. fast_open = (server.fast_open == "1") and true or false,
  147. reuse_port = true
  148. }
  149. if server.type == "ss" then
  150. if server.plugin then
  151. ss.plugin = server.plugin
  152. ss.plugin_opts = (server.simple_obfs) and server.simple_obfs .. server.plugin_opts or (server.v2ray_plugin ~= "none") and server.v2ray_plugin .. server.plugin_opts or nil
  153. end
  154. print(json.stringify(ss, 1))
  155. end
  156. if server.type == "ssr" then
  157. ss.protocol = server.protocol
  158. ss.protocol_param = server.protocol_param
  159. ss.obfs = server.obfs
  160. ss.obfs_param = server.obfs_param
  161. print(json.stringify(ss, 1))
  162. end
  163. if server.type == "vless" or server.type == "vmess" then
  164. print(json.stringify(Xray, 1))
  165. end
  166. if server.type == "trojan" then
  167. print(json.stringify(trojan, 1))
  168. end
  169. if server.type == "naiveproxy" then
  170. print(json.stringify(naiveproxy, 1))
  171. end