client-config.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  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. "none"
  112. }
  113. m = Map("shadowsocksr", translate("Edit ShadowSocksR Server"))
  114. m.redirect = luci.dispatcher.build_url("admin/services/shadowsocksr/servers")
  115. if m.uci:get("shadowsocksr", sid) ~= "servers" then
  116. luci.http.redirect(m.redirect)
  117. return
  118. end
  119. -- [[ Servers Setting ]]--
  120. s = m:section(NamedSection, sid, "servers")
  121. s.anonymous = true
  122. s.addremove = false
  123. o = s:option(DummyValue, "ssr_url", "SS/SSR/V2RAY/TROJAN URL")
  124. o.rawhtml = true
  125. o.template = "shadowsocksr/ssrurl"
  126. o.value = sid
  127. o = s:option(ListValue, "type", translate("Server Node Type"))
  128. if is_finded("xray") or is_finded("v2ray") then
  129. o:value("v2ray", translate("V2Ray/XRay"))
  130. end
  131. if is_finded("ssr-redir") then
  132. o:value("ssr", translate("ShadowsocksR"))
  133. end
  134. if is_finded("ss-local") or is_finded("ss-redir") then
  135. o:value("ss", translate("Shadowsocks-libev Version"))
  136. end
  137. if is_finded("sslocal") or is_finded("ssmanager") then
  138. o:value("ss", translate("Shadowsocks-rust 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("tuic-client") then
  150. o:value("tuic", translate("TUIC"))
  151. end
  152. if is_finded("shadow-tls") and is_finded("sslocal") then
  153. o:value("shadowtls", translate("Shadow-TLS"))
  154. end
  155. if is_finded("ipt2socks") then
  156. o:value("socks5", translate("Socks5"))
  157. end
  158. if is_finded("redsocks2") then
  159. o:value("tun", translate("Network Tunnel"))
  160. end
  161. o.description = translate("Using incorrect encryption mothod may causes service fail to start")
  162. o = s:option(Value, "alias", translate("Alias(optional)"))
  163. o = s:option(ListValue, "iface", translate("Network interface to use"))
  164. for _, e in ipairs(luci.sys.net.devices()) do
  165. if e ~= "lo" then
  166. o:value(e)
  167. end
  168. end
  169. o:depends("type", "tun")
  170. o.description = translate("Redirect traffic to this network interface")
  171. o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol"))
  172. o:value("vless", translate("VLESS"))
  173. o:value("vmess", translate("VMess"))
  174. o:value("trojan", translate("Trojan"))
  175. o:value("shadowsocks", translate("Shadowsocks"))
  176. if is_finded("xray") then
  177. o:value("wireguard", translate("WireGuard"))
  178. end
  179. o:value("socks", translate("Socks"))
  180. o:value("http", translate("HTTP"))
  181. o:depends("type", "v2ray")
  182. o = s:option(Value, "server", translate("Server Address"))
  183. o.datatype = "host"
  184. o.rmempty = false
  185. o:depends("type", "ssr")
  186. o:depends("type", "ss")
  187. o:depends("type", "v2ray")
  188. o:depends("type", "trojan")
  189. o:depends("type", "naiveproxy")
  190. o:depends("type", "hysteria")
  191. o:depends("type", "tuic")
  192. o:depends("type", "shadowtls")
  193. o:depends("type", "socks5")
  194. o = s:option(Value, "server_port", translate("Server Port"))
  195. o.datatype = "port"
  196. o.rmempty = true
  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", "tuic")
  204. o:depends("type", "shadowtls")
  205. o:depends("type", "socks5")
  206. o = s:option(Flag, "auth_enable", translate("Enable Authentication"))
  207. o.rmempty = false
  208. o.default = "0"
  209. o:depends("type", "socks5")
  210. o:depends({type = "v2ray", v2ray_protocol = "http"})
  211. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  212. o = s:option(Value, "username", translate("Username"))
  213. o.rmempty = true
  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", auth_enable = true})
  218. o = s:option(Value, "password", translate("Password"))
  219. o.password = true
  220. o.rmempty = true
  221. o:depends("type", "ssr")
  222. o:depends("type", "ss")
  223. o:depends("type", "trojan")
  224. o:depends("type", "naiveproxy")
  225. o:depends("type", "shadowtls")
  226. o:depends({type = "socks5", auth_enable = true})
  227. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  228. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", auth_enable = true})
  229. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  230. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  231. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  232. for _, v in ipairs(encrypt_methods) do
  233. o:value(v)
  234. end
  235. o.rmempty = true
  236. o:depends("type", "ssr")
  237. o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
  238. for _, v in ipairs(encrypt_methods_ss) do
  239. o:value(v)
  240. end
  241. o.rmempty = true
  242. o:depends("type", "ss")
  243. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  244. o = s:option(Flag, "uot", translate("UDP over TCP"))
  245. o.description = translate("Enable the SUoT protocol, requires server support.")
  246. o.rmempty = true
  247. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  248. o.default = "0"
  249. o = s:option(Flag, "ivCheck", translate("Bloom Filter"))
  250. o.rmempty = true
  251. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  252. o.default = "1"
  253. -- Shadowsocks Plugin
  254. o = s:option(Value, "plugin", translate("Obfs"))
  255. o:value("none", translate("None"))
  256. if is_finded("obfs-local") then
  257. o:value("obfs-local", translate("obfs-local"))
  258. end
  259. if is_finded("v2ray-plugin") then
  260. o:value("v2ray-plugin", translate("v2ray-plugin"))
  261. end
  262. if is_finded("xray-plugin") then
  263. o:value("xray-plugin", translate("xray-plugin"))
  264. end
  265. o.rmempty = true
  266. o:depends("type", "ss")
  267. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  268. o.rmempty = true
  269. o:depends("type", "ss")
  270. o = s:option(ListValue, "protocol", translate("Protocol"))
  271. for _, v in ipairs(protocol) do
  272. o:value(v)
  273. end
  274. o.rmempty = true
  275. o:depends("type", "ssr")
  276. o = s:option(Value, "protocol_param", translate("Protocol param (optional)"))
  277. o:depends("type", "ssr")
  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 = s:option(Value, "obfs_param", translate("Obfs param (optional)"))
  285. o:depends("type", "ssr")
  286. -- [[ Hysteria2 ]]--
  287. o = s:option(Value, "hy2_auth", translate("Users Authentication"))
  288. o:depends("type", "hysteria")
  289. o.rmempty = false
  290. o = s:option(Flag, "flag_port_hopping", translate("Enable Port Hopping"))
  291. o:depends("type", "hysteria")
  292. o.rmempty = true
  293. o.default = "0"
  294. o = s:option(Value, "port_range", translate("Port Range"))
  295. o:depends({type = "hysteria", flag_port_hopping = true})
  296. o.datatype = "portrange"
  297. o.rmempty = true
  298. o = s:option(Flag, "flag_transport", translate("Enable Transport Protocol Settings"))
  299. o:depends("type", "hysteria")
  300. o.rmempty = true
  301. o.default = "0"
  302. o = s:option(ListValue, "transport_protocol", translate("Transport Protocol"))
  303. o:depends({type = "hysteria", flag_transport = true})
  304. o:value("udp", translate("UDP"))
  305. o.default = "udp"
  306. o.rmempty = true
  307. o = s:option(Value, "hopinterval", translate("Port Hopping Interval(Unit:Second)"))
  308. o:depends({type = "hysteria", flag_transport = true, flag_port_hopping = true})
  309. o.datatype = "uinteger"
  310. o.rmempty = true
  311. o.default = "30"
  312. o = s:option(Flag, "flag_obfs", translate("Enable Obfuscation"))
  313. o:depends("type", "hysteria")
  314. o.rmempty = true
  315. o.default = "0"
  316. o = s:option(Flag, "lazy_mode", translate("Enable Lazy Mode"))
  317. o:depends("type", "hysteria")
  318. o.rmempty = true
  319. o.default = "0"
  320. o = s:option(Value, "obfs_type", translate("Obfuscation Type"))
  321. o:depends({type = "hysteria", flag_obfs = "1"})
  322. o.rmempty = true
  323. o.default = "salamander"
  324. o = s:option(Value, "salamander", translate("Obfuscation Password"))
  325. o:depends({type = "hysteria", flag_obfs = "1"})
  326. o.rmempty = true
  327. o.default = "cry_me_a_r1ver"
  328. o = s:option(Flag, "flag_quicparam", translate("Hysterir QUIC parameters"))
  329. o:depends("type", "hysteria")
  330. o.rmempty = true
  331. o.default = "0"
  332. o = s:option(Flag, "disablepathmtudiscovery", translate("Disable QUIC path MTU discovery"))
  333. o:depends({type = "hysteria",flag_quicparam = "1"})
  334. o.rmempty = true
  335. o.default = false
  336. --[[Hysteria2 QUIC parameters setting]]
  337. o = s:option(Value, "initstreamreceivewindow", translate("QUIC initStreamReceiveWindow"))
  338. o:depends({type = "hysteria", flag_quicparam = "1"})
  339. o.datatype = "uinteger"
  340. o.rmempty = true
  341. o.default = "8388608"
  342. o = s:option(Value, "maxstreamseceivewindow", translate("QUIC maxStreamReceiveWindow"))
  343. o:depends({type = "hysteria", flag_quicparam = "1"})
  344. o.datatype = "uinteger"
  345. o.rmempty = true
  346. o.default = "8388608"
  347. o = s:option(Value, "initconnreceivewindow", translate("QUIC initConnReceiveWindow"))
  348. o:depends({type = "hysteria", flag_quicparam = "1"})
  349. o.datatype = "uinteger"
  350. o.rmempty = true
  351. o.default = "20971520"
  352. o = s:option(Value, "maxconnreceivewindow", translate("QUIC maxConnReceiveWindow"))
  353. o:depends({type = "hysteria", flag_quicparam = "1"})
  354. o.datatype = "uinteger"
  355. o.rmempty = true
  356. o.default = "20971520"
  357. o = s:option(Value, "maxidletimeout", translate("QUIC maxIdleTimeout(Unit:second)"))
  358. o:depends({type = "hysteria", flag_quicparam = "1"})
  359. o.rmempty = true
  360. o.datatype = "uinteger"
  361. o.default = "30"
  362. o = s:option(Value, "keepaliveperiod", translate("The keep-alive period.(Unit:second)"))
  363. o.description = translate("Default value 0 indicatesno heartbeat.")
  364. o:depends({type = "hysteria", flag_quicparam = "1"})
  365. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  366. o.rmempty = true
  367. o.datatype = "uinteger"
  368. o.default = "10"
  369. --[[ Shadow-TLS Options ]]
  370. o = s:option(ListValue, "shadowtls_protocol", translate("shadowTLS protocol Version"))
  371. o:depends("type", "shadowtls")
  372. o:value("v3", translate("Enable V3 protocol."))
  373. o:value("v2", translate("Enable V2 protocol."))
  374. o.default = "v3"
  375. o.rmempty = true
  376. o = s:option(Flag, "strict", translate("TLS 1.3 Strict mode"))
  377. o:depends("type", "shadowtls")
  378. o.default = "1"
  379. o.rmempty = false
  380. o = s:option(Flag, "fastopen", translate("TCP Fast Open"))
  381. o:depends("type", "shadowtls")
  382. o.default = "0"
  383. o.rmempty = false
  384. o = s:option(Flag, "disable_nodelay", translate("Disable TCP No_delay"))
  385. o:depends("type", "shadowtls")
  386. o.default = "0"
  387. o.rmempty = true
  388. o = s:option(Value, "shadowtls_sni", translate("shadow-TLS SNI"))
  389. o:depends("type", "shadowtls")
  390. o.datatype = "host"
  391. o.rmempty = true
  392. o.default = ""
  393. --[[ add a ListValue for Choose chain type,sslocal or vmess ]]
  394. o = s:option(ListValue, "chain_type", translate("Shadow-TLS ChainPoxy type"))
  395. o:depends("type", "shadowtls")
  396. if is_finded("sslocal") then
  397. o:value("sslocal", translate("Shadowsocks-rust Version"))
  398. end
  399. if is_finded("xray") or is_finded("v2ray") then
  400. o:value("vmess", translate("Vmess Protocol"))
  401. end
  402. o.default = "sslocal"
  403. o.rmempty = false
  404. o = s:option(Value, "sslocal_password",translate("Shadowsocks password"))
  405. o:depends({type = "shadowtls", chain_type = "sslocal"})
  406. o.rmempty = true
  407. o = s:option(ListValue, "sslocal_method", translate("Encrypt Method"))
  408. o:depends({type = "shadowtls", chain_type = "sslocal"})
  409. for _, v in ipairs(encrypt_methods_ss) do
  410. o:value(v)
  411. end
  412. o = s:option(Value, "vmess_uuid", translate("Vmess UUID"))
  413. o:depends({type = "shadowtls", chain_type = "vmess"})
  414. o.rmempty = false
  415. o.default = uuid
  416. o = s:option(ListValue, "vmess_method", translate("Encrypt Method"))
  417. o:depends({type = "shadowtls", chain_type = "vmess"})
  418. for _, v in ipairs(securitys) do
  419. o:value(v, v:lower())
  420. end
  421. o.rmempty = true
  422. o.default="auto"
  423. -- [[ TUIC ]]
  424. -- TuicNameId
  425. o = s:option(Value, "tuic_uuid", translate("TUIC User UUID"))
  426. o.rmempty = true
  427. o.default = uuid
  428. o:depends("type", "tuic")
  429. --Tuic IP
  430. o = s:option(Value, "tuic_ip", translate("TUIC Server IP Address"))
  431. o.rmempty = true
  432. o.datatype = "ip4addr"
  433. o.default = ""
  434. o:depends("type", "tuic")
  435. -- Tuic Password
  436. o = s:option(Value, "tuic_passwd", translate("TUIC User Password"))
  437. o.rmempty = true
  438. o.default = ""
  439. o:depends("type", "tuic")
  440. o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
  441. o:depends("type", "tuic")
  442. o:value("native", translate("native UDP characteristics"))
  443. o:value("quic", translate("lossless UDP relay using QUIC streams"))
  444. o.default = "native"
  445. o.rmempty = true
  446. o = s:option(ListValue, "congestion_control", translate("Congestion control algorithm"))
  447. o:depends("type", "tuic")
  448. o:value("bbr", translate("BBR"))
  449. o:value("cubic", translate("CUBIC"))
  450. o:value("new_reno", translate("New Reno"))
  451. o.default = "cubic"
  452. o.rmempty = true
  453. o = s:option(Value, "heartbeat", translate("Heartbeat interval(second)"))
  454. o:depends("type", "tuic")
  455. o.datatype = "uinteger"
  456. o.default = "3"
  457. o.rmempty = true
  458. o = s:option(Value, "timeout", translate("Timeout for establishing a connection to server(second)"))
  459. o:depends("type", "tuic")
  460. o.datatype = "uinteger"
  461. o.default = "8"
  462. o.rmempty = true
  463. o = s:option(Value, "gc_interval", translate("Garbage collection interval(second)"))
  464. o:depends("type", "tuic")
  465. o.datatype = "uinteger"
  466. o.default = "3"
  467. o.rmempty = true
  468. o = s:option(Value, "gc_lifetime", translate("Garbage collection lifetime(second)"))
  469. o:depends("type", "tuic")
  470. o.datatype = "uinteger"
  471. o.default = "15"
  472. o.rmempty = true
  473. o = s:option(Value, "send_window", translate("TUIC send window"))
  474. o:depends("type", "tuic")
  475. o.datatype = "uinteger"
  476. o.default = 20971520
  477. o.rmempty = true
  478. o = s:option(Value, "receive_window", translate("TUIC receive window"))
  479. o:depends("type", "tuic")
  480. o.datatype = "uinteger"
  481. o.default = 10485760
  482. o.rmempty = true
  483. o = s:option(Flag, "disable_sni", translate("Disable SNI"))
  484. o:depends("type", "tuic")
  485. o.default = "0"
  486. o.rmempty = true
  487. o = s:option(Flag, "zero_rtt_handshake", translate("Enable 0-RTT QUIC handshake"))
  488. o:depends("type", "tuic")
  489. o.default = "0"
  490. o.rmempty = true
  491. -- Tuic settings for the local inbound socks5 server
  492. o = s:option(Flag, "tuic_dual_stack", translate("Dual-stack Listening Socket"))
  493. o.description = translate("If this option is not set, the socket behavior is platform dependent.")
  494. o:depends("type", "tuic")
  495. o.default = "0"
  496. o.rmempty = true
  497. o = s:option(Value, "tuic_max_package_size", translate("Maximum packet size the socks5 server can receive from external"))
  498. o:depends("type", "tuic")
  499. o.datatype = "uinteger"
  500. o.default = 1500
  501. o.rmempty = true
  502. -- AlterId
  503. o = s:option(Value, "alter_id", translate("AlterId"))
  504. o.datatype = "port"
  505. o.default = 16
  506. o.rmempty = true
  507. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  508. -- VmessId
  509. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  510. o.rmempty = true
  511. o.default = uuid
  512. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  513. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  514. -- VLESS Encryption
  515. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  516. o.rmempty = true
  517. o.default = "none"
  518. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  519. -- 加密方式
  520. o = s:option(ListValue, "security", translate("Encrypt Method"))
  521. for _, v in ipairs(securitys) do
  522. o:value(v, v:upper())
  523. end
  524. o.rmempty = true
  525. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  526. -- SOCKS Version
  527. o = s:option(ListValue, "socks_ver", translate("Socks Version"))
  528. o:value("4", "Socks4")
  529. o:value("4a", "Socks4A")
  530. o:value("5", "Socks5")
  531. o.rmempty = true
  532. o.default = "5"
  533. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  534. -- 传输协议
  535. o = s:option(ListValue, "transport", translate("Transport"))
  536. o:value("raw", "RAW (TCP)")
  537. o:value("kcp", "mKCP")
  538. o:value("ws", "WebSocket")
  539. o:value("httpupgrade", "HTTPUpgrade")
  540. o:value("splithttp", "SplitHTTP")
  541. o:value("h2", "HTTP/2")
  542. o:value("quic", "QUIC")
  543. o:value("grpc", "gRPC")
  544. o.rmempty = true
  545. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  546. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  547. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  548. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  549. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  550. o:depends({type = "v2ray", v2ray_protocol = "http"})
  551. -- [[ RAW部分 ]]--
  552. -- TCP伪装
  553. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  554. o:depends("transport", "raw")
  555. o:value("none", translate("None"))
  556. o:value("http", "HTTP")
  557. o.rmempty = true
  558. -- HTTP域名
  559. o = s:option(Value, "http_host", translate("HTTP Host"))
  560. o:depends("tcp_guise", "http")
  561. o.rmempty = true
  562. -- HTTP路径
  563. o = s:option(Value, "http_path", translate("HTTP Path"))
  564. o:depends("tcp_guise", "http")
  565. o.rmempty = true
  566. -- [[ WS部分 ]]--
  567. -- WS域名
  568. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  569. o:depends({transport = "ws", tls = false})
  570. o.datatype = "hostname"
  571. o.rmempty = true
  572. -- WS路径
  573. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  574. o:depends("transport", "ws")
  575. o.rmempty = true
  576. if is_finded("v2ray") then
  577. -- WS前置数据
  578. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  579. o:depends("ws_ed_enable", true)
  580. o.datatype = "uinteger"
  581. o:value("2048")
  582. o.rmempty = true
  583. -- WS前置数据标头
  584. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  585. o:depends("ws_ed_enable", true)
  586. o:value("Sec-WebSocket-Protocol")
  587. o.rmempty = true
  588. end
  589. -- [[ httpupgrade部分 ]]--
  590. -- httpupgrade域名
  591. o = s:option(Value, "httpupgrade_host", translate("Httpupgrade Host"))
  592. o:depends({transport = "httpupgrade", tls = false})
  593. o.rmempty = true
  594. -- httpupgrade路径
  595. o = s:option(Value, "httpupgrade_path", translate("Httpupgrade Path"))
  596. o:depends("transport", "httpupgrade")
  597. o.rmempty = true
  598. -- [[ splithttp部分 ]]--
  599. -- splithttp域名
  600. o = s:option(Value, "splithttp_host", translate("Splithttp Host"))
  601. o:depends({transport = "splithttp", tls = false})
  602. o.rmempty = true
  603. -- splithttp路径
  604. o = s:option(Value, "splithttp_path", translate("Splithttp Path"))
  605. o:depends("transport", "splithttp")
  606. o.rmempty = true
  607. -- [[ H2部分 ]]--
  608. -- H2域名
  609. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  610. o:depends("transport", "h2")
  611. o.rmempty = true
  612. -- H2路径
  613. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  614. o:depends("transport", "h2")
  615. o.rmempty = true
  616. -- gRPC
  617. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  618. o:depends("transport", "grpc")
  619. o.rmempty = true
  620. if is_finded("xray") then
  621. -- gPRC模式
  622. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  623. o:depends("transport", "grpc")
  624. o:value("gun", translate("Gun"))
  625. o:value("multi", translate("Multi"))
  626. o.rmempty = true
  627. end
  628. if is_finded("xray") then
  629. -- gRPC初始窗口
  630. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  631. o.datatype = "uinteger"
  632. o:depends("transport", "grpc")
  633. o.default = 0
  634. o.rmempty = true
  635. -- H2/gRPC健康检查
  636. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  637. o:depends("transport", "h2")
  638. o:depends("transport", "grpc")
  639. o.rmempty = true
  640. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  641. o.datatype = "uinteger"
  642. o:depends({health_check = true, transport = "h2"})
  643. o.default = 60
  644. o.rmempty = true
  645. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  646. o.datatype = "uinteger"
  647. o:depends({health_check = true, transport = "grpc"})
  648. o.default = 60
  649. o.rmempty = true
  650. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  651. o.datatype = "uinteger"
  652. o:depends("health_check", 1)
  653. o.default = 20
  654. o.rmempty = true
  655. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  656. o:depends({health_check = true, transport = "grpc"})
  657. o.rmempty = true
  658. end
  659. -- [[ QUIC部分 ]]--
  660. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  661. o:depends("transport", "quic")
  662. o:value("none", translate("None"))
  663. o:value("aes-128-gcm", translate("aes-128-gcm"))
  664. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  665. o.rmempty = true
  666. o = s:option(Value, "quic_key", translate("QUIC Key"))
  667. o:depends("transport", "quic")
  668. o.rmempty = true
  669. o = s:option(ListValue, "quic_guise", translate("Header"))
  670. o:depends("transport", "quic")
  671. o.rmempty = true
  672. o:value("none", translate("None"))
  673. o:value("srtp", translate("VideoCall (SRTP)"))
  674. o:value("utp", translate("BitTorrent (uTP)"))
  675. o:value("wechat-video", translate("WechatVideo"))
  676. o:value("dtls", translate("DTLS 1.2"))
  677. o:value("wireguard", translate("WireGuard"))
  678. -- [[ mKCP部分 ]]--
  679. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  680. o:depends("transport", "kcp")
  681. o:value("none", translate("None"))
  682. o:value("srtp", translate("VideoCall (SRTP)"))
  683. o:value("utp", translate("BitTorrent (uTP)"))
  684. o:value("wechat-video", translate("WechatVideo"))
  685. o:value("dtls", translate("DTLS 1.2"))
  686. o:value("wireguard", translate("WireGuard"))
  687. o.rmempty = true
  688. o = s:option(Value, "mtu", translate("MTU"))
  689. o.datatype = "uinteger"
  690. o:depends("transport", "kcp")
  691. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  692. -- o.default = 1350
  693. o.rmempty = true
  694. o = s:option(Value, "tti", translate("TTI"))
  695. o.datatype = "uinteger"
  696. o:depends("transport", "kcp")
  697. o.default = 50
  698. o.rmempty = true
  699. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity(Default:Mbps)"))
  700. o.datatype = "uinteger"
  701. o:depends("transport", "kcp")
  702. o:depends("type", "hysteria")
  703. o.default = 5
  704. o.rmempty = true
  705. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity(Default:Mbps)"))
  706. o.datatype = "uinteger"
  707. o:depends("transport", "kcp")
  708. o:depends("type", "hysteria")
  709. o.default = 20
  710. o.rmempty = true
  711. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  712. o.datatype = "uinteger"
  713. o:depends("transport", "kcp")
  714. o.default = 2
  715. o.rmempty = true
  716. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  717. o.datatype = "uinteger"
  718. o:depends("transport", "kcp")
  719. o.default = 2
  720. o.rmempty = true
  721. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  722. o:depends("transport", "kcp")
  723. o.rmempty = true
  724. o = s:option(Flag, "congestion", translate("Congestion"))
  725. o:depends("transport", "kcp")
  726. o.rmempty = true
  727. -- [[ WireGuard 部分 ]]--
  728. o = s:option(Flag, "kernelmode", translate("Enabled Kernel virtual NIC TUN(optional)"))
  729. o.description = translate("Virtual NIC TUN of Linux kernel can be used only when system supports and have root permission. If used, IPv6 routing table 1023 is occupied.")
  730. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  731. o.default = "0"
  732. o.rmempty = true
  733. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  734. o.datatype = "cidr"
  735. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  736. o.rmempty = true
  737. o = s:option(DynamicList, "reserved", translate("Reserved bytes(optional)"))
  738. o.description = translate("Wireguard reserved bytes.")
  739. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  740. o.rmempty = true
  741. o = s:option(Value, "private_key", translate("Private key"))
  742. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  743. o.password = true
  744. o.rmempty = true
  745. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  746. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  747. o.rmempty = true
  748. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  749. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  750. o.password = true
  751. o.rmempty = true
  752. o = s:option(DynamicList, "allowedips", translate("allowedIPs(optional)"))
  753. o.description = translate("Wireguard allows only traffic from specific source IP.")
  754. o.datatype = "cidr"
  755. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  756. o.default = "0.0.0.0/0"
  757. o.rmempty = true
  758. -- [[ TLS ]]--
  759. o = s:option(Flag, "tls", translate("TLS"))
  760. o.rmempty = true
  761. o.default = "0"
  762. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = false})
  763. o:depends({type = "v2ray", v2ray_protocol = "vmess", reality = false})
  764. o:depends({type = "v2ray", v2ray_protocol = "trojan", reality = false})
  765. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", reality = false})
  766. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", reality = false})
  767. o:depends({type = "v2ray", v2ray_protocol = "http", reality = false})
  768. o:depends("type", "trojan")
  769. o:depends("type", "hysteria")
  770. -- [[ TLS部分 ]] --
  771. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  772. o:depends({type = "trojan", tls = true})
  773. o.default = "0"
  774. if is_finded("xray") then
  775. -- [[ REALITY ]]
  776. o = s:option(Flag, "reality", translate("REALITY"))
  777. o.rmempty = true
  778. o.default = "0"
  779. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = false})
  780. o = s:option(Value, "reality_publickey", translate("Public key"))
  781. o.rmempty = true
  782. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  783. o = s:option(Value, "reality_shortid", translate("Short ID"))
  784. o.rmempty = true
  785. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  786. o = s:option(Value, "reality_spiderx", translate("spiderX"))
  787. o.rmempty = true
  788. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  789. -- [[ XTLS ]]--
  790. o = s:option(ListValue, "tls_flow", translate("Flow"))
  791. for _, v in ipairs(tls_flows) do
  792. if v == "none" then
  793. o.default = "none"
  794. o:value("none", translate("none"))
  795. else
  796. o:value(v, translate(v))
  797. end
  798. end
  799. o.rmempty = true
  800. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", tls = true})
  801. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", reality = true})
  802. -- [[ uTLS ]]--
  803. o = s:option(ListValue, "fingerprint", translate("Finger Print"))
  804. o.default = ""
  805. o:value("chrome", translate("chrome"))
  806. o:value("firefox", translate("firefox"))
  807. o:value("safari", translate("safari"))
  808. o:value("ios", translate("ios"))
  809. o:value("android", translate("android"))
  810. o:value("edge", translate("edge"))
  811. o:value("360", translate("360"))
  812. o:value("qq", translate("qq"))
  813. o:value("random", translate("random"))
  814. o:value("randomized", translate("randomized"))
  815. o:value("", translate("disable"))
  816. o:depends({type = "v2ray", tls = true})
  817. o:depends({type = "v2ray", reality = true})
  818. end
  819. o = s:option(Value, "tls_host", translate("TLS Host"))
  820. o.datatype = "hostname"
  821. o:depends("tls", true)
  822. o:depends("xtls", true)
  823. o:depends("reality", true)
  824. o.rmempty = true
  825. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  826. o:depends("type", "tuic")
  827. o.default = "h3"
  828. o.rmempty = true
  829. -- [[ allowInsecure ]]--
  830. o = s:option(Flag, "insecure", translate("allowInsecure"))
  831. o.rmempty = false
  832. o:depends("tls", true)
  833. o:depends("type", "hysteria")
  834. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  835. -- [[ Hysteria2 TLS pinSHA256 ]] --
  836. o = s:option(Value, "pinsha256", translate("Certificate fingerprint"))
  837. o:depends({type = "hysteria", insecure = true })
  838. o.rmempty = true
  839. -- [[ Mux ]]--
  840. o = s:option(Flag, "mux", translate("Mux"))
  841. o.rmempty = false
  842. o.default = false
  843. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  844. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  845. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  846. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  847. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  848. o:depends({type = "v2ray", v2ray_protocol = "http"})
  849. -- [[ TCP 最大并发连接数 ]]--
  850. o = s:option(ListValue, "concurrency", translate("concurrency"))
  851. o.rmempty = true
  852. o.default = "-1"
  853. o:value("-1", translate("disable"))
  854. o:value("8", translate("8"))
  855. o:depends("mux", true)
  856. -- [[ UDP 最大并发连接数 ]]--
  857. o = s:option(ListValue, "xudpConcurrency", translate("xudpConcurrency"))
  858. o.rmempty = true
  859. o.default = "16"
  860. o:value("-1", translate("disable"))
  861. o:value("16", translate("16"))
  862. o:depends("mux", true)
  863. -- [[ 对被代理的 UDP/443 流量处理方式 ]]--
  864. o = s:option(ListValue, "xudpProxyUDP443", translate("xudpProxyUDP443"))
  865. o.rmempty = true
  866. o.default = "reject"
  867. o:value("reject", translate("reject"))
  868. o:value("allow", translate("allow"))
  869. o:value("skip", translate("skip"))
  870. o:depends("mux", true)
  871. -- [[ MPTCP ]]--
  872. o = s:option(Flag, "mptcp", translate("MPTCP"), translate("Enabling MPTCP Requires Server Support."))
  873. o.rmempty = false
  874. o.default = false
  875. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  876. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  877. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  878. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  879. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  880. o:depends({type = "v2ray", v2ray_protocol = "http"})
  881. -- [[ custom_tcpcongestion 连接服务器节点的 TCP 拥塞控制算法 ]]--
  882. o = s:option(ListValue, "custom_tcpcongestion", translate("custom_tcpcongestion"))
  883. o.rmempty = true
  884. o.default = ""
  885. o:value("", translate("comment_tcpcongestion_disable"))
  886. o:value("bbr", translate("BBR"))
  887. o:value("cubic", translate("CUBIC"))
  888. o:value("reno", translate("Reno"))
  889. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  890. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  891. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  892. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  893. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  894. o:depends({type = "v2ray", v2ray_protocol = "http"})
  895. -- [[ Cert ]]--
  896. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  897. o.rmempty = true
  898. o.default = "0"
  899. o:depends("type", "tuic")
  900. o:depends({type = "hysteria", insecure = false})
  901. o:depends({type = "trojan", tls = true, insecure = false})
  902. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  903. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  904. o.description = translate("If you have a self-signed certificate,please check the box")
  905. o = s:option(DummyValue, "upload", translate("Upload"))
  906. o.template = "shadowsocksr/certupload"
  907. o:depends("certificate", 1)
  908. cert_dir = "/etc/ssl/private/"
  909. local path
  910. luci.http.setfilehandler(function(meta, chunk, eof)
  911. if not fd then
  912. if (not meta) or (not meta.name) or (not meta.file) then
  913. return
  914. end
  915. fd = nixio.open(cert_dir .. meta.file, "w")
  916. if not fd then
  917. path = translate("Create upload file error.")
  918. return
  919. end
  920. end
  921. if chunk and fd then
  922. fd:write(chunk)
  923. end
  924. if eof and fd then
  925. fd:close()
  926. fd = nil
  927. path = '/etc/ssl/private/' .. meta.file .. ''
  928. end
  929. end)
  930. if luci.http.formvalue("upload") then
  931. local f = luci.http.formvalue("ulfile")
  932. if #f <= 0 then
  933. path = translate("No specify upload file.")
  934. end
  935. end
  936. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  937. o:depends("certificate", 1)
  938. o:value("/etc/ssl/private/ca.pem")
  939. o.description = translate("Please confirm the current certificate path")
  940. o.default = "/etc/ssl/private/ca.pem"
  941. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  942. o.rmempty = true
  943. o.default = "0"
  944. o:depends("type", "ssr")
  945. o:depends("type", "ss")
  946. o:depends("type", "trojan")
  947. o:depends("type", "hysteria")
  948. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  949. o.rmempty = false
  950. o.default = "1"
  951. o = s:option(Value, "local_port", translate("Local Port"))
  952. o.datatype = "port"
  953. o.default = 1234
  954. o.rmempty = false
  955. if is_finded("kcptun-client") then
  956. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  957. o.rmempty = true
  958. o.default = "0"
  959. o:depends("type", "ssr")
  960. o:depends("type", "ss")
  961. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  962. o.datatype = "portrange"
  963. o.default = 4000
  964. o:depends("type", "ssr")
  965. o:depends("type", "ss")
  966. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  967. o.password = true
  968. o:depends("type", "ssr")
  969. o:depends("type", "ss")
  970. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  971. o.default = "--nocomp"
  972. o:depends("type", "ssr")
  973. o:depends("type", "ss")
  974. end
  975. return m