client-config.lua 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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. o:value("custom", translate("Custom"))
  318. o.rmempty = true
  319. o:depends({enable_plugin = true})
  320. o = s:option(Value, "custom_plugin", translate("Custom Plugin Path"))
  321. o.placeholder = "/path/to/custom-plugin"
  322. o:depends({plugin = "custom"})
  323. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  324. o.rmempty = true
  325. o:depends({enable_plugin = true})
  326. o = s:option(ListValue, "protocol", translate("Protocol"))
  327. for _, v in ipairs(protocol) do
  328. o:value(v)
  329. end
  330. o.rmempty = true
  331. o:depends("type", "ssr")
  332. o = s:option(Value, "protocol_param", translate("Protocol param (optional)"))
  333. o:depends("type", "ssr")
  334. o = s:option(ListValue, "obfs", translate("Obfs"))
  335. for _, v in ipairs(obfs) do
  336. o:value(v)
  337. end
  338. o.rmempty = true
  339. o:depends("type", "ssr")
  340. o = s:option(Value, "obfs_param", translate("Obfs param (optional)"))
  341. o:depends("type", "ssr")
  342. -- [[ Hysteria2 ]]--
  343. o = s:option(Value, "hy2_auth", translate("Users Authentication"))
  344. o:depends("type", "hysteria2")
  345. o.rmempty = false
  346. o = s:option(Flag, "flag_port_hopping", translate("Enable Port Hopping"))
  347. o:depends("type", "hysteria2")
  348. o.rmempty = true
  349. o.default = "0"
  350. o = s:option(Value, "port_range", translate("Port Range"))
  351. o:depends({type = "hysteria2", flag_port_hopping = true})
  352. o.datatype = "portrange"
  353. o.rmempty = true
  354. o = s:option(Flag, "flag_transport", translate("Enable Transport Protocol Settings"))
  355. o:depends("type", "hysteria2")
  356. o.rmempty = true
  357. o.default = "0"
  358. o = s:option(ListValue, "transport_protocol", translate("Transport Protocol"))
  359. o:depends({type = "hysteria2", flag_transport = true})
  360. o:value("udp", translate("UDP"))
  361. o.default = "udp"
  362. o.rmempty = true
  363. o = s:option(Value, "hopinterval", translate("Port Hopping Interval(Unit:Second)"))
  364. o:depends({type = "hysteria2", flag_transport = true, flag_port_hopping = true})
  365. o.datatype = "uinteger"
  366. o.rmempty = true
  367. o.default = "30"
  368. o = s:option(Flag, "flag_obfs", translate("Enable Obfuscation"))
  369. o:depends("type", "hysteria2")
  370. o.rmempty = true
  371. o.default = "0"
  372. o = s:option(Flag, "lazy_mode", translate("Enable Lazy Mode"))
  373. o:depends("type", "hysteria2")
  374. o.rmempty = true
  375. o.default = "0"
  376. o = s:option(Value, "obfs_type", translate("Obfuscation Type"))
  377. o:depends({type = "hysteria2", flag_obfs = "1"})
  378. o.rmempty = true
  379. o.default = "salamander"
  380. o = s:option(Value, "salamander", translate("Obfuscation Password"))
  381. o:depends({type = "hysteria2", flag_obfs = "1"})
  382. o.rmempty = true
  383. o.default = "cry_me_a_r1ver"
  384. o = s:option(Flag, "flag_quicparam", translate("Hysterir QUIC parameters"))
  385. o:depends("type", "hysteria2")
  386. o.rmempty = true
  387. o.default = "0"
  388. o = s:option(Flag, "disablepathmtudiscovery", translate("Disable QUIC path MTU discovery"))
  389. o:depends({type = "hysteria2",flag_quicparam = "1"})
  390. o.rmempty = true
  391. o.default = false
  392. --[[Hysteria2 QUIC parameters setting]]
  393. o = s:option(Value, "initstreamreceivewindow", translate("QUIC initStreamReceiveWindow"))
  394. o:depends({type = "hysteria2", flag_quicparam = "1"})
  395. o.datatype = "uinteger"
  396. o.rmempty = true
  397. o.default = "8388608"
  398. o = s:option(Value, "maxstreamseceivewindow", translate("QUIC maxStreamReceiveWindow"))
  399. o:depends({type = "hysteria2", flag_quicparam = "1"})
  400. o.datatype = "uinteger"
  401. o.rmempty = true
  402. o.default = "8388608"
  403. o = s:option(Value, "initconnreceivewindow", translate("QUIC initConnReceiveWindow"))
  404. o:depends({type = "hysteria2", flag_quicparam = "1"})
  405. o.datatype = "uinteger"
  406. o.rmempty = true
  407. o.default = "20971520"
  408. o = s:option(Value, "maxconnreceivewindow", translate("QUIC maxConnReceiveWindow"))
  409. o:depends({type = "hysteria2", flag_quicparam = "1"})
  410. o.datatype = "uinteger"
  411. o.rmempty = true
  412. o.default = "20971520"
  413. o = s:option(Value, "maxidletimeout", translate("QUIC maxIdleTimeout(Unit:second)"))
  414. o:depends({type = "hysteria2", flag_quicparam = "1"})
  415. o.rmempty = true
  416. o.datatype = "uinteger"
  417. o.default = "30"
  418. o = s:option(Value, "keepaliveperiod", translate("The keep-alive period.(Unit:second)"))
  419. o.description = translate("Default value 0 indicatesno heartbeat.")
  420. o:depends({type = "hysteria2", flag_quicparam = "1"})
  421. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  422. o.rmempty = true
  423. o.datatype = "uinteger"
  424. o.default = "10"
  425. --[[ Shadow-TLS Options ]]
  426. o = s:option(ListValue, "shadowtls_protocol", translate("shadowTLS protocol Version"))
  427. o:depends("type", "shadowtls")
  428. o:value("v3", translate("Enable V3 protocol."))
  429. o:value("v2", translate("Enable V2 protocol."))
  430. o.default = "v3"
  431. o.rmempty = true
  432. o = s:option(Flag, "strict", translate("TLS 1.3 Strict mode"))
  433. o:depends("type", "shadowtls")
  434. o.default = "1"
  435. o.rmempty = false
  436. o = s:option(Flag, "fastopen", translate("TCP Fast Open"), translate("Enabling TCP Fast Open Requires Server Support."))
  437. o:depends("type", "shadowtls")
  438. o.default = "0"
  439. o.rmempty = false
  440. o = s:option(Flag, "disable_nodelay", translate("Disable TCP No_delay"))
  441. o:depends("type", "shadowtls")
  442. o.default = "0"
  443. o.rmempty = true
  444. o = s:option(Value, "shadowtls_sni", translate("shadow-TLS SNI"))
  445. o:depends("type", "shadowtls")
  446. o.datatype = "host"
  447. o.rmempty = true
  448. o.default = ""
  449. --[[ add a ListValue for Choose chain type,sslocal or vmess ]]
  450. o = s:option(ListValue, "chain_type", translate("Shadow-TLS ChainPoxy type"))
  451. o:depends("type", "shadowtls")
  452. if is_finded("sslocal") then
  453. o:value("sslocal", translate("Shadowsocks-rust Version"))
  454. end
  455. if is_finded("xray") or is_finded("v2ray") then
  456. o:value("vmess", translate("Vmess Protocol"))
  457. end
  458. o.default = "sslocal"
  459. o.rmempty = false
  460. o = s:option(Value, "sslocal_password",translate("Shadowsocks password"))
  461. o:depends({type = "shadowtls", chain_type = "sslocal"})
  462. o.rmempty = true
  463. o = s:option(ListValue, "sslocal_method", translate("Encrypt Method"))
  464. o:depends({type = "shadowtls", chain_type = "sslocal"})
  465. for _, v in ipairs(encrypt_methods_ss) do
  466. o:value(v)
  467. end
  468. o = s:option(Value, "vmess_uuid", translate("Vmess UUID"))
  469. o:depends({type = "shadowtls", chain_type = "vmess"})
  470. o.rmempty = false
  471. o.default = uuid
  472. o = s:option(ListValue, "vmess_method", translate("Encrypt Method"))
  473. o:depends({type = "shadowtls", chain_type = "vmess"})
  474. for _, v in ipairs(securitys) do
  475. o:value(v, v:lower())
  476. end
  477. o.rmempty = true
  478. o.default="auto"
  479. -- [[ TUIC ]]
  480. -- TuicNameId
  481. o = s:option(Value, "tuic_uuid", translate("TUIC User UUID"))
  482. o.rmempty = true
  483. o.default = uuid
  484. o:depends("type", "tuic")
  485. --Tuic IP
  486. o = s:option(Value, "tuic_ip", translate("TUIC Server IP Address"))
  487. o.rmempty = true
  488. o.datatype = "ip4addr"
  489. o.default = ""
  490. o:depends("type", "tuic")
  491. -- Tuic Password
  492. o = s:option(Value, "tuic_passwd", translate("TUIC User Password"))
  493. o.rmempty = true
  494. o.default = ""
  495. o:depends("type", "tuic")
  496. o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
  497. o:depends("type", "tuic")
  498. o:value("native", translate("native UDP characteristics"))
  499. o:value("quic", translate("lossless UDP relay using QUIC streams"))
  500. o.default = "native"
  501. o.rmempty = true
  502. o = s:option(ListValue, "congestion_control", translate("Congestion control algorithm"))
  503. o:depends("type", "tuic")
  504. o:value("bbr", translate("BBR"))
  505. o:value("cubic", translate("CUBIC"))
  506. o:value("new_reno", translate("New Reno"))
  507. o.default = "cubic"
  508. o.rmempty = true
  509. o = s:option(Value, "heartbeat", translate("Heartbeat interval(second)"))
  510. o:depends("type", "tuic")
  511. o.datatype = "uinteger"
  512. o.default = "3"
  513. o.rmempty = true
  514. o = s:option(Value, "timeout", translate("Timeout for establishing a connection to server(second)"))
  515. o:depends("type", "tuic")
  516. o.datatype = "uinteger"
  517. o.default = "8"
  518. o.rmempty = true
  519. o = s:option(Value, "gc_interval", translate("Garbage collection interval(second)"))
  520. o:depends("type", "tuic")
  521. o.datatype = "uinteger"
  522. o.default = "3"
  523. o.rmempty = true
  524. o = s:option(Value, "gc_lifetime", translate("Garbage collection lifetime(second)"))
  525. o:depends("type", "tuic")
  526. o.datatype = "uinteger"
  527. o.default = "15"
  528. o.rmempty = true
  529. o = s:option(Value, "send_window", translate("TUIC send window"))
  530. o:depends("type", "tuic")
  531. o.datatype = "uinteger"
  532. o.default = 20971520
  533. o.rmempty = true
  534. o = s:option(Value, "receive_window", translate("TUIC receive window"))
  535. o:depends("type", "tuic")
  536. o.datatype = "uinteger"
  537. o.default = 10485760
  538. o.rmempty = true
  539. o = s:option(Flag, "disable_sni", translate("Disable SNI"))
  540. o:depends("type", "tuic")
  541. o.default = "0"
  542. o.rmempty = true
  543. o = s:option(Flag, "zero_rtt_handshake", translate("Enable 0-RTT QUIC handshake"))
  544. o:depends("type", "tuic")
  545. o.default = "0"
  546. o.rmempty = true
  547. -- Tuic settings for the local inbound socks5 server
  548. o = s:option(Flag, "tuic_dual_stack", translate("Dual-stack Listening Socket"))
  549. o.description = translate("If this option is not set, the socket behavior is platform dependent.")
  550. o:depends("type", "tuic")
  551. o.default = "0"
  552. o.rmempty = true
  553. o = s:option(Value, "tuic_max_package_size", translate("Maximum packet size the socks5 server can receive from external"))
  554. o:depends("type", "tuic")
  555. o.datatype = "uinteger"
  556. o.default = 1500
  557. o.rmempty = true
  558. -- AlterId
  559. o = s:option(Value, "alter_id", translate("AlterId"))
  560. o.datatype = "port"
  561. o.default = 16
  562. o.rmempty = true
  563. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  564. -- VmessId
  565. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  566. o.rmempty = true
  567. o.default = uuid
  568. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  569. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  570. -- VLESS Encryption
  571. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  572. o.rmempty = true
  573. o.default = "none"
  574. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  575. -- 加密方式
  576. o = s:option(ListValue, "security", translate("Encrypt Method"))
  577. for _, v in ipairs(securitys) do
  578. o:value(v, v:upper())
  579. end
  580. o.rmempty = true
  581. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  582. -- SOCKS Version
  583. o = s:option(ListValue, "socks_ver", translate("Socks Version"))
  584. o:value("4", "Socks4")
  585. o:value("4a", "Socks4A")
  586. o:value("5", "Socks5")
  587. o.rmempty = true
  588. o.default = "5"
  589. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  590. -- 传输协议
  591. o = s:option(ListValue, "transport", translate("Transport"))
  592. o:value("raw", "RAW (TCP)")
  593. o:value("kcp", "mKCP")
  594. o:value("ws", "WebSocket")
  595. o:value("httpupgrade", "HTTPUpgrade")
  596. o:value("splithttp", "SplitHTTP")
  597. o:value("xhttp", "XHTTP")
  598. o:value("h2", "HTTP/2")
  599. o:value("quic", "QUIC")
  600. o:value("grpc", "gRPC")
  601. o.rmempty = true
  602. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  603. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  604. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  605. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  606. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  607. o:depends({type = "v2ray", v2ray_protocol = "http"})
  608. -- [[ RAW部分 ]]--
  609. -- TCP伪装
  610. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  611. o:depends("transport", "raw")
  612. o:value("none", translate("None"))
  613. o:value("http", "HTTP")
  614. o.rmempty = true
  615. -- HTTP域名
  616. o = s:option(Value, "http_host", translate("HTTP Host"))
  617. o:depends("tcp_guise", "http")
  618. o.rmempty = true
  619. -- HTTP路径
  620. o = s:option(Value, "http_path", translate("HTTP Path"))
  621. o:depends("tcp_guise", "http")
  622. o.rmempty = true
  623. -- [[ WS部分 ]]--
  624. -- WS域名
  625. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  626. o:depends({transport = "ws", tls = false})
  627. o.datatype = "hostname"
  628. o.rmempty = true
  629. -- WS路径
  630. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  631. o:depends("transport", "ws")
  632. o.rmempty = true
  633. if is_finded("v2ray") then
  634. -- WS前置数据
  635. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  636. o:depends("ws_ed_enable", true)
  637. o.datatype = "uinteger"
  638. o:value("2048")
  639. o.rmempty = true
  640. -- WS前置数据标头
  641. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  642. o:depends("ws_ed_enable", true)
  643. o:value("Sec-WebSocket-Protocol")
  644. o.rmempty = true
  645. end
  646. -- [[ httpupgrade部分 ]]--
  647. -- httpupgrade域名
  648. o = s:option(Value, "httpupgrade_host", translate("Httpupgrade Host"))
  649. o:depends({transport = "httpupgrade", tls = false})
  650. o.rmempty = true
  651. -- httpupgrade路径
  652. o = s:option(Value, "httpupgrade_path", translate("Httpupgrade Path"))
  653. o:depends("transport", "httpupgrade")
  654. o.rmempty = true
  655. -- [[ splithttp部分 ]]--
  656. -- splithttp域名
  657. o = s:option(Value, "splithttp_host", translate("Splithttp Host"))
  658. o:depends({transport = "splithttp", tls = false})
  659. o.rmempty = true
  660. -- splithttp路径
  661. o = s:option(Value, "splithttp_path", translate("Splithttp Path"))
  662. o:depends("transport", "splithttp")
  663. o.rmempty = true
  664. -- [[ XHTTP部分 ]]--
  665. o = s:option(ListValue, "xhttp_alpn", translate("XHTTP Alpn"))
  666. o.default = ""
  667. o:value("", translate("Default"))
  668. o:value("h3")
  669. o:value("h2")
  670. o:value("h3,h2")
  671. o:value("http/1.1")
  672. o:value("h2,http/1.1")
  673. o:value("h3,h2,http/1.1")
  674. o:depends("transport", "xhttp")
  675. o = s:option(ListValue, "xhttp_mode", translate("XHTTP Mode"))
  676. o:depends("transport", "xhttp")
  677. o.default = "auto"
  678. o:value("auto")
  679. o:value("packet-up")
  680. o:value("stream-up")
  681. o:value("stream-one")
  682. o = s:option(Value, "xhttp_host", translate("XHTTP Host"))
  683. o:depends({transport = "xhttp", tls = false})
  684. o.rmempty = true
  685. o = s:option(Value, "xhttp_path", translate("XHTTP Path"))
  686. o.placeholder = "/"
  687. o:depends("transport", "xhttp")
  688. o.rmempty = true
  689. o = s:option(Flag, "enable_xhttp_extra", translate("XHTTP Extra"))
  690. o.description = translate("Enable this option to configure XHTTP Extra (JSON format).")
  691. o.rmempty = true
  692. o.default = "0"
  693. o:depends("transport", "xhttp")
  694. o = s:option(TextValue, "xhttp_extra", " ")
  695. o.description = translate(
  696. "<font><b>" .. translate("Configure XHTTP Extra Settings (JSON format), see:") .. "</b></font>" ..
  697. " <a href='https://xtls.github.io/config/transports/splithttp.html#extra' target='_blank'>" ..
  698. "<font style='color:green'><b>" .. translate("Click to the page") .. "</b></font></a>")
  699. o:depends("enable_xhttp_extra", true)
  700. o.rmempty = true
  701. o.rows = 10
  702. o.wrap = "off"
  703. o.custom_write = function(self, section, value)
  704. m:set(section, "xhttp_extra", value)
  705. local success, data = pcall(luci.jsonc.parse, value)
  706. if success and data then
  707. local address = (data.extra and data.extra.downloadSettings and data.extra.downloadSettings.address)
  708. or (data.downloadSettings and data.downloadSettings.address)
  709. if address and address ~= "" then
  710. m:set(section, "download_address", address)
  711. else
  712. m:del(section, "download_address")
  713. end
  714. else
  715. m:del(section, "download_address")
  716. end
  717. end
  718. o.validate = function(self, value)
  719. value = value:gsub("\r\n", "\n"):gsub("^[ \t]*\n", ""):gsub("\n[ \t]*$", ""):gsub("\n[ \t]*\n", "\n")
  720. if value:sub(-1) == "\n" then
  721. value = value:sub(1, -2)
  722. end
  723. local success, data = pcall(luci.jsonc.parse, value)
  724. if not success or not data then
  725. return nil, translate("Invalid JSON format")
  726. end
  727. return value
  728. end
  729. -- [[ H2部分 ]]--
  730. -- H2域名
  731. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  732. o:depends("transport", "h2")
  733. o.rmempty = true
  734. -- H2路径
  735. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  736. o:depends("transport", "h2")
  737. o.rmempty = true
  738. -- gRPC
  739. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  740. o:depends("transport", "grpc")
  741. o.rmempty = true
  742. if is_finded("xray") then
  743. -- gPRC模式
  744. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  745. o:depends("transport", "grpc")
  746. o:value("gun", translate("Gun"))
  747. o:value("multi", translate("Multi"))
  748. o.rmempty = true
  749. end
  750. if is_finded("xray") then
  751. -- gRPC初始窗口
  752. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  753. o.datatype = "uinteger"
  754. o:depends("transport", "grpc")
  755. o.default = 0
  756. o.rmempty = true
  757. -- H2/gRPC健康检查
  758. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  759. o:depends("transport", "h2")
  760. o:depends("transport", "grpc")
  761. o.rmempty = true
  762. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  763. o.datatype = "uinteger"
  764. o:depends({health_check = true, transport = "h2"})
  765. o.default = 60
  766. o.rmempty = true
  767. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  768. o.datatype = "uinteger"
  769. o:depends({health_check = true, transport = "grpc"})
  770. o.default = 60
  771. o.rmempty = true
  772. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  773. o.datatype = "uinteger"
  774. o:depends("health_check", 1)
  775. o.default = 20
  776. o.rmempty = true
  777. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  778. o:depends({health_check = true, transport = "grpc"})
  779. o.rmempty = true
  780. end
  781. -- [[ QUIC部分 ]]--
  782. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  783. o:depends("transport", "quic")
  784. o:value("none", translate("None"))
  785. o:value("aes-128-gcm", translate("aes-128-gcm"))
  786. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  787. o.rmempty = true
  788. o = s:option(Value, "quic_key", translate("QUIC Key"))
  789. o:depends("transport", "quic")
  790. o.rmempty = true
  791. o = s:option(ListValue, "quic_guise", translate("Header"))
  792. o:depends("transport", "quic")
  793. o.rmempty = true
  794. o:value("none", translate("None"))
  795. o:value("srtp", translate("VideoCall (SRTP)"))
  796. o:value("utp", translate("BitTorrent (uTP)"))
  797. o:value("wechat-video", translate("WechatVideo"))
  798. o:value("dtls", translate("DTLS 1.2"))
  799. o:value("wireguard", translate("WireGuard"))
  800. -- [[ mKCP部分 ]]--
  801. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  802. o:depends("transport", "kcp")
  803. o:value("none", translate("None"))
  804. o:value("srtp", translate("VideoCall (SRTP)"))
  805. o:value("utp", translate("BitTorrent (uTP)"))
  806. o:value("wechat-video", translate("WechatVideo"))
  807. o:value("dtls", translate("DTLS 1.2"))
  808. o:value("wireguard", translate("WireGuard"))
  809. o.rmempty = true
  810. o = s:option(Value, "mtu", translate("MTU"))
  811. o.datatype = "uinteger"
  812. o:depends("transport", "kcp")
  813. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  814. -- o.default = 1350
  815. o.rmempty = true
  816. o = s:option(Value, "tti", translate("TTI"))
  817. o.datatype = "uinteger"
  818. o:depends("transport", "kcp")
  819. o.default = 50
  820. o.rmempty = true
  821. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity(Default:Mbps)"))
  822. o.datatype = "uinteger"
  823. o:depends("transport", "kcp")
  824. o:depends("type", "hysteria2")
  825. o.default = 5
  826. o.rmempty = true
  827. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity(Default:Mbps)"))
  828. o.datatype = "uinteger"
  829. o:depends("transport", "kcp")
  830. o:depends("type", "hysteria2")
  831. o.default = 20
  832. o.rmempty = true
  833. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  834. o.datatype = "uinteger"
  835. o:depends("transport", "kcp")
  836. o.default = 2
  837. o.rmempty = true
  838. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  839. o.datatype = "uinteger"
  840. o:depends("transport", "kcp")
  841. o.default = 2
  842. o.rmempty = true
  843. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  844. o:depends("transport", "kcp")
  845. o.rmempty = true
  846. o = s:option(Flag, "congestion", translate("Congestion"))
  847. o:depends("transport", "kcp")
  848. o.rmempty = true
  849. -- [[ WireGuard 部分 ]]--
  850. o = s:option(Flag, "kernelmode", translate("Enabled Kernel virtual NIC TUN(optional)"))
  851. 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.")
  852. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  853. o.default = "0"
  854. o.rmempty = true
  855. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  856. o.datatype = "cidr"
  857. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  858. o.rmempty = true
  859. o = s:option(DynamicList, "reserved", translate("Reserved bytes(optional)"))
  860. o.description = translate("Wireguard reserved bytes.")
  861. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  862. o.rmempty = true
  863. o = s:option(Value, "private_key", translate("Private key"))
  864. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  865. o.password = true
  866. o.rmempty = true
  867. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  868. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  869. o.rmempty = true
  870. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  871. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  872. o.password = true
  873. o.rmempty = true
  874. o = s:option(DynamicList, "allowedips", translate("allowedIPs(optional)"))
  875. o.description = translate("Wireguard allows only traffic from specific source IP.")
  876. o.datatype = "cidr"
  877. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  878. o.default = "0.0.0.0/0"
  879. o.rmempty = true
  880. -- [[ TLS ]]--
  881. o = s:option(Flag, "tls", translate("TLS"))
  882. o.rmempty = true
  883. o.default = "0"
  884. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = false})
  885. o:depends({type = "v2ray", v2ray_protocol = "vmess", reality = false})
  886. o:depends({type = "v2ray", v2ray_protocol = "trojan", reality = false})
  887. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", reality = false})
  888. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", reality = false})
  889. o:depends({type = "v2ray", v2ray_protocol = "http", reality = false})
  890. o:depends("type", "trojan")
  891. o:depends("type", "hysteria2")
  892. -- [[ TLS部分 ]] --
  893. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  894. o:depends({type = "trojan", tls = true})
  895. o.default = "0"
  896. if is_finded("xray") then
  897. -- [[ REALITY ]]
  898. o = s:option(Flag, "reality", translate("REALITY"))
  899. o.rmempty = true
  900. o.default = "0"
  901. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = false})
  902. o = s:option(Value, "reality_publickey", translate("Public key"))
  903. o.rmempty = true
  904. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  905. o = s:option(Value, "reality_shortid", translate("Short ID"))
  906. o.rmempty = true
  907. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  908. o = s:option(Value, "reality_spiderx", translate("spiderX"))
  909. o.rmempty = true
  910. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  911. -- [[ XTLS ]]--
  912. o = s:option(ListValue, "tls_flow", translate("Flow"))
  913. for _, v in ipairs(tls_flows) do
  914. if v == "none" then
  915. o.default = "none"
  916. o:value("none", translate("none"))
  917. else
  918. o:value(v, translate(v))
  919. end
  920. end
  921. o.rmempty = true
  922. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", tls = true})
  923. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", reality = true})
  924. o = s:option(ListValue, "xhttp_tls_flow", translate("Flow"))
  925. for _, v in ipairs(tls_flows) do
  926. if v == "none" then
  927. o.default = "none"
  928. o:value("none", translate("none"))
  929. else
  930. o:value("xtls-rprx-vision", translate("xtls-rprx-vision"))
  931. end
  932. end
  933. o.rmempty = true
  934. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp", tls = true})
  935. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp", reality = true})
  936. -- [[ uTLS ]]--
  937. o = s:option(ListValue, "fingerprint", translate("Finger Print"))
  938. o.default = ""
  939. o:value("chrome", translate("chrome"))
  940. o:value("firefox", translate("firefox"))
  941. o:value("safari", translate("safari"))
  942. o:value("ios", translate("ios"))
  943. o:value("android", translate("android"))
  944. o:value("edge", translate("edge"))
  945. o:value("360", translate("360"))
  946. o:value("qq", translate("qq"))
  947. o:value("random", translate("random"))
  948. o:value("randomized", translate("randomized"))
  949. o:value("", translate("disable"))
  950. o:depends({type = "v2ray", tls = true})
  951. o:depends({type = "v2ray", reality = true})
  952. end
  953. o = s:option(Value, "tls_host", translate("TLS Host"))
  954. o.datatype = "hostname"
  955. o:depends("tls", true)
  956. o:depends("xtls", true)
  957. o:depends("reality", true)
  958. o.rmempty = true
  959. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  960. o:depends("type", "tuic")
  961. o.default = "h3"
  962. o.rmempty = true
  963. -- [[ allowInsecure ]]--
  964. o = s:option(Flag, "insecure", translate("allowInsecure"))
  965. o.rmempty = false
  966. o:depends("tls", true)
  967. o:depends("type", "hysteria2")
  968. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  969. -- [[ Hysteria2 TLS pinSHA256 ]] --
  970. o = s:option(Value, "pinsha256", translate("Certificate fingerprint"))
  971. o:depends({type = "hysteria2", insecure = true })
  972. o.rmempty = true
  973. -- [[ Mux.Cool ]] --
  974. o = s:option(Flag, "mux", translate("Mux"), translate("Enable Mux.Cool"))
  975. o.rmempty = false
  976. o.default = false
  977. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw"})
  978. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "ws"})
  979. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "kcp"})
  980. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "httpupgrade"})
  981. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "splithttp"})
  982. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "h2"})
  983. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "quic"})
  984. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "grpc"})
  985. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  986. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  987. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  988. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  989. o:depends({type = "v2ray", v2ray_protocol = "http"})
  990. -- [[ XUDP Mux ]] --
  991. o = s:option(Flag, "xmux", translate("Xudp Mux"), translate("Enable Xudp Mux"))
  992. o.rmempty = false
  993. o.default = false
  994. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp"})
  995. -- [[ TCP 最大并发连接数 ]]--
  996. o = s:option(Value, "concurrency", translate("concurrency"))
  997. o.description = translate(
  998. "<ul>"
  999. .. "<li>" .. translate("Default: disable. When entering a negative number, such as -1, The Mux module will not be used to carry TCP traffic.") .. "</li>"
  1000. .. "<li>" .. translate("Min value is 1, Max value is 128. When omitted or set to 0, it equals 8.") .. "</li>"
  1001. .. "</ul>")
  1002. o.rmempty = true
  1003. o.default = "-1"
  1004. o:value("-1", translate("disable"))
  1005. o:value("8", translate("8"))
  1006. o:depends("mux", true)
  1007. -- [[ UDP 最大并发连接数 ]]--
  1008. o = s:option(Value, "xudpConcurrency", translate("xudpConcurrency"))
  1009. o.description = translate(
  1010. "<ul>"
  1011. .. "<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>"
  1012. .. "<li>" .. translate("Min value is 1, Max value is 1024. When omitted or set to 0, Will same path as TCP traffic.") .. "</li>"
  1013. .. "</ul>")
  1014. o.rmempty = true
  1015. o.default = "16"
  1016. o:value("-1", translate("disable"))
  1017. o:value("16", translate("16"))
  1018. o:depends("mux", true)
  1019. o:depends("xmux", true)
  1020. -- [[ 对被代理的 UDP/443 流量处理方式 ]]--
  1021. o = s:option(ListValue, "xudpProxyUDP443", translate("xudpProxyUDP443"))
  1022. o.description = translate(
  1023. "<ul>"
  1024. .. "<li>" .. translate("Default reject rejects traffic.") .. "</li>"
  1025. .. "<li>" .. translate("allow: Allows use Mux connection.") .. "</li>"
  1026. .. "<li>" .. translate("skip: Not use Mux module to carry UDP 443 traffic, Use original UDP transmission method of proxy protocol.") .. "</li>"
  1027. .. "</ul>")
  1028. o.rmempty = true
  1029. o.default = "reject"
  1030. o:value("reject", translate("reject"))
  1031. o:value("allow", translate("allow"))
  1032. o:value("skip", translate("skip"))
  1033. o:depends("mux", true)
  1034. -- [[ XHTTP TCP Fast Open ]]--
  1035. o = s:option(Flag, "tcpfastopen", translate("TCP Fast Open"), translate("Enabling TCP Fast Open Requires Server Support."))
  1036. o.rmempty = true
  1037. o.default = "0"
  1038. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "xhttp"})
  1039. -- [[ MPTCP ]]--
  1040. o = s:option(Flag, "mptcp", translate("MPTCP"), translate("Enable Multipath TCP, need to be enabled in both server and client configuration."))
  1041. o.rmempty = true
  1042. o.default = "0"
  1043. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  1044. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  1045. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  1046. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  1047. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  1048. o:depends({type = "v2ray", v2ray_protocol = "http"})
  1049. -- [[ custom_tcpcongestion 连接服务器节点的 TCP 拥塞控制算法 ]]--
  1050. o = s:option(ListValue, "custom_tcpcongestion", translate("custom_tcpcongestion"))
  1051. o.rmempty = true
  1052. o.default = ""
  1053. o:value("", translate("comment_tcpcongestion_disable"))
  1054. o:value("bbr", translate("BBR"))
  1055. o:value("cubic", translate("CUBIC"))
  1056. o:value("reno", translate("Reno"))
  1057. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  1058. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  1059. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  1060. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  1061. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  1062. o:depends({type = "v2ray", v2ray_protocol = "http"})
  1063. -- [[ Cert ]]--
  1064. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  1065. o.rmempty = true
  1066. o.default = "0"
  1067. o:depends("type", "tuic")
  1068. o:depends({type = "hysteria2", insecure = false})
  1069. o:depends({type = "trojan", tls = true, insecure = false})
  1070. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  1071. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  1072. o.description = translate("If you have a self-signed certificate,please check the box")
  1073. o = s:option(DummyValue, "upload", translate("Upload"))
  1074. o.template = "shadowsocksr/certupload"
  1075. o:depends("certificate", 1)
  1076. cert_dir = "/etc/ssl/private/"
  1077. local path
  1078. luci.http.setfilehandler(function(meta, chunk, eof)
  1079. if not fd then
  1080. if (not meta) or (not meta.name) or (not meta.file) then
  1081. return
  1082. end
  1083. fd = nixio.open(cert_dir .. meta.file, "w")
  1084. if not fd then
  1085. path = translate("Create upload file error.")
  1086. return
  1087. end
  1088. end
  1089. if chunk and fd then
  1090. fd:write(chunk)
  1091. end
  1092. if eof and fd then
  1093. fd:close()
  1094. fd = nil
  1095. path = '/etc/ssl/private/' .. meta.file .. ''
  1096. end
  1097. end)
  1098. if luci.http.formvalue("upload") then
  1099. local f = luci.http.formvalue("ulfile")
  1100. if #f <= 0 then
  1101. path = translate("No specify upload file.")
  1102. end
  1103. end
  1104. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  1105. o:depends("certificate", 1)
  1106. o:value("/etc/ssl/private/ca.crt")
  1107. o.description = translate("Please confirm the current certificate path")
  1108. o.default = "/etc/ssl/private/ca.crt"
  1109. o = s:option(Flag, "fast_open", translate("TCP Fast Open"), translate("Enabling TCP Fast Open Requires Server Support."))
  1110. o.rmempty = true
  1111. o.default = "0"
  1112. o:depends("type", "ssr")
  1113. o:depends("type", "ss")
  1114. o:depends("type", "trojan")
  1115. o:depends("type", "hysteria2")
  1116. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  1117. o.rmempty = false
  1118. o.default = "1"
  1119. o = s:option(Value, "local_port", translate("Local Port"))
  1120. o.datatype = "port"
  1121. o.default = 1234
  1122. o.rmempty = false
  1123. if is_finded("kcptun-client") then
  1124. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  1125. o.rmempty = true
  1126. o.default = "0"
  1127. o:depends("type", "ssr")
  1128. o:depends("type", "ss")
  1129. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  1130. o.datatype = "portrange"
  1131. o.default = 4000
  1132. o:depends("type", "ssr")
  1133. o:depends("type", "ss")
  1134. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  1135. o.password = true
  1136. o:depends("type", "ssr")
  1137. o:depends("type", "ss")
  1138. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  1139. o.default = "--nocomp"
  1140. o:depends("type", "ssr")
  1141. o:depends("type", "ss")
  1142. end
  1143. return m