client.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. -- Copyright (C) 2017 yushi studio <[email protected]> github.com/ywb94
  2. -- Copyright (C) 2018 lean <[email protected]> github.com/coolsnowwolf
  3. -- Licensed to the public under the GNU General Public License v3.
  4. local m, s, sec, o
  5. local uci = require "luci.model.uci".cursor()
  6. -- 获取 LAN IP 地址
  7. function lanip()
  8. local lan_ip
  9. lan_ip = luci.sys.exec("uci -q get network.lan.ipaddr 2>/dev/null | awk -F '/' '{print $1}' | tr -d '\n'")
  10. if not lan_ip or lan_ip == "" then
  11. lan_ip = luci.sys.exec("ip address show $(uci -q -p /tmp/state get network.lan.ifname || uci -q -p /tmp/state get network.lan.device) | grep -w 'inet' | grep -Eo 'inet [0-9\.]+' | awk '{print $2}' | head -1 | tr -d '\n'")
  12. end
  13. if not lan_ip or lan_ip == "" then
  14. lan_ip = luci.sys.exec("ip addr show | grep -w 'inet' | grep 'global' | grep -Eo 'inet [0-9\.]+' | awk '{print $2}' | head -n 1 | tr -d '\n'")
  15. end
  16. return lan_ip
  17. end
  18. local lan_ip = lanip()
  19. local validation = require "luci.cbi.datatypes"
  20. local function is_finded(e)
  21. return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= ""
  22. end
  23. m = Map("shadowsocksr", translate("ShadowSocksR Plus+ Settings"), translate("<h3>Support SS/SSR/V2RAY/XRAY/TROJAN/TUIC/HYSTERIA2/NAIVEPROXY/SOCKS5/TUN etc.</h3>"))
  24. m:section(SimpleSection).template = "shadowsocksr/status"
  25. local server_table = {}
  26. uci:foreach("shadowsocksr", "servers", function(s)
  27. if s.alias then
  28. server_table[s[".name"]] = "[%s]:%s" % {string.upper(s.v2ray_protocol or s.type), s.alias}
  29. elseif s.server and s.server_port then
  30. server_table[s[".name"]] = "[%s]:%s:%s" % {string.upper(s.v2ray_protocol or s.type), s.server, s.server_port}
  31. end
  32. end)
  33. local key_table = {}
  34. for key, _ in pairs(server_table) do
  35. table.insert(key_table, key)
  36. end
  37. table.sort(key_table)
  38. -- [[ Global Setting ]]--
  39. s = m:section(TypedSection, "global")
  40. s.anonymous = true
  41. o = s:option(ListValue, "global_server", translate("Main Server"))
  42. o:value("nil", translate("Disable"))
  43. for _, key in pairs(key_table) do
  44. o:value(key, server_table[key])
  45. end
  46. o.default = "nil"
  47. o.rmempty = false
  48. o = s:option(ListValue, "udp_relay_server", translate("Game Mode UDP Server"))
  49. o:value("", translate("Disable"))
  50. o:value("same", translate("Same as Global Server"))
  51. for _, key in pairs(key_table) do
  52. o:value(key, server_table[key])
  53. end
  54. if uci:get_first("shadowsocksr", 'global', 'netflix_enable', '0') == '1' then
  55. o = s:option(ListValue, "netflix_server", translate("Netflix Node"))
  56. o:value("nil", translate("Disable"))
  57. o:value("same", translate("Same as Global Server"))
  58. for _, key in pairs(key_table) do
  59. o:value(key, server_table[key])
  60. end
  61. o.default = "nil"
  62. o.rmempty = false
  63. o = s:option(Flag, "netflix_proxy", translate("External Proxy Mode"))
  64. o.rmempty = false
  65. o.description = translate("Forward Netflix Proxy through Main Proxy")
  66. o.default = "0"
  67. end
  68. o = s:option(ListValue, "threads", translate("Multi Threads Option"))
  69. o:value("0", translate("Auto Threads"))
  70. o:value("1", translate("1 Thread"))
  71. o:value("2", translate("2 Threads"))
  72. o:value("4", translate("4 Threads"))
  73. o:value("8", translate("8 Threads"))
  74. o:value("16", translate("16 Threads"))
  75. o:value("32", translate("32 Threads"))
  76. o:value("64", translate("64 Threads"))
  77. o:value("128", translate("128 Threads"))
  78. o.default = "0"
  79. o.rmempty = false
  80. o = s:option(ListValue, "run_mode", translate("Running Mode"))
  81. o:value("gfw", translate("GFW List Mode"))
  82. o:value("router", translate("IP Route Mode"))
  83. o:value("all", translate("Global Mode"))
  84. o:value("oversea", translate("Oversea Mode"))
  85. o.default = gfw
  86. o = s:option(ListValue, "dports", translate("Proxy Ports"))
  87. o:value("1", translate("All Ports"))
  88. o:value("2", translate("Only Common Ports"))
  89. o:value("3", translate("Custom Ports"))
  90. cp = s:option(Value, "custom_ports", translate("Enter Custom Ports"))
  91. cp:depends("dports", "3") -- 仅当用户选择“Custom Ports”时显示
  92. cp.placeholder = "e.g., 80,443,8080"
  93. o.default = 1
  94. o = s:option(ListValue, "pdnsd_enable", translate("Resolve Dns Mode"))
  95. if is_finded("dns2tcp") then
  96. o:value("1", translate("Use DNS2TCP query"))
  97. end
  98. if is_finded("dns2socks") then
  99. o:value("2", translate("Use DNS2SOCKS query and cache"))
  100. end
  101. if is_finded("dns2socks-rust") then
  102. o:value("3", translate("Use DNS2SOCKS-RUST query and cache"))
  103. end
  104. if is_finded("mosdns") then
  105. o:value("4", translate("Use MOSDNS query (Not Support Oversea Mode)"))
  106. end
  107. if is_finded("dnsproxy") then
  108. o:value("5", translate("Use DNSPROXY query and cache"))
  109. end
  110. if is_finded("chinadns-ng") then
  111. o:value("6", translate("Use ChinaDNS-NG query and cache"))
  112. end
  113. o:value("0", translate("Use Local DNS Service listen port 5335"))
  114. o.default = 1
  115. o = s:option(Value, "tunnel_forward", translate("Anti-pollution DNS Server"))
  116. o:value("8.8.4.4:53", translate("Google Public DNS (8.8.4.4)"))
  117. o:value("8.8.8.8:53", translate("Google Public DNS (8.8.8.8)"))
  118. o:value("208.67.222.222:53", translate("OpenDNS (208.67.222.222)"))
  119. o:value("208.67.220.220:53", translate("OpenDNS (208.67.220.220)"))
  120. o:value("209.244.0.3:53", translate("Level 3 Public DNS (209.244.0.3)"))
  121. o:value("209.244.0.4:53", translate("Level 3 Public DNS (209.244.0.4)"))
  122. o:value("4.2.2.1:53", translate("Level 3 Public DNS (4.2.2.1)"))
  123. o:value("4.2.2.2:53", translate("Level 3 Public DNS (4.2.2.2)"))
  124. o:value("4.2.2.3:53", translate("Level 3 Public DNS (4.2.2.3)"))
  125. o:value("4.2.2.4:53", translate("Level 3 Public DNS (4.2.2.4)"))
  126. o:value("1.1.1.1:53", translate("Cloudflare DNS (1.1.1.1)"))
  127. o:value("114.114.114.114:53", translate("Oversea Mode DNS-1 (114.114.114.114)"))
  128. o:value("114.114.115.115:53", translate("Oversea Mode DNS-2 (114.114.115.115)"))
  129. o:depends("pdnsd_enable", "1")
  130. o:depends("pdnsd_enable", "2")
  131. o:depends("pdnsd_enable", "3")
  132. o.description = translate("Custom DNS Server format as IP:PORT (default: 8.8.4.4:53)")
  133. o.datatype = "ip4addrport"
  134. o.default = "8.8.4.4:53"
  135. o = s:option(ListValue, "tunnel_forward_mosdns", translate("Anti-pollution DNS Server"))
  136. o:value("tcp://8.8.4.4:53,tcp://8.8.8.8:53", translate("Google Public DNS"))
  137. o:value("tcp://208.67.222.222:53,tcp://208.67.220.220:53", translate("OpenDNS"))
  138. o:value("tcp://209.244.0.3:53,tcp://209.244.0.4:53", translate("Level 3 Public DNS-1 (209.244.0.3-4)"))
  139. o:value("tcp://4.2.2.1:53,tcp://4.2.2.2:53", translate("Level 3 Public DNS-2 (4.2.2.1-2)"))
  140. o:value("tcp://4.2.2.3:53,tcp://4.2.2.4:53", translate("Level 3 Public DNS-3 (4.2.2.3-4)"))
  141. o:value("tcp://1.1.1.1:53,tcp://1.0.0.1:53", translate("Cloudflare DNS"))
  142. o:depends("pdnsd_enable", "4")
  143. o.description = translate("Custom DNS Server for MosDNS")
  144. o = s:option(Flag, "mosdns_ipv6", translate("Disable IPv6 in MOSDNS query mode"))
  145. o:depends("pdnsd_enable", "4")
  146. o.rmempty = false
  147. o.default = "1"
  148. if is_finded("dnsproxy") then
  149. o = s:option(ListValue, "parse_method", translate("Select DNS parse Mode"))
  150. o.description = translate(
  151. "<ul>" ..
  152. "<li>" .. translate("When use DNS list file, please ensure list file exists and is formatted correctly.") .. "</li>" ..
  153. "<li>" .. translate("Tips: Dnsproxy DNS Parse List Path:") ..
  154. " <a href='http://" .. lan_ip .. "/cgi-bin/luci/admin/services/shadowsocksr/control' target='_blank'>" ..
  155. translate("Click here to view or manage the DNS list file") .. "</a>" .. "</li>" ..
  156. "</ul>"
  157. )
  158. o:value("single_dns", translate("Set Single DNS"))
  159. o:value("parse_file", translate("Use DNS List File"))
  160. o:depends("pdnsd_enable", "5")
  161. o.rmempty = true
  162. o.default = "single_dns"
  163. o = s:option(Value, "dnsproxy_tunnel_forward", translate("Anti-pollution DNS Server"))
  164. o:value("sdns://AgUAAAAAAAAABzguOC40LjQgsKKKE4EwvtIbNjGjagI2607EdKSVHowYZtyvD9iPrkkHOC44LjQuNAovZG5zLXF1ZXJ5", translate("Google DNSCrypt SDNS"))
  165. o:value("sdns://AgcAAAAAAAAAACC2vD25TAYM7EnyCH8Xw1-0g5OccnTsGH9vQUUH0njRtAxkbnMudHduaWMudHcKL2Rucy1xdWVyeQ", translate("TWNIC-101 DNSCrypt SDNS"))
  166. o:value("sdns://AgcAAAAAAAAADzE4NS4yMjIuMjIyLjIyMiAOp5Svj-oV-Fz-65-8H2VKHLKJ0egmfEgrdPeAQlUFFA8xODUuMjIyLjIyMi4yMjIKL2Rucy1xdWVyeQ", translate("dns.sb DNSCrypt SDNS"))
  167. o:value("sdns://AgMAAAAAAAAADTE0OS4xMTIuMTEyLjkgsBkgdEu7dsmrBT4B4Ht-BQ5HPSD3n3vqQ1-v5DydJC8SZG5zOS5xdWFkOS5uZXQ6NDQzCi9kbnMtcXVlcnk", translate("Quad9 DNSCrypt SDNS"))
  168. o:value("sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20", translate("AdGuard DNSCrypt SDNS"))
  169. o:value("sdns://AgcAAAAAAAAABzEuMC4wLjGgENk8mGSlIfMGXMOlIlCcKvq7AVgcrZxtjon911-ep0cg63Ul-I8NlFj4GplQGb_TTLiczclX57DvMV8Q-JdjgRgSZG5zLmNsb3VkZmxhcmUuY29tCi9kbnMtcXVlcnk", translate("Cloudflare DNSCrypt SDNS"))
  170. o:value("sdns://AgcAAAAAAAAADjEwNC4xNi4yNDkuMjQ5ABJjbG91ZGZsYXJlLWRucy5jb20KL2Rucy1xdWVyeQ", translate("cloudflare-dns.com DNSCrypt SDNS"))
  171. o:depends("parse_method", "single_dns")
  172. o.description = translate("Custom DNS Server (support: IP:Port or tls://IP:Port or https://IP/dns-query and other format).")
  173. o = s:option(ListValue, "upstreams_logic_mode", translate("Defines the upstreams logic mode"))
  174. o.description = translate(
  175. "<ul>" ..
  176. "<li>" .. translate("Defines the upstreams logic mode, possible values: load_balance, parallel, fastest_addr (default: load_balance).") .. "</li>" ..
  177. "<li>" .. translate("When two or more DNS servers are deployed, enable this function.") .. "</li>" ..
  178. "</ul>"
  179. )
  180. o:value("load_balance", translate("load_balance"))
  181. o:value("parallel", translate("parallel"))
  182. o:value("fastest_addr", translate("fastest_addr"))
  183. o:depends("parse_method", "parse_file")
  184. o.rmempty = true
  185. o.default = "load_balance"
  186. o = s:option(Flag, "dnsproxy_ipv6", translate("Disable IPv6 query mode"))
  187. o.description = translate("When disabled, all AAAA requests are not resolved.")
  188. o:depends("parse_method", "single_dns")
  189. o:depends("parse_method", "parse_file")
  190. o.rmempty = false
  191. o.default = "1"
  192. end
  193. if is_finded("chinadns-ng") then
  194. o = s:option(Value, "chinadns_ng_tunnel_forward", translate("Anti-pollution DNS Server"))
  195. o:value("8.8.4.4:53", translate("Google Public DNS (8.8.4.4)"))
  196. o:value("8.8.8.8:53", translate("Google Public DNS (8.8.8.8)"))
  197. o:value("208.67.222.222:53", translate("OpenDNS (208.67.222.222)"))
  198. o:value("208.67.220.220:53", translate("OpenDNS (208.67.220.220)"))
  199. o:value("209.244.0.3:53", translate("Level 3 Public DNS (209.244.0.3)"))
  200. o:value("209.244.0.4:53", translate("Level 3 Public DNS (209.244.0.4)"))
  201. o:value("4.2.2.1:53", translate("Level 3 Public DNS (4.2.2.1)"))
  202. o:value("4.2.2.2:53", translate("Level 3 Public DNS (4.2.2.2)"))
  203. o:value("4.2.2.3:53", translate("Level 3 Public DNS (4.2.2.3)"))
  204. o:value("4.2.2.4:53", translate("Level 3 Public DNS (4.2.2.4)"))
  205. o:value("1.1.1.1:53", translate("Cloudflare DNS (1.1.1.1)"))
  206. o:depends("pdnsd_enable", "6")
  207. o.description = translate(
  208. "<ul>" ..
  209. "<li>" .. translate("Custom DNS Server format as IP:PORT (default: 8.8.4.4:53)") .. "</li>" ..
  210. "<li>" .. translate("Muitiple DNS server can saperate with ','") .. "</li>" ..
  211. "</ul>"
  212. )
  213. o = s:option(ListValue, "chinadns_ng_proto", translate("ChinaDNS-NG query protocol"))
  214. o:value("none", translate("UDP/TCP upstream"))
  215. o:value("tcp", translate("TCP upstream"))
  216. o:value("udp", translate("UDP upstream"))
  217. o:value("tls", translate("DoT upstream (Need use wolfssl version)"))
  218. o:depends("pdnsd_enable", "6")
  219. o = s:option(Value, "chinadns_forward", translate("Domestic DNS Server"))
  220. o:value("", translate("Disable ChinaDNS-NG"))
  221. o:value("wan", translate("Use DNS from WAN"))
  222. o:value("wan_114", translate("Use DNS from WAN and 114DNS"))
  223. o:value("114.114.114.114:53", translate("Nanjing Xinfeng 114DNS (114.114.114.114)"))
  224. o:value("119.29.29.29:53", translate("DNSPod Public DNS (119.29.29.29)"))
  225. o:value("223.5.5.5:53", translate("AliYun Public DNS (223.5.5.5)"))
  226. o:value("180.76.76.76:53", translate("Baidu Public DNS (180.76.76.76)"))
  227. o:value("101.226.4.6:53", translate("360 Security DNS (China Telecom) (101.226.4.6)"))
  228. o:value("123.125.81.6:53", translate("360 Security DNS (China Unicom) (123.125.81.6)"))
  229. o:value("1.2.4.8:53", translate("CNNIC SDNS (1.2.4.8)"))
  230. o:depends({pdnsd_enable = "1", run_mode = "router"})
  231. o:depends({pdnsd_enable = "2", run_mode = "router"})
  232. o:depends({pdnsd_enable = "3", run_mode = "router"})
  233. o:depends({pdnsd_enable = "5", run_mode = "router"})
  234. o:depends({pdnsd_enable = "6", run_mode = "router"})
  235. o.description = translate("Custom DNS Server format as IP:PORT (default: disabled)")
  236. o.validate = function(self, value, section)
  237. if (section and value) then
  238. if value == "wan" or value == "wan_114" then
  239. return value
  240. end
  241. if validation.ip4addrport(value) then
  242. return value
  243. end
  244. return nil, translate("Expecting: %s"):format(translate("valid address:port"))
  245. end
  246. return value
  247. end
  248. end
  249. return m