Skip to content

Commit

Permalink
rewrite ui and some function
Browse files Browse the repository at this point in the history
  • Loading branch information
NagaseKouichi committed Jan 19, 2021
1 parent 6ca03cd commit d75fb32
Show file tree
Hide file tree
Showing 20 changed files with 66,120 additions and 39 deletions.
18 changes: 16 additions & 2 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
include $(TOPDIR)/rules.mk
PKG_VERSION:=1.0
PKG_RELEASE:=5

PKG_NAME:=luci-app-chinadns-ng
PKG_VERSION:=1.1
PKG_RELEASE:=6

LUCI_TITLE:=LuCI support for chinadns-ng
LUCI_DESCRIPTION:=LuCI Support for chinadns-ng.
LUCI_DEPENDS:=+chinadns-ng
LUCI_PKGARCH:=all

include $(TOPDIR)/feeds/luci/luci.mk

define Package/chinadns-ng/conffiles
/etc/config/chinadns-ng
/etc/chinadns-ng/chnroute.txt
/etc/chinadns-ng/chnroute6.txt
/etc/chinadns-ng/gfwlist.txt
/etc/chinadns-ng/chinalist.txt
/etc/chinadns-ng/whitelist.txt
/etc/chinadns-ng/blacklist.txt
endef

# call BuildPackage - OpenWrt buildroot signature
Empty file modified README.md
100644 → 100755
Empty file.
29 changes: 28 additions & 1 deletion luasrc/controller/chinadns-ng.lua
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,32 @@ function index()
if not nixio.fs.access("/etc/config/chinadns-ng") then
return
end
entry({"admin", "services", "chinadns-ng"}, cbi("chinadns-ng"), _("ChinaDNS-NG"), 70).dependent = true

entry({"admin", "services", "chinadns-ng"}, alias("admin", "services", "chinadns-ng", "basic"), _("ChinaDNS-NG"), 70).dependent = true
entry({"admin", "services", "chinadns-ng", "basic"}, cbi("chinadns-ng/basic"), _("General Setting"), 80).leaf = true
entry({"admin", "services", "chinadns-ng", "routes"}, cbi("chinadns-ng/routes"), _("Route Setting"), 90).leaf = true
entry({"admin", "services", "chinadns-ng", "update"}, cbi("chinadns-ng/update"), _("Rules Update"), 99).leaf = true
entry({"admin", "services", "chinadns-ng", "status"}, call("act_status")).leaf = true
entry({"admin", "services", "chinadns-ng", "refresh"}, call("refresh_data"))
end

function act_status()
local e={}
e.running=luci.sys.call("ps|grep -v grep|grep -c chinadns-ng >/dev/null")==0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

function refresh_data()
sret=luci.sys.call("/usr/share/chinadns-ng/chinadns-ng_update.sh 2>/dev/null")
if sret== 0 then
retstring ="0"
else
retstring ="-1"
end

luci.http.prepare_content("application/json")
luci.http.write_json({ ret=retstring})
end

-- Fuck GFW and who made it, Freedom!
50 changes: 19 additions & 31 deletions luasrc/model/cbi/chinadns-ng.lua → luasrc/model/cbi/chinadns-ng/basic.lua
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
local m, s, o

if luci.sys.call("pidof chinadns-ng >/dev/null") == 0 then
m = Map("chinadns-ng", translate("ChinaDNS-NG"), "%s - %s" %{translate("ChinaDNS-NG"), translate("RUNNING")})
else
m = Map("chinadns-ng", translate("ChinaDNS-NG"), "%s - %s" %{translate("ChinaDNS-NG"), translate("NOT RUNNING")})
end

m = Map("chinadns-ng", translate("ChinaDNS-NG"),
translate("ChinaDNS-NG is a tool for resolving DNS poisoning. You can find how it works and usage here:")
.. [[<a href="https://github.com/zfl9/chinadns-ng" target="_blank">]]
.. translate("github project")
.. [[</a>]]
)

m:section(SimpleSection).template = "chinadns-ng/status"

