Skip to content

Commit

Permalink
luci-app-mosdns: add github proxy settings support for data updates
Browse files Browse the repository at this point in the history
Signed-off-by: sbwml <[email protected]>
  • Loading branch information
sbwml committed Nov 5, 2023
1 parent 7509532 commit 74d15c2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion luci-app-mosdns/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-mosdns
PKG_VERSION:=1.5.15
PKG_VERSION:=1.5.16
PKG_RELEASE:=1

LUCI_TITLE:=LuCI Support for mosdns
Expand Down
24 changes: 15 additions & 9 deletions luci-app-mosdns/luasrc/model/cbi/mosdns/update.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ s = m:section(TypedSection, "mosdns", translate("Update GeoIP & GeoSite dat"))
s.addremove = false
s.anonymous = true

enable = s:option(Flag, "geo_auto_update", translate("Enable Auto Database Update"))
enable.rmempty = false
o = s:option(Flag, "geo_auto_update", translate("Enable Auto Database Update"))
o.rmempty = false

o = s:option(ListValue, "geo_update_week_time", translate("Update Cycle"))
o:value("*", translate("Every Day"))
Expand All @@ -16,16 +16,22 @@ o:value("4", translate("Every Thursday"))
o:value("5", translate("Every Friday"))
o:value("6", translate("Every Saturday"))
o:value("7", translate("Every Sunday"))
o.default = "*"
o.default = "3"

update_time = s:option(ListValue, "geo_update_day_time", translate("Update Time"))
o = s:option(ListValue, "geo_update_day_time", translate("Update Time"))
for t = 0, 23 do
update_time:value(t, t..":00")
o:value(t, t..":00")
end
update_time.default = 0
default = 3

data_update = s:option(Button, "geo_update_database", translate("Database Update"))
data_update.rawhtml = true
data_update.template = "mosdns/mosdns_geo_update"
o = s:option(Value, "github_proxy", translate("GitHub Proxy"), translate("Update data files with GitHub Proxy, leave blank to disable proxy downloads."))
o:value("https://gh-proxy.com", translate("https://gh-proxy.com"))
o:value("https://ghps.cc", translate("https://ghps.cc"))
o.rmempty = true
o.default = ""

o = s:option(Button, "geo_update_database", translate("Database Update"))
o.rawhtml = true
o.template = "mosdns/mosdns_geo_update"

return m
6 changes: 6 additions & 0 deletions luci-app-mosdns/po/zh-cn/mosdns.po
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ msgstr "每周六"
msgid "Every Sunday"
msgstr "每周日"

msgid "GitHub Proxy"
msgstr "GitHub 代理"

msgid "Update data files with GitHub Proxy, leave blank to disable proxy downloads."
msgstr "通过 GitHub 代理更新数据文件,留空则禁用代理下载。"

msgid "Database Update"
msgstr "数据库更新"

Expand Down
6 changes: 2 additions & 4 deletions luci-app-mosdns/root/usr/share/mosdns/mosdns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ adlist_update() {
[ "$(uci -q get mosdns.config.adblock)" != 1 ] && exit 0
ad_source=$(uci -q get mosdns.config.ad_source)
AD_TMPDIR=$(mktemp -d) || exit 1
google_status=$(curl -I -4 -m 3 -o /dev/null -s -w %{http_code} http://www.google.com/generate_204)
mirror=""
: > /etc/mosdns/rule/.ad_source
has_update=0
Expand All @@ -66,7 +65,7 @@ adlist_update() {
echo "$url" >> /etc/mosdns/rule/.ad_source
filename=$(basename $url)
if echo "$url" | grep -Eq "^https://raw.githubusercontent.com" ; then
[ "$google_status" -ne "204" ] && mirror="https://ghproxy.com/"
[ -n "$(uci -q get mosdns.config.github_proxy)" ] && mirror="$(uci -q get mosdns.config.github_proxy)/"
fi
echo -e "\e[1;32mDownloading $mirror$url\e[0m"
curl --connect-timeout 5 -m 90 --ipv4 -kfSLo "$AD_TMPDIR/$filename" "$mirror$url"
Expand All @@ -89,8 +88,7 @@ adlist_update() {

geodat_update() (
TMPDIR=$(mktemp -d) || exit 1
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://ghproxy.com/"
[ -n "$(uci -q get mosdns.config.github_proxy)" ] && mirror="$(uci -q get mosdns.config.github_proxy)/"
# geoip.dat - cn-private
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat\e[0m"
curl --connect-timeout 5 -m 60 --ipv4 -kfSLo "$TMPDIR/geoip.dat" ""$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat"
Expand Down

0 comments on commit 74d15c2

Please sign in to comment.