client-config.lua 18 KB

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