client-config.lua 12 KB

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