s = m:section(TypedSection, "chinadns-ng", translate("General Setting"))
s.anonymous = true
Expand All @@ -29,16 +33,18 @@ o.default = "0.0.0.0"
o.datatype = "ipaddr"
o.rmempty = false

o = s:option(Value, "chnlist_file", translate("CHNRoute File"))
o.placeholder = "/etc/chinadns-ng/chinalist.txt"
o.default = "/etc/chinadns-ng/chinalist.txt"
o.datatype = "file"
o = s:option(Value, "china_dns",
translate("China DNS Servers"),
translate("Use commas to separate multiple ip address, Max 2 Servers"))
o.placeholder = "114.114.114.114,223.5.5.5"
o.default = "114.114.114.114,223.5.5.5"
o.rmempty = false

o = s:option(Value, "gfwlist_file", translate("GFWRoute File"))
o.placeholder = "/etc/chinadns-ng/gfwlist.txt"
o.default = "/etc/chinadns-ng/gfwlist.txt"
o.datatype = "file"
o = s:option(Value, "trust_dns",
translate("Trusted DNS Servers"),
translate("Use commas to separate multiple ip address, Max 2 Servers"))
o.placeholder = "127.0.0.1#5053,208.67.222.222#443"
o.default = "127.0.0.1#5053,208.67.222.222#443"
o.rmempty = false

o = s:option(Value, "timeout_sec", translate("timeout_sec"))
Expand All @@ -53,20 +59,6 @@ o.default = "1"
o.datatype = "uinteger"
o.rmempty = false

o = s:option(Value, "china_dns",
translate("China DNS Servers"),
translate("Use commas to separate multiple ip address, Max 2 Servers"))
o.placeholder = "114.114.114.114"
o.default = "114.114.114.114"
o.rmempty = false

o = s:option(Value, "trust_dns",
translate("Trusted DNS Servers"),
translate("Use commas to separate multiple ip address,Max 2 Servers"))
o.placeholder = "127.0.0.1#5300"
o.default = "127.0.0.1#5300"
o.rmempty = false

o = s:option(Flag, "chnlist_first",
translate("match chnlist first"),
translate("match chnlist first, default is gfwfirst"))
Expand All @@ -82,8 +74,4 @@ o = s:option(Flag, "noip_as_chnip",
translate("accept reply without ipaddr (A/AAAA query)"))
o.rmempty = false

local apply=luci.http.formvalue("cbi.apply")
if apply then
luci.sys.call("/etc/init.d/chinadns-ng restart >/dev/null 2>&1; logger -t 'luci-app-chinadns-ng' -p info 'chinadns-ng restarted.'")
end
return m
84 changes: 84 additions & 0 deletions luasrc/model/cbi/chinadns-ng/routes.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
require "nixio.fs"
local m, s, o

function sync_value_to_file(file, value)
value = value:gsub("\r\n?", "\n")
local old_value = nixio.fs.readfile(file)
if value ~= old_value then
nixio.fs.writefile(file, value)
end
end

m = Map("chinadns-ng", translate(""))

s = m:section(TypedSection, "chinadns-ng", translate("Route Setting"))
s:tab("blacklist", translate("Black List"))
s:tab("whitelist", translate("White List"))
s.addremove = false
s.anonymous = true


o = s:taboption("blacklist", Value, "gfwlist_file",
translate("Use GFWRoute File"),
translate("Choose black domain list file, Domains in black list will use trusted DNS servers. You can choose one of these or use any other file:")
..[[<br />/etc/chinadns-ng/gfwlist.txt ]]
..translate("(default GFWRoute list, can be updated automaticly. If you use SSR+, don't use gfwlist file for black list.)")
..[[<br />/etc/chinadns-ng/blacklist.txt ]]
..translate("(custom GFWRoute list, you can edit it below)")
)
o.placeholder = "/etc/chinadns-ng/blacklist.txt"
o.default = "/etc/chinadns-ng/blacklist.txt"
o.datatype = "file"
o.rmempty = false

