client-config.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. -- Copyright (C) 2017 yushi studio <[email protected]> github.com/ywb94
  2. -- Licensed to the public under the GNU General Public License v3.
  3. local m, s, o,kcp_enable
  4. local shadowsocksr = "shadowsocksr"
  5. local uci = luci.model.uci.cursor()
  6. local fs = require "nixio.fs"
  7. local sys = require "luci.sys"
  8. local sid = arg[1]
  9. local uuid = luci.sys.exec("cat /proc/sys/kernel/random/uuid")
  10. local http = require "luci.http"
  11. local function isKcptun(file)
  12. if not fs.access(file, "rwx", "rx", "rx") then
  13. fs.chmod(file, 755)
  14. end
  15. local str = sys.exec(file .. " -v | awk '{printf $1}'")
  16. return (str:lower() == "kcptun")
  17. end
  18. local server_table = {}
  19. local encrypt_methods = {
  20. "none",
  21. "table",
  22. "rc4",
  23. "rc4-md5-6",
  24. "rc4-md5",
  25. "aes-128-cfb",
  26. "aes-192-cfb",
  27. "aes-256-cfb",
  28. "aes-128-ctr",
  29. "aes-192-ctr",
  30. "aes-256-ctr",
  31. "bf-cfb",
  32. "camellia-128-cfb",
  33. "camellia-192-cfb",
  34. "camellia-256-cfb",
  35. "cast5-cfb",
  36. "des-cfb",
  37. "idea-cfb",
  38. "rc2-cfb",
  39. "seed-cfb",
  40. "salsa20",
  41. "chacha20",
  42. "chacha20-ietf",
  43. }
  44. local encrypt_methods_ss = {
  45. -- aead
  46. "aes-128-gcm",
  47. "aes-192-gcm",
  48. "aes-256-gcm",
  49. "chacha20-ietf-poly1305",
  50. "xchacha20-ietf-poly1305",
  51. -- stream
  52. "table",
  53. "rc4",
  54. "rc4-md5",
  55. "aes-128-cfb",
  56. "aes-192-cfb",
  57. "aes-256-cfb",
  58. "aes-128-ctr",
  59. "aes-192-ctr",
  60. "aes-256-ctr",
  61. "bf-cfb",
  62. "camellia-128-cfb",
  63. "camellia-192-cfb",
  64. "camellia-256-cfb",
  65. "salsa20",
  66. "chacha20",
  67. "chacha20-ietf",
  68. }
  69. local protocol = {
  70. "origin",
  71. "verify_deflate",
  72. "auth_sha1_v4",
  73. "auth_aes128_sha1",
  74. "auth_aes128_md5",
  75. "auth_chain_a",
  76. "auth_chain_b",
  77. "auth_chain_c",
  78. "auth_chain_d",
  79. "auth_chain_e",
  80. "auth_chain_f",
  81. }
  82. obfs = {
  83. "plain",
  84. "http_simple",
  85. "http_post",
  86. "random_head",
  87. "tls1.2_ticket_auth",
  88. }
  89. local securitys = {
  90. "auto",
  91. "none",
  92. "aes-128-gcm",
  93. "chacha20-poly1305"
  94. }
  95. m = Map(shadowsocksr, translate("Edit ShadowSocksR Server"))
  96. m.redirect = luci.dispatcher.build_url("admin/services/shadowsocksr/servers")
  97. if m.uci:get(shadowsocksr, sid) ~= "servers" then
  98. luci.http.redirect(m.redirect)
  99. return
  100. end
  101. -- [[ Servers Setting ]]--
  102. s = m:section(NamedSection, sid, "servers")
  103. s.anonymous = true
  104. s.addremove = false
  105. o = s:option(DummyValue,"ssr_url","SS/SSR/V2RAY/TROJAN URL")
  106. o.rawhtml = true
  107. o.template = "shadowsocksr/ssrurl"
  108. o.value =sid
  109. o = s:option(ListValue, "type", translate("Server Node Type"))
  110. o:value("ssr", translate("ShadowsocksR"))
  111. if nixio.fs.access("/usr/bin/ss-redir") then
  112. o:value("ss", translate("Shadowsocks New Version"))
  113. end
  114. if nixio.fs.access("/usr/bin/v2ray/v2ray") or nixio.fs.access("/usr/bin/v2ray") then
  115. o:value("v2ray", translate("V2Ray"))
  116. end
  117. if nixio.fs.access("/usr/sbin/trojan") then
  118. o:value("trojan", translate("Trojan"))
  119. end
  120. if nixio.fs.access("/usr/sbin/redsocks2") then
  121. o:value("socks5", translate("Socks5"))
  122. o:value("tun", translate("Network Tunnel"))
  123. end
  124. o.description = translate("Using incorrect encryption mothod may causes service fail to start")
  125. o = s:option(Value, "alias", translate("Alias(optional)"))
  126. o = s:option(ListValue, "iface", translate("Network interface to use"))
  127. for _, e in ipairs(sys.net.devices()) do
  128. if e ~= "lo" then o:value(e) end
  129. end
  130. o:depends("type", "tun")
  131. o.description = translate("Redirect traffic to this network interface")
  132. o = s:option(Value, "server", translate("Server Address"))
  133. o.datatype = "host"
  134. o.rmempty = false
  135. o:depends("type", "ssr")
  136. o:depends("type", "ss")
  137. o:depends("type", "v2ray")
  138. o:depends("type", "trojan")
  139. o:depends("type", "socks5")
  140. o = s:option(Value, "server_port", translate("Server Port"))
  141. o.datatype = "port"
  142. o.rmempty = false
  143. o:depends("type", "ssr")
  144. o:depends("type", "ss")
  145. o:depends("type", "v2ray")
  146. o:depends("type", "trojan")
  147. o:depends("type", "socks5")
  148. o = s:option(Flag, "auth_enable", translate("Enable Authentication"))
  149. o.rmempty = false
  150. o.default = "0"
  151. o:depends("type", "socks5")
  152. o = s:option(Value, "username", translate("Username"))
  153. o.rmempty = true
  154. o:depends("type", "socks5")
  155. o = s:option(Value, "password", translate("Password"))
  156. o.password = true
  157. o.rmempty = true
  158. o:depends("type", "ssr")
  159. o:depends("type", "ss")
  160. o:depends("type", "trojan")
  161. o:depends("type", "socks5")
  162. o = s:option(ListValue, "encrypt_method", translate("Encrypt Method"))
  163. for _, v in ipairs(encrypt_methods) do o:value(v) end
  164. o.rmempty = true
  165. o:depends("type", "ssr")
  166. o = s:option(ListValue, "encrypt_method_ss", translate("Encrypt Method"))
  167. for _, v in ipairs(encrypt_methods_ss) do o:value(v) end
  168. o.rmempty = true
  169. o:depends("type", "ss")
  170. -- Shadowsocks Plugin
  171. o = s:option(Value, "plugin", translate("Plugin"))
  172. o.rmempty = true
  173. o:depends("type", "ss")
  174. o = s:option(Value, "plugin_opts", translate("Plugin Opts"))
  175. o.rmempty = true
  176. o:depends("type", "ss")
  177. o = s:option(ListValue, "protocol", translate("Protocol"))
  178. for _, v in ipairs(protocol) do o:value(v) end
  179. o.rmempty = true
  180. o:depends("type", "ssr")
  181. o = s:option(Value, "protocol_param", translate("Protocol param(optional)"))
  182. o:depends("type", "ssr")
  183. o = s:option(ListValue, "obfs", translate("Obfs"))
  184. for _, v in ipairs(obfs) do o:value(v) end
  185. o.rmempty = true
  186. o:depends("type", "ssr")
  187. o = s:option(Value, "obfs_param", translate("Obfs param(optional)"))
  188. o:depends("type", "ssr")
  189. -- AlterId
  190. o = s:option(Value, "alter_id", translate("AlterId"))
  191. o.datatype = "port"
  192. o.default = 16
  193. o.rmempty = true
  194. o:depends("type", "v2ray")
  195. -- VmessId
  196. o = s:option(Value, "vmess_id", translate("VmessId (UUID)"))
  197. o.rmempty = true
  198. o.default = uuid
  199. o:depends("type", "v2ray")
  200. -- 加密方式
  201. o = s:option(ListValue, "security", translate("Encrypt Method"))
  202. for _, v in ipairs(securitys) do o:value(v, v:upper()) end
  203. o.rmempty = true
  204. o:depends("type", "v2ray")
  205. -- 传输协议
  206. o = s:option(ListValue, "transport", translate("Transport"))
  207. o:value("tcp", "TCP")
  208. o:value("kcp", "mKCP")
  209. o:value("ws", "WebSocket")
  210. o:value("h2", "HTTP/2")
  211. o:value("quic", "QUIC")
  212. o.rmempty = true
  213. o:depends("type", "v2ray")
  214. -- [[ TCP部分 ]]--
  215. -- TCP伪装
  216. o = s:option(ListValue, "tcp_guise", translate("Camouflage Type"))
  217. o:depends("transport", "tcp")
  218. o:value("http", "HTTP")
  219. o:value("none", translate("None"))
  220. o.rmempty = true
  221. -- HTTP域名
  222. o = s:option(Value, "http_host", translate("HTTP Host"))
  223. o:depends("tcp_guise", "http")
  224. o.rmempty = true
  225. -- HTTP路径
  226. o = s:option(Value, "http_path", translate("HTTP Path"))
  227. o:depends("tcp_guise", "http")
  228. o.rmempty = true
  229. -- [[ WS部分 ]]--
  230. -- WS域名
  231. o = s:option(Value, "ws_host", translate("WebSocket Host"))
  232. o:depends("transport", "ws")
  233. o.rmempty = true
  234. -- WS路径
  235. o = s:option(Value, "ws_path", translate("WebSocket Path"))
  236. o:depends("transport", "ws")
  237. o.rmempty = true
  238. -- [[ H2部分 ]]--
  239. -- H2域名
  240. o = s:option(Value, "h2_host", translate("HTTP/2 Host"))
  241. o:depends("transport", "h2")
  242. o.rmempty = true
  243. -- H2路径
  244. o = s:option(Value, "h2_path", translate("HTTP/2 Path"))
  245. o:depends("transport", "h2")
  246. o.rmempty = true
  247. -- [[ QUIC部分 ]]--
  248. o = s:option(ListValue, "quic_security", translate("QUIC Security"))
  249. o:depends("transport", "quic")
  250. o.rmempty = true
  251. o:value("none", translate("None"))
  252. o:value("aes-128-gcm", translate("aes-128-gcm"))
  253. o:value("chacha20-poly1305", translate("chacha20-poly1305"))
  254. o = s:option(Value, "quic_key", translate("QUIC Key"))
  255. o:depends("transport", "quic")
  256. o.rmempty = true
  257. o = s:option(ListValue, "quic_guise", translate("Header"))
  258. o:depends("transport", "quic")
  259. o.rmempty = true
  260. o:value("none", translate("None"))
  261. o:value("srtp", translate("VideoCall (SRTP)"))
  262. o:value("utp", translate("BitTorrent (uTP)"))
  263. o:value("wechat-video", translate("WechatVideo"))
  264. o:value("dtls", "DTLS 1.2")
  265. o:value("wireguard", "WireGuard")
  266. -- [[ mKCP部分 ]]--
  267. o = s:option(ListValue, "kcp_guise", translate("Camouflage Type"))
  268. o:depends("transport", "kcp")
  269. o:value("none", translate("None"))
  270. o:value("srtp", translate("VideoCall (SRTP)"))
  271. o:value("utp", translate("BitTorrent (uTP)"))
  272. o:value("wechat-video", translate("WechatVideo"))
  273. o:value("dtls", "DTLS 1.2")
  274. o:value("wireguard", "WireGuard")
  275. o.rmempty = true
  276. o = s:option(Value, "mtu", translate("MTU"))
  277. o.datatype = "uinteger"
  278. o:depends("transport", "kcp")
  279. o.default = 1350
  280. o.rmempty = true
  281. o = s:option(Value, "tti", translate("TTI"))
  282. o.datatype = "uinteger"
  283. o:depends("transport", "kcp")
  284. o.default = 50
  285. o.rmempty = true
  286. o = s:option(Value, "uplink_capacity", translate("Uplink Capacity"))
  287. o.datatype = "uinteger"
  288. o:depends("transport", "kcp")
  289. o.default = 5
  290. o.rmempty = true
  291. o = s:option(Value, "downlink_capacity", translate("Downlink Capacity"))
  292. o.datatype = "uinteger"
  293. o:depends("transport", "kcp")
  294. o.default = 20
  295. o.rmempty = true
  296. o = s:option(Value, "read_buffer_size", translate("Read Buffer Size"))
  297. o.datatype = "uinteger"
  298. o:depends("transport", "kcp")
  299. o.default = 2
  300. o.rmempty = true
  301. o = s:option(Value, "write_buffer_size", translate("Write Buffer Size"))
  302. o.datatype = "uinteger"
  303. o:depends("transport", "kcp")
  304. o.default = 2
  305. o.rmempty = true
  306. o = s:option(Flag, "congestion", translate("Congestion"))
  307. o:depends("transport", "kcp")
  308. o.rmempty = true
  309. -- [[ allowInsecure ]]--
  310. o = s:option(Flag, "insecure", translate("allowInsecure"))
  311. o.rmempty = true
  312. o:depends("type", "v2ray")
  313. o:depends("type", "trojan")
  314. o.default = "1"
  315. -- [[ TLS ]]--
  316. o = s:option(Flag, "tls", translate("TLS"))
  317. o.rmempty = true
  318. o.default = "0"
  319. o:depends("type", "v2ray")
  320. o:depends("type", "trojan")
  321. o = s:option(Value, "tls_host", translate("TLS Host"))
  322. --o:depends("type", "trojan")
  323. o:depends("tls", "1")
  324. o.rmempty = true
  325. -- [[ Mux ]]--
  326. o = s:option(Flag, "mux", translate("Mux"))
  327. o.rmempty = true
  328. o.default = "0"
  329. o:depends("type", "v2ray")
  330. o = s:option(Value, "concurrency", translate("Concurrency"))
  331. o.datatype = "uinteger"
  332. o.rmempty = true
  333. o.default = "8"
  334. o:depends("mux", "1")
  335. -- [[ Cert ]]--
  336. o = s:option(Flag, "certificate", translate("Self-signed Certificate"))
  337. o.rmempty = true
  338. o.default = "0"
  339. o:depends("type", "trojan")
  340. o:depends("type", "v2ray")
  341. o.description = translate("If you have a self-signed certificate,please check the box")
  342. o = s:option(DummyValue, "upload", translate("Upload"))
  343. o.template = "shadowsocksr/certupload"
  344. o:depends("certificate", 1)
  345. cert_dir = "/etc/ssl/private/"
  346. local path
  347. http.setfilehandler(
  348. function(meta, chunk, eof)
  349. if not fd then
  350. if (not meta) or (not meta.name) or (not meta.file) then return end
  351. fd = nixio.open(cert_dir .. meta.file, "w")
  352. if not fd then
  353. path = translate("Create upload file error.")
  354. return
  355. end
  356. end
  357. if chunk and fd then
  358. fd:write(chunk)
  359. end
  360. if eof and fd then
  361. fd:close()
  362. fd = nil
  363. path = '/etc/ssl/private/' .. meta.file .. ''
  364. end
  365. end
  366. )
  367. if luci.http.formvalue("upload") then
  368. local f = luci.http.formvalue("ulfile")
  369. if #f <= 0 then
  370. path = translate("No specify upload file.")
  371. end
  372. end
  373. o = s:option(Value, "certpath", translate("Current Certificate Path"))
  374. o:depends("certificate", 1)
  375. o:value("/etc/ssl/private/")
  376. o.description = translate("Please confirm the current certificate path")
  377. o.default = "/etc/ssl/private/"
  378. o = s:option(Flag, "fast_open", translate("TCP Fast Open"))
  379. o.rmempty = true
  380. o.default = "0"
  381. o:depends("type", "ssr")
  382. o:depends("type", "ss")
  383. o:depends("type", "trojan")
  384. o = s:option(Flag, "switch_enable", translate("Enable Auto Switch"))
  385. o.rmempty = false
  386. o.default = "1"
  387. o = s:option(Value, "local_port", translate("Local Port"))
  388. o.datatype = "port"
  389. o.default = 1234
  390. o.rmempty = false
  391. if nixio.fs.access("/usr/bin/kcptun-client") then
  392. kcp_enable = s:option(Flag, "kcp_enable", translate("KcpTun Enable"), translate("bin:/usr/bin/kcptun-client"))
  393. kcp_enable.rmempty = true
  394. kcp_enable.default = "0"
  395. kcp_enable:depends("type", "ssr")
  396. kcp_enable:depends("type", "ss")
  397. o = s:option(Value, "kcp_port", translate("KcpTun Port"))
  398. o.datatype = "port"
  399. o.default = 4000
  400. function o.validate(self, value, section)
  401. local kcp_file="/usr/bin/kcptun-client"
  402. local enable = kcp_enable:formvalue(section) or kcp_enable.disabled
  403. if enable == kcp_enable.enabled then
  404. if not fs.access(kcp_file) then
  405. return nil, translate("Haven't a Kcptun executable file")
  406. elseif not isKcptun(kcp_file) then
  407. return nil, translate("Not a Kcptun executable file")
  408. end
  409. end
  410. return value
  411. end
  412. o:depends("type", "ssr")
  413. o:depends("type", "ss")
  414. o = s:option(Value, "kcp_password", translate("KcpTun Password"))
  415. o.password = true
  416. o:depends("type", "ssr")
  417. o:depends("type", "ss")
  418. o = s:option(Value, "kcp_param", translate("KcpTun Param"))
  419. o.default = "--nocomp"
  420. o:depends("type", "ssr")
  421. o:depends("type", "ss")
  422. end
  423. return m