client-config.lua 23 KB

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