luci-app-chinadns: fix bugs

This commit is contained in:
CN_SZTL 2019-07-21 01:55:20 +08:00
parent 97951d0f67
commit 0359a260e4
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
6 changed files with 54 additions and 69 deletions

View File

@ -25,7 +25,7 @@ define Package/luci-app-chinadns
SUBMENU:=3. Applications
TITLE:=LuCI Support for ChinaDNS
PKGARCH:=all
DEPENDS:=+ChinaDNS
DEPENDS:=+ChinaDNS +curl
endef
define Package/luci-app-chinadns/description
@ -66,6 +66,8 @@ define Package/luci-app-chinadns/conffiles
endef
define Package/luci-app-chinadns/install
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/chinadns
$(INSTALL_DATA) ./files/luci/view/chinadns/chinadns_status.htm $(1)/usr/lib/lua/view/chinadns/chinadns_status.htm
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/i18n
$(INSTALL_DATA) $(PKG_BUILD_DIR)/chinadns.*.lmo $(1)/usr/lib/lua/luci/i18n/
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller

View File

@ -10,4 +10,12 @@ function index()
end
entry({"admin", "services", "chinadns"}, cbi("chinadns"), _("ChinaDNS"), 70).dependent = true
entry({"admin", "services", "chinadns", "status"},call("act_status")).leaf=true
end
function act_status()
local e={}
e.running=luci.sys.call("ps | grep /usr/sbin/chinadns | grep -v grep >/dev/null")==0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

View File

@ -37,5 +37,5 @@ msgstr "运行中"
msgid "Upstream Server"
msgstr "上游服务器"
msgid "A DNS server with edns-client-subnet support required."
msgstr "需要具有edns-client-subnet支持的DNS服务器"
msgid "A DNS server with edns-client-subnet support required, fill one only!"
msgstr "需要具有edns-client-subnet支持的DNS服务器,仅限填写一个!"

View File

@ -3,13 +3,8 @@
-- Copyright (C) 2017 Ian Li <OpenSource@ianli.xyz>
-- Licensed to the public under the GNU General Public License v3.
local m, s, o
if luci.sys.call("pidof chinadns >/dev/null") == 0 then
m = Map("chinadns", translate("ChinaDNS"), "%s - %s" %{translate("ChinaDNS"), translate("RUNNING")})
else
m = Map("chinadns", translate("ChinaDNS"), "%s - %s" %{translate("ChinaDNS"), translate("NOT RUNNING")})
end
m = Map("chinadns", translate("ChinaDNS"))
m:section(SimpleSection).template = "chinadns/chinadns_status"
s = m:section(TypedSection, "chinadns", translate("General Setting"))
s.anonymous = true
@ -44,7 +39,7 @@ o:depends("yn_use_proxy", 0)
o = s:option(Value, "server",
translate("Upstream Server"),
translate("A DNS server with edns-client-subnet support required."))
translate("A DNS server with edns-client-subnet support required, fill one only!"))
o.placeholder = "8.8.8.8"
o.default = "8.8.8.8"
o.datatype = "ipaddr"

View File

@ -0,0 +1,22 @@
<script type="text/javascript">//<![CDATA[
XHR.poll(3, '<%=url([[admin]], [[services]], [[chinadns]], [[status]])%>', null,
function(x, data) {
var tb = document.getElementById('chinadns_status');
if (data && tb) {
if (data.running) {
var links = '<em><b><font color=green>ChinaDNS <%:RUNNING%></font></b></em>';
tb.innerHTML = links;
} else {
tb.innerHTML = '<em><b><font color=red>ChinaDNS <%:NOT RUNNING%></font></b></em>';
}
}
}
);
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
<fieldset class="cbi-section">
<p id="chinadns_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>

View File

@ -1,67 +1,25 @@
#!/bin/sh /etc/rc.common
#
# Copyright (C) 2017 Jian Chang <aa65535@live.com>, Ian Li
#
# This is free software, licensed under the GNU General Public License v3.
# See /LICENSE for more information.
#
START=90
START=99
STOP=10
SERVICE_USE_PID=1
SERVICE_WRITE_PID=1
SERVICE_DAEMONIZE=1
chnroute="$(uci get chinadns.@chinadns[0].chnroute)"
enable="$(uci get chinadns.@chinadns[0].enable)"
port="$(uci get chinadns.@chinadns[0].port)"
server="$(uci get chinadns.@chinadns[0].server)"
yn_use_proxy="$(uci get chinadns.@chinadns[0].yn_use_proxy)"
xappend() {
parms="$parms $1"
}
local_subnet="$(curl -4 -s members.3322.org/dyndns/getip | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.')0"
[ "${yn_use_proxy}" -eq "1" ] && foreign_subnet="$(curl -4 -s ip.sb | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.')0)" || foreign_subnet="$(uci get chinadns.@chinadns[0].foreign_subnet)"
append_bool() {
local section="$1"
local option="$2"
local value="$3"
local _loctmp
config_get_bool _loctmp "$section" "$option"
[ "$_loctmp" = 1 ] || return 0
xappend "$value"
}
append_parm() {
local section="$1"
local option="$2"
local switch="$3"
local _loctmp
config_get _loctmp "$section" "$option"
[ -z "$_loctmp" ] && return 0
xappend "$switch $_loctmp"
}
start_chinadns() {
local enable
local yn_use_proxy
local local_subnet
local foreign_subnet
local local_subnet=$(echo `curl -4 -s members.3322.org/dyndns/getip | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.'`0)
config_get_bool enable $1 enable
[ "$enable" = 1 ] || return 0
config_get_bool yn_use_proxy $1 yn_use_proxy
[ "$yn_use_proxy" = 1 ] && local foreign_subnet=$(echo `curl -4 -s ip.sb | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.'`0) || config_get foreign_subnet $1 foreign_subnet
append_parm $1 port "-p"
append_parm $1 server "-s"
append_parm $1 chnroute "-c"
xappend "-e $local_subnet,$foreign_subnet"
service_start /usr/sbin/chinadns \
$parms
return $?
}
start() {
start()
{
stop
config_load chinadns
config_foreach start_chinadns chinadns
[ "${enable}" -eq "0" ] && exit 0
/usr/sbin/chinadns -p "${port}" -s "${server}" -c "${chnroute}" -e "${local_subnet},${foreign_subnet}"
}
stop() {
service_stop /usr/sbin/chinadns
stop()
{
kill -9 "$(ps | grep "/usr/sbin/chinadns" | grep -v grep | awk '{print $1}')" >/dev/null 2>&1
}