client-config.lua 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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, "hysteria_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("Port Hopping"))
  301. o:depends("type", "hysteria")
  302. o.rmempty = true
  303. o.default = "0"
  304. o = s:option(Value, "port_range", translate("Port range"))
  305. o:depends({type = "hysteria", port_hopping = 1})
  306. o.rmempty = false
  307. o = s:option(Flag, "lazy_mode", translate("Enable Lazy Mode"))
  308. o:depends("type", "hysteria")
  309. o.rmempty = true
  310. o.default = "0"
  311. o = s:option(Flag, "flag_obfs", translate("Enable Obfuscation"))
  312. o:depends("type", "hysteria")
  313. o.rmempty = true
  314. o.default = "0"
  315. o = s:option(Value, "obfs_type", translate("Obfuscation Type"))
  316. o:depends({type = "hysteria", flag_obfs = "1"})
  317. o.rmempty = true
  318. o.default = "salamander"
  319. o = s:option(Value, "salamander", translate("Obfuscation Password"))
  320. o:depends({type = "hysteria", flag_obfs = "1"})
  321. o.rmempty = true
  322. o.default = "cry_me_a_r1ver"
  323. o = s:option(Flag, "flag_quicparam", translate("Hysterir QUIC parameters"))
  324. o:depends("type", "hysteria")
  325. o.rmempty = true
  326. o.default = "0"
  327. --[[Hysteria2 QUIC parameters setting]]
  328. o = s:option(Value, "initstreamreceivewindow", translate("QUIC initStreamReceiveWindow"))
  329. o:depends({type = "hysteria",flag_quicparam = "1"})
  330. o.datatype = "uinteger"
  331. o.rmempty = true
  332. o.default = "8388608"
  333. o = s:option(Value, "maxstreamseceivewindow", translate("QUIC maxStreamReceiveWindow"))
  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, "initconnreceivewindow", translate("QUIC initConnReceiveWindow"))
  339. o:depends({type = "hysteria",flag_quicparam = "1"})
  340. o.datatype = "uinteger"
  341. o.rmempty = true
  342. o.default = "20971520"
  343. o = s:option(Value, "maxconnreceivewindow", translate("QUIC maxConnReceiveWindow"))
  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, "maxincomingstreams", translate("QUIC maxIncomingStreams"))
  349. o:depends({type = "hysteria",flag_quicparam = "1"})
  350. o.datatype = "uinteger"
  351. o.rmempty = true
  352. o.default = "1024"
  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.default = "30s"
  357. o = s:option(Value, "keepaliveperiod", translate("The keep-alive period.(Unit:second)"))
  358. o:depends({type = "hysteria",flag_quicparam = "1"})
  359. o.rmempty = true
  360. o.default = "10s"
  361. o = s:option(Flag, "disablepathmtudiscovery", translate("Disable Path MTU discovery"))
  362. o:depends({type = "hysteria",flag_quicparam = "1"})
  363. o.rmempty = true
  364. o.default = false
  365. --[[ Shadow-TLS Options ]]
  366. o = s:option(ListValue, "shadowtls_protocol", translate("shadowTLS protocol Version"))
  367. o:depends("type", "shadowtls")
  368. o:value("v3", translate("Enable V3 protocol."))
  369. o:value("v2", translate("Enable V2 protocol."))
  370. o.default = "v3"
  371. o.rmempty = true
  372. o = s:option(Flag, "strict", translate("TLS 1.3 Strict mode"))
  373. o:depends("type", "shadowtls")
  374. o.default = "1"
  375. o.rmempty = false
  376. o = s:option(Flag, "fastopen", translate("TCP Fast Open"))
  377. o:depends("type", "shadowtls")
  378. o.default = "0"
  379. o.rmempty = false
  380. o = s:option(Flag, "disable_nodelay", translate("Disable TCP No_delay"))
  381. o:depends("type", "shadowtls")
  382. o.default = "0"
  383. o.rmempty = true
  384. o = s:option(Value, "shadowtls_sni", translate("shadow-TLS SNI"))
  385. o:depends("type", "shadowtls")
  386. o.datatype = "host"
  387. o.rmempty = true
  388. o.default = ""
  389. --[[ add a ListValue for Choose chain type,sslocal or vmess ]]
  390. o = s:option(ListValue, "chain_type", translate("Shadow-TLS ChainPoxy type"))
  391. o:depends("type", "shadowtls")
  392. if is_finded("sslocal") then
  393. o:value("sslocal", translate("Shadowsocks-rust Version"))
  394. end
  395. if is_finded("xray") or is_finded("v2ray") then
  396. o:value("vmess", translate("Vmess Protocol"))
  397. end
  398. o.default = "sslocal"
  399. o.rmempty = false
  400. o = s:option(Value, "sslocal_password",translate("Shadowsocks password"))
  401. o:depends({type = "shadowtls", chain_type = "sslocal"})
  402. o.rmempty = true
  403. o = s:option(ListValue, "sslocal_method", translate("Encrypt Method"))
  404. o:depends({type = "shadowtls", chain_type = "sslocal"})
  405. for _, v in ipairs(encrypt_methods_ss) do
  406. o:value(v)
  407. end
  408. o = s:option(Value, "vmess_uuid", translate("Vmess UUID"))
  409. o:depends({type = "shadowtls", chain_type = "vmess"})
  410. o.rmempty = false
  411. o.default = uuid
  412. o = s:option(ListValue, "vmess_method", translate("Encrypt Method"))
  413. o:depends({type = "shadowtls", chain_type = "vmess"})
  414. for _, v in ipairs(securitys) do
  415. o:value(v, v:lower())
  416. end
  417. o.rmempty = true
  418. o.default="auto"
  419. -- [[ TUIC ]]
  420. -- TuicNameId
  421. o = s:option(Value, "tuic_uuid", translate("TUIC User UUID"))
  422. o.rmempty = true
  423. o.default = uuid
  424. o:depends("type", "tuic")
  425. --Tuic IP
  426. o = s:option(Value, "tuic_ip", translate("TUIC Server IP Address"))
  427. o.rmempty = true
  428. o.datatype = "ip4addr"
  429. o.default = ""
  430. o:depends("type", "tuic")
  431. -- Tuic Password
  432. o = s:option(Value, "tuic_passwd", translate("TUIC User Password"))
  433. o.rmempty = true
  434. o.default = ""
  435. o:depends("type", "tuic")
  436. o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
  437. o:depends("type", "tuic")
  438. o:value("native", translate("native UDP characteristics"))
  439. o:value("quic", translate("lossless UDP relay using QUIC streams"))
  440. o.default = "native"
  441. o.rmempty = true
  442. o = s:option(ListValue, "congestion_control", translate("Congestion control algorithm"))
  443. o:depends("type", "tuic")
  444. o:value("bbr", translate("BBR"))
  445. o:value("cubic", translate("CUBIC"))
  446. o:value("new_reno", translate("New Reno"))
  447. o.default = "cubic"
  448. o.rmempty = true
  449. o = s:option(Value, "heartbeat", translate("Heartbeat interval(second)"))
  450. o:depends("type", "tuic")
  451. o.datatype = "uinteger"
  452. o.default = "3"
  453. o.rmempty = true
  454. o = s:option(Value, "timeout", translate("Timeout for establishing a connection to server(second)"))
  455. o:depends("type", "tuic")
  456. o.datatype = "uinteger"
  457. o.default = "8"
  458. o.rmempty = true
  459. o = s:option(Value, "gc_interval", translate("Garbage collection interval(second)"))
  460. o:depends("type", "tuic")
  461. o.datatype = "uinteger"
  462. o.default = "3"
  463. o.rmempty = true
  464. o = s:option(Value, "gc_lifetime", translate("Garbage collection lifetime(second)"))
  465. o:depends("type", "tuic")
  466. o.datatype = "uinteger"
  467. o.default = "15"
  468. o.rmempty = true
  469. o = s:option(Value, "send_window", translate("TUIC send window"))
  470. o:depends("type", "tuic")
  471. o.datatype = "uinteger"
  472. o.default = 20971520
  473. o.rmempty = true
  474. o = s:option(Value, "receive_window", translate("TUIC receive window"))
  475. o:depends("type", "tuic")
  476. o.datatype = "uinteger"
  477. o.default = 10485760
  478. o.rmempty = true
  479. o = s:option(Flag, "disable_sni", translate("Disable SNI"))
  480. o:depends("type", "tuic")
  481. o.default = "0"
  482. o.rmempty = true
  483. o = s:option(Flag, "zero_rtt_handshake", translate("Enable 0-RTT QUIC handshake"))
  484. o:depends("type", "tuic")
  485. o.default = "0"
  486. o.rmempty = true
  487. -- Tuic settings for the local inbound socks5 server
  488. o = s:option(Flag, "tuic_dual_stack", translate("Dual-stack Listening Socket"))
  489. o:depends("type", "tuic")
  490. o.default = "0"
  491. o.rmempty = true
  492. o = s:option(Value, "tuic_max_package_size", translate("Maximum packet size the socks5 server can receive from external"))
  493. o:depends("type", "tuic")
  494. o.datatype = "uinteger"
  495. o.default = 1500
  496. o.rmempty = true
  497. -- VmessId
  498. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  499. o.rmempty = true
  500. o.default = uuid
  501. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  502. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  503. -- VLESS Encryption
  504. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  505. o.rmempty = true
  506. o.default = "none"
  507. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  508. -- 加密方式
  509. o = s:option(ListValue, "security", translate("Encrypt Method"))
  510. for _, v in ipairs(securitys) do
  511. o:value(v, v:upper())
  512. end
  513. o.rmempty = true
  514. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  515. -- SOCKS Version
  516. o = s:option(ListValue, "socks_ver", translate("Socks Version"))
  517. o:value("4", "Socks4")
  518. o:value("4a", "Socks4A")
  519. o:value("5", "Socks5")
  520. o.rmempty = true
  521. o.default = "5"
  522. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  523. -- 传输协议
  524. o = s:option(ListValue, "transport", translate("Transport"))
  525. o:value("tcp", "TCP")
  526. o:value("kcp", "mKCP")
  527. o:value("ws", "WebSocket")
  528. o:value("h2", "HTTP/2")
  529. o:value("quic", "QUIC")
  530. o:value("grpc", "gRPC")
  531. o.rmempty = true
  532. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  533. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  534. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  535. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  536. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  537. o:depends({type = "v2ray", v2ray_protocol = "http"})
  538. -- [[ TCP部分 ]]--
  539. -- TCP伪装
  540. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  541. o:depends("transport", "tcp")
  542. o:value("none", translate("None"))
  543. o:value("http", "HTTP")
  544. o.rmempty = true
  545. -- HTTP域名
  546. o = s:option(Value, "http_host", translate("HTTP Host"))
  547. o:depends("tcp_guise", "http")
  548. o.rmempty = true
  549. -- HTTP路径
  550. o = s:option(Value, "http_path", translate("HTTP Path"))
  551. o:depends("tcp_guise", "http")
  552. o.rmempty = true
  553. -- [[ WS部分 ]]--
  554. -- WS域名
  555. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  556. o:depends({transport = "ws", tls = false})
  557. o.datatype = "hostname"
  558. o.rmempty = true
  559. -- WS路径
  560. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  561. o:depends("transport", "ws")
  562. o.rmempty = true
  563. if is_finded("v2ray") then
  564. -- WS前置数据
  565. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  566. o:depends("ws_ed_enable", true)
  567. o.datatype = "uinteger"
  568. o:value("2048")
  569. o.rmempty = true
  570. -- WS前置数据标头
  571. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  572. o:depends("ws_ed_enable", true)
  573. o:value("Sec-WebSocket-Protocol")
  574. o.rmempty = true
  575. end
  576. -- [[ H2部分 ]]--
  577. -- H2域名
  578. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  579. o:depends("transport", "h2")
  580. o.rmempty = true
  581. -- H2路径
  582. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  583. o:depends("transport", "h2")
  584. o.rmempty = true
  585. -- gRPC
  586. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  587. o:depends("transport", "grpc")
  588. o.rmempty = true
  589. if is_finded("xray") then
  590. -- gPRC模式
  591. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  592. o:depends("transport", "grpc")
  593. o:value("gun", translate("Gun"))
  594. o:value("multi", translate("Multi"))
  595. o.rmempty = true
  596. end
  597. if is_finded("xray") then
  598. -- gRPC初始窗口
  599. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  600. o.datatype = "uinteger"
  601. o:depends("transport", "grpc")
  602. o.default = 0
  603. o.rmempty = true
  604. -- H2/gRPC健康检查
  605. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  606. o:depends("transport", "h2")
  607. o:depends("transport", "grpc")
  608. o.rmempty = true
  609. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  610. o.datatype = "uinteger"
  611. o:depends({health_check = true, transport = "h2"})
  612. o.default = 60
  613. o.rmempty = true
  614. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  615. o.datatype = "uinteger"
  616. o:depends({health_check = true, transport = "grpc"})
  617. o.default = 60
  618. o.rmempty = true
  619. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  620. o.datatype = "uinteger"
  621. o:depends("health_check", 1)
  622. o.default = 20
  623. o.rmempty = true
  624. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  625. o:depends({health_check = true, transport = "grpc"})
  626. o.rmempty = true
  627. end
  628. -- [[ QUIC部分 ]]--
  629. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  630. o:depends("transport", "quic")
  631. o:value("none", translate("None"))
  632. o:value("aes-128-gcm", translate("aes-128-gcm"))
  633. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  634. o.rmempty = true
  635. o = s:option(Value, "quic_key", translate("QUIC Key"))
  636. o:depends("transport", "quic")
  637. o.rmempty = true
  638. o = s:option(ListValue, "quic_guise", translate("Header"))
  639. o:depends("transport", "quic")
  640. o.rmempty = true
  641. o:value("none", translate("None"))
  642. o:value("srtp", translate("VideoCall (SRTP)"))
  643. o:value("utp", translate("BitTorrent (uTP)"))
  644. o:value("wechat-video", translate("WechatVideo"))
  645. o:value("dtls", translate("DTLS 1.2"))
  646. o:value("wireguard", translate("WireGuard"))
  647. -- [[ mKCP部分 ]]--
  648. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  649. o:depends("transport", "kcp")
  650. o:value("none", translate("None"))
  651. o:value("srtp", translate("VideoCall (SRTP)"))
  652. o:value("utp", translate("BitTorrent (uTP)"))
  653. o:value("wechat-video", translate("WechatVideo"))
  654. o:value("dtls", translate("DTLS 1.2"))
  655. o:value("wireguard", translate("WireGuard"))
  656. o.rmempty = true
  657. o = s:option(Value, "mtu", translate("MTU"))
  658. o.datatype = "uinteger"
  659. o:depends("transport", "kcp")
  660. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  661. -- o.default = 1350
  662. o.rmempty = true
  663. o = s:option(Value, "tti", translate("TTI"))
  664. o.datatype = "uinteger"
  665. o:depends("transport", "kcp")
  666. o.default = 50
  667. o.rmempty = true
  668. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity"))
  669. o.datatype = "uinteger"
  670. o:depends("transport", "kcp")
  671. o:depends("type", "hysteria")
  672. o.default = 5
  673. o.rmempty = true
  674. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity"))
  675. o.datatype = "uinteger"
  676. o:depends("transport", "kcp")
  677. o:depends("type", "hysteria")
  678. o.default = 20
  679. o.rmempty = true
  680. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  681. o.datatype = "uinteger"
  682. o:depends("transport", "kcp")
  683. o.default = 2
  684. o.rmempty = true
  685. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  686. o.datatype = "uinteger"
  687. o:depends("transport", "kcp")
  688. o.default = 2
  689. o.rmempty = true
  690. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  691. o:depends("transport", "kcp")
  692. o.rmempty = true
  693. o = s:option(Flag, "congestion", translate("Congestion"))
  694. o:depends("transport", "kcp")
  695. o.rmempty = true
  696. -- [[ WireGuard 部分 ]]--
  697. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  698. o.datatype = "cidr"
  699. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  700. o.rmempty = true
  701. o = s:option(Value, "private_key", translate("Private key"))
  702. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  703. o.password = true
  704. o.rmempty = true
  705. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  706. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  707. o.rmempty = true
  708. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  709. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  710. o.password = true
  711. o.rmempty = true
  712. -- [[ TLS ]]--
  713. o = s:option(Flag, "tls", translate("TLS"))
  714. o.rmempty = true
  715. o.default = "0"
  716. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = false})
  717. o:depends({type = "v2ray", v2ray_protocol = "vmess", reality = false})
  718. o:depends({type = "v2ray", v2ray_protocol = "trojan", reality = false})
  719. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", reality = false})
  720. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", reality = false})
  721. o:depends({type = "v2ray", v2ray_protocol = "http", reality = false})
  722. o:depends("type", "trojan")
  723. -- [[ TLS部分 ]] --
  724. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  725. o:depends({type = "trojan", tls = true})
  726. o.default = "0"
  727. if is_finded("xray") then
  728. -- [[ REALITY ]]
  729. o = s:option(Flag, "reality", translate("REALITY"))
  730. o.rmempty = true
  731. o.default = "0"
  732. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = false})
  733. o = s:option(Value, "reality_publickey", translate("Public key"))
  734. o.rmempty = true
  735. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  736. o = s:option(Value, "reality_shortid", translate("Short ID"))
  737. o.rmempty = true
  738. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  739. o = s:option(Value, "reality_spiderx", translate("spiderX"))
  740. o.rmempty = true
  741. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  742. -- [[ XTLS ]]--
  743. o = s:option(Value, "tls_flow", translate("Flow"))
  744. for _, v in ipairs(tls_flows) do
  745. o:value(v, translate(v))
  746. end
  747. o.rmempty = true
  748. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = true})
  749. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", reality = true})
  750. -- [[ uTLS ]]--
  751. o = s:option(Value, "fingerprint", translate("Finger Print"))
  752. o:value("", translate("disable"))
  753. o:value("chrome", translate("chrome"))
  754. o:value("firefox", translate("firefox"))
  755. o:value("safari", translate("safari"))
  756. o:value("ios", translate("ios"))
  757. o:value("android", translate("android"))
  758. o:value("edge", translate("edge"))
  759. o:value("360", translate("360"))
  760. o:value("qq", translate("qq"))
  761. o:value("random", translate("random"))
  762. o:value("randomized", translate("randomized"))
  763. o:depends({type = "v2ray", tls = true})
  764. o:depends({type = "v2ray", reality = true})
  765. end
  766. o = s:option(Value, "tls_host", translate("TLS Host"))
  767. o.datatype = "hostname"
  768. o:depends("tls", true)
  769. o:depends("reality", true)
  770. o:depends("type", "hysteria")
  771. o.rmempty = true
  772. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  773. o:depends("tls", true)
  774. o:depends("type", "tuic")
  775. o.rmempty = true
  776. o = s:option(Value, "quic_tls_alpn", translate("QUIC TLS ALPN"))
  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