Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lede #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Lede #34

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk

PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Nick Peng <[email protected]>
PKG_VERSION:=1.2019.28
PKG_VERSION:=9.2020.08
PKG_RELEASE:=1

LUCI_TITLE:=LuCI for smartdns
Expand All @@ -15,12 +15,10 @@ LUCI_DEPENDS:=+luci-compat +smartdns
LUCI_PKGARCH:=all

define Package/$(PKG_NAME)/config
# shown in make menuconfig <Help>

help
$(LUCI_TITLE)
Version: $(PKG_VERSION)-$(PKG_RELEASE)
endef

include ../../luci.mk

# call BuildPackage - OpenWrt buildroot signature
17 changes: 7 additions & 10 deletions luasrc/controller/smartdns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

module("luci.controller.smartdns", package.seeall)

local smartdns = require("luci.model.smartdns")
local http = require ("luci.http")
local sys = require ("luci.sys")
local smartdns = require "luci.model.smartdns"

function index()
if not nixio.fs.access("/etc/config/smartdns") then
Expand All @@ -35,7 +32,7 @@ function index()
end

local function is_running()
return sys.call("pidof smartdns >/dev/null") == 0
return luci.sys.call("pidof smartdns >/dev/null") == 0
end

function act_status()
Expand All @@ -60,9 +57,9 @@ function act_status()
ipv6_server = smartdns.get_config_option("smartdns", "smartdns", "ipv6_server", nil);
if e.redirect == 1 then
if e.local_port ~= nil and e.local_port ~= "53" then
e.ipv4_works = sys.call("iptables -t nat -nL PREROUTING 2>/dev/null | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
e.ipv4_works = luci.sys.call("iptables -t nat -nL PREROUTING 2>/dev/null | grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
if ipv6_server == "1" then
e.ipv6_works = sys.call("ip6tables -t nat -nL PREROUTING 2>/dev/null| grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
e.ipv6_works = luci.sys.call("ip6tables -t nat -nL PREROUTING 2>/dev/null| grep REDIRECT | grep dpt:53 | grep %q >/dev/null 2>&1" % e.local_port) == 0
else
e.ipv6_works = 2
end
Expand All @@ -71,7 +68,7 @@ function act_status()
end
elseif e.redirect == 2 then
local str;
local dnsmasq_server = sys.exec("uci get dhcp.@dnsmasq[0].server")
local dnsmasq_server = luci.sys.exec("uci get dhcp.@dnsmasq[0].server")
if e.local_port ~= nil then
str = "127.0.0.1#" .. e.local_port
if string.sub(dnsmasq_server,1,string.len(str)) == str then
Expand All @@ -81,6 +78,6 @@ function act_status()
end
e.running = is_running()

http.prepare_content("application/json")
http.write_json(e)
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end
89 changes: 50 additions & 39 deletions luasrc/model/cbi/smartdns/smartdns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local m, s, o
local custom, addr

local fs = require ("nixio.fs")
local http = require ("luci.http")
local dispatcher = require ("luci.dispatcher")
require ("nixio.fs")
require ("luci.http")
require ("luci.dispatcher")
require ("nixio.fs")

m = Map("smartdns")
m.title = translate("SmartDNS Server")
Expand All @@ -42,9 +40,9 @@ o.rempty = false

---- server name
o = s:taboption("settings", Value, "server_name", translate("Server Name"), translate("Smartdns server name"))
o.placeholder = "smartdns"
o.default = "smartdns"
o.datatype = "hostname"
o.rempty = true
o.rempty = false

---- Port
o = s:taboption("settings", Value, "port", translate("Local Port"), translate("Smartdns local server port"))
Expand Down Expand Up @@ -85,6 +83,15 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

---- Domain Serve expired
o = s:taboption("settings", Flag, "serve_expired", translate("Serve expired"),
translate("Attempts to serve old responses from cache with a TTL of 0 in the response without waiting for the actual resolution to finish."))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

---- Redirect
o = s:taboption("settings", ListValue, "redirect", translate("Redirect"), translate("SmartDNS redirect mode"))
o.placeholder = "none"
Expand Down Expand Up @@ -121,8 +128,8 @@ o.rempty = false

---- Port
o = s:taboption("seconddns", Value, "seconddns_port", translate("Local Port"), translate("Smartdns local server port"))
o.placeholder = 7053
o.default = 7053
o.placeholder = 6553
o.default = 6553
o.datatype = "port"
o.rempty = false

Expand All @@ -134,20 +141,20 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "1"
end

o = s:taboption("seconddns", Flag, "seconddns_no_speed_check", translate("Skip Speed Check"), translate("Do not check speed."))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

---- dns server group
o = s:taboption("seconddns", Value, "seconddns_server_group", translate("Server Group"), translate("Query DNS through specific dns server group, such as office, home."))
o.rmempty = true
o.placeholder = "default"
o.datatype = "hostname"
o.rempty = true

o = s:taboption("seconddns", Flag, "seconddns_no_speed_check", translate("Skip Speed Check"), translate("Do not check speed."))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

---- skip address rules
o = s:taboption("seconddns", Flag, "seconddns_no_rule_addr", translate("Skip Address Rules"), translate("Skip address rules."))
o.rmempty = false
Expand Down Expand Up @@ -180,7 +187,7 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

o = s:taboption("seconddns", Flag, "seconddns_no_dualstack_selection", translate("Skip Dualstack Selection"), translate("Skip Sualstack Selection."))
o = s:taboption("seconddns", Flag, "seconddns_no_dualstack_selection", translate("Skip Dualstack Selection"), translate("Skip Dualstack Selection."))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
Expand All @@ -195,6 +202,14 @@ o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

---- Force AAAA SOA
o = s:taboption("seconddns", Flag, "force_aaaa_soa", translate("Force AAAA SOA"), translate("Force AAAA SOA."))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

----- custom settings
custom = s:taboption("custom", Value, "Custom Settings",
translate(""),
Expand All @@ -204,12 +219,12 @@ custom.template = "cbi/tvalue"
custom.rows = 20

function custom.cfgvalue(self, section)
return fs.readfile("/etc/smartdns/custom.conf")
return nixio.fs.readfile("/etc/smartdns/custom.conf")
end

function custom.write(self, section, value)
value = value:gsub("\r\n?", "\n")
fs.writefile("/etc/smartdns/custom.conf", value)
nixio.fs.writefile("/etc/smartdns/custom.conf", value)
end

o = s:taboption("custom", Flag, "coredump", translate("Generate Coredump"), translate("Generate Coredump file when smartdns crash, coredump file is located at /tmp/smartdns.xxx.core."))
Expand All @@ -226,7 +241,7 @@ s = m:section(TypedSection, "server", translate("Upstream Servers"), translate("
s.anonymous = true
s.addremove = true
s.template = "cbi/tblsection"
s.extedit = dispatcher.build_url("admin/services/smartdns/upstream/%s")
s.extedit = luci.dispatcher.build_url("admin/services/smartdns/upstream/%s")

---- enable flag
o = s:option(Flag, "enabled", translate("Enable"), translate("Enable"))
Expand Down Expand Up @@ -262,48 +277,44 @@ o:value("https", translate("https"))
o.default = "udp"
o.rempty = false

-- Domain Address
s = m:section(TypedSection, "smartdns", translate("Domain Address"),
translate("Set Specific domain ip address."))
s.anonymous = true
s = m:section(TypedSection, "smartdns", translate("Advanced Settings"), translate("Advanced Settings"));
s.anonymous = true;

s:tab("domain-address", translate("Domain Address"), translate("Set Specific domain ip address."));
s:tab("blackip-list", translate("IP Blacklist"), translate("Set Specific ip blacklist."));

---- address
addr = s:option(Value, "address",
-- Doman addresss
addr = s:taboption("domain-address", Value, "address",
translate(""),
translate("Specify an IP address to return for any host in the given domains, Queries in the domains are never forwarded and always replied to with the specified IP address which may be IPv4 or IPv6."))

addr.template = "cbi/tvalue"
addr.rows = 20

function addr.cfgvalue(self, section)
return fs.readfile("/etc/smartdns/address.conf")
return nixio.fs.readfile("/etc/smartdns/address.conf")
end

function addr.write(self, section, value)
value = value:gsub("\r\n?", "\n")
fs.writefile("/etc/smartdns/address.conf", value)
nixio.fs.writefile("/etc/smartdns/address.conf", value)
end

-- IP Blacklist
s = m:section(TypedSection, "smartdns", translate("IP Blacklist"),
translate("Set Specific ip blacklist."))
s.anonymous = true

---- blacklist
addr = s:option(Value, "blacklist_ip",
addr = s:taboption("blackip-list", Value, "blacklist_ip",
translate(""),
translate("Configure IP blacklists that will be filtered from the results of specific DNS server."))

addr.template = "cbi/tvalue"
addr.rows = 20

function addr.cfgvalue(self, section)
return fs.readfile("/etc/smartdns/blacklist-ip.conf")
return nixio.fs.readfile("/etc/smartdns/blacklist-ip.conf")
end

function addr.write(self, section, value)
value = value:gsub("\r\n?", "\n")
fs.writefile("/etc/smartdns/blacklist-ip.conf", value)
nixio.fs.writefile("/etc/smartdns/blacklist-ip.conf", value)
end

-- Technical Support
Expand All @@ -316,15 +327,15 @@ o.title = translate("SmartDNS official website")
o.inputtitle = translate("open website")
o.inputstyle = "apply"
o.write = function()
http.redirect("https://pymumu.github.io/smartdns")
luci.http.redirect("https://pymumu.github.io/smartdns")
end

o = s:option(Button, "Donate")
o.title = translate("Donate to smartdns")
o.inputtitle = translate("Donate")
o.inputstyle = "apply"
o.write = function()
http.redirect("https://pymumu.github.io/smartdns/#donate")
luci.http.redirect("https://pymumu.github.io/smartdns/#donate")
end

return m
Expand Down
36 changes: 16 additions & 20 deletions luasrc/model/cbi/smartdns/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

local m, s, o

local http = require ("luci.http")
local sid = arg[1]

m = Map("smartdns", "%s - %s" %{translate("SmartDNS Server"), translate("Upstream DNS Server Configuration")})
m.redirect = luci.dispatcher.build_url("admin/services/smartdns")

if m.uci:get("smartdns", sid) ~= "server" then
http.redirect(m.redirect)
luci.http.redirect(m.redirect)
return
end

Expand Down Expand Up @@ -58,6 +55,21 @@ o:value("https", translate("https"))
o.default = "udp"
o.rempty = false

---- server group
o = s:option(Value, "server_group", translate("Server Group"), translate("DNS Server group belongs to, used with nameserver, such as office, home."))
o.rmempty = true
o.placeholder = "default"
o.datatype = "hostname"
o.rempty = true

---- blacklist_ip
o = s:option(Flag, "blacklist_ip", translate("IP Blacklist Filtering"), translate("Filtering IP with blacklist"))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

---- TLS host verify
o = s:option(Value, "tls_host_verify", translate("TLS Hostname Verify"), translate("Set TLS hostname to verify."))
o.default = ""
Expand All @@ -81,21 +93,6 @@ o.datatype = "hostname"
o.rempty = true
o:depends("type", "https")

---- server group
o = s:option(Value, "server_group", translate("Server Group"), translate("DNS Server group belongs to, used with nameserver, such as office, home."))
o.rmempty = true
o.placeholder = "default"
o.datatype = "hostname"
o.rempty = true

---- blacklist_ip
o = s:option(Flag, "blacklist_ip", translate("IP Blacklist Filtering"), translate("Filtering IP with blacklist"))
o.rmempty = false
o.default = o.disabled
o.cfgvalue = function(...)
return Flag.cfgvalue(...) or "0"
end

---- anti-Answer-Forgery
-- o = s:option(Flag, "check_edns", translate("Anti Answer Forgery"), translate("Anti answer forgery, if DNS does not work properly after enabling, please turn off this feature"))
-- o.rmempty = false
Expand All @@ -113,7 +110,6 @@ o.rempty = true
o:depends("type", "tls")
o:depends("type", "https")


---- other args
o = s:option(Value, "addition_arg", translate("Additional Server Args"), translate("Additional Args for upstream dns servers"))
o.default = ""
Expand Down
5 changes: 5 additions & 0 deletions luasrc/model/smartdns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.

require ("nixio.fs")
require ("luci.http")
require ("luci.dispatcher")
require ("nixio.fs")

local uci = require "luci.model.uci".cursor()

module("luci.model.smartdns", package.seeall)
Expand Down
Loading