client-config.lua 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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 Version"))
  135. end
  136. if is_finded("sslocal") or is_finded("ssmanager") then
  137. o:value("ss", 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", "v2ray")
  187. o:depends("type", "trojan")
  188. o:depends("type", "naiveproxy")
  189. o:depends("type", "hysteria")
  190. o:depends("type", "tuic")
  191. o:depends("type", "shadowtls")
  192. o:depends("type", "socks5")
  193. o = s:option(Value, "server_port", translate("Server Port"))
  194. o.datatype = "port"
  195. o.rmempty = true
  196. o:depends("type", "ssr")
  197. o:depends("type", "ss")
  198. o:depends("type", "v2ray")
  199. o:depends("type", "trojan")
  200. o:depends("type", "naiveproxy")
  201. o:depends("type", "hysteria")
  202. o:depends("type", "tuic")
  203. o:depends("type", "shadowtls")
  204. o:depends("type", "socks5")
  205. o = s:option(Flag, "auth_enable", translate("Enable Authentication"))
  206. o.rmempty = false
  207. o.default = "0"
  208. o:depends("type", "socks5")
  209. o:depends({type = "v2ray", v2ray_protocol = "http"})
  210. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  211. o = s:option(Value, "username", translate("Username"))
  212. o.rmempty = true
  213. o:depends("type", "naiveproxy")
  214. o:depends({type = "socks5", auth_enable = true})
  215. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  216. o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
  217. o = s:option(Value, "password", translate("Password"))
  218. o.password = true
  219. o.rmempty = true
  220. o:depends("type", "ssr")
  221. o:depends("type", "ss")
  222. o:depends("type", "trojan")
  223. o:depends("type", "naiveproxy")
  224. o:depends("type", "shadowtls")
  225. o:depends({type = "socks5", auth_enable = true})
  226. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  227. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", auth_enable = true})
  228. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  229. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  230. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  231. for _, v in ipairs(encrypt_methods) do
  232. o:value(v)
  233. end
  234. o.rmempty = true
  235. o:depends("type", "ssr")
  236. o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
  237. for _, v in ipairs(encrypt_methods_ss) do
  238. o:value(v)
  239. end
  240. o.rmempty = true
  241. o:depends("type", "ss")
  242. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  243. o = s:option(Flag, "uot", translate("UDP over TCP"))
  244. o.description = translate("Enable the SUoT protocol, requires server support.")
  245. o.rmempty = true
  246. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  247. o.default = "0"
  248. o = s:option(Flag, "ivCheck", translate("Bloom Filter"))
  249. o.rmempty = true
  250. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  251. o.default = "1"
  252. -- Shadowsocks Plugin
  253. o = s:option(Value, "plugin", translate("Obfs"))
  254. o:value("none", translate("None"))
  255. if is_finded("obfs-local") then
  256. o:value("obfs-local", translate("obfs-local"))
  257. end
  258. if is_finded("v2ray-plugin") then
  259. o:value("v2ray-plugin", translate("v2ray-plugin"))
  260. end
  261. if is_finded("xray-plugin") then
  262. o:value("xray-plugin", translate("xray-plugin"))
  263. end
  264. o.rmempty = true
  265. o:depends("type", "ss")
  266. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  267. o.rmempty = true
  268. o:depends("type", "ss")
  269. o = s:option(ListValue, "protocol", translate("Protocol"))
  270. for _, v in ipairs(protocol) do
  271. o:value(v)
  272. end
  273. o.rmempty = true
  274. o:depends("type", "ssr")
  275. o = s:option(Value, "protocol_param", translate("Protocol param (optional)"))
  276. o:depends("type", "ssr")
  277. o = s:option(ListValue, "obfs", translate("Obfs"))
  278. for _, v in ipairs(obfs) do
  279. o:value(v)
  280. end
  281. o.rmempty = true
  282. o:depends("type", "ssr")
  283. o = s:option(Value, "obfs_param", translate("Obfs param (optional)"))
  284. o:depends("type", "ssr")
  285. -- [[ Hysteria2 ]]--
  286. o = s:option(Value, "hy2_auth", translate("Users Authentication"))
  287. o:depends("type", "hysteria")
  288. o.rmempty = false
  289. o = s:option(ListValue, "transport_protocol", translate("Protocol"))
  290. o:depends("type", "hysteria")
  291. o:value("udp", translate("udp"))
  292. o.default = "udp"
  293. o.rmempty = true
  294. o = s:option(Flag, "port_hopping", translate("Enable Port Hopping"))
  295. o:depends("type", "hysteria")
  296. o.rmempty = true
  297. o.default = "0"
  298. o = s:option(Value, "hopinterval", translate("Port Hopping Interval(Unit:Second)"))
  299. o:depends({type = "hysteria", port_hopping = true})
  300. o.datatype = "uinteger"
  301. o.rmempty = true
  302. o.default = "30"
  303. o = s:option(Value, "port_range", translate("Port Range"))
  304. o:depends({type = "hysteria", port_hopping = true})
  305. o.rmempty = true
  306. o = s:option(Flag, "lazy_mode", translate("Enable Lazy Mode"))
  307. o:depends("type", "hysteria")
  308. o.rmempty = true
  309. o.default = "0"
  310. o = s:option(Flag, "flag_obfs", translate("Enable Obfuscation"))
  311. o:depends("type", "hysteria")
  312. o.rmempty = true
  313. o.default = "0"
  314. o = s:option(Value, "obfs_type", translate("Obfuscation Type"))
  315. o:depends({type = "hysteria", flag_obfs = "1"})
  316. o.rmempty = true
  317. o.default = "salamander"
  318. o = s:option(Value, "salamander", translate("Obfuscation Password"))
  319. o:depends({type = "hysteria", flag_obfs = "1"})
  320. o.rmempty = true
  321. o.default = "cry_me_a_r1ver"
  322. o = s:option(Flag, "flag_quicparam", translate("Hysterir QUIC parameters"))
  323. o:depends("type", "hysteria")
  324. o.rmempty = true
  325. o.default = "0"
  326. --[[Hysteria2 QUIC parameters setting]]
  327. o = s:option(Value, "initstreamreceivewindow", translate("QUIC initStreamReceiveWindow"))
  328. o:depends({type = "hysteria", flag_quicparam = "1"})
  329. o.datatype = "uinteger"
  330. o.rmempty = true
  331. o.default = "8388608"
  332. o = s:option(Value, "maxstreamseceivewindow", translate("QUIC maxStreamReceiveWindow"))
  333. o:depends({type = "hysteria", flag_quicparam = "1"})
  334. o.datatype = "uinteger"
  335. o.rmempty = true
  336. o.default = "8388608"
  337. o = s:option(Value, "initconnreceivewindow", translate("QUIC initConnReceiveWindow"))
  338. o:depends({type = "hysteria", flag_quicparam = "1"})
  339. o.datatype = "uinteger"
  340. o.rmempty = true
  341. o.default = "20971520"
  342. o = s:option(Value, "maxconnreceivewindow", translate("QUIC maxConnReceiveWindow"))
  343. o:depends({type = "hysteria", flag_quicparam = "1"})
  344. o.datatype = "uinteger"
  345. o.rmempty = true
  346. o.default = "20971520"
  347. o = s:option(Value, "maxidletimeout", translate("QUIC maxIdleTimeout(Unit:second)"))
  348. o:depends({type = "hysteria", flag_quicparam = "1"})
  349. o.rmempty = true
  350. o.datatype = "uinteger"
  351. o.default = "30"
  352. o = s:option(Value, "keepaliveperiod", translate("The keep-alive period.(Unit:second)"))
  353. o:depends({type = "hysteria", flag_quicparam = "1"})
  354. o.rmempty = true
  355. o.datatype = "uinteger"
  356. o.default = "10"
  357. o = s:option(Flag, "disablepathmtudiscovery", translate("Disable Path MTU discovery"))
  358. o:depends({type = "hysteria", flag_quicparam = "1"})
  359. o.rmempty = true
  360. o.default = false
  361. --[[ Shadow-TLS Options ]]
  362. o = s:option(ListValue, "shadowtls_protocol", translate("shadowTLS protocol Version"))
  363. o:depends("type", "shadowtls")
  364. o:value("v3", translate("Enable V3 protocol."))
  365. o:value("v2", translate("Enable V2 protocol."))
  366. o.default = "v3"
  367. o.rmempty = true
  368. o = s:option(Flag, "strict", translate("TLS 1.3 Strict mode"))
  369. o:depends("type", "shadowtls")
  370. o.default = "1"
  371. o.rmempty = false
  372. o = s:option(Flag, "fastopen", translate("TCP Fast Open"))
  373. o:depends("type", "shadowtls")
  374. o.default = "0"
  375. o.rmempty = false
  376. o = s:option(Flag, "disable_nodelay", translate("Disable TCP No_delay"))
  377. o:depends("type", "shadowtls")
  378. o.default = "0"
  379. o.rmempty = true
  380. o = s:option(Value, "shadowtls_sni", translate("shadow-TLS SNI"))
  381. o:depends("type", "shadowtls")
  382. o.datatype = "host"
  383. o.rmempty = true
  384. o.default = ""
  385. --[[ add a ListValue for Choose chain type,sslocal or vmess ]]
  386. o = s:option(ListValue, "chain_type", translate("Shadow-TLS ChainPoxy type"))
  387. o:depends("type", "shadowtls")
  388. if is_finded("sslocal") then
  389. o:value("sslocal", translate("Shadowsocks-rust Version"))
  390. end
  391. if is_finded("xray") or is_finded("v2ray") then
  392. o:value("vmess", translate("Vmess Protocol"))
  393. end
  394. o.default = "sslocal"
  395. o.rmempty = false
  396. o = s:option(Value, "sslocal_password",translate("Shadowsocks password"))
  397. o:depends({type = "shadowtls", chain_type = "sslocal"})
  398. o.rmempty = true
  399. o = s:option(ListValue, "sslocal_method", translate("Encrypt Method"))
  400. o:depends({type = "shadowtls", chain_type = "sslocal"})
  401. for _, v in ipairs(encrypt_methods_ss) do
  402. o:value(v)
  403. end
  404. o = s:option(Value, "vmess_uuid", translate("Vmess UUID"))
  405. o:depends({type = "shadowtls", chain_type = "vmess"})
  406. o.rmempty = false
  407. o.default = uuid
  408. o = s:option(ListValue, "vmess_method", translate("Encrypt Method"))
  409. o:depends({type = "shadowtls", chain_type = "vmess"})
  410. for _, v in ipairs(securitys) do
  411. o:value(v, v:lower())
  412. end
  413. o.rmempty = true
  414. o.default="auto"
  415. -- [[ TUIC ]]
  416. -- TuicNameId
  417. o = s:option(Value, "tuic_uuid", translate("TUIC User UUID"))
  418. o.rmempty = true
  419. o.default = uuid
  420. o:depends("type", "tuic")
  421. --Tuic IP
  422. o = s:option(Value, "tuic_ip", translate("TUIC Server IP Address"))
  423. o.rmempty = true
  424. o.datatype = "ip4addr"
  425. o.default = ""
  426. o:depends("type", "tuic")
  427. -- Tuic Password
  428. o = s:option(Value, "tuic_passwd", translate("TUIC User Password"))
  429. o.rmempty = true
  430. o.default = ""
  431. o:depends("type", "tuic")
  432. o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
  433. o:depends("type", "tuic")
  434. o:value("native", translate("native UDP characteristics"))
  435. o:value("quic", translate("lossless UDP relay using QUIC streams"))
  436. o.default = "native"
  437. o.rmempty = true
  438. o = s:option(ListValue, "congestion_control", translate("Congestion control algorithm"))
  439. o:depends("type", "tuic")
  440. o:value("bbr", translate("BBR"))
  441. o:value("cubic", translate("CUBIC"))
  442. o:value("new_reno", translate("New Reno"))
  443. o.default = "cubic"
  444. o.rmempty = true
  445. o = s:option(Value, "heartbeat", translate("Heartbeat interval(second)"))
  446. o:depends("type", "tuic")
  447. o.datatype = "uinteger"
  448. o.default = "3"
  449. o.rmempty = true
  450. o = s:option(Value, "timeout", translate("Timeout for establishing a connection to server(second)"))
  451. o:depends("type", "tuic")
  452. o.datatype = "uinteger"
  453. o.default = "8"
  454. o.rmempty = true
  455. o = s:option(Value, "gc_interval", translate("Garbage collection interval(second)"))
  456. o:depends("type", "tuic")
  457. o.datatype = "uinteger"
  458. o.default = "3"
  459. o.rmempty = true
  460. o = s:option(Value, "gc_lifetime", translate("Garbage collection lifetime(second)"))
  461. o:depends("type", "tuic")
  462. o.datatype = "uinteger"
  463. o.default = "15"
  464. o.rmempty = true
  465. o = s:option(Value, "send_window", translate("TUIC send window"))
  466. o:depends("type", "tuic")
  467. o.datatype = "uinteger"
  468. o.default = 20971520
  469. o.rmempty = true
  470. o = s:option(Value, "receive_window", translate("TUIC receive window"))
  471. o:depends("type", "tuic")
  472. o.datatype = "uinteger"
  473. o.default = 10485760
  474. o.rmempty = true
  475. o = s:option(Flag, "disable_sni", translate("Disable SNI"))
  476. o:depends("type", "tuic")
  477. o.default = "0"
  478. o.rmempty = true
  479. o = s:option(Flag, "zero_rtt_handshake", translate("Enable 0-RTT QUIC handshake"))
  480. o:depends("type", "tuic")
  481. o.default = "0"
  482. o.rmempty = true
  483. -- Tuic settings for the local inbound socks5 server
  484. o = s:option(Flag, "tuic_dual_stack", translate("Dual-stack Listening Socket"))
  485. o:depends("type", "tuic")
  486. o.default = "0"
  487. o.rmempty = true
  488. o = s:option(Value, "tuic_max_package_size", translate("Maximum packet size the socks5 server can receive from external"))
  489. o:depends("type", "tuic")
  490. o.datatype = "uinteger"
  491. o.default = 1500
  492. o.rmempty = true
  493. -- AlterId
  494. o = s:option(Value, "alter_id", translate("AlterId"))
  495. o.datatype = "port"
  496. o.default = 16
  497. o.rmempty = true
  498. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  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.default = false
  793. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  794. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  795. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  796. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  797. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  798. o:depends({type = "v2ray", v2ray_protocol = "http"})
  799. o = s:option(Value, "concurrency", translate("concurrency"))
  800. o.datatype = "integer"
  801. o.rmempty = true
  802. o.default = "-1"
  803. o:depends("mux", true)
  804. o = s:option(Value, "xudpConcurrency", translate("xudpConcurrency"))
  805. o.datatype = "integer"
  806. o.rmempty = true
  807. o.default = "16"
  808. o:depends("mux", true)
  809. o = s:option(Value, "xudpProxyUDP443", translate("xudpProxyUDP443"))
  810. o.rmempty = true
  811. o.default = "reject"
  812. o:value("reject", translate("reject"))
  813. o:value("allow", translate("allow"))
  814. o:value("skip", translate("skip"))
  815. o:depends("mux", true)
  816. -- [[ MPTCP ]]--
  817. o = s:option(Flag, "mptcp", translate("MPTCP"))
  818. o.rmempty = false
  819. o.default = false
  820. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  821. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  822. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  823. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  824. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  825. o:depends({type = "v2ray", v2ray_protocol = "http"})
  826. -- [[ custom_tcpcongestion ]]--
  827. o = s:option(Value, "custom_tcpcongestion", translate("custom_tcpcongestion"))
  828. o.rmempty = true
  829. o.default = ""
  830. o:value("", translate("comment_tcpcongestion_disable"))
  831. o:value("bbr", translate("bbr"))
  832. o:value("cubic", translate("cubic"))
  833. o:value("reno", translate("reno"))
  834. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  835. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  836. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  837. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  838. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  839. o:depends({type = "v2ray", v2ray_protocol = "http"})
  840. -- [[ custom_sniffing ]]--
  841. o = s:option(Flag, "custom_sniffing", translate("custom_sniffing"))
  842. o.rmempty = false
  843. o.default = true
  844. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  845. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  846. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  847. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  848. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  849. o:depends({type = "v2ray", v2ray_protocol = "http"})
  850. -- [[ custom_domainsExcluded ]]--
  851. o = s:option(Flag, "custom_domainsExcluded", translate("custom_domainsExcluded"))
  852. o.rmempty = false
  853. o.default = true
  854. o:depends("custom_sniffing", true)
  855. -- [[ custom_routeOnly ]]--
  856. o = s:option(Flag, "custom_routeOnly", translate("custom_routeOnly"))
  857. o.rmempty = false
  858. o.default = false
  859. o:depends("custom_sniffing", true)
  860. -- [[ Cert ]]--
  861. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  862. o.rmempty = true
  863. o.default = "0"
  864. o:depends("type", "tuic")
  865. o:depends({type = "hysteria", insecure = false})
  866. o:depends({type = "trojan", tls = true, insecure = false})
  867. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  868. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  869. o.description = translate("If you have a self-signed certificate,please check the box")
  870. o = s:option(DummyValue, "upload", translate("Upload"))
  871. o.template = "shadowsocksr/certupload"
  872. o:depends("certificate", 1)
  873. cert_dir = "/etc/ssl/private/"
  874. local path
  875. luci.http.setfilehandler(function(meta, chunk, eof)
  876. if not fd then
  877. if (not meta) or (not meta.name) or (not meta.file) then
  878. return
  879. end
  880. fd = nixio.open(cert_dir .. meta.file, "w")
  881. if not fd then
  882. path = translate("Create upload file error.")
  883. return
  884. end
  885. end
  886. if chunk and fd then
  887. fd:write(chunk)
  888. end
  889. if eof and fd then
  890. fd:close()
  891. fd = nil
  892. path = '/etc/ssl/private/' .. meta.file .. ''
  893. end
  894. end)
  895. if luci.http.formvalue("upload") then
  896. local f = luci.http.formvalue("ulfile")
  897. if #f <= 0 then
  898. path = translate("No specify upload file.")
  899. end
  900. end
  901. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  902. o:depends("certificate", 1)
  903. o:value("/etc/ssl/private/ca.pem")
  904. o.description = translate("Please confirm the current certificate path")
  905. o.default = "/etc/ssl/private/ca.pem"
  906. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  907. o.rmempty = true
  908. o.default = "0"
  909. o:depends("type", "ssr")
  910. o:depends("type", "ss")
  911. o:depends("type", "trojan")
  912. o:depends("type", "hysteria")
  913. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  914. o.rmempty = false
  915. o.default = "1"
  916. o = s:option(Value, "local_port", translate("Local Port"))
  917. o.datatype = "port"
  918. o.default = 1234
  919. o.rmempty = false
  920. if is_finded("kcptun-client") then
  921. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  922. o.rmempty = true
  923. o.default = "0"
  924. o:depends("type", "ssr")
  925. o:depends("type", "ss")
  926. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  927. o.datatype = "port"
  928. o.default = 4000
  929. o:depends("type", "ssr")
  930. o:depends("type", "ss")
  931. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  932. o.password = true
  933. o:depends("type", "ssr")
  934. o:depends("type", "ss")
  935. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  936. o.default = "--nocomp"
  937. o:depends("type", "ssr")
  938. o:depends("type", "ss")
  939. end
  940. return m