client-config.lua 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. -- Copyright (C) 2017 yushi studio <[email protected]> github.com/ywb94
  2. -- Licensed to the public under the GNU General Public License v3.
  3. require "nixio.fs"
  4. require "luci.sys"
  5. require "luci.http"
  6. require "luci.jsonc"
  7. require "luci.model.ipkg"
  8. require "luci.model.uci"
  9. local uci = require "luci.model.uci".cursor()
  10. local m, s, o
  11. local sid = arg[1]
  12. local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid")
  13. -- 确保正确判断程序是否存在
  14. local function is_finded(e)
  15. return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= ""
  16. end
  17. local function is_installed(e)
  18. return luci.model.ipkg.installed(e)
  19. end
  20. local has_ss_rust = is_finded("sslocal") or is_finded("ssserver")
  21. local has_ss_libev = is_finded("ss-redir") or is_finded("ss-local")
  22. -- 读取当前存储的 ss_type
  23. local ss_type = uci:get_first("shadowsocksr", "server_subscribe", "ss_type")
  24. local server_table = {}
  25. local encrypt_methods = {
  26. -- ssr
  27. "none",
  28. "table",
  29. "rc4",
  30. "rc4-md5-6",
  31. "rc4-md5",
  32. "aes-128-cfb",
  33. "aes-192-cfb",
  34. "aes-256-cfb",
  35. "aes-128-ctr",
  36. "aes-192-ctr",
  37. "aes-256-ctr",
  38. "bf-cfb",
  39. "camellia-128-cfb",
  40. "camellia-192-cfb",
  41. "camellia-256-cfb",
  42. "cast5-cfb",
  43. "des-cfb",
  44. "idea-cfb",
  45. "rc2-cfb",
  46. "seed-cfb",
  47. "salsa20",
  48. "chacha20",
  49. "chacha20-ietf"
  50. }
  51. local encrypt_methods_ss = {
  52. -- plain
  53. "none",
  54. "plain",
  55. -- aead
  56. "aes-128-gcm",
  57. "aes-192-gcm",
  58. "aes-256-gcm",
  59. "chacha20-ietf-poly1305",
  60. "xchacha20-ietf-poly1305",
  61. -- aead 2022
  62. "2022-blake3-aes-128-gcm",
  63. "2022-blake3-aes-256-gcm",
  64. "2022-blake3-chacha20-poly1305"
  65. --[[ stream
  66. "none",
  67. "plain",
  68. "table",
  69. "rc4",
  70. "rc4-md5",
  71. "aes-128-cfb",
  72. "aes-192-cfb",
  73. "aes-256-cfb",
  74. "aes-128-ctr",
  75. "aes-192-ctr",
  76. "aes-256-ctr",
  77. "bf-cfb",
  78. "camellia-128-cfb",
  79. "camellia-192-cfb",
  80. "camellia-256-cfb",
  81. "salsa20",
  82. "chacha20",
  83. "chacha20-ietf" ]]--
  84. }
  85. local protocol = {
  86. -- ssr
  87. "origin",
  88. "verify_deflate",
  89. "auth_sha1_v4",
  90. "auth_aes128_sha1",
  91. "auth_aes128_md5",
  92. "auth_chain_a",
  93. "auth_chain_b",
  94. "auth_chain_c",
  95. "auth_chain_d",
  96. "auth_chain_e",
  97. "auth_chain_f"
  98. }
  99. local obfs = {
  100. -- ssr
  101. "plain",
  102. "http_simple",
  103. "http_post",
  104. "random_head",
  105. "tls1.2_ticket_auth"
  106. }
  107. local securitys = {
  108. -- vmess
  109. "auto",
  110. "none",
  111. "zero",
  112. "aes-128-gcm",
  113. "chacha20-poly1305"
  114. }
  115. local tls_flows = {
  116. -- tls
  117. "xtls-rprx-vision",
  118. "xtls-rprx-vision-udp443",
  119. "none"
  120. }
  121. m = Map("shadowsocksr", translate("Edit ShadowSocksR Server"))
  122. m.redirect = luci.dispatcher.build_url("admin/services/shadowsocksr/servers")
  123. if m.uci:get("shadowsocksr", sid) ~= "servers" then
  124. luci.http.redirect(m.redirect)
  125. return
  126. end
  127. -- [[ Servers Setting ]]--
  128. s = m:section(NamedSection, sid, "servers")
  129. s.anonymous = true
  130. s.addremove = false
  131. o = s:option(DummyValue, "ssr_url", "SS/SSR/V2RAY/TROJAN/HYSTERIA2 URL")
  132. o.rawhtml = true
  133. o.template = "shadowsocksr/ssrurl"
  134. o.value = sid
  135. o = s:option(ListValue, "type", translate("Server Node Type"))
  136. if is_finded("xray") or is_finded("v2ray") then
  137. o:value("v2ray", translate("V2Ray/XRay"))
  138. end
  139. if is_finded("ssr-redir") then
  140. o:value("ssr", translate("ShadowsocksR"))
  141. end
  142. if has_ss_rust or has_ss_libev then
  143. o:value("ss", translate("ShadowSocks"))
  144. end
  145. if is_finded("trojan") then
  146. o:value("trojan", translate("Trojan"))
  147. end
  148. if is_finded("naive") then
  149. o:value("naiveproxy", translate("NaiveProxy"))
  150. end
  151. if is_finded("hysteria") then
  152. o:value("hysteria2", translate("Hysteria2"))
  153. end
  154. if is_finded("tuic-client") then
  155. o:value("tuic", translate("TUIC"))
  156. end
  157. if is_finded("shadow-tls") and is_finded("sslocal") then
  158. o:value("shadowtls", translate("Shadow-TLS"))
  159. end
  160. if is_finded("ipt2socks") then
  161. o:value("socks5", translate("Socks5"))
  162. end
  163. if is_finded("redsocks2") then
  164. o:value("tun", translate("Network Tunnel"))
  165. end
  166. o.description = translate("Using incorrect encryption mothod may causes service fail to start")
  167. o = s:option(Value, "alias", translate("Alias(optional)"))
  168. o = s:option(ListValue, "iface", translate("Network interface to use"))
  169. for _, e in ipairs(luci.sys.net.devices()) do
  170. if e ~= "lo" then
  171. o:value(e)
  172. end
  173. end
  174. o:depends("type", "tun")
  175. o.description = translate("Redirect traffic to this network interface")
  176. -- 新增一个选择框,用于选择 Shadowsocks 版本
  177. o = s:option(ListValue, "has_ss_type", string.format("<b><span style='color:red;'>%s</span></b>", translate("ShadowSocks Node Use Version")))
  178. o.description = translate("Selection ShadowSocks Node Use Version.")
  179. -- 设置默认 Shadowsocks 版本
  180. -- 动态添加选项
  181. if has_ss_rust then
  182. o:value("ss-rust", translate("ShadowSocks-rust Version"))
  183. end
  184. if has_ss_libev then
  185. o:value("ss-libev", translate("ShadowSocks-libev Version"))
  186. end
  187. -- 设置默认值
  188. if ss_type == "ss-rust" then
  189. o.default = "ss-rust"
  190. elseif ss_type == "ss-libev" then
  191. o.default = "ss-libev"
  192. end
  193. o:depends("type", "ss")
  194. o.write = function(self, section, value)
  195. -- 更新 Shadowsocks 节点的 has_ss_type
  196. uci:foreach("shadowsocksr", "servers", function(s)
  197. local node_type = uci:get("shadowsocksr", s[".name"], "type") -- 获取节点类型
  198. if node_type == "ss" then -- 仅修改 Shadowsocks 节点
  199. local old_value = uci:get("shadowsocksr", s[".name"], "has_ss_type")
  200. if old_value ~= value then
  201. uci:set("shadowsocksr", s[".name"], "has_ss_type", value)
  202. end
  203. end
  204. end)
  205. -- 更新 server_subscribe 的 ss_type
  206. local old_value = uci:get("shadowsocksr", "server_subscribe", "ss_type")
  207. if old_value ~= value then
  208. uci:set("shadowsocksr", "@server_subscribe[0]", "ss_type", value)
  209. end
  210. -- 更新当前 section 的 has_ss_type
  211. Value.write(self, section, value)
  212. end
  213. o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol"))
  214. o:value("vless", translate("VLESS"))
  215. o:value("vmess", translate("VMess"))
  216. o:value("trojan", translate("Trojan"))
  217. o:value("shadowsocks", translate("ShadowSocks"))
  218. if is_finded("xray") then
  219. o:value("wireguard", translate("WireGuard"))
  220. end
  221. o:value("socks", translate("Socks"))
  222. o:value("http", translate("HTTP"))
  223. o:depends("type", "v2ray")
  224. o = s:option(Value, "server", translate("Server Address"))
  225. o.datatype = "host"
  226. o.rmempty = false
  227. o:depends("type", "ssr")
  228. o:depends("type", "ss")
  229. o:depends("type", "v2ray")
  230. o:depends("type", "trojan")
  231. o:depends("type", "naiveproxy")
  232. o:depends("type", "hysteria2")
  233. o:depends("type", "tuic")
  234. o:depends("type", "shadowtls")
  235. o:depends("type", "socks5")
  236. o = s:option(Value, "server_port", translate("Server Port"))
  237. o.datatype = "port"
  238. o.rmempty = true
  239. o:depends("type", "ssr")
  240. o:depends("type", "ss")
  241. o:depends("type", "v2ray")
  242. o:depends("type", "trojan")
  243. o:depends("type", "naiveproxy")
  244. o:depends("type", "hysteria2")
  245. o:depends("type", "tuic")
  246. o:depends("type", "shadowtls")
  247. o:depends("type", "socks5")
  248. o = s:option(Flag, "auth_enable", translate("Enable Authentication"))
  249. o.rmempty = false
  250. o.default = "0"
  251. o:depends("type", "socks5")
  252. o:depends({type = "v2ray", v2ray_protocol = "http"})
  253. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  254. o = s:option(Value, "username", translate("Username"))
  255. o.rmempty = true
  256. o:depends("type", "naiveproxy")
  257. o:depends({type = "socks5", auth_enable = true})
  258. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  259. o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
  260. o = s:option(Value, "password", translate("Password"))
  261. o.password = true
  262. o.rmempty = true
  263. o:depends("type", "ssr")
  264. o:depends("type", "ss")
  265. o:depends("type", "trojan")
  266. o:depends("type", "naiveproxy")
  267. o:depends("type", "shadowtls")
  268. o:depends({type = "socks5", auth_enable = true})
  269. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  270. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", auth_enable = true})
  271. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  272. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  273. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  274. for _, v in ipairs(encrypt_methods) do
  275. o:value(v)
  276. end
  277. o.rmempty = true
  278. o:depends("type", "ssr")
  279. o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
  280. for _, v in ipairs(encrypt_methods_ss) do
  281. if v == "none" then
  282. o.default = "none"
  283. o:value("none", translate("none"))
  284. else
  285. o:value(v, translate(v))
  286. end
  287. end
  288. o.rmempty = true
  289. o:depends("type", "ss")
  290. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  291. o = s:option(Flag, "uot", translate("UDP over TCP"))
  292. o.description = translate("Enable the SUoT protocol, requires server support.")
  293. o.rmempty = true
  294. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  295. o.default = "0"
  296. o = s:option(Flag, "ivCheck", translate("Bloom Filter"))
  297. o.rmempty = true
  298. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  299. o.default = "1"
  300. -- [[ Enable Shadowsocks Plugin ]]--
  301. o = s:option(Flag, "enable_plugin", translate("Enable Plugin"))
  302. o.rmempty = true
  303. o:depends("type", "ss")
  304. o.default = "0"
  305. -- Shadowsocks Plugin
  306. o = s:option(ListValue, "plugin", translate("Obfs"))
  307. o:value("none", translate("None"))
  308. if is_finded("obfs-local") then
  309. o:value("obfs-local", translate("obfs-local"))
  310. end
  311. if is_finded("v2ray-plugin") then
  312. o:value("v2ray-plugin", translate("v2ray-plugin"))
  313. end
  314. if is_finded("xray-plugin") then
  315. o:value("xray-plugin", translate("xray-plugin"))
  316. end
  317. if is_finded("shadow-tls") then
  318. o:value("shadow-tls", translate("shadow-tls"))
  319. end
  320. o:value("custom", translate("Custom"))
  321. o.rmempty = true
  322. o:depends({enable_plugin = true})
  323. o = s:option(Value, "custom_plugin", translate("Custom Plugin Path"))
  324. o.placeholder = "/path/to/custom-plugin"
  325. o:depends({plugin = "custom"})
  326. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  327. o.rmempty = true
  328. o:depends({enable_plugin = true})
  329. o = s:option(ListValue, "protocol", translate("Protocol"))
  330. for _, v in ipairs(protocol) do
  331. o:value(v)
  332. end
  333. o.rmempty = true
  334. o:depends("type", "ssr")
  335. o = s:option(Value, "protocol_param", translate("Protocol param (optional)"))
  336. o:depends("type", "ssr")
  337. o = s:option(ListValue, "obfs", translate("Obfs"))
  338. for _, v in ipairs(obfs) do
  339. o:value(v)
  340. end
  341. o.rmempty = true
  342. o:depends("type", "ssr")
  343. o = s:option(Value, "obfs_param", translate("Obfs param (optional)"))
  344. o:depends("type", "ssr")
  345. -- [[ Hysteria2 ]]--
  346. o = s:option(Value, "hy2_auth", translate("Users Authentication"))
  347. o:depends("type", "hysteria2")
  348. o.rmempty = false
  349. o = s:option(Flag, "flag_port_hopping", translate("Enable Port Hopping"))
  350. o:depends("type", "hysteria2")
  351. o.rmempty = true
  352. o.default = "0"
  353. o = s:option(Value, "port_range", translate("Port hopping range"))
  354. o.description = translate("Format as 10000:20000 or 10000-20000 Multiple groups are separated by commas (,).")
  355. o:depends({type = "hysteria2", flag_port_hopping = true})
  356. --o.datatype = "portrange"
  357. o.rmempty = true
  358. o = s:option(Flag, "flag_transport", translate("Enable Transport Protocol Settings"))
  359. o:depends("type", "hysteria2")
  360. o.rmempty = true
  361. o.default = "0"
  362. o = s:option(ListValue, "transport_protocol", translate("Transport Protocol"))
  363. o:depends({type = "hysteria2", flag_transport = true})
  364. o:value("udp", translate("UDP"))
  365. o.default = "udp"
  366. o.rmempty = true
  367. o = s:option(Value, "hopinterval", translate("Port Hopping Interval(Unit:Second)"))
  368. o:depends({type = "hysteria2", flag_transport = true, flag_port_hopping = true})
  369. o.datatype = "uinteger"
  370. o.rmempty = true
  371. o.default = "30"
  372. o = s:option(Flag, "flag_obfs", translate("Enable Obfuscation"))
  373. o:depends("type", "hysteria2")
  374. o.rmempty = true
  375. o.default = "0"
  376. o = s:option(Flag, "lazy_mode", translate("Enable Lazy Mode"))
  377. o:depends("type", "hysteria2")
  378. o.rmempty = true
  379. o.default = "0"
  380. o = s:option(Value, "obfs_type", translate("Obfuscation Type"))
  381. o:depends({type = "hysteria2", flag_obfs = "1"})
  382. o.rmempty = true
  383. o.default = "salamander"
  384. o = s:option(Value, "salamander", translate("Obfuscation Password"))
  385. o:depends({type = "hysteria2", flag_obfs = "1"})
  386. o.rmempty = true
  387. o = s:option(Flag, "flag_quicparam", translate("Hysterir QUIC parameters"))
  388. o:depends("type", "hysteria2")
  389. o.rmempty = true
  390. o.default = "0"
  391. o = s:option(Flag, "disablepathmtudiscovery", translate("Disable QUIC path MTU discovery"))
  392. o:depends({type = "hysteria2",flag_quicparam = "1"})
  393. o.rmempty = true
  394. o.default = false
  395. --[[Hysteria2 QUIC parameters setting]]
  396. o = s:option(Value, "initstreamreceivewindow", translate("QUIC initStreamReceiveWindow"))
  397. o:depends({type = "hysteria2", flag_quicparam = "1"})
  398. o.datatype = "uinteger"
  399. o.rmempty = true
  400. o.default = "8388608"
  401. o = s:option(Value, "maxstreamseceivewindow", translate("QUIC maxStreamReceiveWindow"))
  402. o:depends({type = "hysteria2", flag_quicparam = "1"})
  403. o.datatype = "uinteger"
  404. o.rmempty = true
  405. o.default = "8388608"
  406. o = s:option(Value, "initconnreceivewindow", translate("QUIC initConnReceiveWindow"))
  407. o:depends({type = "hysteria2", flag_quicparam = "1"})
  408. o.datatype = "uinteger"
  409. o.rmempty = true
  410. o.default = "20971520"
  411. o = s:option(Value, "maxconnreceivewindow", translate("QUIC maxConnReceiveWindow"))
  412. o:depends({type = "hysteria2", flag_quicparam = "1"})
  413. o.datatype = "uinteger"
  414. o.rmempty = true
  415. o.default = "20971520"
  416. o = s:option(Value, "maxidletimeout", translate("QUIC maxIdleTimeout(Unit:second)"))
  417. o:depends({type = "hysteria2", flag_quicparam = "1"})
  418. o.rmempty = true
  419. o.datatype = "uinteger"
  420. o.default = "30"
  421. o = s:option(Value, "keepaliveperiod", translate("The keep-alive period.(Unit:second)"))
  422. o.description = translate("Default value 0 indicatesno heartbeat.")
  423. o:depends({type = "hysteria2", flag_quicparam = "1"})
  424. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  425. o.rmempty = true
  426. o.datatype = "uinteger"
  427. o.default = "10"
  428. --[[ Shadow-TLS Options ]]
  429. o = s:option(ListValue, "shadowtls_protocol", translate("shadowTLS protocol Version"))
  430. o:depends("type", "shadowtls")
  431. o:value("v3", translate("Enable V3 protocol."))
  432. o:value("v2", translate("Enable V2 protocol."))
  433. o.default = "v3"
  434. o.rmempty = true
  435. o = s:option(Flag, "strict", translate("TLS 1.3 Strict mode"))
  436. o:depends("type", "shadowtls")
  437. o.default = "1"
  438. o.rmempty = false
  439. o = s:option(Flag, "fastopen", translate("TCP Fast Open"), translate("Enabling TCP Fast Open Requires Server Support."))
  440. o:depends("type", "shadowtls")
  441. o.default = "0"
  442. o.rmempty = false
  443. o = s:option(Flag, "disable_nodelay", translate("Disable TCP No_delay"))
  444. o:depends("type", "shadowtls")
  445. o.default = "0"
  446. o.rmempty = true
  447. o = s:option(Value, "shadowtls_sni", translate("shadow-TLS SNI"))
  448. o:depends("type", "shadowtls")
  449. o.datatype = "host"
  450. o.rmempty = true
  451. o.default = ""
  452. --[[ add a ListValue for Choose chain type,sslocal or vmess ]]
  453. o = s:option(ListValue, "chain_type", translate("Shadow-TLS ChainPoxy type"))
  454. o:depends("type", "shadowtls")
  455. if is_finded("sslocal") then
  456. o:value("sslocal", translate("ShadowSocks-rust Version"))
  457. end
  458. if is_finded("xray") or is_finded("v2ray") then
  459. o:value("vmess", translate("Vmess Protocol"))
  460. end
  461. o.default = "sslocal"
  462. o.rmempty = false
  463. o = s:option(Value, "sslocal_password",translate("Shadowsocks password"))
  464. o:depends({type = "shadowtls", chain_type = "sslocal"})
  465. o.rmempty = true
  466. o = s:option(ListValue, "sslocal_method", translate("Encrypt Method"))
  467. o:depends({type = "shadowtls", chain_type = "sslocal"})
  468. for _, v in ipairs(encrypt_methods_ss) do
  469. o:value(v)
  470. end
  471. o = s:option(Value, "vmess_uuid", translate("Vmess UUID"))
  472. o:depends({type = "shadowtls", chain_type = "vmess"})
  473. o.rmempty = false
  474. o.default = uuid
  475. o = s:option(ListValue, "vmess_method", translate("Encrypt Method"))
  476. o:depends({type = "shadowtls", chain_type = "vmess"})
  477. for _, v in ipairs(securitys) do
  478. o:value(v, v:lower())
  479. end
  480. o.rmempty = true
  481. o.default="auto"
  482. -- [[ TUIC ]]
  483. -- TuicNameId
  484. o = s:option(Value, "tuic_uuid", translate("TUIC User UUID"))
  485. o.rmempty = true
  486. o.default = uuid
  487. o:depends("type", "tuic")
  488. --Tuic IP
  489. o = s:option(Value, "tuic_ip", translate("TUIC Server IP Address"))
  490. o.rmempty = true
  491. o.datatype = "ip4addr"
  492. o.default = ""
  493. o:depends("type", "tuic")
  494. -- Tuic Password
  495. o = s:option(Value, "tuic_passwd", translate("TUIC User Password"))
  496. o.rmempty = true
  497. o.default = ""
  498. o:depends("type", "tuic")
  499. o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
  500. o:depends("type", "tuic")
  501. o:value("native", translate("native UDP characteristics"))
  502. o:value("quic", translate("lossless UDP relay using QUIC streams"))
  503. o.default = "native"
  504. o.rmempty = true
  505. o = s:option(ListValue, "congestion_control", translate("Congestion control algorithm"))
  506. o:depends("type", "tuic")
  507. o:value("bbr", translate("BBR"))
  508. o:value("cubic", translate("CUBIC"))
  509. o:value("new_reno", translate("New Reno"))
  510. o.default = "cubic"
  511. o.rmempty = true
  512. o = s:option(Value, "heartbeat", translate("Heartbeat interval(second)"))
  513. o:depends("type", "tuic")
  514. o.datatype = "uinteger"
  515. o.default = "3"
  516. o.rmempty = true
  517. o = s:option(Value, "timeout", translate("Timeout for establishing a connection to server(second)"))
  518. o:depends("type", "tuic")
  519. o.datatype = "uinteger"
  520. o.default = "8"
  521. o.rmempty = true
  522. o = s:option(Value, "gc_interval", translate("Garbage collection interval(second)"))
  523. o:depends("type", "tuic")
  524. o.datatype = "uinteger"
  525. o.default = "3"
  526. o.rmempty = true
  527. o = s:option(Value, "gc_lifetime", translate("Garbage collection lifetime(second)"))
  528. o:depends("type", "tuic")
  529. o.datatype = "uinteger"
  530. o.default = "15"
  531. o.rmempty = true
  532. o = s:option(Value, "send_window", translate("TUIC send window"))
  533. o:depends("type", "tuic")
  534. o.datatype = "uinteger"
  535. o.default = 20971520
  536. o.rmempty = true
  537. o = s:option(Value, "receive_window", translate("TUIC receive window"))
  538. o:depends("type", "tuic")
  539. o.datatype = "uinteger"
  540. o.default = 10485760
  541. o.rmempty = true
  542. o = s:option(Flag, "disable_sni", translate("Disable SNI"))
  543. o:depends("type", "tuic")
  544. o.default = "0"
  545. o.rmempty = true
  546. o = s:option(Flag, "zero_rtt_handshake", translate("Enable 0-RTT QUIC handshake"))
  547. o:depends("type", "tuic")
  548. o.default = "0"
  549. o.rmempty = true
  550. -- Tuic settings for the local inbound socks5 server
  551. o = s:option(Flag, "tuic_dual_stack", translate("Dual-stack Listening Socket"))
  552. o.description = translate("If this option is not set, the socket behavior is platform dependent.")
  553. o:depends("type", "tuic")
  554. o.default = "0"
  555. o.rmempty = true
  556. o = s:option(Value, "tuic_max_package_size", translate("Maximum packet size the socks5 server can receive from external"))
  557. o:depends("type", "tuic")
  558. o.datatype = "uinteger"
  559. o.default = 1500
  560. o.rmempty = true
  561. -- AlterId
  562. o = s:option(Value, "alter_id", translate("AlterId"))
  563. o.datatype = "port"
  564. o.default = 16
  565. o.rmempty = true
  566. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  567. -- VmessId
  568. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  569. o.rmempty = true
  570. o.default = uuid
  571. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  572. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  573. -- VLESS Encryption
  574. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  575. o.rmempty = true
  576. o.default = "none"
  577. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  578. -- 加密方式
  579. o = s:option(ListValue, "security", translate("Encrypt Method"))
  580. for _, v in ipairs(securitys) do
  581. o:value(v, v:upper())
  582. end
  583. o.rmempty = true
  584. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  585. -- SOCKS Version
  586. o = s:option(ListValue, "socks_ver", translate("Socks Version"))
  587. o:value("4", "Socks4")
  588. o:value("4a", "Socks4A")
  589. o:value("5", "Socks5")
  590. o.rmempty = true
  591. o.default = "5"
  592. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  593. -- 传输协议
  594. o = s:option(ListValue, "transport", translate("Transport"))
  595. o:value("raw", "RAW (TCP)")
  596. o:value("kcp", "mKCP")
  597. o:value("ws", "WebSocket")
  598. o:value("httpupgrade", "HTTPUpgrade")
  599. o:value("splithttp", "SplitHTTP")
  600. o:value("xhttp", "XHTTP")
  601. o:value("h2", "HTTP/2")
  602. o:value("quic", "QUIC")
  603. o:value("grpc", "gRPC")
  604. o.rmempty = true
  605. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  606. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  607. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  608. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  609. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  610. o:depends({type = "v2ray", v2ray_protocol = "http"})
  611. -- [[ RAW部分 ]]--
  612. -- TCP伪装
  613. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  614. o:depends("transport", "raw")
  615. o:value("none", translate("None"))
  616. o:value("http", "HTTP")
  617. o.rmempty = true
  618. -- HTTP域名
  619. o = s:option(Value, "http_host", translate("HTTP Host"))
  620. o:depends("tcp_guise", "http")
  621. o.rmempty = true
  622. -- HTTP路径
  623. o = s:option(Value, "http_path", translate("HTTP Path"))
  624. o:depends("tcp_guise", "http")
  625. o.rmempty = true
  626. -- [[ WS部分 ]]--
  627. -- WS域名
  628. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  629. o:depends({transport = "ws", tls = false})
  630. o.datatype = "hostname"
  631. o.rmempty = true
  632. -- WS路径
  633. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  634. o:depends("transport", "ws")
  635. o.rmempty = true
  636. if is_finded("v2ray") then
  637. -- WS前置数据
  638. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  639. o:depends("ws_ed_enable", true)
  640. o.datatype = "uinteger"
  641. o:value("2048")
  642. o.rmempty = true
  643. -- WS前置数据标头
  644. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  645. o:depends("ws_ed_enable", true)
  646. o:value("Sec-WebSocket-Protocol")
  647. o.rmempty = true
  648. end
  649. -- [[ httpupgrade部分 ]]--
  650. -- httpupgrade域名
  651. o = s:option(Value, "httpupgrade_host", translate("Httpupgrade Host"))
  652. o:depends({transport = "httpupgrade", tls = false})
  653. o.rmempty = true
  654. -- httpupgrade路径
  655. o = s:option(Value, "httpupgrade_path", translate("Httpupgrade Path"))
  656. o:depends("transport", "httpupgrade")
  657. o.rmempty = true
  658. -- [[ splithttp部分 ]]--
  659. -- splithttp域名
  660. o = s:option(Value, "splithttp_host", translate("Splithttp Host"))
  661. o:depends({transport = "splithttp", tls = false})
  662. o.rmempty = true
  663. -- splithttp路径
  664. o = s:option(Value, "splithttp_path", translate("Splithttp Path"))
  665. o:depends("transport", "splithttp")
  666. o.rmempty = true
  667. -- [[ XHTTP部分 ]]--
  668. o = s:option(ListValue, "xhttp_alpn", translate("XHTTP Alpn"))
  669. o.default = ""
  670. o:value("", translate("Default"))
  671. o:value("h3")
  672. o:value("h2")
  673. o:value("h3,h2")
  674. o:value("http/1.1")
  675. o:value("h2,http/1.1")
  676. o:value("h3,h2,http/1.1")
  677. o:depends("transport", "xhttp")
  678. o = s:option(ListValue, "xhttp_mode", translate("XHTTP Mode"))
  679. o:depends("transport", "xhttp")
  680. o.default = "auto"
  681. o:value("auto")
  682. o:value("packet-up")
  683. o:value("stream-up")
  684. o:value("stream-one")
  685. o = s:option(Value, "xhttp_host", translate("XHTTP Host"))
  686. o:depends({transport = "xhttp", tls = false})
  687. o.rmempty = true
  688. o = s:option(Value, "xhttp_path", translate("XHTTP Path"))
  689. o.placeholder = "/"
  690. o:depends("transport", "xhttp")
  691. o.rmempty = true
  692. o = s:option(Flag, "enable_xhttp_extra", translate("XHTTP Extra"))
  693. o.description = translate("Enable this option to configure XHTTP Extra (JSON format).")
  694. o.rmempty = true
  695. o.default = "0"
  696. o:depends("transport", "xhttp")
  697. o = s:option(TextValue, "xhttp_extra", " ")
  698. o.description = translate(
  699. "<font><b>" .. translate("Configure XHTTP Extra Settings (JSON format), see:") .. "</b></font>" ..
  700. " <a href='https://xtls.github.io/config/transports/splithttp.html#extra' target='_blank'>" ..
  701. "<font style='color:green'><b>" .. translate("Click to the page") .. "</b></font></a>")
  702. o:depends("enable_xhttp_extra", true)
  703. o.rmempty = true
  704. o.rows = 10
  705. o.wrap = "off"
  706. o.custom_write = function(self, section, value)
  707. m:set(section, "xhttp_extra", value)
  708. local success, data = pcall(luci.jsonc.parse, value)
  709. if success and data then
  710. local address = (data.extra and data.extra.downloadSettings and data.extra.downloadSettings.address)
  711. or (data.downloadSettings and data.downloadSettings.address)
  712. if address and address ~= "" then
  713. m:set(section, "download_address", address)
  714. else
  715. m:del(section, "download_address")
  716. end
  717. else
  718. m:del(section, "download_address")
  719. end
  720. end
  721. o.validate = function(self, value)
  722. value = value:gsub("\r\n", "\n"):gsub("^[ \t]*\n", ""):gsub("\n[ \t]*$", ""):gsub("\n[ \t]*\n", "\n")
  723. if value:sub(-1) == "\n" then
  724. value = value:sub(1, -2)
  725. end
  726. local success, data = pcall(luci.jsonc.parse, value)
  727. if not success or not data then
  728. return nil, translate("Invalid JSON format")
  729. end
  730. return value
  731. end
  732. -- [[ H2部分 ]]--
  733. -- H2域名
  734. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  735. o:depends("transport", "h2")
  736. o.rmempty = true
  737. -- H2路径
  738. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  739. o:depends("transport", "h2")
  740. o.rmempty = true
  741. -- gRPC
  742. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  743. o:depends("transport", "grpc")
  744. o.rmempty = true
  745. if is_finded("xray") then
  746. -- gPRC模式
  747. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  748. o:depends("transport", "grpc")
  749. o:value("gun", translate("Gun"))
  750. o:value("multi", translate("Multi"))
  751. o.rmempty = true
  752. end
  753. if is_finded("xray") then
  754. -- gRPC初始窗口
  755. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  756. o.datatype = "uinteger"
  757. o:depends("transport", "grpc")
  758. o.default = 0
  759. o.rmempty = true
  760. -- H2/gRPC健康检查
  761. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  762. o:depends("transport", "h2")
  763. o:depends("transport", "grpc")
  764. o.rmempty = true
  765. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  766. o.datatype = "uinteger"
  767. o:depends({health_check = true, transport = "h2"})
  768. o.default = 60
  769. o.rmempty = true
  770. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  771. o.datatype = "uinteger"
  772. o:depends({health_check = true, transport = "grpc"})
  773. o.default = 60
  774. o.rmempty = true
  775. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  776. o.datatype = "uinteger"
  777. o:depends("health_check", 1)
  778. o.default = 20
  779. o.rmempty = true
  780. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  781. o:depends({health_check = true, transport = "grpc"})
  782. o.rmempty = true
  783. end
  784. -- [[ QUIC部分 ]]--
  785. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  786. o:depends("transport", "quic")
  787. o:value("none", translate("None"))
  788. o:value("aes-128-gcm", translate("aes-128-gcm"))
  789. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  790. o.rmempty = true
  791. o = s:option(Value, "quic_key", translate("QUIC Key"))
  792. o:depends("transport", "quic")
  793. o.rmempty = true
  794. o = s:option(ListValue, "quic_guise", translate("Header"))
  795. o:depends("transport", "quic")
  796. o.rmempty = true
  797. o:value("none", translate("None"))
  798. o:value("srtp", translate("VideoCall (SRTP)"))
  799. o:value("utp", translate("BitTorrent (uTP)"))
  800. o:value("wechat-video", translate("WechatVideo"))
  801. o:value("dtls", translate("DTLS 1.2"))
  802. o:value("wireguard", translate("WireGuard"))
  803. -- [[ mKCP部分 ]]--
  804. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  805. o:depends("transport", "kcp")
  806. o:value("none", translate("None"))
  807. o:value("srtp", translate("VideoCall (SRTP)"))
  808. o:value("utp", translate("BitTorrent (uTP)"))
  809. o:value("wechat-video", translate("WechatVideo"))
  810. o:value("dtls", translate("DTLS 1.2"))
  811. o:value("wireguard", translate("WireGuard"))
  812. o.rmempty = true
  813. o = s:option(Value, "mtu", translate("MTU"))
  814. o.datatype = "uinteger"
  815. o:depends("transport", "kcp")
  816. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  817. -- o.default = 1350
  818. o.rmempty = true
  819. o = s:option(Value, "tti", translate("TTI"))
  820. o.datatype = "uinteger"
  821. o:depends("transport", "kcp")
  822. o.default = 50
  823. o.rmempty = true
  824. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity(Default:Mbps)"))
  825. o.datatype = "uinteger"
  826. o:depends("transport", "kcp")
  827. o:depends("type", "hysteria2")
  828. o.default = 5
  829. o.rmempty = true
  830. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity(Default:Mbps)"))
  831. o.datatype = "uinteger"
  832. o:depends("transport", "kcp")
  833. o:depends("type", "hysteria2")
  834. o.default = 20
  835. o.rmempty = true
  836. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  837. o.datatype = "uinteger"
  838. o:depends("transport", "kcp")
  839. o.default = 2
  840. o.rmempty = true
  841. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  842. o.datatype = "uinteger"
  843. o:depends("transport", "kcp")
  844. o.default = 2
  845. o.rmempty = true
  846. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  847. o:depends("transport", "kcp")
  848. o.rmempty = true
  849. o = s:option(Flag, "congestion", translate("Congestion"))
  850. o:depends("transport", "kcp")
  851. o.rmempty = true
  852. -- [[ WireGuard 部分 ]]--
  853. o = s:option(Flag, "kernelmode", translate("Enabled Kernel virtual NIC TUN(optional)"))
  854. o.description = translate("Virtual NIC TUN of Linux kernel can be used only when system supports and have root permission. If used, IPv6 routing table 1023 is occupied.")
  855. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  856. o.default = "0"
  857. o.rmempty = true
  858. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  859. o.datatype = "cidr"
  860. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  861. o.rmempty = true
  862. o = s:option(DynamicList, "reserved", translate("Reserved bytes(optional)"))
  863. o.description = translate("Wireguard reserved bytes.")
  864. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  865. o.rmempty = true
  866. o = s:option(Value, "private_key", translate("Private key"))
  867. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  868. o.password = true
  869. o.rmempty = true
  870. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  871. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  872. o.rmempty = true
  873. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  874. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  875. o.password = true
  876. o.rmempty = true
  877. o = s:option(DynamicList, "allowedips", translate("allowedIPs(optional)"))
  878. o.description = translate("Wireguard allows only traffic from specific source IP.")
  879. o.datatype = "cidr"
  880. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  881. o.default = "0.0.0.0/0"
  882. o.rmempty = true
  883. -- [[ TLS ]]--
  884. o = s:option(Flag, "tls", translate("TLS"))
  885. o.rmempty = true
  886. o.default = "0"
  887. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = false})
  888. o:depends({type = "v2ray", v2ray_protocol = "vmess", reality = false})
  889. o:depends({type = "v2ray", v2ray_protocol = "trojan", reality = false})
  890. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", reality = false})
  891. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", reality = false})
  892. o:depends({type = "v2ray", v2ray_protocol = "http", reality = false})
  893. o:depends("type", "trojan")
  894. o:depends("type", "hysteria2")
  895. -- [[ TLS部分 ]] --
  896. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  897. o:depends({type = "trojan", tls = true})
  898. o.default = "0"
  899. if is_finded("xray") then
  900. -- [[ REALITY ]]
  901. o = s:option(Flag, "reality", translate("REALITY"))
  902. o.rmempty = true
  903. o.default = "0"
  904. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = false})
  905. o = s:option(Value, "reality_publickey", translate("Public key"))
  906. o.rmempty = true
  907. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  908. o = s:option(Value, "reality_shortid", translate("Short ID"))
  909. o.rmempty = true
  910. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  911. o = s:option(Value, "reality_spiderx", translate("spiderX"))
  912. o.rmempty = true
  913. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  914. -- [[ XTLS ]]--
  915. o = s:option(ListValue, "tls_flow", translate("Flow"))
  916. for _, v in ipairs(tls_flows) do
  917. if v == "none" then
  918. o.default = "none"
  919. o:value("none", translate("none"))
  920. else
  921. o:value(v, translate(v))
  922. end
  923. end
  924. o.rmempty = true
  925. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", tls = true})
  926. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", reality = true})
  927. o = s:option(ListValue, "xhttp_tls_flow", translate("Flow"))
  928. for _, v in ipairs(tls_flows) do
  929. if v == "none" then
  930. o.default = "none"
  931. o:value("none", translate("none"))
  932. else
  933. o:value("xtls-rprx-vision", translate("xtls-rprx-vision"))
  934. end
  935. end
  936. o.rmempty = true
  937. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp", tls = true})
  938. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp", reality = true})
  939. -- [[ uTLS ]]--
  940. o = s:option(ListValue, "fingerprint", translate("Finger Print"))
  941. o.default = ""
  942. o:value("chrome", translate("chrome"))
  943. o:value("firefox", translate("firefox"))
  944. o:value("safari", translate("safari"))
  945. o:value("ios", translate("ios"))
  946. o:value("android", translate("android"))
  947. o:value("edge", translate("edge"))
  948. o:value("360", translate("360"))
  949. o:value("qq", translate("qq"))
  950. o:value("random", translate("random"))
  951. o:value("randomized", translate("randomized"))
  952. o:value("", translate("disable"))
  953. o:depends({type = "v2ray", tls = true})
  954. o:depends({type = "v2ray", reality = true})
  955. end
  956. o = s:option(Value, "tls_host", translate("TLS Host"))
  957. o.datatype = "hostname"
  958. o:depends("tls", true)
  959. o:depends("xtls", true)
  960. o:depends("reality", true)
  961. o.rmempty = true
  962. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  963. o:depends("type", "tuic")
  964. o.default = "h3"
  965. o.rmempty = true
  966. -- [[ allowInsecure ]]--
  967. o = s:option(Flag, "insecure", translate("allowInsecure"))
  968. o.rmempty = false
  969. o:depends("tls", true)
  970. o:depends("type", "hysteria2")
  971. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  972. -- [[ Hysteria2 TLS pinSHA256 ]] --
  973. o = s:option(Value, "pinsha256", translate("Certificate fingerprint"))
  974. o:depends({type = "hysteria2", insecure = true })
  975. o.rmempty = true
  976. -- [[ Mux.Cool ]] --
  977. o = s:option(Flag, "mux", translate("Mux"), translate("Enable Mux.Cool"))
  978. o.rmempty = false
  979. o.default = false
  980. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw"})
  981. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "ws"})
  982. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "kcp"})
  983. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "httpupgrade"})
  984. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "splithttp"})
  985. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "h2"})
  986. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "quic"})
  987. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "grpc"})
  988. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  989. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  990. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  991. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  992. o:depends({type = "v2ray", v2ray_protocol = "http"})
  993. -- [[ XUDP Mux ]] --
  994. o = s:option(Flag, "xmux", translate("Xudp Mux"), translate("Enable Xudp Mux"))
  995. o.rmempty = false
  996. o.default = false
  997. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp"})
  998. -- [[ TCP 最大并发连接数 ]]--
  999. o = s:option(Value, "concurrency", translate("concurrency"))
  1000. o.description = translate(
  1001. "<ul>"
  1002. .. "<li>" .. translate("Default: disable. When entering a negative number, such as -1, The Mux module will not be used to carry TCP traffic.") .. "</li>"
  1003. .. "<li>" .. translate("Min value is 1, Max value is 128. When omitted or set to 0, it equals 8.") .. "</li>"
  1004. .. "</ul>")
  1005. o.rmempty = true
  1006. o.default = "-1"
  1007. o:value("-1", translate("disable"))
  1008. o:value("8", translate("8"))
  1009. o:depends("mux", true)
  1010. -- [[ UDP 最大并发连接数 ]]--
  1011. o = s:option(Value, "xudpConcurrency", translate("xudpConcurrency"))
  1012. o.description = translate(
  1013. "<ul>"
  1014. .. "<li>" .. translate("Default:16. When entering a negative number, such as -1, The Mux module will not be used to carry UDP traffic, Use original UDP transmission method of proxy protocol.") .. "</li>"
  1015. .. "<li>" .. translate("Min value is 1, Max value is 1024. When omitted or set to 0, Will same path as TCP traffic.") .. "</li>"
  1016. .. "</ul>")
  1017. o.rmempty = true
  1018. o.default = "16"
  1019. o:value("-1", translate("disable"))
  1020. o:value("16", translate("16"))
  1021. o:depends("mux", true)
  1022. o:depends("xmux", true)
  1023. -- [[ 对被代理的 UDP/443 流量处理方式 ]]--
  1024. o = s:option(ListValue, "xudpProxyUDP443", translate("xudpProxyUDP443"))
  1025. o.description = translate(
  1026. "<ul>"
  1027. .. "<li>" .. translate("Default reject rejects traffic.") .. "</li>"
  1028. .. "<li>" .. translate("allow: Allows use Mux connection.") .. "</li>"
  1029. .. "<li>" .. translate("skip: Not use Mux module to carry UDP 443 traffic, Use original UDP transmission method of proxy protocol.") .. "</li>"
  1030. .. "</ul>")
  1031. o.rmempty = true
  1032. o.default = "reject"
  1033. o:value("reject", translate("reject"))
  1034. o:value("allow", translate("allow"))
  1035. o:value("skip", translate("skip"))
  1036. o:depends("mux", true)
  1037. -- [[ XHTTP TCP Fast Open ]]--
  1038. o = s:option(Flag, "tcpfastopen", translate("TCP Fast Open"), translate("Enabling TCP Fast Open Requires Server Support."))
  1039. o.rmempty = true
  1040. o.default = "0"
  1041. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp"})
  1042. -- [[ MPTCP ]]--
  1043. o = s:option(Flag, "mptcp", translate("MPTCP"), translate("Enable Multipath TCP, need to be enabled in both server and client configuration."))
  1044. o.rmempty = true
  1045. o.default = "0"
  1046. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  1047. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  1048. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  1049. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  1050. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  1051. o:depends({type = "v2ray", v2ray_protocol = "http"})
  1052. -- [[ custom_tcpcongestion 连接服务器节点的 TCP 拥塞控制算法 ]]--
  1053. o = s:option(ListValue, "custom_tcpcongestion", translate("custom_tcpcongestion"))
  1054. o.rmempty = true
  1055. o.default = ""
  1056. o:value("", translate("comment_tcpcongestion_disable"))
  1057. o:value("bbr", translate("BBR"))
  1058. o:value("cubic", translate("CUBIC"))
  1059. o:value("reno", translate("Reno"))
  1060. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  1061. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  1062. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  1063. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  1064. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  1065. o:depends({type = "v2ray", v2ray_protocol = "http"})
  1066. -- [[ Cert ]]--
  1067. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  1068. o.rmempty = true
  1069. o.default = "0"
  1070. o:depends("type", "tuic")
  1071. o:depends({type = "hysteria2", insecure = false})
  1072. o:depends({type = "trojan", tls = true, insecure = false})
  1073. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  1074. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  1075. o.description = translate("If you have a self-signed certificate,please check the box")
  1076. o = s:option(DummyValue, "upload", translate("Upload"))
  1077. o.template = "shadowsocksr/certupload"
  1078. o:depends("certificate", 1)
  1079. cert_dir = "/etc/ssl/private/"
  1080. local path
  1081. luci.http.setfilehandler(function(meta, chunk, eof)
  1082. if not fd then
  1083. if (not meta) or (not meta.name) or (not meta.file) then
  1084. return
  1085. end
  1086. fd = nixio.open(cert_dir .. meta.file, "w")
  1087. if not fd then
  1088. path = translate("Create upload file error.")
  1089. return
  1090. end
  1091. end
  1092. if chunk and fd then
  1093. fd:write(chunk)
  1094. end
  1095. if eof and fd then
  1096. fd:close()
  1097. fd = nil
  1098. path = '/etc/ssl/private/' .. meta.file .. ''
  1099. end
  1100. end)
  1101. if luci.http.formvalue("upload") then
  1102. local f = luci.http.formvalue("ulfile")
  1103. if #f <= 0 then
  1104. path = translate("No specify upload file.")
  1105. end
  1106. end
  1107. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  1108. o:depends("certificate", 1)
  1109. o:value("/etc/ssl/private/ca.crt")
  1110. o.description = translate("Please confirm the current certificate path")
  1111. o.default = "/etc/ssl/private/ca.crt"
  1112. o = s:option(Flag, "fast_open", translate("TCP Fast Open"), translate("Enabling TCP Fast Open Requires Server Support."))
  1113. o.rmempty = true
  1114. o.default = "0"
  1115. o:depends("type", "ssr")
  1116. o:depends("type", "ss")
  1117. o:depends("type", "trojan")
  1118. o:depends("type", "hysteria2")
  1119. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  1120. o.rmempty = false
  1121. o.default = "1"
  1122. o = s:option(Value, "local_port", translate("Local Port"))
  1123. o.datatype = "port"
  1124. o.default = 1234
  1125. o.rmempty = false
  1126. if is_finded("kcptun-client") then
  1127. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  1128. o.rmempty = true
  1129. o.default = "0"
  1130. o:depends("type", "ssr")
  1131. o:depends("type", "ss")
  1132. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  1133. o.datatype = "portrange"
  1134. o.default = 4000
  1135. o:depends("type", "ssr")
  1136. o:depends("type", "ss")
  1137. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  1138. o.password = true
  1139. o:depends("type", "ssr")
  1140. o:depends("type", "ss")
  1141. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  1142. o.default = "--nocomp"
  1143. o:depends("type", "ssr")
  1144. o:depends("type", "ss")
  1145. end
  1146. return m