genv2config.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 v2ray = {
  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 = "vmess",
  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 = tonumber(server.alter_id),
  49. security = server.security
  50. }
  51. }
  52. }
  53. }
  54. },
  55. -- 底层传输配置
  56. streamSettings = {
  57. network = server.transport,
  58. security = (server.tls == '1') and "tls" or "none",
  59. tlsSettings = {allowInsecure = (server.insecure ~= "0") and true or false,serverName=server.tls_host,},
  60. kcpSettings = (server.transport == "kcp") and {
  61. mtu = tonumber(server.mtu),
  62. tti = tonumber(server.tti),
  63. uplinkCapacity = tonumber(server.uplink_capacity),
  64. downlinkCapacity = tonumber(server.downlink_capacity),
  65. congestion = (server.congestion == "1") and true or false,
  66. readBufferSize = tonumber(server.read_buffer_size),
  67. writeBufferSize = tonumber(server.write_buffer_size),
  68. header = {
  69. type = server.kcp_guise
  70. }
  71. } or nil,
  72. wsSettings = (server.transport == "ws") and (server.ws_path ~= nil or server.ws_host ~= nil) and {
  73. path = server.ws_path,
  74. headers = (server.ws_host ~= nil) and {
  75. Host = server.ws_host
  76. } or nil,
  77. } or nil,
  78. httpSettings = (server.transport == "h2") and {
  79. path = server.h2_path,
  80. host = server.h2_host,
  81. } or nil,
  82. quicSettings = (server.transport == "quic") and {
  83. security = server.quic_security,
  84. key = server.quic_key,
  85. header = {
  86. type = server.quic_guise
  87. }
  88. } or nil
  89. },
  90. mux = {
  91. enabled = (server.mux == "1") and true or false,
  92. concurrency = tonumber(server.concurrency)
  93. }
  94. },
  95. -- 额外传出连接
  96. outboundDetour = {
  97. {
  98. protocol = "freedom",
  99. tag = "direct",
  100. settings = { keep = "" }
  101. }
  102. }
  103. }
  104. print(json.stringify(v2ray, 1))