client-config.lua 32 KB

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