genv2config.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 == "v2ray") and "vmess" or "vless",
  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 == "v2ray") and tonumber(server.alter_id) or nil,
  49. security = (server.type == "v2ray") 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-origin") 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 {allowInsecure = (server.insecure ~= "0") and true or nil,serverName=server.tls_host,} or nil,
  62. xtlsSettings = (server.xtls == '1') and {allowInsecure = (server.insecure ~= "0") and true or nil,serverName=server.tls_host,} or nil,
  63. tcpSettings = (server.transport == "tcp" and server.tcp_guise == "http") and {
  64. header = {
  65. type = server.tcp_guise,
  66. request = {
  67. path = {server.http_path} or {"/"},
  68. headers = {
  69. Host = {server.http_host} or {}
  70. }
  71. }
  72. }
  73. } or nil,
  74. kcpSettings = (server.transport == "kcp") and {
  75. mtu = tonumber(server.mtu),
  76. tti = tonumber(server.tti),
  77. uplinkCapacity = tonumber(server.uplink_capacity),
  78. downlinkCapacity = tonumber(server.downlink_capacity),
  79. congestion = (server.congestion == "1") and true or false,
  80. readBufferSize = tonumber(server.read_buffer_size),
  81. writeBufferSize = tonumber(server.write_buffer_size),
  82. header = {
  83. type = server.kcp_guise
  84. },
  85. seed = server.seed or nil
  86. } or nil,
  87. wsSettings = (server.transport == "ws") and (server.ws_path ~= nil or server.ws_host ~= nil) and {
  88. path = server.ws_path,
  89. headers = (server.ws_host ~= nil) and {
  90. Host = server.ws_host
  91. } or nil,
  92. } or nil,
  93. httpSettings = (server.transport == "h2") and {
  94. path = server.h2_path or "",
  95. host = {server.h2_host} or nil
  96. } or nil,
  97. quicSettings = (server.transport == "quic") and {
  98. security = server.quic_security,
  99. key = server.quic_key,
  100. header = {
  101. type = server.quic_guise
  102. }
  103. } or nil
  104. },
  105. mux = (server.xtls ~= "1") and {
  106. enabled = (server.mux == "1") and true or false,
  107. concurrency = tonumber(server.concurrency)
  108. } or nil
  109. } or nil
  110. }
  111. print(json.stringify(Xray,1))