client-config.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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 flows = {
  108. -- xtls
  109. "xtls-rprx-origin",
  110. "xtls-rprx-origin-udp443",
  111. "xtls-rprx-direct",
  112. "xtls-rprx-direct-udp443",
  113. "xtls-rprx-splice",
  114. "xtls-rprx-splice-udp443"
  115. }
  116. m = Map("shadowsocksr", translate("Edit ShadowSocksR Server"))
  117. m.redirect = luci.dispatcher.build_url("admin/services/shadowsocksr/servers")
  118. if m.uci:get("shadowsocksr", sid) ~= "servers" then
  119. luci.http.redirect(m.redirect)
  120. return
  121. end
  122. -- [[ Servers Setting ]]--
  123. s = m:section(NamedSection, sid, "servers")
  124. s.anonymous = true
  125. s.addremove = false
  126. o = s:option(DummyValue, "ssr_url", "SS/SSR/V2RAY/TROJAN URL")
  127. o.rawhtml = true
  128. o.template = "shadowsocksr/ssrurl"
  129. o.value = sid
  130. o = s:option(ListValue, "type", translate("Server Node Type"))
  131. if is_finded("xray") or is_finded("v2ray") then
  132. o:value("v2ray", translate("V2Ray/XRay"))
  133. end
  134. if is_finded("ssr-redir") then
  135. o:value("ssr", translate("ShadowsocksR"))
  136. end
  137. if is_finded("sslocal") or is_finded("ss-redir") then
  138. o:value("ss", translate("Shadowsocks New Version"))
  139. end
  140. if is_finded("trojan") then
  141. o:value("trojan", translate("Trojan"))
  142. end
  143. if is_finded("naive") then
  144. o:value("naiveproxy", translate("NaiveProxy"))
  145. end
  146. if is_finded("hysteria") then
  147. o:value("hysteria", translate("Hysteria"))
  148. end
  149. if is_finded("ipt2socks") then
  150. o:value("socks5", translate("Socks5"))
  151. end
  152. if is_finded("redsocks2") then
  153. o:value("tun", translate("Network Tunnel"))
  154. end
  155. o.description = translate("Using incorrect encryption mothod may causes service fail to start")
  156. o = s:option(Value, "alias", translate("Alias(optional)"))
  157. o = s:option(ListValue, "iface", translate("Network interface to use"))
  158. for _, e in ipairs(luci.sys.net.devices()) do
  159. if e ~= "lo" then
  160. o:value(e)
  161. end
  162. end
  163. o:depends("type", "tun")
  164. o.description = translate("Redirect traffic to this network interface")
  165. o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol"))
  166. o:value("vless", translate("VLESS"))
  167. o:value("vmess", translate("VMess"))
  168. o:value("trojan", translate("Trojan"))
  169. o:value("shadowsocks", translate("Shadowsocks"))
  170. if is_installed("sagernet-core") then
  171. o:value("shadowsocksr", translate("ShadowsocksR"))
  172. o:value("wireguard", translate("WireGuard"))
  173. end
  174. o:value("socks", translate("Socks"))
  175. o:value("http", translate("HTTP"))
  176. o:depends("type", "v2ray")
  177. o = s:option(Value, "server", translate("Server Address"))
  178. o.datatype = "host"
  179. o.rmempty = false
  180. o:depends("type", "ssr")
  181. o:depends("type", "ss")
  182. o:depends("type", "v2ray")
  183. o:depends("type", "trojan")
  184. o:depends("type", "naiveproxy")
  185. o:depends("type", "hysteria")
  186. o:depends("type", "socks5")
  187. o = s:option(Value, "server_port", translate("Server Port"))
  188. o.datatype = "port"
  189. o.rmempty = false
  190. o:depends("type", "ssr")
  191. o:depends("type", "ss")
  192. o:depends("type", "v2ray")
  193. o:depends("type", "trojan")
  194. o:depends("type", "naiveproxy")
  195. o:depends("type", "hysteria")
  196. o:depends("type", "socks5")
  197. o = s:option(Flag, "auth_enable", translate("Enable Authentication"))
  198. o.rmempty = false
  199. o.default = "0"
  200. o:depends("type", "socks5")
  201. o:depends({type = "v2ray", v2ray_protocol = "http"})
  202. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  203. o = s:option(Value, "username", translate("Username"))
  204. o.rmempty = true
  205. o:depends("type", "naiveproxy")
  206. o:depends({type = "socks5", auth_enable = true})
  207. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  208. o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
  209. o = s:option(Value, "password", translate("Password"))
  210. o.password = true
  211. o.rmempty = true
  212. o:depends("type", "ssr")
  213. o:depends("type", "ss")
  214. o:depends("type", "trojan")
  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", socks_ver = "5", auth_enable = true})
  219. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  220. o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
  221. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  222. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  223. for _, v in ipairs(encrypt_methods) do
  224. o:value(v)
  225. end
  226. o.rmempty = true
  227. o:depends("type", "ssr")
  228. o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
  229. o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
  230. for _, v in ipairs(encrypt_methods_ss) do
  231. o:value(v)
  232. end
  233. o.rmempty = true
  234. o:depends("type", "ss")
  235. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  236. o = s:option(Flag, "uot", translate("UDP over TCP"))
  237. o.description = translate("Enable the SUoT protocol, requires server support.")
  238. o.rmempty = true
  239. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  240. o.default = "0"
  241. o = s:option(Flag, "ivCheck", translate("Bloom Filter"))
  242. o.rmempty = true
  243. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  244. o.default = "1"
  245. -- Shadowsocks Plugin
  246. o = s:option(Value, "plugin", translate("Obfs"))
  247. o:value("none", translate("None"))
  248. if is_finded("obfs-local") or is_installed("sagernet-core") then
  249. o:value("obfs-local", translate("obfs-local"))
  250. end
  251. if is_finded("v2ray-plugin") or is_installed("sagernet-core") then
  252. o:value("v2ray-plugin", translate("v2ray-plugin"))
  253. end
  254. if is_finded("xray-plugin") then
  255. o:value("xray-plugin", translate("xray-plugin"))
  256. end
  257. o.rmempty = true
  258. o:depends("type", "ss")
  259. if is_installed("sagernet-core") then
  260. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  261. end
  262. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  263. o.rmempty = true
  264. o:depends("type", "ss")
  265. if is_installed("sagernet-core") then
  266. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  267. end
  268. o = s:option(ListValue, "protocol", translate("Protocol"))
  269. for _, v in ipairs(protocol) do
  270. o:value(v)
  271. end
  272. o.rmempty = true
  273. o:depends("type", "ssr")
  274. o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
  275. o = s:option(Value, "protocol_param", translate("Protocol param (optional)"))
  276. o:depends("type", "ssr")
  277. o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
  278. o = s:option(ListValue, "obfs", translate("Obfs"))
  279. for _, v in ipairs(obfs) do
  280. o:value(v)
  281. end
  282. o.rmempty = true
  283. o:depends("type", "ssr")
  284. o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
  285. o = s:option(Value, "obfs_param", translate("Obfs param (optional)"))
  286. o:depends("type", "ssr")
  287. o:depends({type = "v2ray", v2ray_protocol = "shadowsocksr"})
  288. -- [[ Hysteria ]]--
  289. o = s:option(ListValue, "hysteria_protocol", translate("Protocol"))
  290. o:depends("type", "hysteria")
  291. o:value("udp", translate("udp"))
  292. o:value("wechat-video", translate("wechat-video"))
  293. o:value("faketcp", translate("faketcp"))
  294. o.default = "udp"
  295. o.rmempty = true
  296. o = s:option(ListValue, "auth_type", translate("Authentication type"))
  297. o:depends("type", "hysteria")
  298. o:value("0", translate("disabled"))
  299. o:value("1", translate("base64"))
  300. o:value("2", translate("string"))
  301. o.rmempty = true
  302. o = s:option(Value, "auth_payload", translate("Authentication payload"))
  303. o:depends({type = "hysteria", auth_type = "1"})
  304. o:depends({type = "hysteria", auth_type = "2"})
  305. o.rmempty = true
  306. o = s:option(Value, "recv_window", translate("QUIC connection receive window"))
  307. o.datatype = "uinteger"
  308. o:depends("type", "hysteria")
  309. o.rmempty = true
  310. o = s:option(Value, "recv_window_conn", translate("QUIC stream receive window"))
  311. o.datatype = "uinteger"
  312. o:depends("type", "hysteria")
  313. o.rmempty = true
  314. o = s:option(Flag, "disable_mtu_discovery", translate("Disable Path MTU discovery"))
  315. o:depends("type", "hysteria")
  316. o.rmempty = true
  317. -- VmessId
  318. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  319. o.rmempty = true
  320. o.default = uuid
  321. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  322. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  323. -- VLESS Encryption
  324. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  325. o.rmempty = true
  326. o.default = "none"
  327. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  328. -- 加密方式
  329. o = s:option(ListValue, "security", translate("Encrypt Method"))
  330. for _, v in ipairs(securitys) do
  331. o:value(v, v:upper())
  332. end
  333. o.rmempty = true
  334. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  335. -- SOCKS Version
  336. o = s:option(ListValue, "socks_ver", translate("Socks Version"))
  337. o:value("4", "Socks4")
  338. o:value("4a", "Socks4A")
  339. o:value("5", "Socks5")
  340. o.rmempty = true
  341. o.default = "5"
  342. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  343. -- 传输协议
  344. o = s:option(ListValue, "transport", translate("Transport"))
  345. o:value("tcp", "TCP")
  346. o:value("kcp", "mKCP")
  347. o:value("ws", "WebSocket")
  348. o:value("h2", "HTTP/2")
  349. o:value("quic", "QUIC")
  350. o:value("grpc", "gRPC")
  351. o.rmempty = true
  352. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  353. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  354. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  355. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  356. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  357. o:depends({type = "v2ray", v2ray_protocol = "http"})
  358. -- [[ TCP部分 ]]--
  359. -- TCP伪装
  360. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  361. o:depends("transport", "tcp")
  362. o:value("none", translate("None"))
  363. o:value("http", "HTTP")
  364. o.rmempty = true
  365. -- HTTP域名
  366. o = s:option(Value, "http_host", translate("HTTP Host"))
  367. o:depends("tcp_guise", "http")
  368. o.rmempty = true
  369. -- HTTP路径
  370. o = s:option(Value, "http_path", translate("HTTP Path"))
  371. o:depends("tcp_guise", "http")
  372. o.rmempty = true
  373. -- [[ WS部分 ]]--
  374. -- WS域名
  375. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  376. o:depends({transport = "ws", tls = false})
  377. o.datatype = "hostname"
  378. o.rmempty = true
  379. -- WS路径
  380. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  381. o:depends("transport", "ws")
  382. o.rmempty = true
  383. if is_finded("v2ray") then
  384. -- 启用WS前置数据
  385. o = s:option(Flag, "ws_ed_enable", translate("Enable early data"))
  386. o:depends("transport", "ws")
  387. -- WS前置数据
  388. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  389. o:depends("ws_ed_enable", true)
  390. o.datatype = "uinteger"
  391. o.default = 2048
  392. o.rmempty = true
  393. -- WS前置数据标头
  394. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  395. o:depends("ws_ed_enable", true)
  396. o.default = "Sec-WebSocket-Protocol"
  397. o.rmempty = true
  398. end
  399. -- [[ H2部分 ]]--
  400. -- H2域名
  401. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  402. o:depends("transport", "h2")
  403. o.rmempty = true
  404. -- H2路径
  405. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  406. o:depends("transport", "h2")
  407. o.rmempty = true
  408. -- gRPC
  409. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  410. o:depends("transport", "grpc")
  411. o.rmempty = true
  412. if is_finded("xray") or is_installed("sagernet-core") then
  413. -- gPRC模式
  414. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  415. o:depends("transport", "grpc")
  416. o:value("gun", translate("Gun"))
  417. o:value("multi", translate("Multi"))
  418. if is_installed("sagernet-core") then
  419. o:value("raw", translate("Raw"))
  420. end
  421. o.rmempty = true
  422. end
  423. if is_finded("xray") or is_installed("sagernet-core") then
  424. -- gRPC初始窗口
  425. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  426. o.datatype = "uinteger"
  427. o:depends("transport", "grpc")
  428. o.default = 0
  429. o.rmempty = true
  430. -- H2/gRPC健康检查
  431. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  432. o:depends("transport", "h2")
  433. o:depends("transport", "grpc")
  434. o.rmempty = true
  435. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  436. o.datatype = "uinteger"
  437. o:depends({health_check = true, transport = "h2"})
  438. o.default = 60
  439. o.rmempty = true
  440. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  441. o.datatype = "uinteger"
  442. o:depends({health_check = true, transport = "grpc"})
  443. o.default = 60
  444. o.rmempty = true
  445. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  446. o.datatype = "uinteger"
  447. o:depends("health_check", 1)
  448. o.default = 20
  449. o.rmempty = true
  450. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  451. o:depends({health_check = true, transport = "grpc"})
  452. o.rmempty = true
  453. end
  454. -- [[ QUIC部分 ]]--
  455. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  456. o:depends("transport", "quic")
  457. o:value("none", translate("None"))
  458. o:value("aes-128-gcm", translate("aes-128-gcm"))
  459. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  460. o.rmempty = true
  461. o = s:option(Value, "quic_key", translate("QUIC Key"))
  462. o:depends("transport", "quic")
  463. o.rmempty = true
  464. o = s:option(ListValue, "quic_guise", translate("Header"))
  465. o:depends("transport", "quic")
  466. o.rmempty = true
  467. o:value("none", translate("None"))
  468. o:value("srtp", translate("VideoCall (SRTP)"))
  469. o:value("utp", translate("BitTorrent (uTP)"))
  470. o:value("wechat-video", translate("WechatVideo"))
  471. o:value("dtls", translate("DTLS 1.2"))
  472. o:value("wireguard", translate("WireGuard"))
  473. -- [[ mKCP部分 ]]--
  474. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  475. o:depends("transport", "kcp")
  476. o:value("none", translate("None"))
  477. o:value("srtp", translate("VideoCall (SRTP)"))
  478. o:value("utp", translate("BitTorrent (uTP)"))
  479. o:value("wechat-video", translate("WechatVideo"))
  480. o:value("dtls", translate("DTLS 1.2"))
  481. o:value("wireguard", translate("WireGuard"))
  482. o.rmempty = true
  483. o = s:option(Value, "mtu", translate("MTU"))
  484. o.datatype = "uinteger"
  485. o:depends("transport", "kcp")
  486. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  487. -- o.default = 1350
  488. o.rmempty = true
  489. o = s:option(Value, "tti", translate("TTI"))
  490. o.datatype = "uinteger"
  491. o:depends("transport", "kcp")
  492. o.default = 50
  493. o.rmempty = true
  494. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity"))
  495. o.datatype = "uinteger"
  496. o:depends("transport", "kcp")
  497. o:depends("type", "hysteria")
  498. o.default = 5
  499. o.rmempty = true
  500. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity"))
  501. o.datatype = "uinteger"
  502. o:depends("transport", "kcp")
  503. o:depends("type", "hysteria")
  504. o.default = 20
  505. o.rmempty = true
  506. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  507. o.datatype = "uinteger"
  508. o:depends("transport", "kcp")
  509. o.default = 2
  510. o.rmempty = true
  511. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  512. o.datatype = "uinteger"
  513. o:depends("transport", "kcp")
  514. o.default = 2
  515. o.rmempty = true
  516. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  517. o:depends("transport", "kcp")
  518. o:depends("type", "hysteria")
  519. o.rmempty = true
  520. o = s:option(Flag, "congestion", translate("Congestion"))
  521. o:depends("transport", "kcp")
  522. o.rmempty = true
  523. -- [[ WireGuard 部分 ]]--
  524. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  525. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  526. o.rmempty = true
  527. o = s:option(Value, "private_key", translate("Private key"))
  528. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  529. o.password = true
  530. o.rmempty = true
  531. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  532. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  533. o.rmempty = true
  534. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  535. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  536. o.password = true
  537. o.rmempty = true
  538. -- [[ TLS ]]--
  539. o = s:option(Flag, "tls", translate("TLS"))
  540. o.rmempty = true
  541. o.default = "0"
  542. o:depends({type = "v2ray", v2ray_protocol = "vless", xtls = false})
  543. o:depends({type = "v2ray", v2ray_protocol = "vmess", xtls = false})
  544. o:depends({type = "v2ray", v2ray_protocol = "trojan", xtls = false})
  545. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", xtls = false})
  546. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", xtls = false})
  547. o:depends({type = "v2ray", v2ray_protocol = "http", xtls = false})
  548. o:depends("type", "trojan")
  549. -- XTLS
  550. if is_finded("xray") then
  551. o = s:option(Flag, "xtls", translate("XTLS"))
  552. o.rmempty = true
  553. o.default = "0"
  554. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = false})
  555. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "kcp", tls = false})
  556. o:depends({type = "v2ray", v2ray_protocol = "trojan", transport = "tcp", tls = false})
  557. o:depends({type = "v2ray", v2ray_protocol = "trojan", transport = "kcp", tls = false})
  558. end
  559. -- Flow
  560. o = s:option(Value, "vless_flow", translate("Flow"))
  561. for _, v in ipairs(flows) do
  562. o:value(v, translate(v))
  563. end
  564. o.rmempty = true
  565. o.default = "xtls-rprx-splice"
  566. o:depends("xtls", true)
  567. -- [[ TLS部分 ]] --
  568. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  569. o:depends({type = "trojan", tls = true})
  570. o.default = "0"
  571. if is_finded("xray") then
  572. -- [[ uTLS ]]--
  573. o = s:option(ListValue, "fingerprint", translate("Finger Print"))
  574. o:value("disable", translate("disable"))
  575. o:value("firefox", translate("firefox"))
  576. o:value("chrome", translate("chrome"))
  577. o:value("safari", translate("safari"))
  578. o:value("randomized", translate("randomized"))
  579. o:depends({type = "v2ray", tls = true})
  580. o.default = "disable"
  581. end
  582. o = s:option(Value, "tls_host", translate("TLS Host"))
  583. o.datatype = "hostname"
  584. o:depends("tls", true)
  585. o:depends("xtls", true)
  586. o:depends("type", "hysteria")
  587. o.rmempty = true
  588. o = s:option(Value, "quic_tls_alpn", translate("QUIC TLS ALPN"))
  589. o:depends("type", "hysteria")
  590. o.rmempty = true
  591. -- [[ allowInsecure ]]--
  592. o = s:option(Flag, "insecure", translate("allowInsecure"))
  593. o.rmempty = false
  594. o:depends("tls", true)
  595. o:depends("xtls", true)
  596. o:depends("type", "hysteria")
  597. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  598. -- [[ Mux ]]--
  599. o = s:option(Flag, "mux", translate("Mux"))
  600. o.rmempty = false
  601. o:depends({type = "v2ray", v2ray_protocol = "vless", xtls = false})
  602. o:depends({type = "v2ray", v2ray_protocol = "vmess", xtls = false})
  603. o:depends({type = "v2ray", v2ray_protocol = "trojan", xtls = false})
  604. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", xtls = false})
  605. o:depends({type = "v2ray", v2ray_protocol = "socks", xtls = false})
  606. o:depends({type = "v2ray", v2ray_protocol = "http", xtls = false})
  607. o = s:option(Value, "concurrency", translate("Concurrency"))
  608. o.datatype = "uinteger"
  609. o.rmempty = true
  610. o.default = "4"
  611. o:depends("mux", "1")
  612. o:depends("type", "naiveproxy")
  613. -- [[ Cert ]]--
  614. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  615. o.rmempty = true
  616. o.default = "0"
  617. o:depends({type = "hysteria", insecure = false})
  618. o:depends({type = "trojan", tls = true, insecure = false})
  619. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  620. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  621. o:depends({type = "v2ray", v2ray_protocol = "vmess", xtls = true, insecure = false})
  622. o:depends({type = "v2ray", v2ray_protocol = "vless", xtls = true, insecure = false})
  623. o.description = translate("If you have a self-signed certificate,please check the box")
  624. o = s:option(DummyValue, "upload", translate("Upload"))
  625. o.template = "shadowsocksr/certupload"
  626. o:depends("certificate", 1)
  627. cert_dir = "/etc/ssl/private/"
  628. local path
  629. luci.http.setfilehandler(function(meta, chunk, eof)
  630. if not fd then
  631. if (not meta) or (not meta.name) or (not meta.file) then
  632. return
  633. end
  634. fd = nixio.open(cert_dir .. meta.file, "w")
  635. if not fd then
  636. path = translate("Create upload file error.")
  637. return
  638. end
  639. end
  640. if chunk and fd then
  641. fd:write(chunk)
  642. end
  643. if eof and fd then
  644. fd:close()
  645. fd = nil
  646. path = '/etc/ssl/private/' .. meta.file .. ''
  647. end
  648. end)
  649. if luci.http.formvalue("upload") then
  650. local f = luci.http.formvalue("ulfile")
  651. if #f <= 0 then
  652. path = translate("No specify upload file.")
  653. end
  654. end
  655. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  656. o:depends("certificate", 1)
  657. o:value("/etc/ssl/private/ca.pem")
  658. o.description = translate("Please confirm the current certificate path")
  659. o.default = "/etc/ssl/private/ca.pem"
  660. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  661. o.rmempty = true
  662. o.default = "0"
  663. o:depends("type", "ssr")
  664. o:depends("type", "ss")
  665. o:depends("type", "trojan")
  666. if is_installed("sagernet-core") then
  667. o = s:option(ListValue, "packet_encoding", translate("Packet Encoding"))
  668. o:value("none", translate("none"))
  669. o:value("packet", translate("packet (v2ray-core v5+)"))
  670. o:value("xudp", translate("xudp (Xray-core)"))
  671. o.default = "xudp"
  672. o.rmempty = true
  673. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  674. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  675. end
  676. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  677. o.rmempty = false
  678. o.default = "1"
  679. o = s:option(Value, "local_port", translate("Local Port"))
  680. o.datatype = "port"
  681. o.default = 1234
  682. o.rmempty = false
  683. if is_finded("kcptun-client") then
  684. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  685. o.rmempty = true
  686. o.default = "0"
  687. o:depends("type", "ssr")
  688. o:depends("type", "ss")
  689. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  690. o.datatype = "port"
  691. o.default = 4000
  692. o:depends("type", "ssr")
  693. o:depends("type", "ss")
  694. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  695. o.password = true
  696. o:depends("type", "ssr")
  697. o:depends("type", "ss")
  698. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  699. o.default = "--nocomp"
  700. o:depends("type", "ssr")
  701. o:depends("type", "ss")
  702. end
  703. return m