overview_tab.lua 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. -- Copyright 2017 Dirk Brenken (dev@brenken.org)
  2. -- This is free software, licensed under the Apache License, Version 2.0
  3. local fs = require("nixio.fs")
  4. local uci = require("luci.model.uci").cursor()
  5. local util = require("luci.util")
  6. local date = require("luci.http.protocol.date")
  7. local res_input = "/usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv"
  8. local dump = util.ubus("network.interface", "dump", {})
  9. local plug_cnt = tonumber(luci.sys.exec("env -i /usr/sbin/dnscrypt-proxy --version | grep 'Support for plugins: present' | wc -l"))
  10. local res_list = {}
  11. local url = "https://download.dnscrypt.org/dnscrypt-proxy/dnscrypt-resolvers.csv"
  12. if not fs.access("/lib/libustream-ssl.so") then
  13. m = SimpleForm("error", nil, translate("SSL support not available, please install an libustream-ssl variant to use this package."))
  14. m.submit = false
  15. m.reset = false
  16. return m
  17. end
  18. if not fs.access(res_input) then
  19. luci.sys.call("env -i /bin/uclient-fetch --no-check-certificate -O " .. res_input .. " " .. url .. " >/dev/null 2>&1")
  20. end
  21. if not uci:get_first("dnscrypt-proxy", "global") then
  22. uci:add("dnscrypt-proxy", "global")
  23. uci:save("dnscrypt-proxy")
  24. uci:commit("dnscrypt-proxy")
  25. end
  26. for line in io.lines(res_input) do
  27. local name = line:match("^[%w_.-]*")
  28. res_list[#res_list + 1] = { name = name }
  29. end
  30. m = Map("dnscrypt-proxy", translate("DNSCrypt-Proxy"),
  31. translate("Configuration of the DNSCrypt-Proxy package. ")
  32. .. translate("Keep in mind to configure Dnsmasq as well. ")
  33. .. translatef("For further information "
  34. .. "<a href=\"%s\" target=\"_blank\">"
  35. .. "see the wiki online</a>", "https://wiki.openwrt.org/inbox/dnscrypt"))
  36. function m.on_after_commit(self)
  37. luci.sys.call("env -i /etc/init.d/dnsmasq restart >/dev/null 2>&1")
  38. luci.sys.call("env -i /etc/init.d/dnscrypt-proxy restart >/dev/null 2>&1")
  39. end
  40. s = m:section(TypedSection, "global", translate("General options"))
  41. s.anonymous = true
  42. -- Main dnscrypt-proxy resource list
  43. o1 = s:option(DummyValue, "", translate("Default Resolver List"))
  44. o1.template = "dnscrypt-proxy/res_options"
  45. o1.value = res_input
  46. o2 = s:option(DummyValue, "", translate("File Date"))
  47. o2.template = "dnscrypt-proxy/res_options"
  48. o2.value = date.to_http(nixio.fs.stat(res_input).mtime)
  49. o3 = s:option(DummyValue, "", translate("File Checksum"))
  50. o3.template = "dnscrypt-proxy/res_options"
  51. o3.value = luci.sys.exec("sha256sum " .. res_input .. " | awk '{print $1}'")
  52. btn = s:option(Button, "", translate("Refresh Resolver List"))
  53. btn.inputtitle = translate("Refresh List")
  54. btn.inputstyle = "apply"
  55. btn.disabled = false
  56. function btn.write(self, section, value)
  57. luci.sys.call("env -i /bin/uclient-fetch --no-check-certificate -O " .. res_input .. " " .. url .. " >/dev/null 2>&1")
  58. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "dnscrypt-proxy"))
  59. end
  60. -- Trigger settings
  61. t = s:option(DynamicList, "procd_trigger", translate("Startup Trigger"),
  62. translate("By default the DNSCrypt-Proxy startup will be triggered by ifup events of multiple network interfaces. ")
  63. .. translate("To restrict the trigger, add only the relevant network interface(s). ")
  64. .. translate("Usually the 'wan' interface should work for most users."))
  65. if dump then
  66. local i, v
  67. for i, v in ipairs(dump.interface) do
  68. if v.interface ~= "loopback" then
  69. t:value(v.interface)
  70. end
  71. end
  72. end
  73. t.rmempty = true
  74. -- Extra options
  75. ds = s:option(DummyValue, "_dummy", translate("Extra options"),
  76. translate("Options for further tweaking in case the defaults are not suitable for you."))
  77. ds.template = "cbi/nullsection"
  78. btn = s:option(Button, "", translate("Create custom config file"),
  79. translate("Create '/etc/resolv-crypt.conf' with 'options timeout:1' to reduce DNS upstream timeouts with multiple DNSCrypt instances. ")
  80. .. translatef("For further information "
  81. .. "<a href=\"%s\" target=\"_blank\">"
  82. .. "see the wiki online</a>", "https://wiki.openwrt.org/inbox/dnscrypt"))
  83. btn.inputtitle = translate("Create Config File")
  84. btn.inputstyle = "apply"
  85. btn.disabled = false
  86. function btn.write(self, section, value)
  87. if not fs.access("/etc/resolv-crypt.conf") then
  88. luci.sys.call("env -i echo 'options timeout:1' > '/etc/resolv-crypt.conf'")
  89. end
  90. end
  91. -- Mandatory options per instance
  92. s = m:section(TypedSection, "dnscrypt-proxy", translate("Instance options"))
  93. s.anonymous = true
  94. s.addremove = true
  95. o1 = s:option(Value, "address", translate("IP Address"),
  96. translate("The local IPv4 or IPv6 address. The latter one should be specified within brackets, e.g. '[::1]'."))
  97. o1.default = address or "127.0.0.1"
  98. o1.rmempty = false
  99. o2 = s:option(Value, "port", translate("Port"),
  100. translate("The listening port for DNS queries."))
  101. o2.datatype = "port"
  102. o2.default = port
  103. o2.rmempty = false
  104. o3 = s:option(ListValue, "resolver", translate("Resolver"),
  105. translate("Name of the remote DNS service for resolving queries."))
  106. o3.datatype = "hostname"
  107. o3.widget = "select"
  108. local i, v
  109. for i, v in ipairs(res_list) do
  110. if v.name ~= "Name" then
  111. o3:value(v.name)
  112. end
  113. end
  114. o3.default = resolver
  115. o3.rmempty = false
  116. -- Extra options per instance
  117. e1 = s:option(Value, "resolvers_list", translate("Alternate Resolver List"),
  118. translate("Specify a non-default Resolver List."))
  119. e1.datatype = "file"
  120. e1.optional = true
  121. e2 = s:option(Value, "ephemeral_keys", translate("Ephemeral Keys"),
  122. translate("Improve privacy by using an ephemeral public key for each query. ")
  123. .. translate("This option requires extra CPU cycles and is useless with most DNSCrypt server."))
  124. e2.datatype = "bool"
  125. e2.value = 1
  126. e2.optional = true
  127. if plug_cnt > 0 then
  128. e3 = s:option(DynamicList, "blacklist", translate("Blacklist"),
  129. translate("Local blacklists allow you to block abuse sites by domains or ip addresses. ")
  130. .. translate("The value for this property is the blocklist type and path to the file, e.g.'domains:/path/to/dbl.txt' or 'ips:/path/to/ipbl.txt'."))
  131. e3.optional = true
  132. e4 = s:option(Value, "block_ipv6", translate("Block IPv6"),
  133. translate("Disable IPv6 to speed up DNSCrypt-Proxy."))
  134. e4.datatype = "bool"
  135. e4.value = 1
  136. e4.optional = true
  137. e5 = s:option(Value, "local_cache", translate("Local Cache"),
  138. translate("Enable Caching to speed up DNSCcrypt-Proxy."))
  139. e5.datatype = "bool"
  140. e5.value = 1
  141. e5.optional = true
  142. e6 = s:option(Value, "query_log_file", translate("DNS Query Logfile"),
  143. translate("Log the received DNS queries to a file, so you can watch in real-time what is happening on the network."))
  144. e6.optional = true
  145. end
  146. return m