🦄 Sync 2026-03-20 20:22:16

This commit is contained in:
github-actions[bot] 2026-03-20 20:22:16 +08:00
parent 55ff9e94f3
commit 0e8d0a14b4
6 changed files with 108 additions and 38 deletions

View File

@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-mosdns
PKG_VERSION:=1.7.0
PKG_RELEASE:=2
PKG_RELEASE:=3
LUCI_TITLE:=LuCI Support for mosdns
LUCI_PKGARCH:=all

View File

@ -453,7 +453,7 @@ msgstr ""
#: htdocs/luci-static/resources/view/mosdns/basic.js:371
msgid ""
"Match the parsing result with the Cloudflare IP ranges, and when there is a "
"successful match, \t\t\t\tuse the 'Custom IP' as the parsing result "
"successful match, use the 'Custom IP' as the parsing result "
"(experimental feature)"
msgstr ""
@ -494,7 +494,7 @@ msgstr ""
#: htdocs/luci-static/resources/view/mosdns/basic.js:434
msgid ""
"This is the content of the file '/etc/mosdns/config_custom.yaml' from which "
"your MosDNS configuration will be generated. \t\t\tOnly accepts "
"your MosDNS configuration will be generated. Only accepts "
"configuration content in yaml format."
msgstr ""

View File

@ -455,7 +455,7 @@ msgstr "支持本地文件例如file:///var/mosdns/example.txt"
#, fuzzy
msgid ""
"Match the parsing result with the Cloudflare IP ranges, and when there is a "
"successful match, \t\t\t\tuse the 'Custom IP' as the parsing result "
"successful match, use the 'Custom IP' as the parsing result "
"(experimental feature)"
msgstr ""
"将解析结果与 Cloudflare IP 范围进行匹配,当匹配成功时,使用 “自选 IP” 作为解"
@ -499,7 +499,7 @@ msgstr "配置编辑器"
#, fuzzy
msgid ""
"This is the content of the file '/etc/mosdns/config_custom.yaml' from which "
"your MosDNS configuration will be generated. \t\t\tOnly accepts "
"your MosDNS configuration will be generated. Only accepts "
"configuration content in yaml format."
msgstr ""
"这是文件 “/etc/mosdns/config_custom.yaml” 的内容,您的 MosDNS 配置将从此文件"

View File

