client-config.lua 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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. }
  112. m = Map("shadowsocksr", translate("Edit ShadowSocksR Server"))
  113. m.redirect = luci.dispatcher.build_url("admin/services/shadowsocksr/servers")
  114. if m.uci:get("shadowsocksr", sid) ~= "servers" then
  115. luci.http.redirect(m.redirect)
  116. return
  117. end
  118. -- [[ Servers Setting ]]--
  119. s = m:section(NamedSection, sid, "servers")
  120. s.anonymous = true
  121. s.addremove = false
  122. o = s:option(DummyValue, "ssr_url", "SS/SSR/V2RAY/TROJAN URL")
  123. o.rawhtml = true
  124. o.template = "shadowsocksr/ssrurl"
  125. o.value = sid
  126. o = s:option(ListValue, "type", translate("Server Node Type"))
  127. if is_finded("xray") or is_finded("v2ray") then
  128. o:value("v2ray", translate("V2Ray/XRay"))
  129. end
  130. if is_finded("ssr-redir") then
  131. o:value("ssr", translate("ShadowsocksR"))
  132. end
  133. if is_finded("ss-local") or is_finded("ss-redir") then
  134. o:value("ss", translate("Shadowsocks-libev New Version"))
  135. end
  136. if is_finded("sslocal") or is_finded("ssmanager") then
  137. o:value("ss_rust", translate("Shadowsocks-rust Version"))
  138. end
  139. if is_finded("trojan") then
  140. o:value("trojan", translate("Trojan"))
  141. end
  142. if is_finded("naive") then
  143. o:value("naiveproxy", translate("NaiveProxy"))
  144. end
  145. if is_finded("hysteria") then
  146. o:value("hysteria", translate("Hysteria"))
  147. end
  148. if is_finded("tuic-client") then
  149. o:value("tuic", translate("TUIC"))
  150. end
  151. if is_finded("shadow-tls") and is_finded("sslocal") then
  152. o:value("shadowtls", translate("Shadow-TLS"))
  153. end
  154. if is_finded("ipt2socks") then
  155. o:value("socks5", translate("Socks5"))
  156. end
  157. if is_finded("redsocks2") then
  158. o:value("tun", translate("Network Tunnel"))
  159. end
  160. o.description = translate("Using incorrect encryption mothod may causes service fail to start")
  161. o = s:option(Value, "alias", translate("Alias(optional)"))
  162. o = s:option(ListValue, "iface", translate("Network interface to use"))
  163. for _, e in ipairs(luci.sys.net.devices()) do
  164. if e ~= "lo" then
  165. o:value(e)
  166. end
  167. end
  168. o:depends("type", "tun")
  169. o.description = translate("Redirect traffic to this network interface")
  170. o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol"))
  171. o:value("vless", translate("VLESS"))
  172. o:value("vmess", translate("VMess"))
  173. o:value("trojan", translate("Trojan"))
  174. o:value("shadowsocks", translate("Shadowsocks"))
  175. if is_finded("xray") then
  176. o:value("wireguard", translate("WireGuard"))
  177. end
  178. o:value("socks", translate("Socks"))
  179. o:value("http", translate("HTTP"))
  180. o:depends("type", "v2ray")
  181. o = s:option(Value, "server", translate("Server Address"))
  182. o.datatype = "host"
  183. o.rmempty = false
  184. o:depends("type", "ssr")
  185. o:depends("type", "ss")
  186. o:depends("type", "ss_rust")
  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", "ss_rust")
  200. o:depends("type", "v2ray")
  201. o:depends("type", "trojan")
  202. o:depends("type", "naiveproxy")
  203. o:depends({type = "hysteria",port_hopping = "0"})
  204. o:depends("type", "tuic")
  205. o:depends("type", "shadowtls")
  206. o:depends("type", "socks5")
  207. o = s:option(Flag, "auth_enable", translate("Enable Authentication"))
  208. o.rmempty = false
  209. o.default = "0"
  210. o:depends("type", "socks5")
  211. o:depends({type = "v2ray", v2ray_protocol = "http"})
  212. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  213. o = s:option(Value, "username", translate("Username"))
  214. o.rmempty = true
  215. o:depends("type", "naiveproxy")
  216. o:depends({type = "socks5", auth_enable = true})
  217. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  218. o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
  219. o = s:option(Value, "password", translate("Password"))
  220. o.password = true
  221. o.rmempty = true
  222. o:depends("type", "ssr")
  223. o:depends("type", "ss")
  224. o:depends("type", "ss_rust")
  225. o:depends("type", "trojan")
  226. o:depends("type", "naiveproxy")
  227. o:depends("type", "shadowtls")
  228. o:depends({type = "socks5", auth_enable = true})
  229. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  230. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", auth_enable = true})
  231. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  232. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  233. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  234. for _, v in ipairs(encrypt_methods) do
  235. o:value(v)
  236. end
  237. o.rmempty = true
  238. o:depends("type", "ssr")
  239. o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
  240. for _, v in ipairs(encrypt_methods_ss) do
  241. o:value(v)
  242. end
  243. o.rmempty = true
  244. o:depends("type", "ss")
  245. o:depends("type", "ss_rust")
  246. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  247. o = s:option(Flag, "uot", translate("UDP over TCP"))
  248. o.description = translate("Enable the SUoT protocol, requires server support.")
  249. o.rmempty = true
  250. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  251. o.default = "0"
  252. o = s:option(Flag, "ivCheck", translate("Bloom Filter"))
  253. o.rmempty = true
  254. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  255. o.default = "1"
  256. -- Shadowsocks Plugin
  257. o = s:option(Value, "plugin", translate("Obfs"))
  258. o:value("none", translate("None"))
  259. if is_finded("obfs-local") then
  260. o:value("obfs-local", translate("obfs-local"))
  261. end
  262. if is_finded("v2ray-plugin") then
  263. o:value("v2ray-plugin", translate("v2ray-plugin"))
  264. end
  265. if is_finded("xray-plugin") then
  266. o:value("xray-plugin", translate("xray-plugin"))
  267. end
  268. o.rmempty = true
  269. o:depends("type", "ss")
  270. o:depends("type", "ss_rust")
  271. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  272. o.rmempty = true
  273. o:depends("type", "ss")
  274. o:depends("type", "ss_rust")
  275. o = s:option(ListValue, "protocol", translate("Protocol"))
  276. for _, v in ipairs(protocol) do
  277. o:value(v)
  278. end
  279. o.rmempty = true
  280. o:depends("type", "ssr")
  281. o = s:option(Value, "protocol_param", translate("Protocol param (optional)"))
  282. o:depends("type", "ssr")
  283. o = s:option(ListValue, "obfs", translate("Obfs"))
  284. for _, v in ipairs(obfs) do
  285. o:value(v)
  286. end
  287. o.rmempty = true
  288. o:depends("type", "ssr")
  289. o = s:option(Value, "obfs_param", translate("Obfs param (optional)"))
  290. o:depends("type", "ssr")
  291. -- [[ Hysteria2 ]]--
  292. o = s:option(Value, "hy2_auth", translate("Users Authentication"))
  293. o:depends("type", "hysteria")
  294. o.rmempty = false
  295. o = s:option(ListValue, "transport_protocol", translate("Protocol"))
  296. o:depends("type", "hysteria")
  297. o:value("udp", translate("udp"))
  298. o.default = "udp"
  299. o.rmempty = true
  300. o = s:option(Flag, "port_hopping", translate("Enable Port Hopping"))
  301. o:depends("type", "hysteria")
  302. o.rmempty = true
  303. o.default = "0"
  304. o = s:option(Value, "hopinterval", translate("Port Hopping Interval(Unit:Second)"))
  305. o:depends({type = "hysteria", port_hopping = "1"})
  306. o.datatype = "uinteger"
  307. o.rmempty = true
  308. o.default = "30"
  309. o = s:option(Value, "port_range", translate("Port Range"))
  310. o:depends({type = "hysteria", port_hopping = "1"})
  311. o.rmempty = false
  312. o = s:option(Flag, "lazy_mode", translate("Enable Lazy Mode"))
  313. o:depends("type", "hysteria")
  314. o.rmempty = true
  315. o.default = "0"
  316. o = s:option(Flag, "flag_obfs", translate("Enable Obfuscation"))
  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. --[[Hysteria2 QUIC parameters setting]]
  333. o = s:option(Value, "initstreamreceivewindow", translate("QUIC initStreamReceiveWindow"))
  334. o:depends({type = "hysteria",flag_quicparam = "1"})
  335. o.datatype = "uinteger"
  336. o.rmempty = true
  337. o.default = "8388608"
  338. o = s:option(Value, "maxstreamseceivewindow", translate("QUIC maxStreamReceiveWindow"))
  339. o:depends({type = "hysteria",flag_quicparam = "1"})
  340. o.datatype = "uinteger"
  341. o.rmempty = true
  342. o.default = "8388608"
  343. o = s:option(Value, "initconnreceivewindow", translate("QUIC initConnReceiveWindow"))
  344. o:depends({type = "hysteria",flag_quicparam = "1"})
  345. o.datatype = "uinteger"
  346. o.rmempty = true
  347. o.default = "20971520"
  348. o = s:option(Value, "maxconnreceivewindow", translate("QUIC maxConnReceiveWindow"))
  349. o:depends({type = "hysteria",flag_quicparam = "1"})
  350. o.datatype = "uinteger"
  351. o.rmempty = true
  352. o.default = "20971520"
  353. o = s:option(Value, "maxidletimeout", translate("QUIC maxIdleTimeout(Unit:second)"))
  354. o:depends({type = "hysteria",flag_quicparam = "1"})
  355. o.rmempty = true
  356. o.datatype = "uinteger"
  357. o.default = "30"
  358. o = s:option(Value, "keepaliveperiod", translate("The keep-alive period.(Unit:second)"))
  359. o:depends({type = "hysteria",flag_quicparam = "1"})
  360. o.rmempty = true
  361. o.datatype = "uinteger"
  362. o.default = "10"
  363. o = s:option(Flag, "disablepathmtudiscovery", translate("Disable Path MTU discovery"))
  364. o:depends({type = "hysteria",flag_quicparam = "1"})
  365. o.rmempty = true
  366. o.default = false
  367. --[[ Shadow-TLS Options ]]
  368. o = s:option(ListValue, "shadowtls_protocol", translate("shadowTLS protocol Version"))
  369. o:depends("type", "shadowtls")
  370. o:value("v3", translate("Enable V3 protocol."))
  371. o:value("v2", translate("Enable V2 protocol."))
  372. o.default = "v3"
  373. o.rmempty = true
  374. o = s:option(Flag, "strict", translate("TLS 1.3 Strict mode"))
  375. o:depends("type", "shadowtls")
  376. o.default = "1"
  377. o.rmempty = false
  378. o = s:option(Flag, "fastopen", translate("TCP Fast Open"))
  379. o:depends("type", "shadowtls")
  380. o.default = "0"
  381. o.rmempty = false
  382. o = s:option(Flag, "disable_nodelay", translate("Disable TCP No_delay"))
  383. o:depends("type", "shadowtls")
  384. o.default = "0"
  385. o.rmempty = true
  386. o = s:option(Value, "shadowtls_sni", translate("shadow-TLS SNI"))
  387. o:depends("type", "shadowtls")
  388. o.datatype = "host"
  389. o.rmempty = true
  390. o.default = ""
  391. --[[ add a ListValue for Choose chain type,sslocal or vmess ]]
  392. o = s:option(ListValue, "chain_type", translate("Shadow-TLS ChainPoxy type"))
  393. o:depends("type", "shadowtls")
  394. if is_finded("sslocal") then
  395. o:value("sslocal", translate("Shadowsocks-rust Version"))
  396. end
  397. if is_finded("xray") or is_finded("v2ray") then
  398. o:value("vmess", translate("Vmess Protocol"))
  399. end
  400. o.default = "sslocal"
  401. o.rmempty = false
  402. o = s:option(Value, "sslocal_password",translate("Shadowsocks password"))
  403. o:depends({type = "shadowtls", chain_type = "sslocal"})
  404. o.rmempty = true
  405. o = s:option(ListValue, "sslocal_method", translate("Encrypt Method"))
  406. o:depends({type = "shadowtls", chain_type = "sslocal"})
  407. for _, v in ipairs(encrypt_methods_ss) do
  408. o:value(v)
  409. end
  410. o = s:option(Value, "vmess_uuid", translate("Vmess UUID"))
  411. o:depends({type = "shadowtls", chain_type = "vmess"})
  412. o.rmempty = false
  413. o.default = uuid
  414. o = s:option(ListValue, "vmess_method", translate("Encrypt Method"))
  415. o:depends({type = "shadowtls", chain_type = "vmess"})
  416. for _, v in ipairs(securitys) do
  417. o:value(v, v:lower())
  418. end
  419. o.rmempty = true
  420. o.default="auto"
  421. -- [[ TUIC ]]
  422. -- TuicNameId
  423. o = s:option(Value, "tuic_uuid", translate("TUIC User UUID"))
  424. o.rmempty = true
  425. o.default = uuid
  426. o:depends("type", "tuic")
  427. --Tuic IP
  428. o = s:option(Value, "tuic_ip", translate("TUIC Server IP Address"))
  429. o.rmempty = true
  430. o.datatype = "ip4addr"
  431. o.default = ""
  432. o:depends("type", "tuic")
  433. -- Tuic Password
  434. o = s:option(Value, "tuic_passwd", translate("TUIC User Password"))
  435. o.rmempty = true
  436. o.default = ""
  437. o:depends("type", "tuic")
  438. o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
  439. o:depends("type", "tuic")
  440. o:value("native", translate("native UDP characteristics"))
  441. o:value("quic", translate("lossless UDP relay using QUIC streams"))
  442. o.default = "native"
  443. o.rmempty = true
  444. o = s:option(ListValue, "congestion_control", translate("Congestion control algorithm"))
  445. o:depends("type", "tuic")
  446. o:value("bbr", translate("BBR"))
  447. o:value("cubic", translate("CUBIC"))
  448. o:value("new_reno", translate("New Reno"))
  449. o.default = "cubic"
  450. o.rmempty = true
  451. o = s:option(Value, "heartbeat", translate("Heartbeat interval(second)"))
  452. o:depends("type", "tuic")
  453. o.datatype = "uinteger"
  454. o.default = "3"
  455. o.rmempty = true
  456. o = s:option(Value, "timeout", translate("Timeout for establishing a connection to server(second)"))
  457. o:depends("type", "tuic")
  458. o.datatype = "uinteger"
  459. o.default = "8"
  460. o.rmempty = true
  461. o = s:option(Value, "gc_interval", translate("Garbage collection interval(second)"))
  462. o:depends("type", "tuic")
  463. o.datatype = "uinteger"
  464. o.default = "3"
  465. o.rmempty = true
  466. o = s:option(Value, "gc_lifetime", translate("Garbage collection lifetime(second)"))
  467. o:depends("type", "tuic")
  468. o.datatype = "uinteger"
  469. o.default = "15"
  470. o.rmempty = true
  471. o = s:option(Value, "send_window", translate("TUIC send window"))
  472. o:depends("type", "tuic")
  473. o.datatype = "uinteger"
  474. o.default = 20971520
  475. o.rmempty = true
  476. o = s:option(Value, "receive_window", translate("TUIC receive window"))
  477. o:depends("type", "tuic")
  478. o.datatype = "uinteger"
  479. o.default = 10485760
  480. o.rmempty = true
  481. o = s:option(Flag, "disable_sni", translate("Disable SNI"))
  482. o:depends("type", "tuic")
  483. o.default = "0"
  484. o.rmempty = true
  485. o = s:option(Flag, "zero_rtt_handshake", translate("Enable 0-RTT QUIC handshake"))
  486. o:depends("type", "tuic")
  487. o.default = "0"
  488. o.rmempty = true
  489. -- Tuic settings for the local inbound socks5 server
  490. o = s:option(Flag, "tuic_dual_stack", translate("Dual-stack Listening Socket"))
  491. o:depends("type", "tuic")
  492. o.default = "0"
  493. o.rmempty = true
  494. o = s:option(Value, "tuic_max_package_size", translate("Maximum packet size the socks5 server can receive from external"))
  495. o:depends("type", "tuic")
  496. o.datatype = "uinteger"
  497. o.default = 1500
  498. o.rmempty = true
  499. -- VmessId
  500. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  501. o.rmempty = true
  502. o.default = uuid
  503. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  504. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  505. -- VLESS Encryption
  506. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  507. o.rmempty = true
  508. o.default = "none"
  509. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  510. -- 加密方式
  511. o = s:option(ListValue, "security", translate("Encrypt Method"))
  512. for _, v in ipairs(securitys) do
  513. o:value(v, v:upper())
  514. end
  515. o.rmempty = true
  516. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  517. -- SOCKS Version
  518. o = s:option(ListValue, "socks_ver", translate("Socks Version"))
  519. o:value("4", "Socks4")
  520. o:value("4a", "Socks4A")
  521. o:value("5", "Socks5")
  522. o.rmempty = true
  523. o.default = "5"
  524. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  525. -- 传输协议
  526. o = s:option(ListValue, "transport", translate("Transport"))
  527. o:value("tcp", "TCP")
  528. o:value("kcp", "mKCP")
  529. o:value("ws", "WebSocket")
  530. o:value("h2", "HTTP/2")
  531. o:value("quic", "QUIC")
  532. o:value("grpc", "gRPC")
  533. o.rmempty = true
  534. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  535. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  536. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  537. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  538. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  539. o:depends({type = "v2ray", v2ray_protocol = "http"})
  540. -- [[ TCP部分 ]]--
  541. -- TCP伪装
  542. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  543. o:depends("transport", "tcp")
  544. o:value("none", translate("None"))
  545. o:value("http", "HTTP")
  546. o.rmempty = true
  547. -- HTTP域名
  548. o = s:option(Value, "http_host", translate("HTTP Host"))
  549. o:depends("tcp_guise", "http")
  550. o.rmempty = true
  551. -- HTTP路径
  552. o = s:option(Value, "http_path", translate("HTTP Path"))
  553. o:depends("tcp_guise", "http")
  554. o.rmempty = true
  555. -- [[ WS部分 ]]--
  556. -- WS域名
  557. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  558. o:depends({transport = "ws", tls = false})
  559. o.datatype = "hostname"
  560. o.rmempty = true
  561. -- WS路径
  562. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  563. o:depends("transport", "ws")
  564. o.rmempty = true
  565. if is_finded("v2ray") then
  566. -- WS前置数据
  567. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  568. o:depends("ws_ed_enable", true)
  569. o.datatype = "uinteger"
  570. o:value("2048")
  571. o.rmempty = true
  572. -- WS前置数据标头
  573. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  574. o:depends("ws_ed_enable", true)
  575. o:value("Sec-WebSocket-Protocol")
  576. o.rmempty = true
  577. end
  578. -- [[ H2部分 ]]--
  579. -- H2域名
  580. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  581. o:depends("transport", "h2")
  582. o.rmempty = true
  583. -- H2路径
  584. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  585. o:depends("transport", "h2")
  586. o.rmempty = true
  587. -- gRPC
  588. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  589. o:depends("transport", "grpc")
  590. o.rmempty = true
  591. if is_finded("xray") then
  592. -- gPRC模式
  593. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  594. o:depends("transport", "grpc")
  595. o:value("gun", translate("Gun"))
  596. o:value("multi", translate("Multi"))
  597. o.rmempty = true
  598. end
  599. if is_finded("xray") then
  600. -- gRPC初始窗口
  601. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  602. o.datatype = "uinteger"
  603. o:depends("transport", "grpc")
  604. o.default = 0
  605. o.rmempty = true
  606. -- H2/gRPC健康检查
  607. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  608. o:depends("transport", "h2")
  609. o:depends("transport", "grpc")
  610. o.rmempty = true
  611. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  612. o.datatype = "uinteger"
  613. o:depends({health_check = true, transport = "h2"})
  614. o.default = 60
  615. o.rmempty = true
  616. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  617. o.datatype = "uinteger"
  618. o:depends({health_check = true, transport = "grpc"})
  619. o.default = 60
  620. o.rmempty = true
  621. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  622. o.datatype = "uinteger"
  623. o:depends("health_check", 1)
  624. o.default = 20
  625. o.rmempty = true
  626. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  627. o:depends({health_check = true, transport = "grpc"})
  628. o.rmempty = true
  629. end
  630. -- [[ QUIC部分 ]]--
  631. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  632. o:depends("transport", "quic")
  633. o:value("none", translate("None"))
  634. o:value("aes-128-gcm", translate("aes-128-gcm"))
  635. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  636. o.rmempty = true
  637. o = s:option(Value, "quic_key", translate("QUIC Key"))
  638. o:depends("transport", "quic")
  639. o.rmempty = true
  640. o = s:option(ListValue, "quic_guise", translate("Header"))
  641. o:depends("transport", "quic")
  642. o.rmempty = true
  643. o:value("none", translate("None"))
  644. o:value("srtp", translate("VideoCall (SRTP)"))
  645. o:value("utp", translate("BitTorrent (uTP)"))
  646. o:value("wechat-video", translate("WechatVideo"))
  647. o:value("dtls", translate("DTLS 1.2"))
  648. o:value("wireguard", translate("WireGuard"))
  649. -- [[ mKCP部分 ]]--
  650. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  651. o:depends("transport", "kcp")
  652. o:value("none", translate("None"))
  653. o:value("srtp", translate("VideoCall (SRTP)"))
  654. o:value("utp", translate("BitTorrent (uTP)"))
  655. o:value("wechat-video", translate("WechatVideo"))
  656. o:value("dtls", translate("DTLS 1.2"))
  657. o:value("wireguard", translate("WireGuard"))
  658. o.rmempty = true
  659. o = s:option(Value, "mtu", translate("MTU"))
  660. o.datatype = "uinteger"
  661. o:depends("transport", "kcp")
  662. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  663. -- o.default = 1350
  664. o.rmempty = true
  665. o = s:option(Value, "tti", translate("TTI"))
  666. o.datatype = "uinteger"
  667. o:depends("transport", "kcp")
  668. o.default = 50
  669. o.rmempty = true
  670. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity(Default:Mbps)"))
  671. o.datatype = "uinteger"
  672. o:depends("transport", "kcp")
  673. o:depends("type", "hysteria")
  674. o.default = 5
  675. o.rmempty = true
  676. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity(Default:Mbps)"))
  677. o.datatype = "uinteger"
  678. o:depends("transport", "kcp")
  679. o:depends("type", "hysteria")
  680. o.default = 20
  681. o.rmempty = true
  682. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  683. o.datatype = "uinteger"
  684. o:depends("transport", "kcp")
  685. o.default = 2
  686. o.rmempty = true
  687. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  688. o.datatype = "uinteger"
  689. o:depends("transport", "kcp")
  690. o.default = 2
  691. o.rmempty = true
  692. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  693. o:depends("transport", "kcp")
  694. o.rmempty = true
  695. o = s:option(Flag, "congestion", translate("Congestion"))
  696. o:depends("transport", "kcp")
  697. o.rmempty = true
  698. -- [[ WireGuard 部分 ]]--
  699. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  700. o.datatype = "cidr"
  701. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  702. o.rmempty = true
  703. o = s:option(Value, "private_key", translate("Private key"))
  704. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  705. o.password = true
  706. o.rmempty = true
  707. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  708. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  709. o.rmempty = true
  710. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  711. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  712. o.password = true
  713. o.rmempty = true
  714. -- [[ TLS ]]--
  715. o = s:option(Flag, "tls", translate("TLS"))
  716. o.rmempty = true
  717. o.default = "0"
  718. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = false})
  719. o:depends({type = "v2ray", v2ray_protocol = "vmess", reality = false})
  720. o:depends({type = "v2ray", v2ray_protocol = "trojan", reality = false})
  721. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", reality = false})
  722. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", reality = false})
  723. o:depends({type = "v2ray", v2ray_protocol = "http", reality = false})
  724. o:depends("type", "trojan")
  725. o:depends("type", "hysteria")
  726. -- [[ TLS部分 ]] --
  727. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  728. o:depends({type = "trojan", tls = true})
  729. o.default = "0"
  730. if is_finded("xray") then
  731. -- [[ REALITY ]]
  732. o = s:option(Flag, "reality", translate("REALITY"))
  733. o.rmempty = true
  734. o.default = "0"
  735. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = false})
  736. o = s:option(Value, "reality_publickey", translate("Public key"))
  737. o.rmempty = true
  738. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  739. o = s:option(Value, "reality_shortid", translate("Short ID"))
  740. o.rmempty = true
  741. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  742. o = s:option(Value, "reality_spiderx", translate("spiderX"))
  743. o.rmempty = true
  744. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  745. -- [[ XTLS ]]--
  746. o = s:option(Value, "tls_flow", translate("Flow"))
  747. for _, v in ipairs(tls_flows) do
  748. o:value(v, translate(v))
  749. end
  750. o.rmempty = true
  751. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = true})
  752. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", reality = true})
  753. -- [[ uTLS ]]--
  754. o = s:option(Value, "fingerprint", translate("Finger Print"))
  755. o:value("", translate("disable"))
  756. o:value("chrome", translate("chrome"))
  757. o:value("firefox", translate("firefox"))
  758. o:value("safari", translate("safari"))
  759. o:value("ios", translate("ios"))
  760. o:value("android", translate("android"))
  761. o:value("edge", translate("edge"))
  762. o:value("360", translate("360"))
  763. o:value("qq", translate("qq"))
  764. o:value("random", translate("random"))
  765. o:value("randomized", translate("randomized"))
  766. o:depends({type = "v2ray", tls = true})
  767. o:depends({type = "v2ray", reality = true})
  768. end
  769. o = s:option(Value, "tls_host", translate("TLS Host"))
  770. o.datatype = "hostname"
  771. o:depends("tls", true)
  772. o:depends("reality", true)
  773. o.rmempty = true
  774. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  775. o:depends("tls", true)
  776. o:depends("type", "tuic")
  777. o:depends("type", "hysteria")
  778. o.rmempty = true
  779. -- [[ allowInsecure ]]--
  780. o = s:option(Flag, "insecure", translate("allowInsecure"))
  781. o.rmempty = false
  782. o:depends("tls", true)
  783. o:depends("type", "hysteria")
  784. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  785. -- [[ Hysteria2 TLS pinSHA256 ]] --
  786. o = s:option(Value, "pinsha256", translate("Certificate fingerprint"))
  787. o:depends({type ="hysteria", insecure = true })
  788. o.rmempty = true
  789. -- [[ Mux ]]--
  790. o = s:option(Flag, "mux", translate("Mux"))
  791. o.rmempty = false
  792. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  793. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  794. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  795. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  796. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  797. o:depends({type = "v2ray", v2ray_protocol = "http"})
  798. o = s:option(Value, "concurrency", translate("Concurrency"))
  799. o.datatype = "uinteger"
  800. o.rmempty = true
  801. o.default = "4"
  802. o:depends("mux", "1")
  803. o:depends("type", "naiveproxy")
  804. -- [[ Cert ]]--
  805. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  806. o.rmempty = true
  807. o.default = "0"
  808. o:depends("type", "tuic")
  809. o:depends({type = "hysteria", insecure = false})
  810. o:depends({type = "trojan", tls = true, insecure = false})
  811. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  812. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  813. o.description = translate("If you have a self-signed certificate,please check the box")
  814. o = s:option(DummyValue, "upload", translate("Upload"))
  815. o.template = "shadowsocksr/certupload"
  816. o:depends("certificate", 1)
  817. cert_dir = "/etc/ssl/private/"
  818. local path
  819. luci.http.setfilehandler(function(meta, chunk, eof)
  820. if not fd then
  821. if (not meta) or (not meta.name) or (not meta.file) then
  822. return
  823. end
  824. fd = nixio.open(cert_dir .. meta.file, "w")
  825. if not fd then
  826. path = translate("Create upload file error.")
  827. return
  828. end
  829. end
  830. if chunk and fd then
  831. fd:write(chunk)
  832. end
  833. if eof and fd then
  834. fd:close()
  835. fd = nil
  836. path = '/etc/ssl/private/' .. meta.file .. ''
  837. end
  838. end)
  839. if luci.http.formvalue("upload") then
  840. local f = luci.http.formvalue("ulfile")
  841. if #f <= 0 then
  842. path = translate("No specify upload file.")
  843. end
  844. end
  845. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  846. o:depends("certificate", 1)
  847. o:value("/etc/ssl/private/ca.pem")
  848. o.description = translate("Please confirm the current certificate path")
  849. o.default = "/etc/ssl/private/ca.pem"
  850. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  851. o.rmempty = true
  852. o.default = "0"
  853. o:depends("type", "ssr")
  854. o:depends("type", "ss")
  855. o:depends("type", "ss_rust")
  856. o:depends("type", "trojan")
  857. o:depends("type", "hysteria")
  858. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  859. o.rmempty = false
  860. o.default = "1"
  861. o = s:option(Value, "local_port", translate("Local Port"))
  862. o.datatype = "port"
  863. o.default = 1234
  864. o.rmempty = false
  865. if is_finded("kcptun-client") then
  866. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  867. o.rmempty = true
  868. o.default = "0"
  869. o:depends("type", "ssr")
  870. o:depends("type", "ss")
  871. o:depends("type", "ss_rust")
  872. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  873. o.datatype = "port"
  874. o.default = 4000
  875. o:depends("type", "ssr")
  876. o:depends("type", "ss")
  877. o:depends("type", "ss_rust")
  878. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  879. o.password = true
  880. o:depends("type", "ssr")
  881. o:depends("type", "ss")
  882. o:depends("type", "ss_rust")
  883. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  884. o.default = "--nocomp"
  885. o:depends("type", "ssr")
  886. o:depends("type", "ss")
  887. o:depends("type", "ss_rust")
  888. end
  889. return m