client-config.lua 22 KB

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