diff --git a/package/cnsztl/luci-app-chinadns/Makefile b/package/cnsztl/luci-app-chinadns/Makefile index e2b499d1bd..f287549587 100644 --- a/package/cnsztl/luci-app-chinadns/Makefile +++ b/package/cnsztl/luci-app-chinadns/Makefile @@ -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 diff --git a/package/cnsztl/luci-app-chinadns/files/luci/controller/chinadns.lua b/package/cnsztl/luci-app-chinadns/files/luci/controller/chinadns.lua index a037ad3a9d..cd8056a4c0 100644 --- a/package/cnsztl/luci-app-chinadns/files/luci/controller/chinadns.lua +++ b/package/cnsztl/luci-app-chinadns/files/luci/controller/chinadns.lua @@ -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 diff --git a/package/cnsztl/luci-app-chinadns/files/luci/i18n/chinadns.zh-cn.po b/package/cnsztl/luci-app-chinadns/files/luci/i18n/chinadns.zh-cn.po index b0af7bd25a..7682c8ee76 100644 --- a/package/cnsztl/luci-app-chinadns/files/luci/i18n/chinadns.zh-cn.po +++ b/package/cnsztl/luci-app-chinadns/files/luci/i18n/chinadns.zh-cn.po @@ -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服务器,仅限填写一个!" diff --git a/package/cnsztl/luci-app-chinadns/files/luci/model/cbi/chinadns.lua b/package/cnsztl/luci-app-chinadns/files/luci/model/cbi/chinadns.lua index 774125ef02..66e1561d23 100644 --- a/package/cnsztl/luci-app-chinadns/files/luci/model/cbi/chinadns.lua +++ b/package/cnsztl/luci-app-chinadns/files/luci/model/cbi/chinadns.lua @@ -3,13 +3,8 @@ -- Copyright (C) 2017 Ian Li -- 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" diff --git a/package/cnsztl/luci-app-chinadns/files/luci/view/chinadns/chinadns_status.htm b/package/cnsztl/luci-app-chinadns/files/luci/view/chinadns/chinadns_status.htm new file mode 100644 index 0000000000..6e63ee3b8b --- /dev/null +++ b/package/cnsztl/luci-app-chinadns/files/luci/view/chinadns/chinadns_status.htm @@ -0,0 +1,22 @@ + + +
+

+ <%:Collecting data...%> +

+
diff --git a/package/cnsztl/luci-app-chinadns/files/root/etc/init.d/chinadns b/package/cnsztl/luci-app-chinadns/files/root/etc/init.d/chinadns index a4c0f9fd60..2e4a78e36f 100755 --- a/package/cnsztl/luci-app-chinadns/files/root/etc/init.d/chinadns +++ b/package/cnsztl/luci-app-chinadns/files/root/etc/init.d/chinadns @@ -1,67 +1,25 @@ #!/bin/sh /etc/rc.common -# -# Copyright (C) 2017 Jian Chang , 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 }