client-config.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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("sslocal") or is_finded("ss-redir") then
  134. o:value("ss", translate("Shadowsocks New Version"))
  135. end
  136. if is_finded("trojan") then
  137. o:value("trojan", translate("Trojan"))
  138. end
  139. if is_finded("naive") then
  140. o:value("naiveproxy", translate("NaiveProxy"))
  141. end
  142. if is_finded("hysteria") then
  143. o:value("hysteria", translate("Hysteria"))
  144. end
  145. if is_finded("tuic-client") then
  146. o:value("tuic", translate("TUIC"))
  147. end
  148. if is_finded("ipt2socks") then
  149. o:value("socks5", translate("Socks5"))
  150. end
  151. if is_finded("redsocks2") then
  152. o:value("tun", translate("Network Tunnel"))
  153. end
  154. o.description = translate("Using incorrect encryption mothod may causes service fail to start")
  155. o = s:option(Value, "alias", translate("Alias(optional)"))
  156. o = s:option(ListValue, "iface", translate("Network interface to use"))
  157. for _, e in ipairs(luci.sys.net.devices()) do
  158. if e ~= "lo" then
  159. o:value(e)
  160. end
  161. end
  162. o:depends("type", "tun")
  163. o.description = translate("Redirect traffic to this network interface")
  164. o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol"))
  165. o:value("vless", translate("VLESS"))
  166. o:value("vmess", translate("VMess"))
  167. o:value("trojan", translate("Trojan"))
  168. o:value("shadowsocks", translate("Shadowsocks"))
  169. if is_finded("xray") then
  170. o:value("wireguard", translate("WireGuard"))
  171. end
  172. o:value("socks", translate("Socks"))
  173. o:value("http", translate("HTTP"))
  174. o:depends("type", "v2ray")
  175. o = s:option(Value, "server", translate("Server Address"))
  176. o.datatype = "host"
  177. o.rmempty = false
  178. o:depends("type", "ssr")
  179. o:depends("type", "ss")
  180. o:depends("type", "v2ray")
  181. o:depends("type", "trojan")
  182. o:depends("type", "naiveproxy")
  183. o:depends("type", "hysteria")
  184. o:depends("type", "tuic")
  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", "tuic")
  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", "tuic")
  207. o:depends({type = "socks5", auth_enable = true})
  208. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  209. o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
  210. o = s:option(Value, "password", translate("Password"))
  211. o.password = true
  212. o.rmempty = true
  213. o:depends("type", "ssr")
  214. o:depends("type", "ss")
  215. o:depends("type", "trojan")
  216. o:depends("type", "naiveproxy")
  217. o:depends("type", "tuic")
  218. o:depends({type = "socks5", auth_enable = true})
  219. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  220. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", auth_enable = true})
  221. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  222. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  223. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  224. for _, v in ipairs(encrypt_methods) do
  225. o:value(v)
  226. end
  227. o.rmempty = true
  228. o:depends("type", "ssr")
  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") then
  249. o:value("obfs-local", translate("obfs-local"))
  250. end
  251. if is_finded("v2ray-plugin") 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. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  260. o.rmempty = true
  261. o:depends("type", "ss")
  262. o = s:option(ListValue, "protocol", translate("Protocol"))
  263. for _, v in ipairs(protocol) do
  264. o:value(v)
  265. end
  266. o.rmempty = true
  267. o:depends("type", "ssr")
  268. o = s:option(Value, "protocol_param", translate("Protocol param (optional)"))
  269. o:depends("type", "ssr")
  270. o = s:option(ListValue, "obfs", translate("Obfs"))
  271. for _, v in ipairs(obfs) do
  272. o:value(v)
  273. end
  274. o.rmempty = true
  275. o:depends("type", "ssr")
  276. o = s:option(Value, "obfs_param", translate("Obfs param (optional)"))
  277. o:depends("type", "ssr")
  278. -- [[ Hysteria ]]--
  279. o = s:option(ListValue, "hysteria_protocol", translate("Protocol"))
  280. o:depends("type", "hysteria")
  281. o:value("udp", translate("udp"))
  282. o:value("wechat-video", translate("wechat-video"))
  283. o:value("faketcp", translate("faketcp"))
  284. o.default = "udp"
  285. o.rmempty = true
  286. o = s:option(ListValue, "auth_type", translate("Authentication type"))
  287. o:depends("type", "hysteria")
  288. o:value("0", translate("disabled"))
  289. o:value("1", translate("base64"))
  290. o:value("2", translate("string"))
  291. o.rmempty = true
  292. o = s:option(Value, "auth_payload", translate("Authentication payload"))
  293. o:depends({type = "hysteria", auth_type = "1"})
  294. o:depends({type = "hysteria", auth_type = "2"})
  295. o.rmempty = true
  296. o = s:option(Value, "recv_window", translate("QUIC connection receive window"))
  297. o.datatype = "uinteger"
  298. o:depends("type", "hysteria")
  299. o.rmempty = true
  300. o = s:option(Value, "recv_window_conn", translate("QUIC stream receive window"))
  301. o.datatype = "uinteger"
  302. o:depends("type", "hysteria")
  303. o.rmempty = true
  304. o = s:option(Flag, "disable_mtu_discovery", translate("Disable Path MTU discovery"))
  305. o:depends("type", "hysteria")
  306. o.rmempty = true
  307. o = s:option(Flag, "lazy_start", translate("Lazy Start"))
  308. o:depends("type", "hysteria")
  309. o.rmempty = true
  310. o.default = "0"
  311. -- [[ TUIC ]]
  312. -- TuicNameId
  313. o = s:option(Value, "tuic_uuid", translate("TUIC user UUID"))
  314. o.rmempty = true
  315. o.default = uuid
  316. o:depends("type", "tuic")
  317. o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
  318. o:depends("type", "tuic")
  319. o:value("native", translate("native"))
  320. o:value("quic", translate("QUIC"))
  321. o.default = "native"
  322. o.rmempty = true
  323. o = s:option(ListValue, "congestion_controller", translate("Congestion control algorithm"))
  324. o:depends("type", "tuic")
  325. o:value("bbr", translate("BBR"))
  326. o:value("cubic", translate("CUBIC"))
  327. o:value("new_reno", translate("New Reno"))
  328. o.default = "cubic"
  329. o.rmempty = true
  330. o = s:option(Value, "heartbeat_interval", translate("Heartbeat interval"))
  331. o:depends("type", "tuic")
  332. --o.datatype = "uinteger"
  333. o.default = "3s"
  334. o.rmempty = true
  335. o = s:option(Flag, "disable_sni", translate("Disable SNI"))
  336. o:depends("type", "tuic")
  337. o.default = 0
  338. o.rmempty = true
  339. o = s:option(Flag, "reduce_rtt", translate("Enable 0-RTT QUIC handshake"))
  340. o:depends("type", "tuic")
  341. o.default = 0
  342. o.rmempty = false
  343. o = s:option(Value, "send_window", translate("TUIC send window"))
  344. o.datatype = "uinteger"
  345. o:depends("type", "tuic")
  346. o.default = 16777216
  347. o.rmempty = true
  348. o = s:option(Value, "receive_window", translate("TUIC receive window"))
  349. o.datatype = "uinteger"
  350. o:depends("type", "tuic")
  351. o.default = 8388608
  352. o.rmempty = true
  353. o = s:option(Value, "max_udp_relay_packet_size", translate("Max UDP relay packet size"))
  354. o:depends("type", "tuic")
  355. o.datatype = "uinteger"
  356. o.default = "1500"
  357. o.rmempty = true
  358. -- VmessId
  359. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  360. o.rmempty = true
  361. o.default = uuid
  362. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  363. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  364. -- VLESS Encryption
  365. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  366. o.rmempty = true
  367. o.default = "none"
  368. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  369. -- 加密方式
  370. o = s:option(ListValue, "security", translate("Encrypt Method"))
  371. for _, v in ipairs(securitys) do
  372. o:value(v, v:upper())
  373. end
  374. o.rmempty = true
  375. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  376. -- SOCKS Version
  377. o = s:option(ListValue, "socks_ver", translate("Socks Version"))
  378. o:value("4", "Socks4")
  379. o:value("4a", "Socks4A")
  380. o:value("5", "Socks5")
  381. o.rmempty = true
  382. o.default = "5"
  383. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  384. -- 传输协议
  385. o = s:option(ListValue, "transport", translate("Transport"))
  386. o:value("tcp", "TCP")
  387. o:value("kcp", "mKCP")
  388. o:value("ws", "WebSocket")
  389. o:value("h2", "HTTP/2")
  390. o:value("quic", "QUIC")
  391. o:value("grpc", "gRPC")
  392. o.rmempty = true
  393. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  394. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  395. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  396. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  397. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  398. o:depends({type = "v2ray", v2ray_protocol = "http"})
  399. -- [[ TCP部分 ]]--
  400. -- TCP伪装
  401. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  402. o:depends("transport", "tcp")
  403. o:value("none", translate("None"))
  404. o:value("http", "HTTP")
  405. o.rmempty = true
  406. -- HTTP域名
  407. o = s:option(Value, "http_host", translate("HTTP Host"))
  408. o:depends("tcp_guise", "http")
  409. o.rmempty = true
  410. -- HTTP路径
  411. o = s:option(Value, "http_path", translate("HTTP Path"))
  412. o:depends("tcp_guise", "http")
  413. o.rmempty = true
  414. -- [[ WS部分 ]]--
  415. -- WS域名
  416. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  417. o:depends({transport = "ws", tls = false})
  418. o.datatype = "hostname"
  419. o.rmempty = true
  420. -- WS路径
  421. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  422. o:depends("transport", "ws")
  423. o.rmempty = true
  424. if is_finded("v2ray") then
  425. -- WS前置数据
  426. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  427. o:depends("ws_ed_enable", true)
  428. o.datatype = "uinteger"
  429. o:value("2048")
  430. o.rmempty = true
  431. -- WS前置数据标头
  432. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  433. o:depends("ws_ed_enable", true)
  434. o:value("Sec-WebSocket-Protocol")
  435. o.rmempty = true
  436. end
  437. -- [[ H2部分 ]]--
  438. -- H2域名
  439. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  440. o:depends("transport", "h2")
  441. o.rmempty = true
  442. -- H2路径
  443. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  444. o:depends("transport", "h2")
  445. o.rmempty = true
  446. -- gRPC
  447. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  448. o:depends("transport", "grpc")
  449. o.rmempty = true
  450. if is_finded("xray") then
  451. -- gPRC模式
  452. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  453. o:depends("transport", "grpc")
  454. o:value("gun", translate("Gun"))
  455. o:value("multi", translate("Multi"))
  456. o.rmempty = true
  457. end
  458. if is_finded("xray") then
  459. -- gRPC初始窗口
  460. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  461. o.datatype = "uinteger"
  462. o:depends("transport", "grpc")
  463. o.default = 0
  464. o.rmempty = true
  465. -- H2/gRPC健康检查
  466. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  467. o:depends("transport", "h2")
  468. o:depends("transport", "grpc")
  469. o.rmempty = true
  470. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  471. o.datatype = "uinteger"
  472. o:depends({health_check = true, transport = "h2"})
  473. o.default = 60
  474. o.rmempty = true
  475. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  476. o.datatype = "uinteger"
  477. o:depends({health_check = true, transport = "grpc"})
  478. o.default = 60
  479. o.rmempty = true
  480. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  481. o.datatype = "uinteger"
  482. o:depends("health_check", 1)
  483. o.default = 20
  484. o.rmempty = true
  485. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  486. o:depends({health_check = true, transport = "grpc"})
  487. o.rmempty = true
  488. end
  489. -- [[ QUIC部分 ]]--
  490. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  491. o:depends("transport", "quic")
  492. o:value("none", translate("None"))
  493. o:value("aes-128-gcm", translate("aes-128-gcm"))
  494. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  495. o.rmempty = true
  496. o = s:option(Value, "quic_key", translate("QUIC Key"))
  497. o:depends("transport", "quic")
  498. o.rmempty = true
  499. o = s:option(ListValue, "quic_guise", translate("Header"))
  500. o:depends("transport", "quic")
  501. o.rmempty = true
  502. o:value("none", translate("None"))
  503. o:value("srtp", translate("VideoCall (SRTP)"))
  504. o:value("utp", translate("BitTorrent (uTP)"))
  505. o:value("wechat-video", translate("WechatVideo"))
  506. o:value("dtls", translate("DTLS 1.2"))
  507. o:value("wireguard", translate("WireGuard"))
  508. -- [[ mKCP部分 ]]--
  509. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  510. o:depends("transport", "kcp")
  511. o:value("none", translate("None"))
  512. o:value("srtp", translate("VideoCall (SRTP)"))
  513. o:value("utp", translate("BitTorrent (uTP)"))
  514. o:value("wechat-video", translate("WechatVideo"))
  515. o:value("dtls", translate("DTLS 1.2"))
  516. o:value("wireguard", translate("WireGuard"))
  517. o.rmempty = true
  518. o = s:option(Value, "mtu", translate("MTU"))
  519. o.datatype = "uinteger"
  520. o:depends("transport", "kcp")
  521. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  522. -- o.default = 1350
  523. o.rmempty = true
  524. o = s:option(Value, "tti", translate("TTI"))
  525. o.datatype = "uinteger"
  526. o:depends("transport", "kcp")
  527. o.default = 50
  528. o.rmempty = true
  529. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity"))
  530. o.datatype = "uinteger"
  531. o:depends("transport", "kcp")
  532. o:depends("type", "hysteria")
  533. o.default = 5
  534. o.rmempty = true
  535. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity"))
  536. o.datatype = "uinteger"
  537. o:depends("transport", "kcp")
  538. o:depends("type", "hysteria")
  539. o.default = 20
  540. o.rmempty = true
  541. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  542. o.datatype = "uinteger"
  543. o:depends("transport", "kcp")
  544. o.default = 2
  545. o.rmempty = true
  546. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  547. o.datatype = "uinteger"
  548. o:depends("transport", "kcp")
  549. o.default = 2
  550. o.rmempty = true
  551. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  552. o:depends("transport", "kcp")
  553. o:depends("type", "hysteria")
  554. o.rmempty = true
  555. o = s:option(Flag, "congestion", translate("Congestion"))
  556. o:depends("transport", "kcp")
  557. o.rmempty = true
  558. -- [[ WireGuard 部分 ]]--
  559. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  560. o.datatype = "cidr"
  561. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  562. o.rmempty = true
  563. o = s:option(Value, "private_key", translate("Private key"))
  564. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  565. o.password = true
  566. o.rmempty = true
  567. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  568. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  569. o.rmempty = true
  570. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  571. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  572. o.password = true
  573. o.rmempty = true
  574. -- [[ TLS ]]--
  575. o = s:option(Flag, "tls", translate("TLS"))
  576. o.rmempty = true
  577. o.default = "0"
  578. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = false})
  579. o:depends({type = "v2ray", v2ray_protocol = "vmess", reality = false})
  580. o:depends({type = "v2ray", v2ray_protocol = "trojan", reality = false})
  581. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", reality = false})
  582. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", reality = false})
  583. o:depends({type = "v2ray", v2ray_protocol = "http", reality = false})
  584. o:depends("type", "trojan")
  585. -- [[ TLS部分 ]] --
  586. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  587. o:depends({type = "trojan", tls = true})
  588. o.default = "0"
  589. if is_finded("xray") then
  590. -- [[ REALITY ]]
  591. o = s:option(Flag, "reality", translate("REALITY"))
  592. o.rmempty = true
  593. o.default = "0"
  594. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = false})
  595. o = s:option(Value, "reality_publickey", translate("Public key"))
  596. o.rmempty = true
  597. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  598. o = s:option(Value, "reality_shortid", translate("Short ID"))
  599. o.rmempty = true
  600. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  601. o = s:option(Value, "reality_spiderx", translate("spiderX"))
  602. o.rmempty = true
  603. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  604. -- [[ XTLS ]]--
  605. o = s:option(Value, "tls_flow", translate("Flow"))
  606. for _, v in ipairs(tls_flows) do
  607. o:value(v, translate(v))
  608. end
  609. o.rmempty = true
  610. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = true})
  611. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", reality = true})
  612. -- [[ uTLS ]]--
  613. o = s:option(Value, "fingerprint", translate("Finger Print"))
  614. o:value("", translate("disable"))
  615. o:value("chrome", translate("chrome"))
  616. o:value("firefox", translate("firefox"))
  617. o:value("safari", translate("safari"))
  618. o:value("ios", translate("ios"))
  619. o:value("android", translate("android"))
  620. o:value("edge", translate("edge"))
  621. o:value("360", translate("360"))
  622. o:value("qq", translate("qq"))
  623. o:value("random", translate("random"))
  624. o:value("randomized", translate("randomized"))
  625. o:depends({type = "v2ray", tls = true})
  626. o:depends({type = "v2ray", reality = true})
  627. end
  628. o = s:option(Value, "tls_host", translate("TLS Host"))
  629. o.datatype = "hostname"
  630. o:depends("tls", true)
  631. o:depends("reality", true)
  632. o:depends("type", "hysteria")
  633. o.rmempty = true
  634. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  635. o:depends("tls", true)
  636. o:depends("type", "tuic")
  637. o.rmempty = true
  638. o = s:option(Value, "quic_tls_alpn", translate("QUIC TLS ALPN"))
  639. o:depends("type", "hysteria")
  640. o.rmempty = true
  641. -- [[ allowInsecure ]]--
  642. o = s:option(Flag, "insecure", translate("allowInsecure"))
  643. o.rmempty = false
  644. o:depends("tls", true)
  645. o:depends("type", "hysteria")
  646. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  647. -- [[ Mux ]]--
  648. o = s:option(Flag, "mux", translate("Mux"))
  649. o.rmempty = false
  650. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  651. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  652. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  653. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  654. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  655. o:depends({type = "v2ray", v2ray_protocol = "http"})
  656. o = s:option(Value, "concurrency", translate("Concurrency"))
  657. o.datatype = "uinteger"
  658. o.rmempty = true
  659. o.default = "4"
  660. o:depends("mux", "1")
  661. o:depends("type", "naiveproxy")
  662. -- [[ Cert ]]--
  663. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  664. o.rmempty = true
  665. o.default = "0"
  666. o:depends("type", "tuic")
  667. o:depends({type = "hysteria", insecure = false})
  668. o:depends({type = "trojan", tls = true, insecure = false})
  669. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  670. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  671. o.description = translate("If you have a self-signed certificate,please check the box")
  672. o = s:option(DummyValue, "upload", translate("Upload"))
  673. o.template = "shadowsocksr/certupload"
  674. o:depends("certificate", 1)
  675. cert_dir = "/etc/ssl/private/"
  676. local path
  677. luci.http.setfilehandler(function(meta, chunk, eof)
  678. if not fd then
  679. if (not meta) or (not meta.name) or (not meta.file) then
  680. return
  681. end
  682. fd = nixio.open(cert_dir .. meta.file, "w")
  683. if not fd then
  684. path = translate("Create upload file error.")
  685. return
  686. end
  687. end
  688. if chunk and fd then
  689. fd:write(chunk)
  690. end
  691. if eof and fd then
  692. fd:close()
  693. fd = nil
  694. path = '/etc/ssl/private/' .. meta.file .. ''
  695. end
  696. end)
  697. if luci.http.formvalue("upload") then
  698. local f = luci.http.formvalue("ulfile")
  699. if #f <= 0 then
  700. path = translate("No specify upload file.")
  701. end
  702. end
  703. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  704. o:depends("certificate", 1)
  705. o:value("/etc/ssl/private/ca.pem")
  706. o.description = translate("Please confirm the current certificate path")
  707. o.default = "/etc/ssl/private/ca.pem"
  708. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  709. o.rmempty = true
  710. o.default = "0"
  711. o:depends("type", "ssr")
  712. o:depends("type", "ss")
  713. o:depends("type", "trojan")
  714. o:depends("type", "hysteria")
  715. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  716. o.rmempty = false
  717. o.default = "1"
  718. o = s:option(Value, "local_port", translate("Local Port"))
  719. o.datatype = "port"
  720. o.default = 1234
  721. o.rmempty = false
  722. if is_finded("kcptun-client") then
  723. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  724. o.rmempty = true
  725. o.default = "0"
  726. o:depends("type", "ssr")
  727. o:depends("type", "ss")
  728. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  729. o.datatype = "port"
  730. o.default = 4000
  731. o:depends("type", "ssr")
  732. o:depends("type", "ss")
  733. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  734. o.password = true
  735. o:depends("type", "ssr")
  736. o:depends("type", "ss")
  737. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  738. o.default = "--nocomp"
  739. o:depends("type", "ssr")
  740. o:depends("type", "ss")
  741. end
  742. return m