genv2config.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 = local_port,
  16. protocol = "dokodemo-door",
  17. settings = {
  18. network = proto,
  19. followRedirect = true
  20. },
  21. sniffing = {
  22. enabled = true,
  23. destOverride = { "http", "tls" }
  24. }
  25. } or nil,
  26. -- 开启 socks 代理
  27. inboundDetour = (proto == "tcp" and socks_port ~= "0") and {
  28. {
  29. protocol = "socks",
  30. port = socks_port,
  31. settings = {
  32. auth = "noauth",
  33. udp = true
  34. }
  35. }
  36. } or nil,
  37. -- 传出连接
  38. outbound = {
  39. protocol = server.type,
  40. settings = {
  41. vnext = {
  42. {
  43. address = server.server,
  44. port = tonumber(server.server_port),
  45. users = {
  46. {
  47. id = server.vmess_id,
  48. alterId = (server.type == "vmess") and tonumber(server.alter_id) or nil,
  49. security = (server.type == "vmess") and server.security or nil,
  50. encryption = (server.type == "vless") and server.vless_encryption or nil,
  51. flow = (server.xtls == '1') and (server.vless_flow and server.vless_flow or "xtls-rprx-splice") or nil,
  52. }
  53. }
  54. }
  55. }
  56. },
  57. -- 底层传输配置
  58. streamSettings = {
  59. network = server.transport,
  60. security = (server.tls == '1') and ((server.xtls == '1') and "xtls" or "tls") or "none",
  61. tlsSettings = (server.tls == '1' and server.xtls ~= '1' and (server.insecure == "1" or server.tls_host)) and {
  62. allowInsecure = (server.insecure == "1") and true or nil,
  63. serverName=server.tls_host
  64. } or nil,
  65. xtlsSettings = (server.xtls == '1' and (server.insecure == "1" or server.tls_host)) and {
  66. allowInsecure = (server.insecure == "1") and true or nil,
  67. serverName=server.tls_host
  68. } or nil,
  69. tcpSettings = (server.transport == "tcp" and server.tcp_guise == "http") and {
  70. header = {
  71. type = server.tcp_guise,
  72. request = {
  73. path = {server.http_path} or {"/"},
  74. headers = {
  75. Host = {server.http_host} or {}
  76. }
  77. }
  78. }
  79. } or nil,
  80. kcpSettings = (server.transport == "kcp") and {
  81. mtu = tonumber(server.mtu),
  82. tti = tonumber(server.tti),
  83. uplinkCapacity = tonumber(server.uplink_capacity),
  84. downlinkCapacity = tonumber(server.downlink_capacity),
  85. congestion = (server.congestion == "1") and true or false,
  86. readBufferSize = tonumber(server.read_buffer_size),
  87. writeBufferSize = tonumber(server.write_buffer_size),
  88. header = {
  89. type = server.kcp_guise
  90. },
  91. seed = server.seed or nil
  92. } or nil,
  93. wsSettings = (server.transport == "ws") and (server.ws_path ~= nil or server.ws_host ~= nil) and {
  94. path = server.ws_path,
  95. headers = (server.ws_host ~= nil) and {
  96. Host = server.ws_host
  97. } or nil,
  98. } or nil,
  99. httpSettings = (server.transport == "h2") and {
  100. path = server.h2_path or "",
  101. host = {server.h2_host} or nil
  102. } or nil,
  103. quicSettings = (server.transport == "quic") and {
  104. security = server.quic_security,
  105. key = server.quic_key,
  106. header = {
  107. type = server.quic_guise
  108. }
  109. } or nil
  110. },
  111. mux = (server.xtls ~= "1") and {
  112. enabled = (server.mux == "1") and true or false,
  113. concurrency = tonumber(server.concurrency)
  114. } or nil
  115. } or nil
  116. }
  117. print(json.stringify(Xray,1))