mirror of
https://github.com/coolsnowwolf/luci
synced 2025-01-08 11:27:28 +08:00
luci-app-mosdns: update from upstream (#209)
This commit is contained in:
parent
8186ccc9d3
commit
1cae4d198a
@ -1,7 +1,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-mosdns
|
||||
PKG_VERSION:=1.5.2
|
||||
PKG_VERSION:=1.5.3
|
||||
PKG_RELEASE:=1
|
||||
|
||||
LUCI_TITLE:=LuCI Support for mosdns
|
||||
|
@ -20,6 +20,7 @@ function index()
|
||||
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")).leaf = true
|
||||
entry({"admin", "services", "mosdns", "flush_cache"}, call("flush_cache")).leaf = true
|
||||
end
|
||||
|
||||
function act_status()
|
||||
@ -43,3 +44,10 @@ function geo_update()
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(e)
|
||||
end
|
||||
|
||||
function flush_cache()
|
||||
local e = {}
|
||||
e.flushing = sys.call("/usr/share/mosdns/mosdns.sh flush >/dev/null") == 0
|
||||
http.prepare_content("application/json")
|
||||
http.write_json(e)
|
||||
end
|
||||
|
@ -114,6 +114,16 @@ o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/etc/mosdns/config.yaml")
|
||||
|
||||
o = s:taboption("advanced", Flag, "enable_http3", translate("Enable HTTP/3"), translate("Enable DoH HTTP/3 protocol support for remote DNS, Upstream DNS server support is required (Experimental)"))
|
||||
o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/etc/mosdns/config.yaml")
|
||||
|
||||
o = s:taboption("advanced", Flag, "enable_ecs_remote", translate("Enable EDNS client subnet"), translate("Add the EDNS Client Subnet option (ECS) to Remote DNS") .. '<br />' .. translate("MosDNS will auto identify the IP address subnet segment of your remote connection (.0/24)") .. '<br />' .. translate("If your remote access network changes, May need restart MosDNS to update the ECS request address"))
|
||||
o.rmempty = false
|
||||
o.default = false
|
||||
o:depends("configfile", "/etc/mosdns/config.yaml")
|
||||
|
||||
o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size"))
|
||||
o.datatype = "and(uinteger,min(0))"
|
||||
o.default = "20000"
|
||||
@ -160,7 +170,7 @@ o:value("https://raw.githubusercontent.com/QiuSimons/openwrt-mos/master/dat/serv
|
||||
|
||||
o = s:taboption("basic", Button, "_reload", translate("Reload Service"), translate("Reload service to take effect of new configuration"))
|
||||
o.write = function()
|
||||
sys.exec("/etc/init.d/mosdns reload")
|
||||
sys.exec("/etc/init.d/mosdns reload")
|
||||
end
|
||||
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
||||
|
||||
@ -179,15 +189,24 @@ function o.write(self, section, value)
|
||||
fs.writefile("/etc/mosdns/config_custom.yaml", value)
|
||||
end
|
||||
|
||||
s:tab("api", translate("API Setting"))
|
||||
|
||||
o = s:taboption("api", Flag, "enabled_api", translate("Enabled API"))
|
||||
o:depends("configfile", "/etc/mosdns/config.yaml")
|
||||
o.default = false
|
||||
s:tab("api", translate("API Options"))
|
||||
|
||||
o = s:taboption("api", Value, "listen_port_api", translate("API Listen port"))
|
||||
o.datatype = "and(port,min(1))"
|
||||
o.default = 9091
|
||||
o:depends("configfile", "/etc/mosdns/config.yaml")
|
||||
|
||||
o = s:taboption("api", Button, "flush_cache", translate("Flush Cache"), translate("Flushing Cache will clear any IP addresses or DNS records from MosDNS cache"))
|
||||
o.rawhtml = true
|
||||
o.template = "mosdns/mosdns_flush_cache"
|
||||
o:depends("configfile", "/etc/mosdns/config.yaml")
|
||||
|
||||
s:tab("geodata", translate("GeoData Export"))
|
||||
|
||||
o = s:taboption("geodata", DynamicList, "geosite_tags", translate("GeoSite Tags"), translate("Enter the GeoSite.dat category to be exported, Allow add multiple tags") .. '<br />' .. translate("Export directory: /var/mosdns"))
|
||||
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
||||
|
||||
o = s:taboption("geodata", DynamicList, "geoip_tags", translate("GeoIP Tags"), translate("Enter the GeoIP.dat category to be exported, Allow add multiple tags") .. '<br />' .. translate("Export directory: /var/mosdns"))
|
||||
o:depends("configfile", "/etc/mosdns/config_custom.yaml")
|
||||
|
||||
return m
|
||||
|
@ -6,6 +6,7 @@ local grey_list_file = "/etc/mosdns/rule/greylist.txt"
|
||||
local hosts_list_file = "/etc/mosdns/rule/hosts.txt"
|
||||
local redirect_list_file = "/etc/mosdns/rule/redirect.txt"
|
||||
local local_ptr_file = "/etc/mosdns/rule/local-ptr.txt"
|
||||
local ddns_list_file = "/etc/mosdns/rule/ddnslist.txt"
|
||||
|
||||
m = Map("mosdns")
|
||||
|
||||
@ -15,6 +16,7 @@ s.anonymous = true
|
||||
s:tab("white_list", translate("White Lists"))
|
||||
s:tab("block_list", translate("Block Lists"))
|
||||
s:tab("grey_list", translate("Grey Lists"))
|
||||
s:tab("ddns_list", translate("DDNS Lists"))
|
||||
s:tab("hosts_list", translate("Hosts"))
|
||||
s:tab("redirect_list", translate("Redirect"))
|
||||
s:tab("local_ptr_list", translate("Block PTR"))
|
||||
@ -49,6 +51,16 @@ o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("ddns_list", TextValue, "ddns", "", "<font color='red'>" .. translate("These domains are always resolved using local DNS. And force TTL 5 seconds, DNS resolution results will not enter the cache. For example: myddns.example.com.") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
o.cfgvalue = function(self, section) return nixio.fs.readfile(ddns_list_file) or "" end
|
||||
o.write = function(self, section, value) nixio.fs.writefile(ddns_list_file, value:gsub("\r\n", "\n")) end
|
||||
o.remove = function(self, section, value) nixio.fs.writefile(ddns_list_file, "") end
|
||||
o.validate = function(self, value)
|
||||
return value
|
||||
end
|
||||
|
||||
o = s:taboption("hosts_list", TextValue, "hosts", "", "<font color='red'>" .. translate("Hosts For example: baidu.com 10.0.0.1") .. "</font>" .. "<font color='#00bd3e'>" .. translate("<br>The list of rules only apply to 'Default Config' profiles.") .. "</font>")
|
||||
o.rows = 15
|
||||
o.wrap = "off"
|
||||
|
@ -0,0 +1,34 @@
|
||||
<%+cbi/valueheader%>
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
function flush_cache(btn, dataname)
|
||||
{
|
||||
btn.disabled = true;
|
||||
btn.value = '<%:Flushing...%> ';
|
||||
st=dataname;
|
||||
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "mosdns", "flush_cache")%>',
|
||||
{ set:st },
|
||||
function(x,data)
|
||||
{
|
||||
var tb = document.getElementById(dataname+'-status');
|
||||
if (tb)
|
||||
{
|
||||
switch (data.flushing)
|
||||
{
|
||||
case true:
|
||||
tb.innerHTML = "<font color='green'>" + "<%:Flushing Success%>" + "</font>";
|
||||
break;
|
||||
case false:
|
||||
tb.innerHTML = "<font color='red'>" + "<%:Flushing Failed, Please check if MosDNS is enabled%>" + "</font>";
|
||||
break;
|
||||
}
|
||||
}
|
||||
btn.disabled = false;
|
||||
btn.value = '<%:Flush Cache%>';
|
||||
}
|
||||
);
|
||||
return false;
|
||||
}
|
||||
//]]></script>
|
||||
<input type="button" class="btn cbi-button cbi-button-reload" value="<%:Flush Cache%>" onclick="return flush_cache(this,'<%=self.option%>')" />
|
||||
<span id="<%=self.option%>-status"><em><%=self.value%></em></span>
|
||||
<%+cbi/valuefooter%>
|
@ -7,6 +7,9 @@ msgstr "基本选项"
|
||||
msgid "Advanced Options"
|
||||
msgstr "高级选项"
|
||||
|
||||
msgid "API Options"
|
||||
msgstr "API 选项"
|
||||
|
||||
msgid "MosDNS is a 'programmable' DNS forwarder."
|
||||
msgstr "MosDNS 是一个插件化的 DNS 转发/分流器。"
|
||||
|
||||
@ -25,15 +28,24 @@ msgstr "启用"
|
||||
msgid "Listen port"
|
||||
msgstr "监听端口"
|
||||
|
||||
msgid "API Setting"
|
||||
msgstr "API 设置"
|
||||
|
||||
msgid "Enabled API"
|
||||
msgstr "启用 API"
|
||||
|
||||
msgid "API Listen port"
|
||||
msgstr "API 监听端口"
|
||||
|
||||
msgid "Flush Cache"
|
||||
msgstr "刷新缓存"
|
||||
|
||||
msgid "Flushing Cache will clear any IP addresses or DNS records from MosDNS cache"
|
||||
msgstr "刷新缓存会清空 MosDNS 所有 IP 地址和 DNS 解析缓存"
|
||||
|
||||
msgid "Flushing..."
|
||||
msgstr "正在刷新..."
|
||||
|
||||
msgid "Flushing Success"
|
||||
msgstr "刷新成功"
|
||||
|
||||
msgid "Flushing Failed, Please check if MosDNS is enabled"
|
||||
msgstr "刷新失败,请检查 MosDNS 是否已启用"
|
||||
|
||||
msgid "Log Level"
|
||||
msgstr "日志等级"
|
||||
|
||||
@ -175,6 +187,24 @@ msgstr "禁用 TLS 证书"
|
||||
msgid "Disable TLS Servers certificate validation, Can be useful if system CA certificate expires or the system time is out of order"
|
||||
msgstr "禁用 TLS 服务器证书验证,当系统 CA 证书过期或系统时间错乱时,本选项可能会有用"
|
||||
|
||||
msgid "Enable HTTP/3"
|
||||
msgstr "启用 HTTP/3"
|
||||
|
||||
msgid "Enable DoH HTTP/3 protocol support for remote DNS, Upstream DNS server support is required (Experimental)"
|
||||
msgstr "为远程 DNS 启用 DoH HTTP/3 协议支持,需要上游 DNS 服务器支持(实验性,谨慎启用该功能)"
|
||||
|
||||
msgid "Enable EDNS client subnet"
|
||||
msgstr "启用 EDNS 客户端子网"
|
||||
|
||||
msgid "Add the EDNS Client Subnet option (ECS) to Remote DNS"
|
||||
msgstr "在远程 DNS 请求中加入 EDNS 客户端子网(即 ECS)选项(需要上游 DNS 服务器支持)"
|
||||
|
||||
msgid "MosDNS will auto identify the IP address subnet segment of your remote connection (.0/24)"
|
||||
msgstr "MosDNS 将会自动获取您访问远程连接时使用的 IP 子网段(.0/24)"
|
||||
|
||||
msgid "If your remote access network changes, May need restart MosDNS to update the ECS request address"
|
||||
msgstr "如果您的远程访问网络发生改变时可能需要重启 MosDNS 以更新 ECS 请求地址"
|
||||
|
||||
msgid "DNS Cache Size"
|
||||
msgstr "DNS 缓存大小(条)"
|
||||
|
||||
@ -235,6 +265,12 @@ msgstr "灰名单"
|
||||
msgid "These domains are always resolved using remote DNS. Please input the domain names of websites, every line can input only one website domain. For example: google.com."
|
||||
msgstr "加入的域名始终使用 “远程 DNS” 进行解析(每个域名一行,支持域名匹配规则)"
|
||||
|
||||
msgid "DDNS Lists"
|
||||
msgstr "DDNS 域名"
|
||||
|
||||
msgid "These domains are always resolved using local DNS. And force TTL 5 seconds, DNS resolution results will not enter the cache. For example: myddns.example.com."
|
||||
msgstr "加入的域名始终使用 “本地 DNS” 进行解析,并且强制 TTL 5 秒,解析结果不会进入缓存(每个域名一行,支持域名匹配规则)"
|
||||
|
||||
msgid "Hosts For example: baidu.com 10.0.0.1"
|
||||
msgstr "自定义 Hosts 重写,如:baidu.com 10.0.0.1(每个规则一行)"
|
||||
|
||||
@ -249,3 +285,21 @@ msgstr "PTR 黑名单"
|
||||
|
||||
msgid "These domains are blocked from PTR requests"
|
||||
msgstr "加入的域名将阻止 PTR 请求(每个域名一行,支持域名匹配规则)"
|
||||
|
||||
msgid "GeoData Export"
|
||||
msgstr "GeoData 导出"
|
||||
|
||||
msgid "GeoSite Tags"
|
||||
msgstr "GeoSite 标签"
|
||||
|
||||
msgid "Enter the GeoSite.dat category to be exported, Allow add multiple tags"
|
||||
msgstr "填写需要导出的 GeoSite.dat 类别条目,允许添加多个标签"
|
||||
|
||||
msgid "GeoIP Tags"
|
||||
msgstr "GeoIP 标签"
|
||||
|
||||
msgid "Enter the GeoIP.dat category to be exported, Allow add multiple tags"
|
||||
msgstr "输入需要导出的 GeoIP.dat 类别条目,允许添加多个标签"
|
||||
|
||||
msgid "Export directory: /var/mosdns"
|
||||
msgstr "导出目录:/var/mosdns"
|
||||
|
@ -21,7 +21,7 @@ config mosdns 'config'
|
||||
option custom_local_dns '0'
|
||||
option enable_pipeline '0'
|
||||
option insecure_skip_verify '0'
|
||||
option enabled_api '0'
|
||||
option enable_http3 '0'
|
||||
option listen_port_api '9091'
|
||||
option bootstrap_dns '119.29.29.29'
|
||||
list remote_dns 'tls://8.8.8.8'
|
||||
|
@ -26,7 +26,6 @@ USE_PROCD=1
|
||||
PROG=/usr/bin/mosdns
|
||||
CONF=$(uci -q get mosdns.config.configfile)
|
||||
CRON_FILE=/etc/crontabs/root
|
||||
V2DAT_DIR=/usr/share/v2ray
|
||||
DUMP_FILE=/etc/mosdns/cache.dump
|
||||
DUMP_FILE_DEFAULT=/usr/share/mosdns/cache.dump
|
||||
DEFAULT_CONF=/usr/share/mosdns/default.yaml
|
||||
@ -53,12 +52,13 @@ get_config() {
|
||||
config_get remote_dns $1 remote_dns "tls://8.8.8.8 tls://1.1.1.1"
|
||||
config_get custom_local_dns $1 custom_local_dns 0
|
||||
config_get bootstrap_dns $1 bootstrap_dns "119.29.29.29"
|
||||
config_get enabled_api $1 enabled_api 0
|
||||
config_get listen_port_api $1 listen_port_api 9091
|
||||
config_get concurrent $1 concurrent 1
|
||||
config_get max_conns $1 max_conns 2
|
||||
config_get insecure_skip_verify $1 insecure_skip_verify 0
|
||||
config_get idle_timeout $1 idle_timeout 30
|
||||
config_get enable_http3 $1 enable_http3 0
|
||||
config_get enable_ecs_remote $1 enable_ecs_remote 0
|
||||
}
|
||||
|
||||
init_yaml() {
|
||||
@ -66,25 +66,30 @@ init_yaml() {
|
||||
adlist=$($MOSDNS_SCRIPT ad)
|
||||
[ $enable_pipeline -eq 1 ] && enable_pipeline=true || enable_pipeline=false
|
||||
[ $insecure_skip_verify -eq 1 ] && insecure_skip_verify=true || insecure_skip_verify=false
|
||||
[ $enable_http3 -eq 1 ] && enable_http3=true || enable_http3=false
|
||||
[ "$custom_local_dns" -eq 1 ] && \
|
||||
local_dns=$($MOSDNS_SCRIPT dns | awk '{for(i=1;i<=NF;i++)printf "%s- addr: %s\n%s bootstrap: '${bootstrap_dns}'\n%s enable_pipeline: '${enable_pipeline}'\n%s max_conns: '${max_conns}'\n%s insecure_skip_verify: '${insecure_skip_verify}'\n%s idle_timeout: '${idle_timeout}'\n",s,$i,s,s,s,s,s}' s=' ') || \
|
||||
local_dns=$($MOSDNS_SCRIPT dns | awk '{for(i=1;i<=NF;i++)printf "%s- addr: %s\n",s,$i,s}' s=' ')
|
||||
remote_dns=$(echo $remote_dns | awk '{for(i=1;i<=NF;i++)printf "%s- addr: %s\n%s bootstrap: '${bootstrap_dns}'\n%s enable_pipeline: '${enable_pipeline}'\n%s max_conns: '${max_conns}'\n%s insecure_skip_verify: '${insecure_skip_verify}'\n%s idle_timeout: '${idle_timeout}'\n",s,$i,s,s,s,s,s}' s=' ')
|
||||
remote_dns=$(echo $remote_dns | awk '{for(i=1;i<=NF;i++)printf "%s- addr: %s\n%s bootstrap: '${bootstrap_dns}'\n%s enable_pipeline: '${enable_pipeline}'\n%s max_conns: '${max_conns}'\n%s insecure_skip_verify: '${insecure_skip_verify}'\n%s idle_timeout: '${idle_timeout}'\n%s enable_http3: '${enable_http3}'\n",s,$i,s,s,s,s,s,s}' s=' ')
|
||||
sed "s,log_level,$log_level,g;s,log_file,$log_file,g; \
|
||||
s,listen_port,$listen_port,g;s,cache_size,$cache_size,g; \
|
||||
s,cache_survival_time,$cache_survival_time,g; \
|
||||
s,minimal_ttl_custom,$minimal_ttl_custom,g; \
|
||||
s,maximum_ttl_custom,$maximum_ttl_custom,g; \
|
||||
s,concurrent_num,$concurrent,g; \
|
||||
s,concurrent_num,$concurrent,g;s,api_port,$listen_port_api,g; \
|
||||
s,adblock,$adlist,g;s,remote_dns_pipeline,$enable_pipeline,g" $DEFAULT_CONF > $CONF
|
||||
echo "${local_dns}" > $TMPDIR/local_dns.txt
|
||||
echo "${remote_dns}" > $TMPDIR/remote_dns.txt
|
||||
sed -i -e '/- addr: local_dns/{r '$TMPDIR/local_dns.txt -e';d};/- addr: remote_dns/{r '$TMPDIR/remote_dns.txt -e';d}' $CONF
|
||||
[ "$enabled_api" -eq 1 ] && sed -i "s/api_port/$listen_port_api/g" $CONF
|
||||
[ "$enabled_api" -eq 0 ] && sed -i "/api:/d;/http:/d;" $CONF
|
||||
[ "$dump_file" -eq 1 ] && sed -i "/lazy_cache_ttl/a\ dump_file: $DUMP_FILE\n dump_interval: $dump_interval" $CONF
|
||||
[ "$dump_file" -eq 1 ] && [ ! -f $DUMP_FILE ] && cp -a $DUMP_FILE_DEFAULT $DUMP_FILE
|
||||
[ "$dump_file" -eq 0 ] && \cp -a $DUMP_FILE_DEFAULT $DUMP_FILE
|
||||
if [ "$enable_ecs_remote" -eq 1 ]; then
|
||||
ecs_remote=$(sh /usr/share/mosdns/mosdns.sh ecs_remote)
|
||||
sed -i "s,ecs_remote,$ecs_remote,g" $CONF
|
||||
else
|
||||
sed -i "/ecs_remote/d;" $CONF
|
||||
fi
|
||||
rm -rf $TMPDIR
|
||||
}
|
||||
|
||||
@ -141,11 +146,7 @@ delcron() {
|
||||
}
|
||||
|
||||
v2dat_dump() {
|
||||
mkdir -p /var/mosdns
|
||||
rm -f /var/mosdns/geo*.txt
|
||||
v2dat unpack geoip -o /var/mosdns -f cn $V2DAT_DIR/geoip.dat
|
||||
v2dat unpack geosite -o /var/mosdns -f cn -f 'geolocation-!cn' $V2DAT_DIR/geosite.dat
|
||||
[ "$adblock" -eq 1 ] && [ "$ad_source" = "geosite.dat" ] && v2dat unpack geosite -o /var/mosdns -f category-ads-all $V2DAT_DIR/geosite.dat
|
||||
$MOSDNS_SCRIPT v2dat_dump
|
||||
}
|
||||
|
||||
start_service() {
|
||||
|
@ -2,6 +2,12 @@ log:
|
||||
level: info
|
||||
file: "/tmp/mosdns.log"
|
||||
|
||||
# API 入口设置
|
||||
api:
|
||||
http: "0.0.0.0:9091"
|
||||
|
||||
include: []
|
||||
|
||||
plugins:
|
||||
# 国内域名
|
||||
- tag: geosite_cn
|
||||
@ -45,6 +51,13 @@ plugins:
|
||||
files:
|
||||
- "/etc/mosdns/rule/greylist.txt"
|
||||
|
||||
# DDNS域名 加入的域名始终使用 “本地 DNS” 进行解析,并且修改 TTL 为 5 秒,解析结果不进行缓存
|
||||
- tag: ddnslist
|
||||
type: domain_set
|
||||
args:
|
||||
files:
|
||||
- "/etc/mosdns/rule/ddnslist.txt"
|
||||
|
||||
# 自定义 Hosts 重写
|
||||
- tag: hosts
|
||||
type: hosts
|
||||
@ -74,7 +87,7 @@ plugins:
|
||||
- "/usr/share/mosdns/sp_low.tdata"
|
||||
|
||||
# 缓存
|
||||
- tag: cache
|
||||
- tag: lazy_cache
|
||||
type: cache
|
||||
args:
|
||||
size: 20000
|
||||
@ -105,6 +118,12 @@ plugins:
|
||||
args:
|
||||
- exec: ttl 0-0
|
||||
|
||||
# 修改 ddns 域名 ttl(默认 5秒)
|
||||
- tag: modify_ddns_ttl
|
||||
type: sequence
|
||||
args:
|
||||
- exec: ttl 5-5
|
||||
|
||||
# 国内解析
|
||||
- tag: local_sequence
|
||||
type: sequence
|
||||
@ -118,11 +137,14 @@ plugins:
|
||||
- exec: prefer_ipv4
|
||||
- exec: $forward_remote
|
||||
|
||||
# 有响应终止返回
|
||||
# 有响应则修改 TTL 并终止返回
|
||||
- tag: has_resp_sequence
|
||||
type: sequence
|
||||
args:
|
||||
- exec: $modify_ttl
|
||||
- matches: qname $ddnslist
|
||||
exec: $modify_ddns_ttl
|
||||
- matches: "!qname $ddnslist"
|
||||
exec: $modify_ttl
|
||||
- matches: has_resp
|
||||
exec: accept
|
||||
|
||||
@ -150,6 +172,13 @@ plugins:
|
||||
threshold: 500
|
||||
always_standby: true
|
||||
|
||||
# 查询 DDNS 域名
|
||||
- tag: query_is_ddns_domain
|
||||
type: sequence
|
||||
args:
|
||||
- matches: qname $ddnslist
|
||||
exec: $local_sequence
|
||||
|
||||
# 查询国内域名
|
||||
- tag: query_is_local_domain
|
||||
type: sequence
|
||||
@ -201,12 +230,20 @@ plugins:
|
||||
args:
|
||||
- exec: $hosts
|
||||
- exec: jump has_resp_sequence
|
||||
# 非 “拒绝名单” 或 “DDNS域名” 则启用缓存
|
||||
- matches:
|
||||
- "!qname $ddnslist"
|
||||
- "!qname $blocklist"
|
||||
- "!qname $sp_low"
|
||||
- "!qname $local_ptr"
|
||||
exec: $lazy_cache
|
||||
- exec: $redirect
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_ddns_domain
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_whitelist_domain
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_reject_domain
|
||||
- exec: $cache
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_greylist_domain
|
||||
- exec: jump has_resp_sequence
|
||||
|
@ -44,6 +44,12 @@ plugins:
|
||||
files:
|
||||
- "/etc/mosdns/rule/greylist.txt"
|
||||
|
||||
- tag: ddnslist
|
||||
type: domain_set
|
||||
args:
|
||||
files:
|
||||
- "/etc/mosdns/rule/ddnslist.txt"
|
||||
|
||||
- tag: hosts
|
||||
type: hosts
|
||||
args:
|
||||
@ -74,7 +80,7 @@ plugins:
|
||||
files:
|
||||
- "/usr/share/mosdns/sp_low.tdata"
|
||||
|
||||
- tag: cache
|
||||
- tag: lazy_cache
|
||||
type: cache
|
||||
args:
|
||||
size: cache_size
|
||||
@ -99,6 +105,11 @@ plugins:
|
||||
args:
|
||||
- exec: ttl minimal_ttl_custom-maximum_ttl_custom
|
||||
|
||||
- tag: modify_ddns_ttl
|
||||
type: sequence
|
||||
args:
|
||||
- exec: ttl 5-5
|
||||
|
||||
- tag: local_sequence
|
||||
type: sequence
|
||||
args:
|
||||
@ -108,12 +119,16 @@ plugins:
|
||||
type: sequence
|
||||
args:
|
||||
- exec: prefer_ipv4
|
||||
- exec: ecs_remote
|
||||
- exec: $forward_remote
|
||||
|
||||
- tag: has_resp_sequence
|
||||
type: sequence
|
||||
args:
|
||||
- exec: $modify_ttl
|
||||
- matches: qname $ddnslist
|
||||
exec: $modify_ddns_ttl
|
||||
- matches: "!qname $ddnslist"
|
||||
exec: $modify_ttl
|
||||
- matches: has_resp
|
||||
exec: accept
|
||||
|
||||
@ -137,6 +152,12 @@ plugins:
|
||||
threshold: 500
|
||||
always_standby: true
|
||||
|
||||
- tag: query_is_ddns_domain
|
||||
type: sequence
|
||||
args:
|
||||
- matches: qname $ddnslist
|
||||
exec: $local_sequence
|
||||
|
||||
- tag: query_is_local_domain
|
||||
type: sequence
|
||||
args:
|
||||
@ -182,12 +203,20 @@ plugins:
|
||||
args:
|
||||
- exec: $hosts
|
||||
- exec: jump has_resp_sequence
|
||||
- matches:
|
||||
- "!qname $ddnslist"
|
||||
- "!qname $blocklist"
|
||||
- "!qname $adlist"
|
||||
- "!qname $sp_low"
|
||||
- "!qname $local_ptr"
|
||||
exec: $lazy_cache
|
||||
- exec: $redirect
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_ddns_domain
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_whitelist_domain
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_reject_domain
|
||||
- exec: $cache
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_greylist_domain
|
||||
- exec: jump has_resp_sequence
|
||||
|
@ -84,6 +84,44 @@ restart_service() {
|
||||
/etc/init.d/mosdns restart
|
||||
}
|
||||
|
||||
ecs_local() {
|
||||
ipaddr=$(curl -s -4 --connect-timeout 2 -H "Host:ip.3322.org" 118.184.169.32) || ipaddr=119.29.0.0
|
||||
echo "ecs ${ipaddr%.*}.0/24"
|
||||
}
|
||||
|
||||
ecs_remote() {
|
||||
ipaddr=$(curl -s -4 --connect-timeout 2 -H "Host:icanhazip.com" 104.18.114.97) || ipaddr=103.103.65.0
|
||||
echo "ecs ${ipaddr%.*}.0/24"
|
||||
}
|
||||
|
||||
flush_cache() {
|
||||
curl -s 127.0.0.1:$(uci -q get mosdns.config.listen_port_api)/plugins/lazy_cache/flush || exit 1
|
||||
}
|
||||
|
||||
v2dat_dump() {
|
||||
# env
|
||||
v2dat_dir=/usr/share/v2ray
|
||||
adblock=$(uci -q get mosdns.config.adblock)
|
||||
ad_source=$(uci -q get mosdns.config.ad_source)
|
||||
configfile=$(uci -q get mosdns.config.configfile)
|
||||
mkdir -p /var/mosdns
|
||||
rm -f /var/mosdns/geo*.txt
|
||||
if [ "$configfile" = "/etc/mosdns/config.yaml" ]; then
|
||||
# default config
|
||||
v2dat unpack geoip -o /var/mosdns -f cn $v2dat_dir/geoip.dat
|
||||
v2dat unpack geosite -o /var/mosdns -f cn -f 'geolocation-!cn' $v2dat_dir/geosite.dat
|
||||
[ "$adblock" -eq 1 ] && [ "$ad_source" = "geosite.dat" ] && v2dat unpack geosite -o /var/mosdns -f category-ads-all $v2dat_dir/geosite.dat
|
||||
else
|
||||
# custom config
|
||||
v2dat unpack geoip -o /var/mosdns -f cn $v2dat_dir/geoip.dat
|
||||
v2dat unpack geosite -o /var/mosdns -f cn -f 'geolocation-!cn' $v2dat_dir/geosite.dat
|
||||
geoip_tags=$(uci -q get mosdns.config.geoip_tags)
|
||||
geosite_tags=$(uci -q get mosdns.config.geosite_tags)
|
||||
[ -n "$geoip_tags" ] && v2dat unpack geoip -o /var/mosdns $(echo $geoip_tags | sed -r 's/\S+/-f &/g') $v2dat_dir/geoip.dat
|
||||
[ -n "$geosite_tags" ] && v2dat unpack geosite -o /var/mosdns $(echo $geosite_tags | sed -r 's/\S+/-f &/g') $v2dat_dir/geosite.dat
|
||||
fi
|
||||
}
|
||||
|
||||
case $script_action in
|
||||
"dns")
|
||||
interface_dns
|
||||
@ -100,6 +138,18 @@ case $script_action in
|
||||
"adlist_update")
|
||||
adlist_update && restart_service
|
||||
;;
|
||||
"ecs_local")
|
||||
ecs_local
|
||||
;;
|
||||
"ecs_remote")
|
||||
ecs_remote
|
||||
;;
|
||||
"flush")
|
||||
flush_cache
|
||||
;;
|
||||
"v2dat_dump")
|
||||
v2dat_dump
|
||||
;;
|
||||
"version")
|
||||
mosdns version
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user