client-config.lua 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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("tcp", "TCP")
  537. o:value("raw", "RAW")
  538. o:value("kcp", "mKCP")
  539. o:value("ws", "WebSocket")
  540. o:value("httpupgrade", "HTTPUpgrade")
  541. o:value("splithttp", "SplitHTTP")
  542. o:value("h2", "HTTP/2")
  543. o:value("quic", "QUIC")
  544. o:value("grpc", "gRPC")
  545. o.rmempty = true
  546. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  547. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  548. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  549. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  550. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  551. o:depends({type = "v2ray", v2ray_protocol = "http"})
  552. -- [[ TCP部分 ]]--
  553. -- TCP伪装
  554. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  555. o:depends("transport", "tcp")
  556. o:value("none", translate("None"))
  557. o:value("http", "HTTP")
  558. o.rmempty = true
  559. -- [[ RAW部分 ]]--
  560. -- RAW伪装
  561. o = s:option(ListValue, "raw_guise", translate("Camouflage Type"))
  562. o:depends("transport", "raw")
  563. o:value("none", translate("None"))
  564. o:value("http", "HTTP")
  565. o.rmempty = true
  566. -- HTTP域名
  567. o = s:option(Value, "http_host", translate("HTTP Host"))
  568. o:depends("tcp_guise", "http")
  569. o:depends("raw_guise", "http")
  570. o.rmempty = true
  571. -- HTTP路径
  572. o = s:option(Value, "http_path", translate("HTTP Path"))
  573. o:depends("tcp_guise", "http")
  574. o:depends("raw_guise", "http")
  575. o.rmempty = true
  576. -- [[ WS部分 ]]--
  577. -- WS域名
  578. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  579. o:depends({transport = "ws", tls = false})
  580. o.datatype = "hostname"
  581. o.rmempty = true
  582. -- WS路径
  583. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  584. o:depends("transport", "ws")
  585. o.rmempty = true
  586. if is_finded("v2ray") then
  587. -- WS前置数据
  588. o = s:option(Value, "ws_ed", translate("Max Early Data"))
  589. o:depends("ws_ed_enable", true)
  590. o.datatype = "uinteger"
  591. o:value("2048")
  592. o.rmempty = true
  593. -- WS前置数据标头
  594. o = s:option(Value, "ws_ed_header", translate("Early Data Header Name"))
  595. o:depends("ws_ed_enable", true)
  596. o:value("Sec-WebSocket-Protocol")
  597. o.rmempty = true
  598. end
  599. -- [[ httpupgrade部分 ]]--
  600. -- httpupgrade域名
  601. o = s:option(Value, "httpupgrade_host", translate("Httpupgrade Host"))
  602. o:depends({transport = "httpupgrade", tls = false})
  603. o.rmempty = true
  604. -- httpupgrade路径
  605. o = s:option(Value, "httpupgrade_path", translate("Httpupgrade Path"))
  606. o:depends("transport", "httpupgrade")
  607. o.rmempty = true
  608. -- [[ splithttp部分 ]]--
  609. -- splithttp域名
  610. o = s:option(Value, "splithttp_host", translate("Splithttp Host"))
  611. o:depends({transport = "splithttp", tls = false})
  612. o.rmempty = true
  613. -- splithttp路径
  614. o = s:option(Value, "splithttp_path", translate("Splithttp Path"))
  615. o:depends("transport", "splithttp")
  616. o.rmempty = true
  617. -- [[ H2部分 ]]--
  618. -- H2域名
  619. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  620. o:depends("transport", "h2")
  621. o.rmempty = true
  622. -- H2路径
  623. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  624. o:depends("transport", "h2")
  625. o.rmempty = true
  626. -- gRPC
  627. o = s:option(Value, "serviceName", translate("gRPC Service Name"))
  628. o:depends("transport", "grpc")
  629. o.rmempty = true
  630. if is_finded("xray") then
  631. -- gPRC模式
  632. o = s:option(ListValue, "grpc_mode", translate("gRPC Mode"))
  633. o:depends("transport", "grpc")
  634. o:value("gun", translate("Gun"))
  635. o:value("multi", translate("Multi"))
  636. o.rmempty = true
  637. end
  638. if is_finded("xray") then
  639. -- gRPC初始窗口
  640. o = s:option(Value, "initial_windows_size", translate("Initial Windows Size"))
  641. o.datatype = "uinteger"
  642. o:depends("transport", "grpc")
  643. o.default = 0
  644. o.rmempty = true
  645. -- H2/gRPC健康检查
  646. o = s:option(Flag, "health_check", translate("H2/gRPC Health Check"))
  647. o:depends("transport", "h2")
  648. o:depends("transport", "grpc")
  649. o.rmempty = true
  650. o = s:option(Value, "read_idle_timeout", translate("H2 Read Idle Timeout"))
  651. o.datatype = "uinteger"
  652. o:depends({health_check = true, transport = "h2"})
  653. o.default = 60
  654. o.rmempty = true
  655. o = s:option(Value, "idle_timeout", translate("gRPC Idle Timeout"))
  656. o.datatype = "uinteger"
  657. o:depends({health_check = true, transport = "grpc"})
  658. o.default = 60
  659. o.rmempty = true
  660. o = s:option(Value, "health_check_timeout", translate("Health Check Timeout"))
  661. o.datatype = "uinteger"
  662. o:depends("health_check", 1)
  663. o.default = 20
  664. o.rmempty = true
  665. o = s:option(Flag, "permit_without_stream", translate("Permit Without Stream"))
  666. o:depends({health_check = true, transport = "grpc"})
  667. o.rmempty = true
  668. end
  669. -- [[ QUIC部分 ]]--
  670. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  671. o:depends("transport", "quic")
  672. o:value("none", translate("None"))
  673. o:value("aes-128-gcm", translate("aes-128-gcm"))
  674. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  675. o.rmempty = true
  676. o = s:option(Value, "quic_key", translate("QUIC Key"))
  677. o:depends("transport", "quic")
  678. o.rmempty = true
  679. o = s:option(ListValue, "quic_guise", translate("Header"))
  680. o:depends("transport", "quic")
  681. o.rmempty = true
  682. o:value("none", translate("None"))
  683. o:value("srtp", translate("VideoCall (SRTP)"))
  684. o:value("utp", translate("BitTorrent (uTP)"))
  685. o:value("wechat-video", translate("WechatVideo"))
  686. o:value("dtls", translate("DTLS 1.2"))
  687. o:value("wireguard", translate("WireGuard"))
  688. -- [[ mKCP部分 ]]--
  689. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  690. o:depends("transport", "kcp")
  691. o:value("none", translate("None"))
  692. o:value("srtp", translate("VideoCall (SRTP)"))
  693. o:value("utp", translate("BitTorrent (uTP)"))
  694. o:value("wechat-video", translate("WechatVideo"))
  695. o:value("dtls", translate("DTLS 1.2"))
  696. o:value("wireguard", translate("WireGuard"))
  697. o.rmempty = true
  698. o = s:option(Value, "mtu", translate("MTU"))
  699. o.datatype = "uinteger"
  700. o:depends("transport", "kcp")
  701. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  702. -- o.default = 1350
  703. o.rmempty = true
  704. o = s:option(Value, "tti", translate("TTI"))
  705. o.datatype = "uinteger"
  706. o:depends("transport", "kcp")
  707. o.default = 50
  708. o.rmempty = true
  709. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity(Default:Mbps)"))
  710. o.datatype = "uinteger"
  711. o:depends("transport", "kcp")
  712. o:depends("type", "hysteria")
  713. o.default = 5
  714. o.rmempty = true
  715. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity(Default:Mbps)"))
  716. o.datatype = "uinteger"
  717. o:depends("transport", "kcp")
  718. o:depends("type", "hysteria")
  719. o.default = 20
  720. o.rmempty = true
  721. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  722. o.datatype = "uinteger"
  723. o:depends("transport", "kcp")
  724. o.default = 2
  725. o.rmempty = true
  726. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  727. o.datatype = "uinteger"
  728. o:depends("transport", "kcp")
  729. o.default = 2
  730. o.rmempty = true
  731. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  732. o:depends("transport", "kcp")
  733. o.rmempty = true
  734. o = s:option(Flag, "congestion", translate("Congestion"))
  735. o:depends("transport", "kcp")
  736. o.rmempty = true
  737. -- [[ WireGuard 部分 ]]--
  738. o = s:option(Flag, "kernelmode", translate("Enabled Kernel virtual NIC TUN(optional)"))
  739. 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.")
  740. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  741. o.default = "0"
  742. o.rmempty = true
  743. o = s:option(DynamicList, "local_addresses", translate("Local addresses"))
  744. o.datatype = "cidr"
  745. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  746. o.rmempty = true
  747. o = s:option(DynamicList, "reserved", translate("Reserved bytes(optional)"))
  748. o.description = translate("Wireguard reserved bytes.")
  749. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  750. o.rmempty = true
  751. o = s:option(Value, "private_key", translate("Private key"))
  752. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  753. o.password = true
  754. o.rmempty = true
  755. o = s:option(Value, "peer_pubkey", translate("Peer public key"))
  756. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  757. o.rmempty = true
  758. o = s:option(Value, "preshared_key", translate("Pre-shared key"))
  759. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  760. o.password = true
  761. o.rmempty = true
  762. o = s:option(DynamicList, "allowedips", translate("allowedIPs(optional)"))
  763. o.description = translate("Wireguard allows only traffic from specific source IP.")
  764. o.datatype = "cidr"
  765. o:depends({type = "v2ray", v2ray_protocol = "wireguard"})
  766. o.default = "0.0.0.0/0"
  767. o.rmempty = true
  768. -- [[ TLS ]]--
  769. o = s:option(Flag, "tls", translate("TLS"))
  770. o.rmempty = true
  771. o.default = "0"
  772. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = false})
  773. o:depends({type = "v2ray", v2ray_protocol = "vmess", reality = false})
  774. o:depends({type = "v2ray", v2ray_protocol = "trojan", reality = false})
  775. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks", reality = false})
  776. o:depends({type = "v2ray", v2ray_protocol = "socks", socks_ver = "5", reality = false})
  777. o:depends({type = "v2ray", v2ray_protocol = "http", reality = false})
  778. o:depends("type", "trojan")
  779. o:depends("type", "hysteria")
  780. -- [[ TLS部分 ]] --
  781. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  782. o:depends({type = "trojan", tls = true})
  783. o.default = "0"
  784. if is_finded("xray") then
  785. -- [[ REALITY ]]
  786. o = s:option(Flag, "reality", translate("REALITY"))
  787. o.rmempty = true
  788. o.default = "0"
  789. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = false})
  790. o = s:option(Value, "reality_publickey", translate("Public key"))
  791. o.rmempty = true
  792. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  793. o = s:option(Value, "reality_shortid", translate("Short ID"))
  794. o.rmempty = true
  795. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  796. o = s:option(Value, "reality_spiderx", translate("spiderX"))
  797. o.rmempty = true
  798. o:depends({type = "v2ray", v2ray_protocol = "vless", reality = true})
  799. -- [[ XTLS ]]--
  800. o = s:option(ListValue, "tls_flow", translate("Flow"))
  801. for _, v in ipairs(tls_flows) do
  802. if v == "none" then
  803. o.default = "none"
  804. o:value("none", translate("none"))
  805. else
  806. o:value(v, translate(v))
  807. end
  808. end
  809. o.rmempty = true
  810. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = true})
  811. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", tls = true})
  812. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", reality = true})
  813. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", reality = true})
  814. -- [[ uTLS ]]--
  815. o = s:option(ListValue, "fingerprint", translate("Finger Print"))
  816. o.default = "chrome"
  817. o:value("chrome", translate("chrome"))
  818. o:value("firefox", translate("firefox"))
  819. o:value("safari", translate("safari"))
  820. o:value("ios", translate("ios"))
  821. o:value("android", translate("android"))
  822. o:value("edge", translate("edge"))
  823. o:value("360", translate("360"))
  824. o:value("qq", translate("qq"))
  825. o:value("random", translate("random"))
  826. o:value("randomized", translate("randomized"))
  827. o:value("", translate("disable"))
  828. o:depends({type = "v2ray", tls = true})
  829. o:depends({type = "v2ray", reality = true})
  830. end
  831. o = s:option(Value, "tls_host", translate("TLS Host"))
  832. o.datatype = "hostname"
  833. o:depends("tls", true)
  834. o:depends("xtls", true)
  835. o:depends("reality", true)
  836. o.rmempty = true
  837. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  838. o:depends("type", "tuic")
  839. o.default = "h3"
  840. o.rmempty = true
  841. -- [[ allowInsecure ]]--
  842. o = s:option(Flag, "insecure", translate("allowInsecure"))
  843. o.rmempty = false
  844. o:depends("tls", true)
  845. o:depends("type", "hysteria")
  846. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  847. -- [[ Hysteria2 TLS pinSHA256 ]] --
  848. o = s:option(Value, "pinsha256", translate("Certificate fingerprint"))
  849. o:depends({type = "hysteria", insecure = true })
  850. o.rmempty = true
  851. -- [[ Mux ]]--
  852. o = s:option(Flag, "mux", translate("Mux"))
  853. o.rmempty = false
  854. o.default = false
  855. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  856. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  857. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  858. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  859. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  860. o:depends({type = "v2ray", v2ray_protocol = "http"})
  861. -- [[ TCP 最大并发连接数 ]]--
  862. o = s:option(ListValue, "concurrency", translate("concurrency"))
  863. o.rmempty = true
  864. o.default = "-1"
  865. o:value("-1", translate("disable"))
  866. o:value("8", translate("8"))
  867. o:depends("mux", true)
  868. -- [[ UDP 最大并发连接数 ]]--
  869. o = s:option(ListValue, "xudpConcurrency", translate("xudpConcurrency"))
  870. o.rmempty = true
  871. o.default = "16"
  872. o:value("-1", translate("disable"))
  873. o:value("16", translate("16"))
  874. o:depends("mux", true)
  875. -- [[ 对被代理的 UDP/443 流量处理方式 ]]--
  876. o = s:option(ListValue, "xudpProxyUDP443", translate("xudpProxyUDP443"))
  877. o.rmempty = true
  878. o.default = "reject"
  879. o:value("reject", translate("reject"))
  880. o:value("allow", translate("allow"))
  881. o:value("skip", translate("skip"))
  882. o:depends("mux", true)
  883. -- [[ MPTCP ]]--
  884. o = s:option(Flag, "mptcp", translate("MPTCP"))
  885. o.rmempty = false
  886. o.default = false
  887. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  888. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  889. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  890. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  891. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  892. o:depends({type = "v2ray", v2ray_protocol = "http"})
  893. -- [[ custom_tcpcongestion 连接服务器节点的 TCP 拥塞控制算法 ]]--
  894. o = s:option(ListValue, "custom_tcpcongestion", translate("custom_tcpcongestion"))
  895. o.rmempty = true
  896. o.default = ""
  897. o:value("", translate("comment_tcpcongestion_disable"))
  898. o:value("bbr", translate("BBR"))
  899. o:value("cubic", translate("CUBIC"))
  900. o:value("reno", translate("Reno"))
  901. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  902. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  903. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  904. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  905. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  906. o:depends({type = "v2ray", v2ray_protocol = "http"})
  907. -- [[ Cert ]]--
  908. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  909. o.rmempty = true
  910. o.default = "0"
  911. o:depends("type", "tuic")
  912. o:depends({type = "hysteria", insecure = false})
  913. o:depends({type = "trojan", tls = true, insecure = false})
  914. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  915. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  916. o.description = translate("If you have a self-signed certificate,please check the box")
  917. o = s:option(DummyValue, "upload", translate("Upload"))
  918. o.template = "shadowsocksr/certupload"
  919. o:depends("certificate", 1)
  920. cert_dir = "/etc/ssl/private/"
  921. local path
  922. luci.http.setfilehandler(function(meta, chunk, eof)
  923. if not fd then
  924. if (not meta) or (not meta.name) or (not meta.file) then
  925. return
  926. end
  927. fd = nixio.open(cert_dir .. meta.file, "w")
  928. if not fd then
  929. path = translate("Create upload file error.")
  930. return
  931. end
  932. end
  933. if chunk and fd then
  934. fd:write(chunk)
  935. end
  936. if eof and fd then
  937. fd:close()
  938. fd = nil
  939. path = '/etc/ssl/private/' .. meta.file .. ''
  940. end
  941. end)
  942. if luci.http.formvalue("upload") then
  943. local f = luci.http.formvalue("ulfile")
  944. if #f <= 0 then
  945. path = translate("No specify upload file.")
  946. end
  947. end
  948. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  949. o:depends("certificate", 1)
  950. o:value("/etc/ssl/private/ca.pem")
  951. o.description = translate("Please confirm the current certificate path")
  952. o.default = "/etc/ssl/private/ca.pem"
  953. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  954. o.rmempty = true
  955. o.default = "0"
  956. o:depends("type", "ssr")
  957. o:depends("type", "ss")
  958. o:depends("type", "trojan")
  959. o:depends("type", "hysteria")
  960. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  961. o.rmempty = false
  962. o.default = "1"
  963. o = s:option(Value, "local_port", translate("Local Port"))
  964. o.datatype = "port"
  965. o.default = 1234
  966. o.rmempty = false
  967. if is_finded("kcptun-client") then
  968. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  969. o.rmempty = true
  970. o.default = "0"
  971. o:depends("type", "ssr")
  972. o:depends("type", "ss")
  973. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  974. o.datatype = "portrange"
  975. o.default = 4000
  976. o:depends("type", "ssr")
  977. o:depends("type", "ss")
  978. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  979. o.password = true
  980. o:depends("type", "ssr")
  981. o:depends("type", "ss")
  982. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  983. o.default = "--nocomp"
  984. o:depends("type", "ssr")
  985. o:depends("type", "ss")
  986. end
  987. return m