luci-app-mosdns: Add manual update of geodata result display(close #15, resolve #16)

* print success or failed
This commit is contained in:
sbwml 2022-08-17 04:14:39 +08:00
parent 801eb6a368
commit 594980b6c9
6 changed files with 59 additions and 9 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-mosdns
PKG_VERSION:=1.4.1
PKG_VERSION:=1.4.2
PKG_RELEASE:=1
LUCI_TITLE:=LuCI Support for mosdns

View File

@ -16,6 +16,7 @@ function index()
entry({"admin", "services", "mosdns", "status"}, call("act_status")).leaf = true
entry({"admin", "services", "mosdns", "get_log"}, call("get_log")).leaf = true
entry({"admin", "services", "mosdns", "clear_log"}, call("clear_log")).leaf = true
entry({"admin", "services", "mosdns", "geo_update"}, call("geo_update"))
end
function act_status()
@ -32,3 +33,10 @@ end
function clear_log()
luci.sys.call("cat /dev/null > $(/usr/share/mosdns/mosdns.sh logfile)")
end
function geo_update()
local e = {}
e.updating = luci.sys.call("/usr/share/mosdns/mosdns.sh geodata") == 0
luci.http.prepare_content("application/json")
luci.http.write_json(e)
end

View File

@ -24,11 +24,8 @@ for t = 0, 23 do
end
update_time.default = 0
data_update = s:option(Button, "geo_update_database", translate("Database Update"))
data_update.inputtitle = translate("Check And Update")
data_update.inputstyle = "reload"
data_update.write = function()
luci.sys.exec("/usr/share/mosdns/mosdns.sh geodata &> /dev/null &")
end
data_update = s:option(Button, "geo_update_database", translate("Check And Update"))
data_update.rawhtml = true
data_update.template = "mosdns/geo_update"
return m

View File

@ -0,0 +1,34 @@
<%+cbi/valueheader%>
<script type="text/javascript">//<![CDATA[
function update_data(btn, dataname)
{
btn.disabled = true;
btn.value = '<%:Updating...%> ';
st=dataname;
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "mosdns", "geo_update")%>',
{ set:st },
function(x,data)
{
var tb = document.getElementById(dataname+'-status');
if (tb)
{
switch (data.updating)
{
case true:
tb.innerHTML = "<font color='green'>" + "<%:Update success%>" + "</font>";
break;
case false:
tb.innerHTML = "<font color='red'>" + "<%:Update failed, Please check the network status%>" + "</font>";
break;
}
}
btn.disabled = false;
btn.value = '<%:Check And Update%>';
}
);
return false;
}
//]]></script>
<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Check And Update%>" onclick="return update_data(this,'<%=self.option%>')" />
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
<%+cbi/valuefooter%>

View File

@ -85,6 +85,15 @@ msgstr "检查并更新"
msgid "Enable Auto Database Update"
msgstr "启用自动更新"
msgid "Updating..."
msgstr "正在更新..."
msgid "Update success"
msgstr "更新成功"
msgid "Update failed, Please check the network status"
msgstr "更新失败,请检查网络状态"
msgid "Config File"
msgstr "配置文件"

View File

@ -36,16 +36,18 @@ geodat_update() (
geodat_download() (
google_status=$(curl -I -4 -m 3 -o /dev/null -s -w %{http_code} http://www.google.com/generate_204)
[ $google_status -ne "204" ] && mirror="https://github.cooluc.com/"
echo -e "\e[1;32m"$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/$1\e[0m"
curl --connect-timeout 60 -m 900 -fSLo "$TMPDIR/$1" ""$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/$1"
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/$1\e[0m"
curl --connect-timeout 60 -m 900 --ipv4 -fSLo "$TMPDIR/$1" ""$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/$1"
)
TMPDIR=$(mktemp -d) || exit 1
geodat_download geoip.dat
geodat_download geosite.dat
if [ "$(grep -o CN "$TMPDIR"/geoip.dat | wc -l)" -eq "0" ]; then
rm -rf "$TMPDIR"/geoip.dat
exit 1
elif [ "$(grep -o .com "$TMPDIR"/geosite.dat | wc -l)" -lt "1000" ]; then
rm -rf "$TMPDIR"/geosite.dat
exit 1
fi
cp -f "$TMPDIR"/* /usr/share/v2ray
rm -rf "$TMPDIR"