genvlessconfig.lua 2.7 KB

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