local blacklist = "/etc/chinadns-ng/blacklist.txt"
o = s:taboption("blacklist", TextValue, "blacklist",
translate("Custom GFWRoute List (Black Domain List)"),
translate("Edit the content of custom black domain list file (/etc/chinadns-ng/blacklist.txt)"))
o.rows = 13
o.wrap = "off"
o.rmempty = true

o.cfgvalue = function(self, section)
return nixio.fs.readfile(blacklist) or " "
end
o.write = function(self, section, value)
sync_value_to_file(blacklist, value)
end
o.remove = function(self, section, value)
nixio.fs.writefile(blacklist, "")
end


o = s:taboption("whitelist", Value, "chnlist_file",
translate("Use CHNRoute File"),
translate("Choose white domain list file, domains in white list will use China DNS servers. You can choose one of these or use any other file:")
..[[<br />/etc/chinadns-ng/chinalist.txt ]]
..translate("(default CHNRoute list, can be updated automaticly)")
..[[<br />/etc/chinadns-ng/whitelist.txt ]]
..translate("(custom CHNRoute list, you can edit it below)")
)
o.placeholder = "/etc/chinadns-ng/whitelist.txt"
o.default = "/etc/chinadns-ng/whitelist.txt"
o.datatype = "file"
o.rmempty = false

local whitelist = "/etc/chinadns-ng/whitelist.txt"
o = s:taboption("whitelist", TextValue, "whitelist",
translate("Custom CHNRoute List (White Domain List)"),
translate("Edit the content of custom white domain list file (/etc/chinadns-ng/whitelist.txt)"))
o.rows = 13
o.wrap = "off"
o.rmempty = true

o.cfgvalue = function(self, section)
return nixio.fs.readfile(whitelist) or " "
end
o.write = function(self, section, value)
sync_value_to_file(whitelist, value)
end
o.remove = function(self, section, value)
nixio.fs.writefile(whitelist, "")
end

return m
17 changes: 17 additions & 0 deletions luasrc/model/cbi/chinadns-ng/update.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local m, s, o

m = Map("chinadns-ng", translate(""))

s = m:section(TypedSection, "chinadns-ng", translate("Rules Update"))
s.addremove = false
s.anonymous = true

o = s:option(Flag, "auto_update", translate("Auto Update"), translate("Auto update China ipset and route lists at 3:00 on Saturday"))
o.rmempty = false

o=s:option(DummyValue,"chinadns-ng_data",translate("Update Now"))
o.rawhtml = true
o.template = "chinadns-ng/refresh"
o.value = " "

return m
29 changes: 29 additions & 0 deletions luasrc/view/chinadns-ng/refresh.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[
function refresh_data(btn,dataname)
{
btn.disabled = true;
btn.value = '<%:Refresh...%> ';
murl=dataname;
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "chinadns-ng","refresh")%>',
{ set:murl },
function(x,rv)
{
var s = document.getElementById(dataname +'-status');
if (s)
{
if(rv.ret=="-1")
s.innerHTML ="<font color='red'>"+"<%:Refresh Error!%> "+"</font>";
else
s.innerHTML ="<font color='green'>"+"<%:Refresh OK!%> "+"</font>";
}
btn.disabled = false;
btn.value = '<%:Refresh %>';
}
);
return false;
}
//]]></script>
<input type="button" class="cbi-button cbi-input-reload" value="<%:Refresh%> " onclick="return refresh_data(this,'<%=self.option%>')" />
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
<%+cbi/valuefooter%>
22 changes: 22 additions & 0 deletions luasrc/view/chinadns-ng/status.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[services]], [[chinadns-ng]], [[status]])%>', null,
function(x, data) {
var tb = document.getElementById('chinadns-ng_status');
if (data && tb) {
if (data.running) {
var links = '<em><b><font color=green>ChinaDNS-NG <%:RUNNING%></font></b></em>';
tb.innerHTML = links;
} else {
tb.innerHTML = '<em><b><font color=red>ChinaDNS-NG <%:NOT RUNNING%></font></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="chinadns-ng_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>
Loading

0 comments on commit d75fb32

Please sign in to comment.