client-config.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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:depends({type = "hysteria", flag_quicparam = "1"})
  364. o.rmempty = true
  365. o.datatype = "uinteger"
  366. o.default = "10"
  367. --[[ Shadow-TLS Options ]]
  368. o = s:option(ListValue, "shadowtls_protocol", translate("shadowTLS protocol Version"))
  369. o:depends("type", "shadowtls")
  370. o:value("v3", translate("Enable V3 protocol."))
  371. o:value("v2", translate("Enable V2 protocol."))
  372. o.default = "v3"
  373. o.rmempty = true
  374. o = s:option(Flag, "strict", translate("TLS 1.3 Strict mode"))
  375. o:depends("type", "shadowtls")
  376. o.default = "1"
  377. o.rmempty = false
  378. o = s:option(Flag, "fastopen", translate("TCP Fast Open"))
  379. o:depends("type", "shadowtls")
  380. o.default = "0"
  381. o.rmempty = false
  382. o = s:option(Flag, "disable_nodelay", translate("Disable TCP No_delay"))
  383. o:depends("type", "shadowtls")
  384. o.default = "0"
  385. o.rmempty = true
  386. o = s:option(Value, "shadowtls_sni", translate("shadow-TLS SNI"))
  387. o:depends("type", "shadowtls")
  388. o.datatype = "host"
  389. o.rmempty = true
  390. o.default = ""
  391. --[[ add a ListValue for Choose chain type,sslocal or vmess ]]
  392. o = s:option(ListValue, "chain_type", translate("Shadow-TLS ChainPoxy type"))
  393. o:depends("type", "shadowtls")
  394. if is_finded("sslocal") then
  395. o:value("sslocal", translate("Shadowsocks-rust Version"))
  396. end
  397. if is_finded("xray") or is_finded("v2ray") then
  398. o:value("vmess", translate("Vmess Protocol"))
  399. end
  400. o.default = "sslocal"
  401. o.rmempty = false
  402. o = s:option(Value, "sslocal_password",translate("Shadowsocks password"))
  403. o:depends({type = "shadowtls", chain_type = "sslocal"})
  404. o.rmempty = true
  405. o = s:option(ListValue, "sslocal_method", translate("Encrypt Method"))
  406. o:depends({type = "shadowtls", chain_type = "sslocal"})
  407. for _, v in ipairs(encrypt_methods_ss) do
  408. o:value(v)
  409. end
  410. o = s:option(Value, "vmess_uuid", translate("Vmess UUID"))
  411. o:depends({type = "shadowtls", chain_type = "vmess"})
  412. o.rmempty = false
  413. o.default = uuid
  414. o = s:option(ListValue, "vmess_method", translate("Encrypt Method"))
  415. o:depends({type = "shadowtls", chain_type = "vmess"})
  416. for _, v in ipairs(securitys) do
  417. o:value(v, v:lower())
  418. end
  419. o.rmempty = true
  420. o.default="auto"
  421. -- [[ TUIC ]]
  422. -- TuicNameId
  423. o = s:option(Value, "tuic_uuid", translate("TUIC User UUID"))
  424. o.rmempty = true
  425. o.default = uuid
  426. o:depends("type", "tuic")
  427. --Tuic IP
  428. o = s:option(Value, "tuic_ip", translate("TUIC Server IP Address"))
  429. o.rmempty = true
  430. o.datatype = "ip4addr"
  431. o.default = ""
  432. o:depends("type", "tuic")
  433. -- Tuic Password
  434. o = s:option(Value, "tuic_passwd", translate("TUIC User Password"))
  435. o.rmempty = true
  436. o.default = ""
  437. o:depends("type", "tuic")
  438. o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
  439. o:depends("type", "tuic")
  440. o:value("native", translate("native UDP characteristics"))
  441. o:value("quic", translate("lossless UDP relay using QUIC streams"))
  442. o.default = "native"
  443. o.rmempty = true
  444. o = s:option(ListValue, "congestion_control", translate("Congestion control algorithm"))
  445. o:depends("type", "tuic")
  446. o:value("bbr", translate("BBR"))
  447. o:value("cubic", translate("CUBIC"))
  448. o:value("new_reno", translate("New Reno"))
  449. o.default = "cubic"
  450. o.rmempty = true
  451. o = s:option(Value, "heartbeat", translate("Heartbeat interval(second)"))
  452. o:depends("type", "tuic")
  453. o.datatype = "uinteger"
  454. o.default = "3"
  455. o.rmempty = true
  456. o = s:option(Value, "timeout", translate("Timeout for establishing a connection to server(second)"))
  457. o.description = translate("Default value 0 indicatesno heartbeat.")
  458. o:depends("type", "tuic")
  459. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  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:depends("type", "tuic")
  494. o.default = "0"
  495. o.rmempty = true
  496. o = s:option(Value, "tuic_max_package_size", translate("Maximum packet size the socks5 server can receive from external"))
  497. o:depends("type", "tuic")
  498. o.datatype = "uinteger"
  499. o.default = 1500
  500. o.rmempty = true
  501. -- AlterId
  502. o = s:option(Value, "alter_id", translate("AlterId"))
  503. o.datatype = "port"
  504. o.default = 16
  505. o.rmempty = true
  506. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  507. -- VmessId
  508. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  509. o.rmempty = true
  510. o.default = uuid
  511. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  512. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  513. -- VLESS Encryption
  514. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  515. o.rmempty = true
  516. o.default = "none"
  517. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  518. -- 加密方式
  519. o = s:option(ListValue, "security", translate("Encrypt Method"))
  520. for _, v in ipairs(securitys) do
  521. o:value(v, v:upper())
  522. end
  523. o.rmempty = true
  524. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  525. -- SOCKS Version
  526. o = s:option(ListValue, "socks_ver", translate("Socks Version"))
  527. o:value("4", "Socks4")
  528. o:value("4a", "Socks4A")
  529. o:value("5", "Socks5")
  530. o.rmempty = true
  531. o.default = "5"
  532. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  533. -- 传输协议
  534. o = s:option(ListValue, "transport", translate("Transport"))
  535. o:value("tcp", "TCP")
  536. o:value("kcp", "mKCP")
  537. o:value("ws", "WebSocket")
  538. o:value("httpupgrade", "HTTPUpgrade")
  539. o:value("h2", "HTTP/2")
  540. o:value("quic", "QUIC")
  541. o:value("grpc", "gRPC")
  542. o.rmempty = true
  543. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  544. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  545. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  546. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  547. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  548. o:depends({type = "v2ray", v2ray_protocol = "http"})
  549. -- [[ TCP部分 ]]--
  550. -- TCP伪装
  551. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  552. o:depends("transport", "tcp")
  553. o:value("none", translate("None"))
  554. o:value("http", "HTTP")
  555. o.rmempty = true
  556. -- HTTP域名
  557. o = s:option(Value, "http_host", translate("HTTP Host"))
  558. o:depends("tcp_guise", "http")
  559. o.rmempty = true
  560. -- HTTP路径
  561. o = s:option(Value, "http_path", translate("HTTP Path"))
  562. o:depends("tcp_guise", "http")
  563. o.rmempty = true
  564. -- [[ WS部分 ]]--
  565. -- WS域名
  566. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  567. o:depends({transport = "ws", tls = false})
  568. o.datatype = "hostname"
  569. o.rmempty = true
  570. -- WS路径
  571. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  572. o:depends("transport", "ws")
  573. o.rmempty = true
  574. if is_finded("v2ray") then
  575. -- WS前置数据
  576. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  577. o:depends("ws_ed_enable", true)
  578. o.datatype = "uinteger"
  579. o:value("2048")
  580. o.rmempty = true
  581. -- WS前置数据标头
  582. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  583. o:depends("ws_ed_enable", true)
  584. o:value("Sec-WebSocket-Protocol")
  585. o.rmempty = true
  586. end
  587. -- [[ httpupgrade部分 ]]--
  588. -- httpupgrade域名
  589. o = s:option(Value, "httpupgrade_host", translate("Httpupgrade Host"))
  590. o:depends({transport = "httpupgrade", tls = false})
  591. o.rmempty = true
  592. -- httpupgrade路径
  593. o = s:option(Value, "httpupgrade_path", translate("Httpupgrade Path"))
  594. o:depends("transport", "httpupgrade")
  595. o.rmempty = true
  596. -- [[ H2部分 ]]--
  597. -- H2域名
  598. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  599. o:depends("transport", "h2")
  600. o.rmempty = true
  601. -- H2路径
  602. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  603. o:depends("transport", "h2")
  604. o.rmempty = true
  605. -- gRPC
  606. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  607. o:depends("transport", "grpc")
  608. o.rmempty = true
  609. if is_finded("xray") then
  610. -- gPRC模式
  611. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  612. o:depends("transport", "grpc")
  613. o:value("gun", translate("Gun"))
  614. o:value("multi", translate("Multi"))
  615. o.rmempty = true
  616. end
  617. if is_finded("xray") then
  618. -- gRPC初始窗口
  619. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  620. o.datatype = "uinteger"
  621. o:depends("transport", "grpc")
  622. o.default = 0
  623. o.rmempty = true
  624. -- H2/gRPC健康检查
  625. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  626. o:depends("transport", "h2")
  627. o:depends("transport", "grpc")
  628. o.rmempty = true
  629. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  630. o.datatype = "uinteger"
  631. o:depends({health_check = true, transport = "h2"})
  632. o.default = 60
  633. o.rmempty = true
  634. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  635. o.datatype = "uinteger"
  636. o:depends({health_check = true, transport = "grpc"})
  637. o.default = 60
  638. o.rmempty = true
  639. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  640. o.datatype = "uinteger"
  641. o:depends("health_check", 1)
  642. o.default = 20
  643. o.rmempty = true
  644. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  645. o:depends({health_check = true, transport = "grpc"})
  646. o.rmempty = true
  647. end
  648. -- [[ QUIC部分 ]]--
  649. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  650. o:depends("transport", "quic")
  651. o:value("none", translate("None"))
  652. o:value("aes-128-gcm", translate("aes-128-gcm"))
  653. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  654. o.rmempty = true
  655. o = s:option(Value, "quic_key", translate("QUIC Key"))
  656. o:depends("transport", "quic")
  657. o.rmempty = true
  658. o = s:option(ListValue, "quic_guise", translate("Header"))
  659. o:depends("transport", "quic")
  660. o.rmempty = true
  661. o:value("none", translate("None"))
  662. o:value("srtp", translate("VideoCall (SRTP)"))
  663. o:value("utp", translate("BitTorrent (uTP)"))
  664. o:value("wechat-video", translate("WechatVideo"))
  665. o:value("dtls", translate("DTLS 1.2"))
  666. o:value("wireguard", translate("WireGuard"))
  667. -- [[ mKCP部分 ]]--
  668. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  669. o:depends("transport", "kcp")
  670. o:value("none", translate("None"))
  671. o:value("srtp", translate("VideoCall (SRTP)"))
  672. o:value("utp", translate("BitTorrent (uTP)"))
  673. o:value("wechat-video", translate("WechatVideo"))
  674. o:value("dtls", translate("DTLS 1.2"))
  675. o:value("wireguard", translate("WireGuard"))
  676. o.rmempty = true
  677. o = s:option(Value, "mtu", translate("MTU"))
  678. o.datatype = "uinteger"
  679. o:depends("transport", "kcp")
  680. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  681. -- o.default = 1350
  682. o.rmempty = true
  683. o = s:option(Value, "tti", translate("TTI"))
  684. o.datatype = "uinteger"
  685. o:depends("transport", "kcp")
  686. o.default = 50
  687. o.rmempty = true
  688. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity(Default:Mbps)"))
  689. o.datatype = "uinteger"
  690. o:depends("transport", "kcp")
  691. o:depends("type", "hysteria")
  692. o.default = 5
  693. o.rmempty = true
  694. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity(Default:Mbps)"))
  695. o.datatype = "uinteger"
  696. o:depends("transport", "kcp")
  697. o:depends("type", "hysteria")
  698. o.default = 20
  699. o.rmempty = true
  700. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  701. o.datatype = "uinteger"
  702. o:depends("transport", "kcp")
  703. o.default = 2
  704. o.rmempty = true
  705. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  706. o.datatype = "uinteger"
  707. o:depends("transport", "kcp")
  708. o.default = 2
  709. o.rmempty = true
  710. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  711. o:depends("transport", "kcp")
  712. o.rmempty = true
  713. o = s:option(Flag, "congestion", translate("Congestion"))
  714. o:depends("transport", "kcp")
  715. o.rmempty = true
  716. -- [[ WireGuard 部分 ]]--
  717. o = s:option(Flag, "kernelmode", translate("Enabled Kernel virtual NIC TUN(optional)"))
  718. 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.")
  719. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  720. o.default = "0"
  721. o.rmempty = true
  722. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  723. o.datatype = "cidr"
  724. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  725. o.rmempty = true
  726. o = s:option(DynamicList, "reserved", translate("Reserved bytes(optional)"))
  727. o.description = translate("Wireguard reserved bytes.")
  728. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  729. o.rmempty = true
  730. o = s:option(Value, "private_key", translate("Private key"))
  731. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  732. o.password = true
  733. o.rmempty = true
  734. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  735. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  736. o.rmempty = true
  737. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  738. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  739. o.password = true
  740. o.rmempty = true
  741. o = s:option(DynamicList, "allowedips", translate("allowedIPs(optional)"))
  742. o.description = translate("Wireguard allows only traffic from specific source IP.")
  743. o.datatype = "cidr"
  744. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  745. o.default = "0.0.0.0/0"
  746. o.rmempty = true
  747. -- [[ TLS ]]--
  748. o = s:option(Flag, "tls", translate("TLS"))
  749. o.rmempty = true
  750. o.default = "0"
  751. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = false})
  752. o:depends({type = "v2ray", v2ray_protocol = "vmess", reality = false})
  753. o:depends({type = "v2ray", v2ray_protocol = "trojan", reality = false})
  754. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", reality = false})
  755. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", reality = false})
  756. o:depends({type = "v2ray", v2ray_protocol = "http", reality = false})
  757. o:depends("type", "trojan")
  758. o:depends("type", "hysteria")
  759. -- [[ TLS部分 ]] --
  760. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  761. o:depends({type = "trojan", tls = true})
  762. o.default = "0"
  763. if is_finded("xray") then
  764. -- [[ REALITY ]]
  765. o = s:option(Flag, "reality", translate("REALITY"))
  766. o.rmempty = true
  767. o.default = "0"
  768. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = false})
  769. o = s:option(Value, "reality_publickey", translate("Public key"))
  770. o.rmempty = true
  771. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  772. o = s:option(Value, "reality_shortid", translate("Short ID"))
  773. o.rmempty = true
  774. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  775. o = s:option(Value, "reality_spiderx", translate("spiderX"))
  776. o.rmempty = true
  777. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  778. -- [[ XTLS ]]--
  779. o = s:option(ListValue, "tls_flow", translate("Flow"))
  780. for _, v in ipairs(tls_flows) do
  781. o:value(v, translate(v))
  782. end
  783. o.rmempty = true
  784. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = true})
  785. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", reality = true})
  786. -- [[ uTLS ]]--
  787. o = s:option(Value, "fingerprint", translate("Finger Print"))
  788. o.default = "chrome"
  789. o:value("chrome", translate("chrome"))
  790. o:value("firefox", translate("firefox"))
  791. o:value("safari", translate("safari"))
  792. o:value("ios", translate("ios"))
  793. o:value("android", translate("android"))
  794. o:value("edge", translate("edge"))
  795. o:value("360", translate("360"))
  796. o:value("qq", translate("qq"))
  797. o:value("random", translate("random"))
  798. o:value("randomized", translate("randomized"))
  799. o:value("", translate("disable"))
  800. o:depends({type = "v2ray", tls = true})
  801. o:depends({type = "v2ray", reality = true})
  802. end
  803. o = s:option(Value, "tls_host", translate("TLS Host"))
  804. o.datatype = "hostname"
  805. o:depends("tls", true)
  806. o:depends("reality", true)
  807. o.rmempty = true
  808. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  809. o:depends({type = "tuic", tls = true})
  810. o.rmempty = true
  811. -- [[ allowInsecure ]]--
  812. o = s:option(Flag, "insecure", translate("allowInsecure"))
  813. o.rmempty = false
  814. o:depends("tls", true)
  815. o:depends("type", "hysteria")
  816. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  817. -- [[ Hysteria2 TLS pinSHA256 ]] --
  818. o = s:option(Value, "pinsha256", translate("Certificate fingerprint"))
  819. o:depends({type = "hysteria", insecure = true })
  820. o.rmempty = true
  821. -- [[ Mux ]]--
  822. o = s:option(Flag, "mux", translate("Mux"))
  823. o.rmempty = false
  824. o.default = false
  825. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  826. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  827. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  828. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  829. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  830. o:depends({type = "v2ray", v2ray_protocol = "http"})
  831. -- [[ TCP 最大并发连接数 ]]--
  832. o = s:option(ListValue, "concurrency", translate("concurrency"))
  833. o.rmempty = true
  834. o.default = "-1"
  835. o:value("-1", translate("disable"))
  836. o:value("8", translate("8"))
  837. o:depends("mux", true)
  838. -- [[ UDP 最大并发连接数 ]]--
  839. o = s:option(ListValue, "xudpConcurrency", translate("xudpConcurrency"))
  840. o.rmempty = true
  841. o.default = "16"
  842. o:value("-1", translate("disable"))
  843. o:value("16", translate("16"))
  844. o:depends("mux", true)
  845. -- [[ 对被代理的 UDP/443 流量处理方式 ]]--
  846. o = s:option(ListValue, "xudpProxyUDP443", translate("xudpProxyUDP443"))
  847. o.rmempty = true
  848. o.default = "reject"
  849. o:value("reject", translate("reject"))
  850. o:value("allow", translate("allow"))
  851. o:value("skip", translate("skip"))
  852. o:depends("mux", true)
  853. -- [[ MPTCP ]]--
  854. o = s:option(Flag, "mptcp", translate("MPTCP"))
  855. o.rmempty = false
  856. o.default = false
  857. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  858. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  859. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  860. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  861. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  862. o:depends({type = "v2ray", v2ray_protocol = "http"})
  863. -- [[ custom_tcpcongestion 连接服务器节点的 TCP 拥塞控制算法 ]]--
  864. o = s:option(ListValue, "custom_tcpcongestion", translate("custom_tcpcongestion"))
  865. o.rmempty = true
  866. o.default = ""
  867. o:value("", translate("comment_tcpcongestion_disable"))
  868. o:value("bbr", translate("BBR"))
  869. o:value("cubic", translate("CUBIC"))
  870. o:value("reno", translate("Reno"))
  871. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  872. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  873. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  874. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  875. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  876. o:depends({type = "v2ray", v2ray_protocol = "http"})
  877. -- [[ Cert ]]--
  878. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  879. o.rmempty = true
  880. o.default = "0"
  881. o:depends("type", "tuic")
  882. o:depends({type = "hysteria", insecure = false})
  883. o:depends({type = "trojan", tls = true, insecure = false})
  884. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  885. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  886. o.description = translate("If you have a self-signed certificate,please check the box")
  887. o = s:option(DummyValue, "upload", translate("Upload"))
  888. o.template = "shadowsocksr/certupload"
  889. o:depends("certificate", 1)
  890. cert_dir = "/etc/ssl/private/"
  891. local path
  892. luci.http.setfilehandler(function(meta, chunk, eof)
  893. if not fd then
  894. if (not meta) or (not meta.name) or (not meta.file) then
  895. return
  896. end
  897. fd = nixio.open(cert_dir .. meta.file, "w")
  898. if not fd then
  899. path = translate("Create upload file error.")
  900. return
  901. end
  902. end
  903. if chunk and fd then
  904. fd:write(chunk)
  905. end
  906. if eof and fd then
  907. fd:close()
  908. fd = nil
  909. path = '/etc/ssl/private/' .. meta.file .. ''
  910. end
  911. end)
  912. if luci.http.formvalue("upload") then
  913. local f = luci.http.formvalue("ulfile")
  914. if #f <= 0 then
  915. path = translate("No specify upload file.")
  916. end
  917. end
  918. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  919. o:depends("certificate", 1)
  920. o:value("/etc/ssl/private/ca.pem")
  921. o.description = translate("Please confirm the current certificate path")
  922. o.default = "/etc/ssl/private/ca.pem"
  923. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  924. o.rmempty = true
  925. o.default = "0"
  926. o:depends("type", "ssr")
  927. o:depends("type", "ss")
  928. o:depends("type", "trojan")
  929. o:depends("type", "hysteria")
  930. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  931. o.rmempty = false
  932. o.default = "1"
  933. o = s:option(Value, "local_port", translate("Local Port"))
  934. o.datatype = "port"
  935. o.default = 1234
  936. o.rmempty = false
  937. if is_finded("kcptun-client") then
  938. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  939. o.rmempty = true
  940. o.default = "0"
  941. o:depends("type", "ssr")
  942. o:depends("type", "ss")
  943. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  944. o.datatype = "portrange"
  945. o.default = 4000
  946. o:depends("type", "ssr")
  947. o:depends("type", "ss")
  948. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  949. o.password = true
  950. o:depends("type", "ssr")
  951. o:depends("type", "ss")
  952. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  953. o.default = "--nocomp"
  954. o:depends("type", "ssr")
  955. o:depends("type", "ss")
  956. end
  957. return m