client-config.lua 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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. o:value(v, translate(v))
  803. end
  804. o.rmempty = true
  805. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = true})
  806. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", tls = true})
  807. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", reality = true})
  808. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "raw", reality = true})
  809. -- [[ uTLS ]]--
  810. o = s:option(ListValue, "fingerprint", translate("Finger Print"))
  811. o.default = "chrome"
  812. o:value("chrome", translate("chrome"))
  813. o:value("firefox", translate("firefox"))
  814. o:value("safari", translate("safari"))
  815. o:value("ios", translate("ios"))
  816. o:value("android", translate("android"))
  817. o:value("edge", translate("edge"))
  818. o:value("360", translate("360"))
  819. o:value("qq", translate("qq"))
  820. o:value("random", translate("random"))
  821. o:value("randomized", translate("randomized"))
  822. o:value("", translate("disable"))
  823. o:depends({type = "v2ray", tls = true})
  824. o:depends({type = "v2ray", reality = true})
  825. end
  826. o = s:option(Value, "tls_host", translate("TLS Host"))
  827. o.datatype = "hostname"
  828. o:depends("tls", true)
  829. o:depends("xtls", true)
  830. o:depends("reality", true)
  831. o.rmempty = true
  832. o = s:option(DynamicList, "tls_alpn", translate("TLS ALPN"))
  833. o:depends("type", "tuic")
  834. o.default = "h3"
  835. o.rmempty = true
  836. -- [[ allowInsecure ]]--
  837. o = s:option(Flag, "insecure", translate("allowInsecure"))
  838. o.rmempty = false
  839. o:depends("tls", true)
  840. o:depends("type", "hysteria")
  841. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  842. -- [[ Hysteria2 TLS pinSHA256 ]] --
  843. o = s:option(Value, "pinsha256", translate("Certificate fingerprint"))
  844. o:depends({type = "hysteria", insecure = true })
  845. o.rmempty = true
  846. -- [[ Mux ]]--
  847. o = s:option(Flag, "mux", translate("Mux"))
  848. o.rmempty = false
  849. o.default = false
  850. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  851. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  852. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  853. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  854. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  855. o:depends({type = "v2ray", v2ray_protocol = "http"})
  856. -- [[ TCP 最大并发连接数 ]]--
  857. o = s:option(ListValue, "concurrency", translate("concurrency"))
  858. o.rmempty = true
  859. o.default = "-1"
  860. o:value("-1", translate("disable"))
  861. o:value("8", translate("8"))
  862. o:depends("mux", true)
  863. -- [[ UDP 最大并发连接数 ]]--
  864. o = s:option(ListValue, "xudpConcurrency", translate("xudpConcurrency"))
  865. o.rmempty = true
  866. o.default = "16"
  867. o:value("-1", translate("disable"))
  868. o:value("16", translate("16"))
  869. o:depends("mux", true)
  870. -- [[ 对被代理的 UDP/443 流量处理方式 ]]--
  871. o = s:option(ListValue, "xudpProxyUDP443", translate("xudpProxyUDP443"))
  872. o.rmempty = true
  873. o.default = "reject"
  874. o:value("reject", translate("reject"))
  875. o:value("allow", translate("allow"))
  876. o:value("skip", translate("skip"))
  877. o:depends("mux", true)
  878. -- [[ MPTCP ]]--
  879. o = s:option(Flag, "mptcp", translate("MPTCP"))
  880. o.rmempty = false
  881. o.default = false
  882. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  883. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  884. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  885. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  886. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  887. o:depends({type = "v2ray", v2ray_protocol = "http"})
  888. -- [[ custom_tcpcongestion 连接服务器节点的 TCP 拥塞控制算法 ]]--
  889. o = s:option(ListValue, "custom_tcpcongestion", translate("custom_tcpcongestion"))
  890. o.rmempty = true
  891. o.default = ""
  892. o:value("", translate("comment_tcpcongestion_disable"))
  893. o:value("bbr", translate("BBR"))
  894. o:value("cubic", translate("CUBIC"))
  895. o:value("reno", translate("Reno"))
  896. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  897. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  898. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  899. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  900. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  901. o:depends({type = "v2ray", v2ray_protocol = "http"})
  902. -- [[ Cert ]]--
  903. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  904. o.rmempty = true
  905. o.default = "0"
  906. o:depends("type", "tuic")
  907. o:depends({type = "hysteria", insecure = false})
  908. o:depends({type = "trojan", tls = true, insecure = false})
  909. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  910. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  911. o.description = translate("If you have a self-signed certificate,please check the box")
  912. o = s:option(DummyValue, "upload", translate("Upload"))
  913. o.template = "shadowsocksr/certupload"
  914. o:depends("certificate", 1)
  915. cert_dir = "/etc/ssl/private/"
  916. local path
  917. luci.http.setfilehandler(function(meta, chunk, eof)
  918. if not fd then
  919. if (not meta) or (not meta.name) or (not meta.file) then
  920. return
  921. end
  922. fd = nixio.open(cert_dir .. meta.file, "w")
  923. if not fd then
  924. path = translate("Create upload file error.")
  925. return
  926. end
  927. end
  928. if chunk and fd then
  929. fd:write(chunk)
  930. end
  931. if eof and fd then
  932. fd:close()
  933. fd = nil
  934. path = '/etc/ssl/private/' .. meta.file .. ''
  935. end
  936. end)
  937. if luci.http.formvalue("upload") then
  938. local f = luci.http.formvalue("ulfile")
  939. if #f <= 0 then
  940. path = translate("No specify upload file.")
  941. end
  942. end
  943. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  944. o:depends("certificate", 1)
  945. o:value("/etc/ssl/private/ca.pem")
  946. o.description = translate("Please confirm the current certificate path")
  947. o.default = "/etc/ssl/private/ca.pem"
  948. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  949. o.rmempty = true
  950. o.default = "0"
  951. o:depends("type", "ssr")
  952. o:depends("type", "ss")
  953. o:depends("type", "trojan")
  954. o:depends("type", "hysteria")
  955. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  956. o.rmempty = false
  957. o.default = "1"
  958. o = s:option(Value, "local_port", translate("Local Port"))
  959. o.datatype = "port"
  960. o.default = 1234
  961. o.rmempty = false
  962. if is_finded("kcptun-client") then
  963. o = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  964. o.rmempty = true
  965. o.default = "0"
  966. o:depends("type", "ssr")
  967. o:depends("type", "ss")
  968. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  969. o.datatype = "portrange"
  970. o.default = 4000
  971. o:depends("type", "ssr")
  972. o:depends("type", "ss")
  973. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  974. o.password = true
  975. o:depends("type", "ssr")
  976. o:depends("type", "ss")
  977. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  978. o.default = "--nocomp"
  979. o:depends("type", "ssr")
  980. o:depends("type", "ss")
  981. end
  982. return m