genxrayconfig.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 outbound_security = "none"
  9. if (server.xtls == '1')
  10. then
  11. outbound_security = "xtls"
  12. elseif (server.tls == '1')
  13. then
  14. outbound_security = "tls"
  15. end
  16. local vless = {
  17. log = {
  18. -- error = "/var/ssrplus.log",
  19. loglevel = "warning"
  20. },
  21. -- 传入连接
  22. inbound = (local_port ~= "0") and {
  23. port = local_port,
  24. protocol = "dokodemo-door",
  25. settings = {
  26. network = proto,
  27. followRedirect = true
  28. },
  29. sniffing = {
  30. enabled = true,
  31. destOverride = { "http", "tls" }
  32. }
  33. } or nil,
  34. -- 开启 socks 代理
  35. inboundDetour = (proto == "tcp" and socks_port ~= "0") and {
  36. {
  37. protocol = "socks",
  38. port = socks_port,
  39. settings = {
  40. auth = "noauth",
  41. udp = true
  42. }
  43. }
  44. } or nil,
  45. -- 传出连接
  46. outbound = {
  47. protocol = "vless",
  48. settings = {
  49. vnext = {
  50. {
  51. address = server.server,
  52. port = tonumber(server.server_port),
  53. users = {
  54. {
  55. id = server.vmess_id,
  56. flow = (server.xtls == '1') and (server.vless_flow and server.vless_flow or "xtls-rprx-origin") or nil,
  57. encryption = server.vless_encryption
  58. }
  59. }
  60. }
  61. }
  62. },
  63. -- 底层传输配置
  64. streamSettings = {
  65. network = server.transport,
  66. security = outbound_security,
  67. tlsSettings = (outbound_security == "tls") and {allowInsecure = (server.insecure ~= "0") and true or false,serverName=server.tls_host,} or nil,
  68. xtlsSettings = (outbound_security == "xtls") and {allowInsecure = (server.insecure ~= "0") and true or false,serverName=server.tls_host,} or nil,
  69. tcpSettings = (server.transport == "tcp") 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. } or {}
  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,
  101. host = server.h2_host,
  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 = {
  112. enabled = (server.mux == "1") and true or false,
  113. concurrency = tonumber(server.concurrency)
  114. }
  115. },
  116. -- 额外传出连接
  117. outboundDetour = {
  118. {
  119. protocol = "freedom",
  120. tag = "direct",
  121. settings = { keep = "" }
  122. }
  123. }
  124. }
  125. print(json.stringify(vless, 1))