2
0

genv2config.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. tcpSettings = (server.transport == "tcp") and {
  61. header = {
  62. type = server.tcp_guise,
  63. request = {
  64. path = server.http_path or {"/"},
  65. headers = {
  66. Host = server.http_host or {}
  67. }
  68. } or {}
  69. }
  70. } or nil,
  71. kcpSettings = (server.transport == "kcp") and {
  72. mtu = tonumber(server.mtu),
  73. tti = tonumber(server.tti),
  74. uplinkCapacity = tonumber(server.uplink_capacity),
  75. downlinkCapacity = tonumber(server.downlink_capacity),
  76. congestion = (server.congestion == "1") and true or false,
  77. readBufferSize = tonumber(server.read_buffer_size),
  78. writeBufferSize = tonumber(server.write_buffer_size),
  79. header = {
  80. type = server.kcp_guise
  81. }
  82. } or nil,
  83. wsSettings = (server.transport == "ws") and (server.ws_path ~= nil or server.ws_host ~= nil) and {
  84. path = server.ws_path,
  85. headers = (server.ws_host ~= nil) and {
  86. Host = server.ws_host
  87. } or nil,
  88. } or nil,
  89. httpSettings = (server.transport == "h2") and {
  90. path = server.h2_path,
  91. host = server.h2_host,
  92. } or nil,
  93. quicSettings = (server.transport == "quic") and {
  94. security = server.quic_security,
  95. key = server.quic_key,
  96. header = {
  97. type = server.quic_guise
  98. }
  99. } or nil
  100. },
  101. mux = {
  102. enabled = (server.mux == "1") and true or false,
  103. concurrency = tonumber(server.concurrency)
  104. }
  105. },
  106. -- 额外传出连接
  107. outboundDetour = {
  108. {
  109. protocol = "freedom",
  110. tag = "direct",
  111. settings = { keep = "" }
  112. }
  113. }
  114. }
  115. print(json.stringify(v2ray, 1))