advanced.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. local m, s, o
  2. local uci = require "luci.model.uci".cursor()
  3. local server_table = {}
  4. local type_table = {}
  5. local function is_finded(e)
  6. return luci.sys.exec(string.format('type -t -p "%s" 2>/dev/null', e)) ~= ""
  7. end
  8. uci:foreach("shadowsocksr", "servers", function(s)
  9. if s.alias then
  10. server_table[s[".name"]] = "[%s]:%s" % {string.upper(s.v2ray_protocol or s.type), s.alias}
  11. elseif s.server and s.server_port then
  12. server_table[s[".name"]] = "[%s]:%s:%s" % {string.upper(s.v2ray_protocol or s.type), s.server, s.server_port}
  13. end
  14. if s.type then
  15. type_table[s[".name"]] = s.type
  16. end
  17. end)
  18. local key_table = {}
  19. for key, _ in pairs(server_table) do
  20. table.insert(key_table, key)
  21. end
  22. table.sort(key_table)
  23. m = Map("shadowsocksr")
  24. -- [[ global ]]--
  25. s = m:section(TypedSection, "global", translate("Server failsafe auto swith and custom update settings"))
  26. s.anonymous = true
  27. -- o = s:option(Flag, "monitor_enable", translate("Enable Process Deamon"))
  28. -- o.rmempty = false
  29. -- o.default = "1"
  30. o = s:option(Flag, "enable_switch", translate("Enable Auto Switch"))
  31. o.rmempty = false
  32. o.default = "1"
  33. o = s:option(Value, "switch_time", translate("Switch check cycly(second)"))
  34. o.datatype = "uinteger"
  35. o:depends("enable_switch", "1")
  36. o.default = 667
  37. o = s:option(Value, "switch_timeout", translate("Check timout(second)"))
  38. o.datatype = "uinteger"
  39. o:depends("enable_switch", "1")
  40. o.default = 5
  41. o = s:option(Value, "switch_try_count", translate("Check Try Count"))
  42. o.datatype = "uinteger"
  43. o:depends("enable_switch", "1")
  44. o.default = 3
  45. o = s:option(Value, "gfwlist_url", translate("gfwlist Update url"))
  46. o:value("https://fastly.jsdelivr.net/gh/YW5vbnltb3Vz/domain-list-community@release/gfwlist.txt", translate("v2fly/domain-list-community"))
  47. o:value("https://fastly.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/gfw.txt", translate("Loyalsoldier/v2ray-rules-dat"))
  48. o:value("https://fastly.jsdelivr.net/gh/Loukky/gfwlist-by-loukky/gfwlist.txt", translate("Loukky/gfwlist-by-loukky"))
  49. o:value("https://fastly.jsdelivr.net/gh/gfwlist/gfwlist/gfwlist.txt", translate("gfwlist/gfwlist"))
  50. o.default = "https://fastly.jsdelivr.net/gh/YW5vbnltb3Vz/domain-list-community@release/gfwlist.txt"
  51. o = s:option(Value, "chnroute_url", translate("Chnroute Update url"))
  52. o:value("https://ispip.clang.cn/all_cn.txt", translate("Clang.CN"))
  53. o:value("https://ispip.clang.cn/all_cn_cidr.txt", translate("Clang.CN.CIDR"))
  54. o:value("https://fastly.jsdelivr.net/gh/gaoyifan/china-operator-ip@ip-lists/china.txt", translate("china-operator-ip"))
  55. o.default = "https://ispip.clang.cn/all_cn.txt"
  56. o = s:option(Flag, "netflix_enable", translate("Enable Netflix Mode"))
  57. o.description = translate("When disabled shunt mode, will same time stopped shunt service.")
  58. o.rmempty = false
  59. o = s:option(Value, "nfip_url", translate("nfip_url"))
  60. o:value("https://fastly.jsdelivr.net/gh/QiuSimons/Netflix_IP/NF_only.txt", translate("Netflix IP Only"))
  61. o:value("https://fastly.jsdelivr.net/gh/QiuSimons/Netflix_IP/getflix.txt", translate("Netflix and AWS"))
  62. o.default = "https://fastly.jsdelivr.net/gh/QiuSimons/Netflix_IP/NF_only.txt"
  63. o.description = translate("Customize Netflix IP Url")
  64. o:depends("netflix_enable", "1")
  65. o = s:option(ListValue, "shunt_dns_mode", translate("DNS Query Mode For Shunt Mode"))
  66. o:value("1", translate("Use DNS2SOCKS query and cache"))
  67. if is_finded("mosdns") then
  68. o:value("2", translate("Use MOSDNS query"))
  69. end
  70. o:depends("netflix_enable", "1")
  71. o.default = 1
  72. o = s:option(Value, "shunt_dnsserver", translate("Anti-pollution DNS Server For Shunt Mode"))
  73. o:value("8.8.4.4:53", translate("Google Public DNS (8.8.4.4)"))
  74. o:value("8.8.8.8:53", translate("Google Public DNS (8.8.8.8)"))
  75. o:value("208.67.222.222:53", translate("OpenDNS (208.67.222.222)"))
  76. o:value("208.67.220.220:53", translate("OpenDNS (208.67.220.220)"))
  77. o:value("209.244.0.3:53", translate("Level 3 Public DNS (209.244.0.3)"))
  78. o:value("209.244.0.4:53", translate("Level 3 Public DNS (209.244.0.4)"))
  79. o:value("4.2.2.1:53", translate("Level 3 Public DNS (4.2.2.1)"))
  80. o:value("4.2.2.2:53", translate("Level 3 Public DNS (4.2.2.2)"))
  81. o:value("4.2.2.3:53", translate("Level 3 Public DNS (4.2.2.3)"))
  82. o:value("4.2.2.4:53", translate("Level 3 Public DNS (4.2.2.4)"))
  83. o:value("1.1.1.1:53", translate("Cloudflare DNS (1.1.1.1)"))
  84. o:depends("shunt_dns_mode", "1")
  85. o.description = translate("Custom DNS Server format as IP:PORT (default: 8.8.4.4:53)")
  86. o.datatype = "ip4addrport"
  87. o = s:option(ListValue, "shunt_mosdns_dnsserver", translate("Anti-pollution DNS Server"))
  88. o:value("tcp://8.8.4.4:53,tcp://8.8.8.8:53", translate("Google Public DNS"))
  89. o:value("tcp://208.67.222.222:53,tcp://208.67.220.220:53", translate("OpenDNS"))
  90. 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)"))
  91. 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)"))
  92. 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)"))
  93. o:value("tcp://1.1.1.1:53,tcp://1.0.0.1:53", translate("Cloudflare DNS"))
  94. o:depends("shunt_dns_mode", "2")
  95. o.description = translate("Custom DNS Server for mosdns")
  96. o = s:option(Flag, "shunt_mosdns_ipv6", translate("Disable IPv6 In MOSDNS Query Mode (Shunt Mode)"))
  97. o:depends("shunt_dns_mode", "2")
  98. o.rmempty = false
  99. o.default = "0"
  100. o = s:option(Flag, "apple_optimization", translate("Apple domains optimization"), translate("For Apple domains equipped with Chinese mainland CDN, always responsive to Chinese CDN IP addresses"))
  101. o.rmempty = false
  102. o.default = "1"
  103. o = s:option(Value, "apple_url", translate("Apple Domains Update url"))
  104. o:value("https://fastly.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/apple.china.conf", translate("felixonmars/dnsmasq-china-list"))
  105. o.default = "https://fastly.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/apple.china.conf"
  106. o:depends("apple_optimization", "1")
  107. o = s:option(Value, "apple_dns", translate("Apple Domains DNS"), translate("If empty, Not change Apple domains parsing DNS (Default is empty)"))
  108. o.rmempty = true
  109. o.default = ""
  110. o.datatype = "ip4addr"
  111. o:depends("apple_optimization", "1")
  112. o = s:option(Flag, "adblock", translate("Enable adblock"))
  113. o.rmempty = false
  114. o = s:option(Value, "adblock_url", translate("adblock_url"))
  115. o:value("https://raw.githubusercontent.com/neodevpro/neodevhost/master/lite_dnsmasq.conf", translate("NEO DEV HOST Lite"))
  116. o:value("https://raw.githubusercontent.com/neodevpro/neodevhost/master/dnsmasq.conf", translate("NEO DEV HOST Full"))
  117. o:value("https://anti-ad.net/anti-ad-for-dnsmasq.conf", translate("anti-AD"))
  118. o.default = "https://raw.githubusercontent.com/neodevpro/neodevhost/master/lite_dnsmasq.conf"
  119. o:depends("adblock", "1")
  120. o.description = translate("Support AdGuardHome and DNSMASQ format list")
  121. o = s:option(Button, "Reset", translate("Reset to defaults"))
  122. o.inputstyle = "reload"
  123. o.write = function()
  124. luci.sys.call("/etc/init.d/shadowsocksr reset")
  125. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "shadowsocksr", "servers"))
  126. end
  127. -- [[ SOCKS5 Proxy ]]--
  128. s = m:section(TypedSection, "socks5_proxy", translate("Global SOCKS5 Proxy Server"))
  129. s.anonymous = true
  130. -- Enable/Disable Option
  131. o = s:option(Flag, "enabled", translate("Enable"))
  132. o.default = 0
  133. o.rmempty = false
  134. -- Server Selection
  135. o = s:option(ListValue, "server", translate("Server"))
  136. o:value("same", translate("Same as Global Server"))
  137. for _, key in pairs(key_table) do
  138. o:value(key, server_table[key])
  139. end
  140. o.default = "same"
  141. o.rmempty = false
  142. -- Dynamic value handling based on enabled/disabled state
  143. o.cfgvalue = function(self, section)
  144. local enabled = m:get(section, "enabled")
  145. if enabled == "0" then
  146. return m:get(section, "old_server")
  147. end
  148. return Value.cfgvalue(self, section) -- Default to `same` when enabled
  149. end
  150. o.write = function(self, section, value)
  151. local enabled = m:get(section, "enabled")
  152. if enabled == "0" then
  153. local old_server = Value.cfgvalue(self, section)
  154. if old_server ~= "nil" then
  155. m:set(section, "old_server", old_server)
  156. end
  157. m:set(section, "server", "nil")
  158. else
  159. m:del(section, "old_server")
  160. -- Write the value normally when enabled
  161. Value.write(self, section, value)
  162. end
  163. end
  164. -- Socks Auth
  165. if is_finded("xray") then
  166. o = s:option(ListValue, "socks5_auth", translate("Socks5 Auth Mode"), translate("Socks protocol auth methods, default:noauth."))
  167. o.default = "noauth"
  168. o:value("noauth", "NOAUTH")
  169. o:value("password", "PASSWORD")
  170. o.rmempty = true
  171. for key, server_type in pairs(type_table) do
  172. if server_type == "v2ray" then
  173. -- 如果服务器类型是 v2ray,则设置依赖项显示
  174. o:depends("server", key)
  175. end
  176. end
  177. o:depends({server = "same", disable = true})
  178. -- Socks User
  179. o = s:option(Value, "socks5_user", translate("Socks5 User"), translate("Only when Socks5 Auth Mode is password valid, Mandatory."))
  180. o.rmempty = true
  181. o:depends("socks5_auth", "password")
  182. -- Socks Password
  183. o = s:option(Value, "socks5_pass", translate("Socks5 Password"), translate("Only when Socks5 Auth Mode is password valid, Not mandatory."))
  184. o.password = true
  185. o.rmempty = true
  186. o:depends("socks5_auth", "password")
  187. -- Socks Mixed
  188. o = s:option(Flag, "socks5_mixed", translate("Enabled Mixed"), translate("Mixed as an alias of socks, default:Enabled."))
  189. o.default = "1"
  190. o.rmempty = false
  191. for key, server_type in pairs(type_table) do
  192. if server_type == "v2ray" then
  193. -- 如果服务器类型是 v2ray,则设置依赖项显示
  194. o:depends("server", key)
  195. end
  196. end
  197. o:depends({server = "same", disable = true})
  198. end
  199. -- Local Port
  200. o = s:option(Value, "local_port", translate("Local Port"))
  201. o.datatype = "port"
  202. o.default = 1080
  203. o.rmempty = false
  204. -- [[ fragmen Settings ]]--
  205. if is_finded("xray") then
  206. s = m:section(TypedSection, "global_xray_fragment", translate("Xray Fragment Settings"))
  207. s.anonymous = true
  208. o = s:option(Flag, "fragment", translate("Fragment"), translate("TCP fragments, which can deceive the censorship system in some cases, such as bypassing SNI blacklists."))
  209. o.default = 0
  210. o = s:option(ListValue, "fragment_packets", translate("Fragment Packets"), translate("\"1-3\" is for segmentation at TCP layer, applying to the beginning 1 to 3 data writes by the client. \"tlshello\" is for TLS client hello packet fragmentation."))
  211. o.default = "tlshello"
  212. o:value("tlshello", "tlshello")
  213. o:value("1-1", "1-1")
  214. o:value("1-2", "1-2")
  215. o:value("1-3", "1-3")
  216. o:value("1-5", "1-5")
  217. o:depends("fragment", true)
  218. o = s:option(Value, "fragment_length", translate("Fragment Length"), translate("Fragmented packet length (byte)"))
  219. o.default = "100-200"
  220. o:depends("fragment", true)
  221. o = s:option(Value, "fragment_interval", translate("Fragment Interval"), translate("Fragmentation interval (ms)"))
  222. o.default = "10-20"
  223. o:depends("fragment", true)
  224. o = s:option(Flag, "noise", translate("Noise"), translate("UDP noise, Under some circumstances it can bypass some UDP based protocol restrictions."))
  225. o.default = 0
  226. s = m:section(TypedSection, "xray_noise_packets", translate("Xray Noise Packets"))
  227. s.description = translate(
  228. "<font style='color:red'>" .. translate("To send noise packets, select \"Noise\" in Xray Settings.") .. "</font>" ..
  229. "<br/><font><b>" .. translate("For specific usage, see:") .. "</b></font>" ..
  230. "<a href='https://xtls.github.io/config/outbounds/freedom.html' target='_blank'>" ..
  231. "<font style='color:green'><b>" .. translate("Click to the page") .. "</b></font></a>")
  232. s.template = "cbi/tblsection"
  233. s.sortable = true
  234. s.anonymous = true
  235. s.addremove = true
  236. s.remove = function(self, section)
  237. for k, v in pairs(self.children) do
  238. v.rmempty = true
  239. v.validate = nil
  240. end
  241. TypedSection.remove(self, section)
  242. end
  243. o = s:option(Flag, "enabled", translate("Enable"))
  244. o.default = 1
  245. o.rmempty = false
  246. o = s:option(ListValue, "type", translate("Type"))
  247. o.default = "base64"
  248. o:value("rand", "rand")
  249. o:value("str", "str")
  250. o:value("base64", "base64")
  251. o = s:option(Value, "domainStrategy", translate("Domain Strategy"))
  252. o.default = "UseIP"
  253. o:value("AsIs", "AsIs")
  254. o:value("UseIP", "UseIP")
  255. o:value("UseIPv4", "UseIPv4")
  256. o:value("ForceIP", "ForceIP")
  257. o:value("ForceIPv4", "ForceIPv4")
  258. o.rmempty = false
  259. o = s:option(Value, "packet", translate("Packet"))
  260. o.datatype = "minlength(1)"
  261. o.rmempty = false
  262. o = s:option(Value, "delay", translate("Delay (ms)"))
  263. o.datatype = "or(uinteger,portrange)"
  264. o.rmempty = false
  265. end
  266. return m