client-config.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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. local m, s, o, kcp_enable
  7. local sid = arg[1]
  8. local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid")
  9. function is_finded(e)
  10. return luci.sys.exec('type -t -p "%s"' % e) ~= "" and true or false
  11. end
  12. local server_table = {}
  13. local encrypt_methods = {
  14. -- ssr
  15. "none",
  16. "table",
  17. "rc4",
  18. "rc4-md5-6",
  19. "rc4-md5",
  20. "aes-128-cfb",
  21. "aes-192-cfb",
  22. "aes-256-cfb",
  23. "aes-128-ctr",
  24. "aes-192-ctr",
  25. "aes-256-ctr",
  26. "bf-cfb",
  27. "camellia-128-cfb",
  28. "camellia-192-cfb",
  29. "camellia-256-cfb",
  30. "cast5-cfb",
  31. "des-cfb",
  32. "idea-cfb",
  33. "rc2-cfb",
  34. "seed-cfb",
  35. "salsa20",
  36. "chacha20",
  37. "chacha20-ietf"
  38. }
  39. local encrypt_methods_ss = {
  40. -- aead
  41. "aes-128-gcm",
  42. "aes-192-gcm",
  43. "aes-256-gcm",
  44. "chacha20-ietf-poly1305",
  45. "xchacha20-ietf-poly1305"
  46. --[[ stream
  47. "none",
  48. "plain",
  49. "table",
  50. "rc4",
  51. "rc4-md5",
  52. "aes-128-cfb",
  53. "aes-192-cfb",
  54. "aes-256-cfb",
  55. "aes-128-ctr",
  56. "aes-192-ctr",
  57. "aes-256-ctr",
  58. "bf-cfb",
  59. "camellia-128-cfb",
  60. "camellia-192-cfb",
  61. "camellia-256-cfb",
  62. "salsa20",
  63. "chacha20",
  64. "chacha20-ietf" ]]
  65. }
  66. local encrypt_methods_v2ray_ss = {
  67. -- xray_ss
  68. "none",
  69. "plain",
  70. -- aead
  71. "aes-128-gcm",
  72. "aes-256-gcm",
  73. "chacha20-poly1305",
  74. "chacha20-ietf-poly1305",
  75. "aead_aes_128_gcm",
  76. "aead_aes_256_gcm",
  77. "aead_chacha20_poly1305"
  78. }
  79. local protocol = {
  80. -- ssr
  81. "origin",
  82. "verify_deflate",
  83. "auth_sha1_v4",
  84. "auth_aes128_sha1",
  85. "auth_aes128_md5",
  86. "auth_chain_a",
  87. "auth_chain_b",
  88. "auth_chain_c",
  89. "auth_chain_d",
  90. "auth_chain_e",
  91. "auth_chain_f"
  92. }
  93. obfs = {
  94. -- ssr
  95. "plain",
  96. "http_simple",
  97. "http_post",
  98. "random_head",
  99. "tls1.2_ticket_auth"
  100. }
  101. local securitys = {
  102. -- vmess
  103. "auto",
  104. "none",
  105. "aes-128-gcm",
  106. "chacha20-poly1305"
  107. }
  108. local flows = {
  109. -- xlts
  110. "xtls-rprx-origin",
  111. "xtls-rprx-origin-udp443",
  112. "xtls-rprx-direct",
  113. "xtls-rprx-direct-udp443",
  114. "xtls-rprx-splice",
  115. "xtls-rprx-splice-udp443"
  116. }
  117. m = Map("shadowsocksr", translate("Edit ShadowSocksR Server"))
  118. m.redirect = luci.dispatcher.build_url("admin/services/shadowsocksr/servers")
  119. if m.uci:get("shadowsocksr", sid) ~= "servers" then
  120. luci.http.redirect(m.redirect)
  121. return
  122. end
  123. -- [[ Servers Setting ]]--
  124. s = m:section(NamedSection, sid, "servers")
  125. s.anonymous = true
  126. s.addremove = false
  127. o = s:option(DummyValue, "ssr_url", "SS/SSR/V2RAY/TROJAN URL")
  128. o.rawhtml = true
  129. o.template = "shadowsocksr/ssrurl"
  130. o.value = sid
  131. o = s:option(ListValue, "type", translate("Server Node Type"))
  132. if is_finded("xray") or is_finded("v2ray") then
  133. o:value("v2ray", translate("V2Ray/XRay"))
  134. end
  135. if is_finded("ssr-redir") then
  136. o:value("ssr", translate("ShadowsocksR"))
  137. end
  138. if is_finded("sslocal") or is_finded("ss-redir") then
  139. o:value("ss", translate("Shadowsocks New Version"))
  140. end
  141. if is_finded("trojan") then
  142. o:value("trojan", translate("Trojan"))
  143. end
  144. if is_finded("naive") then
  145. o:value("naiveproxy", translate("NaiveProxy"))
  146. end
  147. if is_finded("ipt2socks") then
  148. o:value("socks5", translate("Socks5"))
  149. end
  150. if is_finded("redsocks2") then
  151. o:value("tun", translate("Network Tunnel"))
  152. end
  153. o.description = translate("Using incorrect encryption mothod may causes service fail to start")
  154. o = s:option(Value, "alias", translate("Alias(optional)"))
  155. o = s:option(ListValue, "iface", translate("Network interface to use"))
  156. for _, e in ipairs(luci.sys.net.devices()) do
  157. if e ~= "lo" then
  158. o:value(e)
  159. end
  160. end
  161. o:depends("type", "tun")
  162. o.description = translate("Redirect traffic to this network interface")
  163. o = s:option(ListValue, "v2ray_protocol", translate("V2Ray/XRay protocol"))
  164. o:value("vless", translate("VLESS"))
  165. o:value("vmess", translate("VMess"))
  166. o:value("trojan", translate("Trojan"))
  167. o:value("shadowsocks", translate("Shadowsocks"))
  168. o:value("socks", translate("Socks"))
  169. o:value("http", translate("HTTP"))
  170. o:depends("type", "v2ray")
  171. o = s:option(Value, "server", translate("Server Address"))
  172. o.datatype = "host"
  173. o.rmempty = false
  174. o:depends("type", "ssr")
  175. o:depends("type", "ss")
  176. o:depends("type", "v2ray")
  177. o:depends("type", "trojan")
  178. o:depends("type", "naiveproxy")
  179. o:depends("type", "socks5")
  180. o = s:option(Value, "server_port", translate("Server Port"))
  181. o.datatype = "port"
  182. o.rmempty = false
  183. o:depends("type", "ssr")
  184. o:depends("type", "ss")
  185. o:depends("type", "v2ray")
  186. o:depends("type", "trojan")
  187. o:depends("type", "naiveproxy")
  188. o:depends("type", "socks5")
  189. o = s:option(Flag, "auth_enable", translate("Enable Authentication"))
  190. o.rmempty = false
  191. o.default = "0"
  192. o:depends("type", "socks5")
  193. o:depends({type = "v2ray", v2ray_protocol = "http"})
  194. o:depends({type = "v2ray", v2ray_protocol = "socks"})
  195. o = s:option(Value, "username", translate("Username"))
  196. o.rmempty = true
  197. o:depends("type", "naiveproxy")
  198. o:depends({type = "socks5", auth_enable = true})
  199. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  200. o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
  201. o = s:option(Value, "password", translate("Password"))
  202. o.password = true
  203. o.rmempty = true
  204. o:depends("type", "ssr")
  205. o:depends("type", "ss")
  206. o:depends("type", "trojan")
  207. o:depends("type", "naiveproxy")
  208. o:depends({type = "socks5", auth_enable = true})
  209. o:depends({type = "v2ray", v2ray_protocol = "http", auth_enable = true})
  210. o:depends({type = "v2ray", v2ray_protocol = "socks", auth_enable = true})
  211. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  212. o:depends({type = "v2ray", v2ray_protocol = "trojan"})
  213. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  214. for _, v in ipairs(encrypt_methods) do
  215. o:value(v)
  216. end
  217. o.rmempty = true
  218. o:depends("type", "ssr")
  219. o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
  220. for _, v in ipairs(encrypt_methods_ss) do
  221. o:value(v)
  222. end
  223. o.rmempty = true
  224. o:depends("type", "ss")
  225. o = s:option(ListValue, "encrypt_method_v2ray_ss", translate("Encrypt Method"))
  226. for _, v in ipairs(encrypt_methods_v2ray_ss) do
  227. o:value(v)
  228. end
  229. o.rmempty = true
  230. o:depends({type = "v2ray", v2ray_protocol = "shadowsocks"})
  231. -- Shadowsocks Plugin
  232. o = s:option(Value, "plugin", translate("Obfs"))
  233. o:value("none", translate("None"))
  234. if is_finded("obfs-local") then
  235. o:value("obfs-local", translate("obfs-local"))
  236. end
  237. if is_finded("v2ray-plugin") then
  238. o:value("v2ray-plugin", translate("v2ray-plugin"))
  239. end
  240. if is_finded("xray-plugin") then
  241. o:value("xray-plugin", translate("xray-plugin"))
  242. end
  243. o.rmempty = true
  244. o:depends("type", "ss")
  245. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  246. o.rmempty = true
  247. o:depends({type = "ss", plugin = "obfs-local"})
  248. o:depends({type = "ss", plugin = "v2ray-plugin"})
  249. o:depends({type = "ss", plugin = "xray-plugin"})
  250. o = s:option(ListValue, "protocol", translate("Protocol"))
  251. for _, v in ipairs(protocol) do
  252. o:value(v)
  253. end
  254. o.rmempty = true
  255. o:depends("type", "ssr")
  256. o = s:option(Value, "protocol_param", translate("Protocol param(optional)"))
  257. o:depends("type", "ssr")
  258. o = s:option(ListValue, "obfs", translate("Obfs"))
  259. for _, v in ipairs(obfs) do
  260. o:value(v)
  261. end
  262. o.rmempty = true
  263. o:depends("type", "ssr")
  264. o = s:option(Value, "obfs_param", translate("Obfs param(optional)"))
  265. o:depends("type", "ssr")
  266. -- AlterId
  267. o = s:option(Value, "alter_id", translate("AlterId"))
  268. o.datatype = "port"
  269. o.default = 16
  270. o.rmempty = true
  271. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  272. -- VmessId
  273. o = s:option(Value, "vmess_id", translate("Vmess/VLESS ID (UUID)"))
  274. o.rmempty = true
  275. o.default = uuid
  276. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  277. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  278. -- VLESS Encryption
  279. o = s:option(Value, "vless_encryption", translate("VLESS Encryption"))
  280. o.rmempty = true
  281. o.default = "none"
  282. o:depends({type = "v2ray", v2ray_protocol = "vless"})
  283. -- 加密方式
  284. o = s:option(ListValue, "security", translate("Encrypt Method"))
  285. for _, v in ipairs(securitys) do
  286. o:value(v, v:upper())
  287. end
  288. o.rmempty = true
  289. o:depends({type = "v2ray", v2ray_protocol = "vmess"})
  290. -- 传输协议
  291. o = s:option(ListValue, "transport", translate("Transport"))
  292. o:value("tcp", "TCP")
  293. o:value("kcp", "mKCP")
  294. o:value("ws", "WebSocket")
  295. o:value("h2", "HTTP/2")
  296. o:value("quic", "QUIC")
  297. o:value("grpc", "gRPC")
  298. o.rmempty = true
  299. o:depends("type", "v2ray")
  300. -- [[ TCP部分 ]]--
  301. -- TCP伪装
  302. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  303. o:depends("transport", "tcp")
  304. o:value("none", translate("None"))
  305. o:value("http", "HTTP")
  306. o.rmempty = true
  307. -- HTTP域名
  308. o = s:option(Value, "http_host", translate("HTTP Host"))
  309. o:depends("tcp_guise", "http")
  310. o.rmempty = true
  311. -- HTTP路径
  312. o = s:option(Value, "http_path", translate("HTTP Path"))
  313. o:depends("tcp_guise", "http")
  314. o.rmempty = true
  315. -- [[ WS部分 ]]--
  316. -- WS域名
  317. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  318. o:depends({transport = "ws", tls = false})
  319. o.datatype = "hostname"
  320. o.rmempty = true
  321. -- WS路径
  322. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  323. o:depends("transport", "ws")
  324. o.rmempty = true
  325. -- [[ H2部分 ]]--
  326. -- H2域名
  327. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  328. o:depends("transport", "h2")
  329. o.rmempty = true
  330. -- H2路径
  331. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  332. o:depends("transport", "h2")
  333. o.rmempty = true
  334. -- gRPC
  335. o = s:option(Value, "serviceName", translate("serviceName"))
  336. o:depends("transport", "grpc")
  337. o.rmempty = true
  338. -- [[ QUIC部分 ]]--
  339. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  340. o:depends("transport", "quic")
  341. o:value("none", translate("None"))
  342. o:value("aes-128-gcm", translate("aes-128-gcm"))
  343. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  344. o.rmempty = true
  345. o = s:option(Value, "quic_key", translate("QUIC Key"))
  346. o:depends("transport", "quic")
  347. o.rmempty = true
  348. o = s:option(ListValue, "quic_guise", translate("Header"))
  349. o:depends("transport", "quic")
  350. o.rmempty = true
  351. o:value("none", translate("None"))
  352. o:value("srtp", translate("VideoCall (SRTP)"))
  353. o:value("utp", translate("BitTorrent (uTP)"))
  354. o:value("wechat-video", translate("WechatVideo"))
  355. o:value("dtls", translate("DTLS 1.2"))
  356. o:value("wireguard", translate("WireGuard"))
  357. -- [[ mKCP部分 ]]--
  358. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  359. o:depends("transport", "kcp")
  360. o:value("none", translate("None"))
  361. o:value("srtp", translate("VideoCall (SRTP)"))
  362. o:value("utp", translate("BitTorrent (uTP)"))
  363. o:value("wechat-video", translate("WechatVideo"))
  364. o:value("dtls", translate("DTLS 1.2"))
  365. o:value("wireguard", translate("WireGuard"))
  366. o.rmempty = true
  367. o = s:option(Value, "mtu", translate("MTU"))
  368. o.datatype = "uinteger"
  369. o:depends("transport", "kcp")
  370. o.default = 1350
  371. o.rmempty = true
  372. o = s:option(Value, "tti", translate("TTI"))
  373. o.datatype = "uinteger"
  374. o:depends("transport", "kcp")
  375. o.default = 50
  376. o.rmempty = true
  377. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity"))
  378. o.datatype = "uinteger"
  379. o:depends("transport", "kcp")
  380. o.default = 5
  381. o.rmempty = true
  382. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity"))
  383. o.datatype = "uinteger"
  384. o:depends("transport", "kcp")
  385. o.default = 20
  386. o.rmempty = true
  387. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  388. o.datatype = "uinteger"
  389. o:depends("transport", "kcp")
  390. o.default = 2
  391. o.rmempty = true
  392. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  393. o.datatype = "uinteger"
  394. o:depends("transport", "kcp")
  395. o.default = 2
  396. o.rmempty = true
  397. o = s:option(Value, "seed", translate("Obfuscate password (optional)"))
  398. o:depends({v2ray_protocol = "vless", transport = "kcp"})
  399. o.rmempty = true
  400. o = s:option(Flag, "congestion", translate("Congestion"))
  401. o:depends("transport", "kcp")
  402. o.rmempty = true
  403. -- [[ TLS ]]--
  404. o = s:option(Flag, "tls", translate("TLS"))
  405. o.rmempty = true
  406. o.default = "0"
  407. o:depends({type = "v2ray", xtls = false})
  408. -- o:depends({type = "v2ray", v2ray_protocol = "vless", xtls = false})
  409. o:depends("type", "trojan")
  410. -- XTLS
  411. if is_finded("xray") then
  412. o = s:option(Flag, "xtls", translate("XTLS"))
  413. o.rmempty = true
  414. o.default = "0"
  415. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "tcp", tls = false})
  416. o:depends({type = "v2ray", v2ray_protocol = "vless", transport = "kcp", tls = false})
  417. o:depends({type = "v2ray", v2ray_protocol = "trojan", transport = "tcp", tls = false})
  418. o:depends({type = "v2ray", v2ray_protocol = "trojan", transport = "kcp", tls = false})
  419. end
  420. -- Flow
  421. o = s:option(Value, "vless_flow", translate("Flow"))
  422. for _, v in ipairs(flows) do
  423. o:value(v, translate(v))
  424. end
  425. o.rmempty = true
  426. o.default = "xtls-rprx-splice"
  427. o:depends("xtls", true)
  428. -- [[ TLS部分 ]] --
  429. o = s:option(Flag, "tls_sessionTicket", translate("Session Ticket"))
  430. o:depends({type = "trojan", tls = true})
  431. o.default = "0"
  432. -- [[ uTLS ]]--
  433. o = s:option(ListValue, "fingerprint", translate("Finger Print"))
  434. o:value("disable", translate("disable"))
  435. o:value("firefox", translate("firefox"))
  436. o:value("chrome", translate("chrome"))
  437. o:value("safari", translate("safari"))
  438. o:value("randomized", translate("randomized"))
  439. o:depends({type = "v2ray", tls = true})
  440. o.default = "disable"
  441. o = s:option(Value, "tls_host", translate("TLS Host"))
  442. o.datatype = "hostname"
  443. o:depends("tls", true)
  444. o:depends("xtls", true)
  445. o.rmempty = true
  446. -- [[ allowInsecure ]]--
  447. o = s:option(Flag, "insecure", translate("allowInsecure"))
  448. o.rmempty = false
  449. o:depends("tls", true)
  450. o:depends("xtls", true)
  451. o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
  452. -- [[ Mux ]]--
  453. o = s:option(Flag, "mux", translate("Mux"))
  454. o.rmempty = false
  455. o:depends({type = "v2ray", xtls = false})
  456. o = s:option(Value, "concurrency", translate("Concurrency"))
  457. o.datatype = "uinteger"
  458. o.rmempty = true
  459. o.default = "8"
  460. o:depends("mux", "1")
  461. -- [[ Cert ]]--
  462. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  463. o.rmempty = true
  464. o.default = "0"
  465. o:depends({type = "trojan", tls = true, insecure = false})
  466. o:depends({type = "v2ray", v2ray_protocol = "vmess", tls = true, insecure = false})
  467. o:depends({type = "v2ray", v2ray_protocol = "vless", tls = true, insecure = false})
  468. o:depends({type = "v2ray", v2ray_protocol = "vmess", xtls = true, insecure = false})
  469. o:depends({type = "v2ray", v2ray_protocol = "vless", xtls = true, insecure = false})
  470. o.description = translate("If you have a self-signed certificate,please check the box")
  471. o = s:option(DummyValue, "upload", translate("Upload"))
  472. o.template = "shadowsocksr/certupload"
  473. o:depends("certificate", 1)
  474. cert_dir = "/etc/ssl/private/"
  475. local path
  476. luci.http.setfilehandler(function(meta, chunk, eof)
  477. if not fd then
  478. if (not meta) or (not meta.name) or (not meta.file) then
  479. return
  480. end
  481. fd = nixio.open(cert_dir .. meta.file, "w")
  482. if not fd then
  483. path = translate("Create upload file error.")
  484. return
  485. end
  486. end
  487. if chunk and fd then
  488. fd:write(chunk)
  489. end
  490. if eof and fd then
  491. fd:close()
  492. fd = nil
  493. path = '/etc/ssl/private/' .. meta.file .. ''
  494. end
  495. end)
  496. if luci.http.formvalue("upload") then
  497. local f = luci.http.formvalue("ulfile")
  498. if #f <= 0 then
  499. path = translate("No specify upload file.")
  500. end
  501. end
  502. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  503. o:depends("certificate", 1)
  504. o:value("/etc/ssl/private/ca.pem")
  505. o.description = translate("Please confirm the current certificate path")
  506. o.default = "/etc/ssl/private/ca.pem"
  507. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  508. o.rmempty = true
  509. o.default = "0"
  510. o:depends("type", "ssr")
  511. o:depends("type", "ss")
  512. o:depends("type", "trojan")
  513. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  514. o.rmempty = false
  515. o.default = "1"
  516. o = s:option(Value, "local_port", translate("Local Port"))
  517. o.datatype = "port"
  518. o.default = 1234
  519. o.rmempty = false
  520. if is_finded("kcptun-client") then
  521. kcp_enable = s:option(Flag, "kcp_enable", translate("KcpTun Enable"))
  522. kcp_enable.rmempty = true
  523. kcp_enable.default = "0"
  524. kcp_enable:depends("type", "ssr")
  525. kcp_enable:depends("type", "ss")
  526. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  527. o.datatype = "port"
  528. o.default = 4000
  529. o:depends("type", "ssr")
  530. o:depends("type", "ss")
  531. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  532. o.password = true
  533. o:depends("type", "ssr")
  534. o:depends("type", "ss")
  535. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  536. o.default = "--nocomp"
  537. o:depends("type", "ssr")
  538. o:depends("type", "ss")
  539. end
  540. return m