@ -11,6 +11,7 @@ CRON_FILE=/etc/crontabs/root
DUMP_FILE=/etc/mosdns/cache.dump
DUMP_FILE_DEFAULT=/usr/share/mosdns/cache.dump
MOSDNS_SCRIPT=/usr/share/mosdns/mosdns.uc
REDIRECT_LOCK_FILE=/etc/mosdns/redirect.lock
get_config() {
config_get enabled $1 enabled 0
@ -694,15 +695,15 @@ service_triggers() {
procd_add_reload_trigger "mosdns"
}
restore_setting() {
rm -f /etc/mosdns/redirect.lock
sed -i "/list server/d" /etc/config/dhcp
uci set dhcp.@dnsmasq[0].noresolv='0'
uci del dhcp.@dnsmasq[0].cachesize
uci commit dhcp
}
dhcp_setting() {
[ ! -f "$REDIRECT_LOCK_FILE" ] && {
printf "rebind_protection=$(uci -q get dhcp.@dnsmasq[0].rebind_protection)\n"
printf "rebind_localhost=$(uci -q get dhcp.@dnsmasq[0].rebind_localhost)\n"
printf "noresolv=$(uci -q get dhcp.@dnsmasq[0].noresolv)\n"
printf "resolvfile=$(uci -q get dhcp.@dnsmasq[0].resolvfile)\n"
printf "cachesize=$(uci -q get dhcp.@dnsmasq[0].cachesize)\n"
} > $REDIRECT_LOCK_FILE
redirect_setting() {
if [ "${CONF}" = "/var/etc/mosdns.json" ]; then
sed -i "/list server/d" /etc/config/dhcp
uci add_list dhcp.@dnsmasq[0].server="127.0.0.1#$listen_port"
@ -718,7 +719,33 @@ redirect_setting() {
uci set dhcp.@dnsmasq[0].cachesize='0'
uci commit dhcp
fi
touch /etc/mosdns/redirect.lock
}
uci_set_or_del() {
local key="$1"
local val="$2"
if [ -n "$val" ]; then
uci set "$key=$val"
else
uci del "$key"
fi
}
restore_dhcp_setting() {
if [ -f "$REDIRECT_LOCK_FILE" ]; then
sed -i "/list server/d" /etc/config/dhcp
source "$REDIRECT_LOCK_FILE"
uci_set_or_del dhcp.@dnsmasq[0].rebind_protection "$rebind_protection"
uci_set_or_del dhcp.@dnsmasq[0].resolvfile "$resolvfile"
uci_set_or_del dhcp.@dnsmasq[0].rebind_localhost "$rebind_localhost"
uci_set_or_del dhcp.@dnsmasq[0].noresolv "$noresolv"
uci_set_or_del dhcp.@dnsmasq[0].cachesize "$cachesize"
uci commit dhcp
rm -f "$REDIRECT_LOCK_FILE"
fi
}
reload_dnsmasq() {
@ -764,8 +791,8 @@ start_service() {
procd_set_param respawn
procd_close_instance mosdns
[ "$redirect" -ne 1 ] && [ -f "/etc/mosdns/redirect.lock" ] && restore_setting
[ "$redirect" -eq 1 ] && redirect_setting
[ "$redirect" -ne 1 ] && restore_dhcp_setting
[ "$redirect" -eq 1 ] && dhcp_setting
reload_dnsmasq
# dns hijack
@ -804,7 +831,7 @@ start_service() {
stop_service() {
config_load "mosdns"
config_foreach get_config "mosdns"
[ "$enabled" -eq "0" ] && [ -f "/etc/mosdns/redirect.lock" ] && restore_setting
[ "$enabled" -eq "0" ] && restore_dhcp_setting
! nft --check list table inet mosdns > "/dev/null" 2>&1 || \
nft delete table inet mosdns
reload_dnsmasq

View File

@ -185,44 +185,76 @@ function update_geodat() {
if (tmp_res.code !== 0) exit(1);
let tmpdir = tmp_res.stdout;
exec_sys(`mkdir -p "${v2dat_dir}"`);
let geoip_updated = false;
let geoip_url = mirror + "https://github.com/Loyalsoldier/geoip/releases/latest/download/" + geoip_type + ".dat";
print(`Downloading ${geoip_url}\n`);
if (exec_sys(`curl --connect-timeout 5 -m 120 --ipv4 -kfSLo "${tmpdir}/geoip.dat" "${geoip_url}"`).code !== 0) {
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
}
print(`Downloading ${geoip_url}.sha256sum\n`);
if (exec_sys(`curl --connect-timeout 5 -m 20 --ipv4 -kfSLo "${tmpdir}/geoip.dat.sha256sum" "${geoip_url}.sha256sum"`).code !== 0) {
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
}
let sum_local = split(exec_sys(`sha256sum "${tmpdir}/geoip.dat"`).stdout, /[ \t\n]+/)[0];
let sum_remote = split(exec_sys(`cat "${tmpdir}/geoip.dat.sha256sum"`).stdout, /[ \t\n]+/)[0];
if (sum_local !== sum_remote) {
print("\x1b[1;31mgeoip.dat checksum error\n");
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
let geoip_sum_remote = split(exec_sys(`cat "${tmpdir}/geoip.dat.sha256sum"`).stdout, /[ \t\n]+/)[0];
let geoip_sum_local = "";
if (stat(`${v2dat_dir}/geoip.dat`)) {
geoip_sum_local = split(exec_sys(`sha256sum "${v2dat_dir}/geoip.dat"`).stdout, /[ \t\n]+/)[0];
}
let geosite_url = mirror + "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat";
print(`Downloading ${geosite_url}\n`);
if (exec_sys(`curl --connect-timeout 5 -m 120 --ipv4 -kfSLo "${tmpdir}/geosite.dat" "${geosite_url}"`).code !== 0) {
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
if (geoip_sum_local === geoip_sum_remote) {
print("geoip.dat is up to date.\n");
} else {
print(`Downloading ${geoip_url}\n`);
if (exec_sys(`curl --connect-timeout 5 -m 120 --ipv4 -kfSLo "${tmpdir}/geoip.dat" "${geoip_url}"`).code !== 0) {
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
}
let sum_downloaded = split(exec_sys(`sha256sum "${tmpdir}/geoip.dat"`).stdout, /[ \t\n]+/)[0];
if (sum_downloaded !== geoip_sum_remote) {
print("\x1b[1;31mgeoip.dat checksum error\n");
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
}
geoip_updated = true;
}
let geosite_updated = false;
let geosite_url = mirror + "https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat";
print(`Downloading ${geosite_url}.sha256sum\n`);
if (exec_sys(`curl --connect-timeout 5 -m 20 --ipv4 -kfSLo "${tmpdir}/geosite.dat.sha256sum" "${geosite_url}.sha256sum"`).code !== 0) {
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
}
sum_local = split(exec_sys(`sha256sum "${tmpdir}/geosite.dat"`).stdout, /[ \t\n]+/)[0];
sum_remote = split(exec_sys(`cat "${tmpdir}/geosite.dat.sha256sum"`).stdout, /[ \t\n]+/)[0];
if (sum_local !== sum_remote) {
print("\x1b[1;31mgeosite.dat checksum error\n");
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
let geosite_sum_remote = split(exec_sys(`cat "${tmpdir}/geosite.dat.sha256sum"`).stdout, /[ \t\n]+/)[0];
let geosite_sum_local = "";
if (stat(`${v2dat_dir}/geosite.dat`)) {
geosite_sum_local = split(exec_sys(`sha256sum "${v2dat_dir}/geosite.dat"`).stdout, /[ \t\n]+/)[0];
}
if (geosite_sum_local === geosite_sum_remote) {
print("geosite.dat is up to date.\n");
} else {
print(`Downloading ${geosite_url}\n`);
if (exec_sys(`curl --connect-timeout 5 -m 120 --ipv4 -kfSLo "${tmpdir}/geosite.dat" "${geosite_url}"`).code !== 0) {
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
}
let sum_downloaded = split(exec_sys(`sha256sum "${tmpdir}/geosite.dat"`).stdout, /[ \t\n]+/)[0];
if (sum_downloaded !== geosite_sum_remote) {
print("\x1b[1;31mgeosite.dat checksum error\n");
exec_sys(`rm -rf "${tmpdir}"`); exit(1);
}
geosite_updated = true;
}
if (geoip_updated) {
exec_sys(`cp -a "${tmpdir}/geoip.dat" "${v2dat_dir}/"`);
}
if (geosite_updated) {
exec_sys(`cp -a "${tmpdir}/geosite.dat" "${v2dat_dir}/"`);
}
exec_sys(`rm -rf "${tmpdir}"/*.sha256sum`);
exec_sys(`cp -a "${tmpdir}"/* "${v2dat_dir}/"`);
exec_sys(`rm -rf "${tmpdir}"`);
}

View File

@ -47,9 +47,20 @@ function get_logfile_path_internal() {
if (configfile === '/var/etc/mosdns.json' || !configfile) {
return uci_cursor.get('mosdns', 'config', 'log_file');
} else {
let content = readfile(configfile);
if (content) {
let m = match(content, /file:\s*([^\r\n]+)/);
if (m && m[1]) {
let log_path = m[1];
log_path = replace(log_path, /^\s+|\s+$/g, '');
log_path = replace(log_path, /^["']|["']$/g, '');
if (log_path != "") {
return log_path;
}
}
}
return '/var/log/mosdns.log';
}
return null;
}
const methods = {