luci-app-mosdns: init at 97867ea
This commit is contained in:
parent
6c536e3c19
commit
90cc8ca0d2
44 changed files with 2546 additions and 0 deletions
30
luci-app-mosdns/root/etc/config/mosdns
Normal file
30
luci-app-mosdns/root/etc/config/mosdns
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
config mosdns 'config'
|
||||
option enabled '0'
|
||||
option listen_port '5335'
|
||||
option geo_auto_update '0'
|
||||
option geo_update_week_time '*'
|
||||
option geo_update_day_time '2'
|
||||
option redirect '1'
|
||||
option prefer_ipv4 '1'
|
||||
option adblock '0'
|
||||
option configfile '/var/etc/mosdns.json'
|
||||
option log_level 'info'
|
||||
option log_file '/var/log/mosdns.log'
|
||||
option cache_size '8000'
|
||||
option lazy_cache_ttl '86400'
|
||||
option dump_file '0'
|
||||
option concurrent '1'
|
||||
option idle_timeout '30'
|
||||
option minimal_ttl '0'
|
||||
option maximum_ttl '0'
|
||||
option custom_local_dns '0'
|
||||
option enable_pipeline '0'
|
||||
option insecure_skip_verify '0'
|
||||
option dns_leak '0'
|
||||
option cloudflare '0'
|
||||
option listen_port_api '9091'
|
||||
option bootstrap_dns '119.29.29.29'
|
||||
list remote_dns 'tls://8.8.8.8'
|
||||
list remote_dns 'tls://1.1.1.1'
|
||||
|
2
luci-app-mosdns/root/etc/hotplug.d/iface/99-mosdns
Executable file
2
luci-app-mosdns/root/etc/hotplug.d/iface/99-mosdns
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
[ "$ACTION" = ifup ] && /etc/init.d/mosdns restart
|
705
luci-app-mosdns/root/etc/init.d/mosdns
Executable file
705
luci-app-mosdns/root/etc/init.d/mosdns
Executable file
|
@ -0,0 +1,705 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (C) 2020-2022, IrineSistiana
|
||||
# Copyright (C) 2023-2024, sbwml <admin@cooluc.com>
|
||||
#
|
||||
# This file is part of mosdns.
|
||||
#
|
||||
# mosdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# mosdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
START=51
|
||||
USE_PROCD=1
|
||||
|
||||
PROG=/usr/bin/mosdns
|
||||
CONF=$(uci -q get mosdns.config.configfile)
|
||||
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.sh
|
||||
|
||||
get_config() {
|
||||
config_get enabled $1 enabled 0
|
||||
config_get adblock $1 adblock 0
|
||||
config_get ad_source $1 ad_source ""
|
||||
config_get cache_size $1 cache_size 8000
|
||||
config_get lazy_cache_ttl $1 lazy_cache_ttl 86400
|
||||
config_get dump_file $1 dump_file 0
|
||||
config_get dump_interval $1 dump_interval 3600
|
||||
config_get enable_pipeline $1 enable_pipeline 0
|
||||
config_get geo_auto_update $1 geo_auto_update 0
|
||||
config_get geo_update_day_time $1 geo_update_day_time 2
|
||||
config_get geo_update_week_time $1 geo_update_week_time "*"
|
||||
config_get listen_port $1 listen_port 5335
|
||||
config_get log_file $1 log_file "/var/log/mosdns.log"
|
||||
config_get log_level $1 log_level "info"
|
||||
config_get minimal_ttl $1 minimal_ttl 0
|
||||
config_get maximum_ttl $1 maximum_ttl 0
|
||||
config_get redirect $1 redirect 0
|
||||
config_get prefer_ipv4 $1 prefer_ipv4 0
|
||||
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 apple_optimization $1 apple_optimization 0
|
||||
config_get bootstrap_dns $1 bootstrap_dns "119.29.29.29"
|
||||
config_get listen_port_api $1 listen_port_api 9091
|
||||
config_get concurrent $1 concurrent 1
|
||||
config_get insecure_skip_verify $1 insecure_skip_verify 0
|
||||
config_get idle_timeout $1 idle_timeout 30
|
||||
config_get enable_ecs_remote $1 enable_ecs_remote 0
|
||||
config_get remote_ecs_ip $1 remote_ecs_ip "110.34.181.1"
|
||||
config_get dns_leak $1 dns_leak 0
|
||||
config_get cloudflare $1 cloudflare 0
|
||||
config_get cloudflare_ip $1 cloudflare_ip ""
|
||||
}
|
||||
|
||||
generate_config() {
|
||||
# jshn shell library
|
||||
. /usr/share/libubox/jshn.sh
|
||||
# json data
|
||||
json_init
|
||||
# log
|
||||
json_add_object 'log'
|
||||
json_add_string "level" "$log_level"
|
||||
json_add_string "file" "$log_file"
|
||||
json_close_object
|
||||
# api
|
||||
json_add_object 'api'
|
||||
json_add_string "http" "0.0.0.0:$listen_port_api"
|
||||
json_close_object
|
||||
# include
|
||||
json_add_array "include"
|
||||
json_close_array
|
||||
# plugins
|
||||
json_add_array "plugins"
|
||||
# plugin: geosite_cn
|
||||
json_add_object
|
||||
json_add_string "tag" "geosite_cn"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/var/mosdns/geosite_cn.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: geoip_cn
|
||||
json_add_object
|
||||
json_add_string "tag" "geoip_cn"
|
||||
json_add_string "type" "ip_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/var/mosdns/geoip_cn.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: geosite_apple
|
||||
json_add_object
|
||||
json_add_string "tag" "geosite_apple"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/var/mosdns/geosite_apple.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: geosite_no_cn
|
||||
json_add_object
|
||||
json_add_string "tag" "geosite_no_cn"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/var/mosdns/geosite_geolocation-!cn.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: whitelist
|
||||
json_add_object
|
||||
json_add_string "tag" "whitelist"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/etc/mosdns/rule/whitelist.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: blocklist
|
||||
json_add_object
|
||||
json_add_string "tag" "blocklist"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/etc/mosdns/rule/blocklist.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: greylist
|
||||
json_add_object
|
||||
json_add_string "tag" "greylist"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/etc/mosdns/rule/greylist.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: ddnslist
|
||||
json_add_object
|
||||
json_add_string "tag" "ddnslist"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/etc/mosdns/rule/ddnslist.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: hosts
|
||||
json_add_object
|
||||
json_add_string "tag" "hosts"
|
||||
json_add_string "type" "hosts"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/etc/mosdns/rule/hosts.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: redirect
|
||||
json_add_object
|
||||
json_add_string "tag" "redirect"
|
||||
json_add_string "type" "redirect"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/etc/mosdns/rule/redirect.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: adlist
|
||||
json_add_object
|
||||
json_add_string "tag" "adlist"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
adlist=$($MOSDNS_SCRIPT adlist)
|
||||
for list in $adlist; do
|
||||
json_add_string "" "$list"
|
||||
done
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: local_ptr
|
||||
json_add_object
|
||||
json_add_string "tag" "local_ptr"
|
||||
json_add_string "type" "domain_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/etc/mosdns/rule/local-ptr.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: cloudflare_cidr
|
||||
json_add_object
|
||||
json_add_string "tag" "cloudflare_cidr"
|
||||
json_add_string "type" "ip_set"
|
||||
json_add_object "args"
|
||||
json_add_array "files"
|
||||
json_add_string "" "/etc/mosdns/rule/cloudflare-cidr.txt"
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: lazy_cache
|
||||
json_add_object
|
||||
json_add_string "tag" "lazy_cache"
|
||||
json_add_string "type" "cache"
|
||||
json_add_object "args"
|
||||
json_add_int "size" "$cache_size"
|
||||
json_add_int "lazy_cache_ttl" "$lazy_cache_ttl"
|
||||
[ "$dump_file" -eq 1 ] && {
|
||||
json_add_string "dump_file" "/etc/mosdns/cache.dump"
|
||||
json_add_int "dump_interval" "$dump_interval"
|
||||
}
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: forward_xinfeng_udp
|
||||
json_add_object
|
||||
json_add_string "tag" "forward_xinfeng_udp"
|
||||
json_add_string "type" "forward"
|
||||
json_add_object "args"
|
||||
json_add_int "concurrent" 2
|
||||
json_add_array "upstreams"
|
||||
json_add_object
|
||||
json_add_string "addr" "114.114.114.114"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "addr" "114.114.115.115"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: forward_local
|
||||
json_add_object
|
||||
json_add_string "tag" "forward_local"
|
||||
json_add_string "type" "forward"
|
||||
json_add_object "args"
|
||||
json_add_int "concurrent" "$concurrent"
|
||||
json_add_array "upstreams"
|
||||
local_dns=$($MOSDNS_SCRIPT dns)
|
||||
for addr in $local_dns; do
|
||||
enable_http3=0
|
||||
if echo "$addr" | grep -q "^h3://"; then
|
||||
enable_http3=1
|
||||
addr=$(echo $addr | sed 's/h3:\/\//https:\/\//g')
|
||||
fi
|
||||
json_add_object
|
||||
json_add_string "addr" "$addr"
|
||||
json_add_string "bootstrap" "$bootstrap_dns"
|
||||
json_add_boolean "enable_pipeline" "$enable_pipeline"
|
||||
json_add_boolean "insecure_skip_verify" "$insecure_skip_verify"
|
||||
json_add_int "idle_timeout" "$idle_timeout"
|
||||
[ "$enable_http3" -eq 1 ] && json_add_boolean "enable_http3" "1"
|
||||
json_close_object
|
||||
done
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: forward_remote
|
||||
json_add_object
|
||||
json_add_string "tag" "forward_remote"
|
||||
json_add_string "type" "forward"
|
||||
json_add_object "args"
|
||||
json_add_int "concurrent" "$concurrent"
|
||||
json_add_array "upstreams"
|
||||
for addr in $remote_dns; do
|
||||
enable_http3=0
|
||||
if echo "$addr" | grep -q "^h3://"; then
|
||||
enable_http3=1
|
||||
addr=$(echo $addr | sed 's/h3:\/\//https:\/\//g')
|
||||
fi
|
||||
json_add_object
|
||||
json_add_string "addr" "$addr"
|
||||
json_add_string "bootstrap" "$bootstrap_dns"
|
||||
json_add_boolean "enable_pipeline" "$enable_pipeline"
|
||||
json_add_boolean "insecure_skip_verify" "$insecure_skip_verify"
|
||||
json_add_int "idle_timeout" "$idle_timeout"
|
||||
[ "$enable_http3" -eq 1 ] && json_add_boolean "enable_http3" "1"
|
||||
json_close_object
|
||||
done
|
||||
json_close_array
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: forward_remote_upstream
|
||||
json_add_object
|
||||
json_add_string "tag" "forward_remote_upstream"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
[ "$prefer_ipv4" -eq 1 ] && {
|
||||
json_add_object
|
||||
json_add_string "exec" "prefer_ipv4"
|
||||
json_close_object
|
||||
}
|
||||
[ "$enable_ecs_remote" -eq 1 ] && {
|
||||
json_add_object
|
||||
json_add_string "exec" "ecs $remote_ecs_ip"
|
||||
json_close_object
|
||||
}
|
||||
json_add_object
|
||||
json_add_string "exec" "\$forward_remote"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: modify_ttl
|
||||
json_add_object
|
||||
json_add_string "tag" "modify_ttl"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "exec" "ttl $minimal_ttl-$maximum_ttl"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: modify_ddns_ttl
|
||||
json_add_object
|
||||
json_add_string "tag" "modify_ddns_ttl"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "exec" "ttl 5-5"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: has_resp_sequence
|
||||
json_add_object
|
||||
json_add_string "tag" "has_resp_sequence"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "matches" "qname \$ddnslist"
|
||||
json_add_string "exec" "\$modify_ddns_ttl"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "matches" "!qname \$ddnslist"
|
||||
json_add_string "exec" "\$modify_ttl"
|
||||
json_close_object
|
||||
[ "$cloudflare" -eq 1 ] && {
|
||||
json_add_object
|
||||
json_add_string "matches" "resp_ip \$cloudflare_cidr"
|
||||
json_add_string "exec" "black_hole $cloudflare_ip"
|
||||
json_close_object
|
||||
}
|
||||
json_add_object
|
||||
json_add_string "matches" "has_resp"
|
||||
json_add_string "exec" "accept"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: query_is_non_local_ip
|
||||
json_add_object
|
||||
json_add_string "tag" "query_is_non_local_ip"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "exec" "\$forward_local"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "matches" "!resp_ip \$geoip_cn"
|
||||
json_add_string "exec" "drop_resp"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: fallback
|
||||
json_add_object
|
||||
json_add_string "tag" "fallback"
|
||||
json_add_string "type" "fallback"
|
||||
json_add_object "args"
|
||||
[ "$dns_leak" -eq 1 ] && json_add_string "primary" "forward_remote_upstream" || json_add_string "primary" "query_is_non_local_ip"
|
||||
json_add_string "secondary" "forward_remote_upstream"
|
||||
json_add_int "threshold" 500
|
||||
json_add_boolean "always_standby" 1
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: apple_domain_fallback
|
||||
json_add_object
|
||||
json_add_string "tag" "apple_domain_fallback"
|
||||
json_add_string "type" "fallback"
|
||||
json_add_object "args"
|
||||
json_add_string "primary" "query_is_non_local_ip"
|
||||
json_add_string "secondary" "forward_xinfeng_udp"
|
||||
json_add_int "threshold" 100
|
||||
json_add_boolean "always_standby" 1
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: query_is_apple_domain
|
||||
json_add_object
|
||||
json_add_string "tag" "query_is_apple_domain"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "matches" "!qname \$geosite_apple"
|
||||
json_add_string "exec" "return"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "\$apple_domain_fallback"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: query_is_ddns_domain
|
||||
json_add_object
|
||||
json_add_string "tag" "query_is_ddns_domain"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "matches" "qname \$ddnslist"
|
||||
json_add_string "exec" "\$forward_local"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: query_is_local_domain
|
||||
json_add_object
|
||||
json_add_string "tag" "query_is_local_domain"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "matches" "qname \$geosite_cn"
|
||||
json_add_string "exec" "\$forward_local"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: query_is_no_local_domain
|
||||
json_add_object
|
||||
json_add_string "tag" "query_is_no_local_domain"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "matches" "qname \$geosite_no_cn"
|
||||
json_add_string "exec" "\$forward_remote_upstream"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: query_is_whitelist_domain
|
||||
json_add_object
|
||||
json_add_string "tag" "query_is_whitelist_domain"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "matches" "qname \$whitelist"
|
||||
json_add_string "exec" "\$forward_local"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: query_is_greylist_domain
|
||||
json_add_object
|
||||
json_add_string "tag" "query_is_greylist_domain"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "matches" "qname \$greylist"
|
||||
json_add_string "exec" "\$forward_remote_upstream"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: query_is_reject_domain
|
||||
json_add_object
|
||||
json_add_string "tag" "query_is_reject_domain"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "matches" "qname \$blocklist"
|
||||
json_add_string "exec" "reject 3"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "matches" "qname \$adlist"
|
||||
json_add_string "exec" "reject 3"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_array "matches"
|
||||
json_add_string "" "qtype 12"
|
||||
json_add_string "" "qname \$local_ptr"
|
||||
json_close_array
|
||||
json_add_string "exec" "reject 3"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "matches" "qtype 65"
|
||||
json_add_string "exec" "reject 3"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: main_sequence
|
||||
json_add_object
|
||||
json_add_string "tag" "main_sequence"
|
||||
json_add_string "type" "sequence"
|
||||
json_add_array "args"
|
||||
json_add_object
|
||||
json_add_string "exec" "\$hosts"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_array "matches"
|
||||
json_add_string "" "!qname \$ddnslist"
|
||||
json_add_string "" "!qname \$blocklist"
|
||||
json_add_string "" "!qname \$adlist"
|
||||
json_add_string "" "!qname \$local_ptr"
|
||||
json_close_array
|
||||
json_add_string "exec" "\$lazy_cache"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "\$redirect"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
[ "$apple_optimization" -eq 1 ] && {
|
||||
json_add_string "exec" "\$query_is_apple_domain"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
}
|
||||
json_add_string "exec" "\$query_is_ddns_domain"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "\$query_is_whitelist_domain"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "\$query_is_reject_domain"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "\$query_is_greylist_domain"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "\$query_is_local_domain"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "\$query_is_no_local_domain"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "jump has_resp_sequence"
|
||||
json_close_object
|
||||
json_add_object
|
||||
json_add_string "exec" "\$fallback"
|
||||
json_close_object
|
||||
json_close_array
|
||||
json_close_object
|
||||
# plugin: udp_server
|
||||
json_add_object
|
||||
json_add_string "tag" "udp_server"
|
||||
json_add_string "type" "udp_server"
|
||||
json_add_object "args"
|
||||
json_add_string "entry" "main_sequence"
|
||||
json_add_string "listen" ":$listen_port"
|
||||
json_close_object
|
||||
json_close_object
|
||||
# plugin: tcp_server
|
||||
json_add_object
|
||||
json_add_string "tag" "tcp_server"
|
||||
json_add_string "type" "tcp_server"
|
||||
json_add_object "args"
|
||||
json_add_string "entry" "main_sequence"
|
||||
json_add_string "listen" ":$listen_port"
|
||||
json_close_object
|
||||
json_close_object
|
||||
# close plugins array
|
||||
json_close_array
|
||||
# print json
|
||||
json_dump > /var/etc/mosdns.json
|
||||
|
||||
# init dump_file
|
||||
[ "$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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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"
|
||||
uci set dhcp.@dnsmasq[0].rebind_protection='0'
|
||||
uci set dhcp.@dnsmasq[0].noresolv="1"
|
||||
uci set dhcp.@dnsmasq[0].cachesize='0'
|
||||
uci commit dhcp
|
||||
else
|
||||
sed -i "/list server/d" /etc/config/dhcp
|
||||
uci add_list dhcp.@dnsmasq[0].server="127.0.0.1#$(awk -F'[:" ]+' '/^\s+listen:/{for(i=1;i<=NF;i++){if($i~/^[0-9]+$/){print $i;exit}}}' $CONF)"
|
||||
uci set dhcp.@dnsmasq[0].rebind_protection='0'
|
||||
uci set dhcp.@dnsmasq[0].noresolv="1"
|
||||
uci set dhcp.@dnsmasq[0].cachesize='0'
|
||||
uci commit dhcp
|
||||
fi
|
||||
touch /etc/mosdns/redirect.lock
|
||||
}
|
||||
|
||||
reload_dnsmasq() {
|
||||
/etc/init.d/dnsmasq reload
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
||||
setcron() {
|
||||
sed -i '/mosdns.sh/d' $CRON_FILE 2>/dev/null
|
||||
[ "$geo_auto_update" -eq 1 ] && echo "0 $geo_update_day_time * * $geo_update_week_time $MOSDNS_SCRIPT geodata" >> $CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
delcron() {
|
||||
sed -i '/mosdns.sh/d' $CRON_FILE 2>/dev/null
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
v2dat_dump() {
|
||||
$MOSDNS_SCRIPT v2dat_dump
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "mosdns"
|
||||
config_foreach get_config "mosdns"
|
||||
[ $enabled -ne 1 ] && return 1
|
||||
delcron ; setcron
|
||||
:> $($MOSDNS_SCRIPT logfile)
|
||||
if [ "${log_level}" = "error" ] || [ "${log_level}" = "warn" ]; then
|
||||
v2dat_dump > /dev/null 2>&1
|
||||
else
|
||||
v2dat_dump >> $($MOSDNS_SCRIPT logfile) 2>&1
|
||||
fi
|
||||
[ "${CONF}" = "/var/etc/mosdns.json" ] && generate_config
|
||||
|
||||
procd_open_instance mosdns
|
||||
procd_set_param env QUIC_GO_DISABLE_RECEIVE_BUFFER_WARNING=true
|
||||
procd_set_param command $PROG start
|
||||
procd_append_param command -c "$CONF"
|
||||
procd_append_param command -d "/etc/mosdns"
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance mosdns
|
||||
[ "$redirect" -ne 1 ] && [ -f "/etc/mosdns/redirect.lock" ] && restore_setting
|
||||
[ "$redirect" -eq 1 ] && redirect_setting
|
||||
reload_dnsmasq
|
||||
# Update Adlist
|
||||
update_list=0
|
||||
if [ "$adblock" -eq 1 ]; then
|
||||
if [ -f "/etc/mosdns/rule/.ad_source" ]; then
|
||||
for url in $ad_source;
|
||||
do
|
||||
if [ "$url" = "geosite.dat" ] || [ $(echo "$url" | grep -c -E "^file://") -eq 1 ]; then
|
||||
continue
|
||||
fi
|
||||
if [ $(grep -c "$url" "/etc/mosdns/rule/.ad_source") -eq 0 ]; then
|
||||
update_list=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
update_list=1
|
||||
fi
|
||||
fi
|
||||
[ "$update_list" -eq 1 ] && $MOSDNS_SCRIPT adlist_update &> /dev/null &
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
config_load "mosdns"
|
||||
config_foreach get_config "mosdns"
|
||||
[ "$enabled" -eq "0" ] && [ -f "/etc/mosdns/redirect.lock" ] && restore_setting
|
||||
reload_dnsmasq
|
||||
delcron
|
||||
}
|
142
luci-app-mosdns/root/etc/mosdns/config_custom.yaml
Normal file
142
luci-app-mosdns/root/etc/mosdns/config_custom.yaml
Normal file
|
@ -0,0 +1,142 @@
|
|||
log:
|
||||
level: info
|
||||
file: "/var/log/mosdns.log"
|
||||
|
||||
# API 入口设置
|
||||
api:
|
||||
http: "0.0.0.0:9091"
|
||||
|
||||
include: []
|
||||
|
||||
plugins:
|
||||
# 国内域名
|
||||
- tag: geosite_cn
|
||||
type: domain_set
|
||||
args:
|
||||
files:
|
||||
- "/var/mosdns/geosite_cn.txt"
|
||||
|
||||
# 国内 IP
|
||||
- tag: geoip_cn
|
||||
type: ip_set
|
||||
args:
|
||||
files:
|
||||
- "/var/mosdns/geoip_cn.txt"
|
||||
|
||||
# 国外域名
|
||||
- tag: geosite_no_cn
|
||||
type: domain_set
|
||||
args:
|
||||
files:
|
||||
- "/var/mosdns/geosite_geolocation-!cn.txt"
|
||||
|
||||
# 缓存
|
||||
- tag: lazy_cache
|
||||
type: cache
|
||||
args:
|
||||
size: 20000
|
||||
lazy_cache_ttl: 86400
|
||||
dump_file: "/etc/mosdns/cache.dump"
|
||||
dump_interval: 600
|
||||
|
||||
# 转发至本地服务器
|
||||
- tag: forward_local
|
||||
type: forward
|
||||
args:
|
||||
upstreams:
|
||||
- addr: "https://doh.pub/dns-query"
|
||||
bootstrap: 180.76.76.76
|
||||
- addr: 119.29.29.29
|
||||
|
||||
# 转发至远程服务器
|
||||
- tag: forward_remote
|
||||
type: forward
|
||||
args:
|
||||
upstreams:
|
||||
- addr: tls://8.8.8.8
|
||||
enable_pipeline: false
|
||||
|
||||
# 国内解析
|
||||
- tag: local_sequence
|
||||
type: sequence
|
||||
args:
|
||||
- exec: $forward_local
|
||||
|
||||
# 国外解析
|
||||
- tag: remote_sequence
|
||||
type: sequence
|
||||
args:
|
||||
- exec: prefer_ipv4
|
||||
- exec: $forward_remote
|
||||
|
||||
# 有响应终止返回
|
||||
- tag: has_resp_sequence
|
||||
type: sequence
|
||||
args:
|
||||
- matches: has_resp
|
||||
exec: accept
|
||||
|
||||
# fallback 用本地服务器 sequence
|
||||
# 返回非国内 ip 则 drop_resp
|
||||
- tag: query_is_local_ip
|
||||
type: sequence
|
||||
args:
|
||||
- exec: $local_sequence
|
||||
- matches: "!resp_ip $geoip_cn"
|
||||
exec: drop_resp
|
||||
|
||||
# fallback 用远程服务器 sequence
|
||||
- tag: query_is_remote
|
||||
type: sequence
|
||||
args:
|
||||
- exec: $remote_sequence
|
||||
|
||||
# fallback 用远程服务器 sequence
|
||||
- tag: fallback
|
||||
type: fallback
|
||||
args:
|
||||
primary: query_is_local_ip
|
||||
secondary: query_is_remote
|
||||
threshold: 500
|
||||
always_standby: true
|
||||
|
||||
# 查询国内域名
|
||||
- tag: query_is_local_domain
|
||||
type: sequence
|
||||
args:
|
||||
- matches: qname $geosite_cn
|
||||
exec: $local_sequence
|
||||
|
||||
# 查询国外域名
|
||||
- tag: query_is_no_local_domain
|
||||
type: sequence
|
||||
args:
|
||||
- matches: qname $geosite_no_cn
|
||||
exec: $remote_sequence
|
||||
|
||||
# 主要的运行逻辑插件
|
||||
# sequence 插件中调用的插件 tag 必须在 sequence 前定义,
|
||||
# 否则 sequence 找不到对应插件。
|
||||
- tag: main_sequence
|
||||
type: sequence
|
||||
args:
|
||||
- exec: $lazy_cache
|
||||
- exec: $query_is_local_domain
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $query_is_no_local_domain
|
||||
- exec: jump has_resp_sequence
|
||||
- exec: $fallback
|
||||
|
||||
# 启动 udp 服务器。
|
||||
- tag: udp_server
|
||||
type: udp_server
|
||||
args:
|
||||
entry: main_sequence
|
||||
listen: ":5335"
|
||||
|
||||
# 启动 tcp 服务器。
|
||||
- tag: tcp_server
|
||||
type: tcp_server
|
||||
args:
|
||||
entry: main_sequence
|
||||
listen: ":5335"
|
0
luci-app-mosdns/root/etc/mosdns/rule/blocklist.txt
Normal file
0
luci-app-mosdns/root/etc/mosdns/rule/blocklist.txt
Normal file
22
luci-app-mosdns/root/etc/mosdns/rule/cloudflare-cidr.txt
Normal file
22
luci-app-mosdns/root/etc/mosdns/rule/cloudflare-cidr.txt
Normal file
|
@ -0,0 +1,22 @@
|
|||
173.245.48.0/20
|
||||
103.21.244.0/22
|
||||
103.22.200.0/22
|
||||
103.31.4.0/22
|
||||
141.101.64.0/18
|
||||
108.162.192.0/18
|
||||
190.93.240.0/20
|
||||
188.114.96.0/20
|
||||
197.234.240.0/22
|
||||
198.41.128.0/17
|
||||
162.158.0.0/15
|
||||
104.16.0.0/13
|
||||
104.24.0.0/14
|
||||
172.64.0.0/13
|
||||
131.0.72.0/22
|
||||
2400:cb00::/32
|
||||
2606:4700::/32
|
||||
2803:f800::/32
|
||||
2405:b500::/32
|
||||
2405:8100::/32
|
||||
2a06:98c0::/29
|
||||
2c0f:f248::/32
|
0
luci-app-mosdns/root/etc/mosdns/rule/ddnslist.txt
Normal file
0
luci-app-mosdns/root/etc/mosdns/rule/ddnslist.txt
Normal file
0
luci-app-mosdns/root/etc/mosdns/rule/greylist.txt
Normal file
0
luci-app-mosdns/root/etc/mosdns/rule/greylist.txt
Normal file
0
luci-app-mosdns/root/etc/mosdns/rule/hosts.txt
Normal file
0
luci-app-mosdns/root/etc/mosdns/rule/hosts.txt
Normal file
87
luci-app-mosdns/root/etc/mosdns/rule/local-ptr.txt
Normal file
87
luci-app-mosdns/root/etc/mosdns/rule/local-ptr.txt
Normal file
|
@ -0,0 +1,87 @@
|
|||
0.in-addr.arpa
|
||||
10.in-addr.arpa
|
||||
127.in-addr.arpa
|
||||
16.172.in-addr.arpa
|
||||
17.172.in-addr.arpa
|
||||
18.172.in-addr.arpa
|
||||
19.172.in-addr.arpa
|
||||
20.172.in-addr.arpa
|
||||
21.172.in-addr.arpa
|
||||
22.172.in-addr.arpa
|
||||
23.172.in-addr.arpa
|
||||
24.172.in-addr.arpa
|
||||
25.172.in-addr.arpa
|
||||
26.172.in-addr.arpa
|
||||
27.172.in-addr.arpa
|
||||
28.172.in-addr.arpa
|
||||
29.172.in-addr.arpa
|
||||
30.172.in-addr.arpa
|
||||
31.172.in-addr.arpa
|
||||
64.100.in-addr.arpa
|
||||
65.100.in-addr.arpa
|
||||
66.100.in-addr.arpa
|
||||
67.100.in-addr.arpa
|
||||
68.100.in-addr.arpa
|
||||
69.100.in-addr.arpa
|
||||
70.100.in-addr.arpa
|
||||
71.100.in-addr.arpa
|
||||
72.100.in-addr.arpa
|
||||
73.100.in-addr.arpa
|
||||
74.100.in-addr.arpa
|
||||
75.100.in-addr.arpa
|
||||
76.100.in-addr.arpa
|
||||
77.100.in-addr.arpa
|
||||
78.100.in-addr.arpa
|
||||
79.100.in-addr.arpa
|
||||
80.100.in-addr.arpa
|
||||
81.100.in-addr.arpa
|
||||
82.100.in-addr.arpa
|
||||
83.100.in-addr.arpa
|
||||
84.100.in-addr.arpa
|
||||
85.100.in-addr.arpa
|
||||
86.100.in-addr.arpa
|
||||
87.100.in-addr.arpa
|
||||
88.100.in-addr.arpa
|
||||
89.100.in-addr.arpa
|
||||
90.100.in-addr.arpa
|
||||
91.100.in-addr.arpa
|
||||
92.100.in-addr.arpa
|
||||
93.100.in-addr.arpa
|
||||
94.100.in-addr.arpa
|
||||
95.100.in-addr.arpa
|
||||
96.100.in-addr.arpa
|
||||
97.100.in-addr.arpa
|
||||
98.100.in-addr.arpa
|
||||
99.100.in-addr.arpa
|
||||
100.100.in-addr.arpa
|
||||
101.100.in-addr.arpa
|
||||
102.100.in-addr.arpa
|
||||
103.100.in-addr.arpa
|
||||
104.100.in-addr.arpa
|
||||
105.100.in-addr.arpa
|
||||
106.100.in-addr.arpa
|
||||
107.100.in-addr.arpa
|
||||
108.100.in-addr.arpa
|
||||
109.100.in-addr.arpa
|
||||
110.100.in-addr.arpa
|
||||
111.100.in-addr.arpa
|
||||
112.100.in-addr.arpa
|
||||
113.100.in-addr.arpa
|
||||
114.100.in-addr.arpa
|
||||
115.100.in-addr.arpa
|
||||
116.100.in-addr.arpa
|
||||
117.100.in-addr.arpa
|
||||
118.100.in-addr.arpa
|
||||
119.100.in-addr.arpa
|
||||
120.100.in-addr.arpa
|
||||
121.100.in-addr.arpa
|
||||
122.100.in-addr.arpa
|
||||
123.100.in-addr.arpa
|
||||
124.100.in-addr.arpa
|
||||
125.100.in-addr.arpa
|
||||
126.100.in-addr.arpa
|
||||
127.100.in-addr.arpa
|
||||
2.0.192.in-addr.arpa
|
||||
168.192.in-addr.arpa
|
||||
255.255.255.255.in-addr.arpa
|
||||
domain:ip6.arpa
|
0
luci-app-mosdns/root/etc/mosdns/rule/redirect.txt
Normal file
0
luci-app-mosdns/root/etc/mosdns/rule/redirect.txt
Normal file
11
luci-app-mosdns/root/etc/mosdns/rule/whitelist.txt
Normal file
11
luci-app-mosdns/root/etc/mosdns/rule/whitelist.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
domain:bing.com
|
||||
domain:live.com
|
||||
domain:msn.com
|
||||
domain:ntp.org
|
||||
domain:office.com
|
||||
domain:qlogo.cn
|
||||
domain:qq.com
|
||||
domain:redhat.com
|
||||
keyword:douyin
|
||||
keyword:microsoft
|
||||
keyword:windows
|
11
luci-app-mosdns/root/etc/uci-defaults/luci-mosdns
Executable file
11
luci-app-mosdns/root/etc/uci-defaults/luci-mosdns
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@mosdns[-1]
|
||||
add ucitrack mosdns
|
||||
set ucitrack.@mosdns[-1].init=mosdns
|
||||
commit ucitrack
|
||||
EOF
|
||||
|
||||
rm -rf /tmp/luci-*
|
||||
exit 0
|
BIN
luci-app-mosdns/root/usr/share/mosdns/cache.dump
Normal file
BIN
luci-app-mosdns/root/usr/share/mosdns/cache.dump
Normal file
Binary file not shown.
192
luci-app-mosdns/root/usr/share/mosdns/mosdns.sh
Executable file
192
luci-app-mosdns/root/usr/share/mosdns/mosdns.sh
Executable file
|
@ -0,0 +1,192 @@
|
|||
#!/bin/sh
|
||||
|
||||
script_action=${1}
|
||||
|
||||
logfile_path() (
|
||||
configfile=$(uci -q get mosdns.config.configfile)
|
||||
if [ "$configfile" = "/var/etc/mosdns.json" ]; then
|
||||
uci -q get mosdns.config.log_file
|
||||
else
|
||||
[ ! -f /etc/mosdns/config_custom.yaml ] && exit 1
|
||||
awk '/^log:/{f=1;next}f==1{if($0~/file:/){print;exit}if($0~/^[^ ]/)exit}' /etc/mosdns/config_custom.yaml | grep -Eo "/[^'\"]+"
|
||||
fi
|
||||
)
|
||||
|
||||
interface_dns() (
|
||||
if [ "$(uci -q get mosdns.config.custom_local_dns)" = 1 ]; then
|
||||
uci -q get mosdns.config.local_dns
|
||||
else
|
||||
peerdns=$(uci -q get network.wan.peerdns)
|
||||
proto=$(uci -q get network.wan.proto)
|
||||
if [ "$peerdns" = 0 ] || [ "$proto" = "static" ]; then
|
||||
uci -q get network.wan.dns
|
||||
else
|
||||
interface_status=$(ubus call network.interface.wan status)
|
||||
echo $interface_status | jsonfilter -e "@['dns-server'][0]"
|
||||
echo $interface_status | jsonfilter -e "@['dns-server'][1]"
|
||||
fi
|
||||
[ $? -ne 0 ] && echo "119.29.29.29 223.5.5.5"
|
||||
fi
|
||||
)
|
||||
|
||||
get_adlist() (
|
||||
adblock=$(uci -q get mosdns.config.adblock)
|
||||
if [ "$adblock" = 1 ]; then
|
||||
mkdir -p /etc/mosdns/rule/adlist
|
||||
ad_source=$(uci -q get mosdns.config.ad_source)
|
||||
for url in $ad_source;
|
||||
do
|
||||
if [ $(echo $url) = 'geosite.dat' ]; then
|
||||
echo "/var/mosdns/geosite_category-ads-all.txt"
|
||||
elif echo "$url" | grep -Eq "^file://" ; then
|
||||
echo "$url" | sed 's/file:\/\///'
|
||||
else
|
||||
echo "/etc/mosdns/rule/adlist/$(basename $url)"
|
||||
[ ! -f "/etc/mosdns/rule/adlist/$(basename $url)" ] && touch /etc/mosdns/rule/adlist/$(basename $url)
|
||||
fi
|
||||
done
|
||||
else
|
||||
rm -rf /etc/mosdns/rule/adlist /etc/mosdns/rule/.ad_source
|
||||
touch /var/mosdns/disable-ads.txt
|
||||
echo "/var/mosdns/disable-ads.txt"
|
||||
fi
|
||||
)
|
||||
|
||||
adlist_update() {
|
||||
[ "$(uci -q get mosdns.config.adblock)" != 1 ] && return 0
|
||||
lock_file=/var/lock/mosdns_ad_update.lock
|
||||
ad_source=$(uci -q get mosdns.config.ad_source)
|
||||
: > /etc/mosdns/rule/.ad_source
|
||||
if [ -f "$lock_file" ]; then
|
||||
has_update=0
|
||||
exit 0
|
||||
else
|
||||
: > $lock_file
|
||||
fi
|
||||
AD_TMPDIR=$(mktemp -d) || exit 1
|
||||
has_update=0
|
||||
for url in $ad_source;
|
||||
do
|
||||
if [ "$url" != "geosite.dat" ] && [ $(echo "$url" | grep -c -E "^file://") -eq 0 ]; then
|
||||
has_update=1
|
||||
echo "$url" >> /etc/mosdns/rule/.ad_source
|
||||
filename=$(basename $url)
|
||||
if echo "$url" | grep -Eq "^https://raw.githubusercontent.com" ; then
|
||||
[ -n "$(uci -q get mosdns.config.github_proxy)" ] && mirror="$(uci -q get mosdns.config.github_proxy)/"
|
||||
else
|
||||
mirror=""
|
||||
fi
|
||||
echo -e "\e[1;32mDownloading $mirror$url\e[0m"
|
||||
curl --connect-timeout 5 -m 90 --ipv4 -kfSLo "$AD_TMPDIR/$filename" "$mirror$url"
|
||||
fi
|
||||
done
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "\e[1;31mRules download failed.\e[0m"
|
||||
rm -rf "$AD_TMPDIR" "$lock_file"
|
||||
exit 1
|
||||
else
|
||||
[ $has_update -eq 1 ] && {
|
||||
mkdir -p /etc/mosdns/rule/adlist
|
||||
rm -rf /etc/mosdns/rule/adlist/*
|
||||
\cp $AD_TMPDIR/* /etc/mosdns/rule/adlist
|
||||
}
|
||||
fi
|
||||
rm -rf "$AD_TMPDIR" "$lock_file"
|
||||
}
|
||||
|
||||
geodat_update() (
|
||||
TMPDIR=$(mktemp -d) || exit 1
|
||||
[ -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"
|
||||
[ $? -ne 0 ] && rm -rf "$TMPDIR" && exit 1
|
||||
# checksum - geoip.dat
|
||||
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat.sha256sum\e[0m"
|
||||
curl --connect-timeout 5 -m 10 --ipv4 -kfSLo "$TMPDIR/geoip.dat.sha256sum" ""$mirror"https://github.com/Loyalsoldier/geoip/releases/latest/download/geoip-only-cn-private.dat.sha256sum"
|
||||
[ $? -ne 0 ] && rm -rf "$TMPDIR" && exit 1
|
||||
if [ "$(sha256sum "$TMPDIR/geoip.dat" | awk '{print $1}')" != "$(cat "$TMPDIR/geoip.dat.sha256sum" | awk '{print $1}')" ]; then
|
||||
echo -e "\e[1;31mgeoip.dat checksum error\e[0m"
|
||||
rm -rf "$TMPDIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# geosite.dat
|
||||
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat\e[0m"
|
||||
curl --connect-timeout 5 -m 120 --ipv4 -kfSLo "$TMPDIR/geosite.dat" ""$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat"
|
||||
[ $? -ne 0 ] && rm -rf "$TMPDIR" && exit 1
|
||||
# checksum - geosite.dat
|
||||
echo -e "\e[1;32mDownloading "$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat.sha256sum\e[0m"
|
||||
curl --connect-timeout 5 -m 10 --ipv4 -kfSLo "$TMPDIR/geosite.dat.sha256sum" ""$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat.sha256sum"
|
||||
[ $? -ne 0 ] && rm -rf "$TMPDIR" && exit 1
|
||||
if [ "$(sha256sum "$TMPDIR/geosite.dat" | awk '{print $1}')" != "$(cat "$TMPDIR/geosite.dat.sha256sum" | awk '{print $1}')" ]; then
|
||||
echo -e "\e[1;31mgeosite.dat checksum error\e[0m"
|
||||
rm -rf "$TMPDIR"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf "$TMPDIR"/*.sha256sum
|
||||
\cp -a "$TMPDIR"/* /usr/share/v2ray
|
||||
rm -rf "$TMPDIR"
|
||||
)
|
||||
|
||||
restart_service() {
|
||||
/etc/init.d/mosdns restart
|
||||
}
|
||||
|
||||
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" = "/var/etc/mosdns.json" ]; then
|
||||
# default config
|
||||
v2dat unpack geoip -o /var/mosdns -f cn $v2dat_dir/geoip.dat
|
||||
v2dat unpack geosite -o /var/mosdns -f cn -f apple -f 'geolocation-!cn' $v2dat_dir/geosite.dat
|
||||
[ "$adblock" -eq 1 ] && [ $(echo $ad_source | grep -c geosite.dat) -ge '1' ] && 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
|
||||
;;
|
||||
"adlist")
|
||||
get_adlist
|
||||
;;
|
||||
"geodata")
|
||||
geodat_update && adlist_update && restart_service
|
||||
;;
|
||||
"logfile")
|
||||
logfile_path
|
||||
;;
|
||||
"adlist_update")
|
||||
adlist_update && [ "$has_update" -eq 1 ] && restart_service
|
||||
;;
|
||||
"flush")
|
||||
flush_cache
|
||||
;;
|
||||
"v2dat_dump")
|
||||
v2dat_dump
|
||||
;;
|
||||
"version")
|
||||
mosdns version
|
||||
;;
|
||||
*)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"luci-app-mosdns": {
|
||||
"description": "Grant UCI access for luci-app-mosdns",
|
||||
"read": {
|
||||
"uci": [ "mosdns" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "mosdns" ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
!function(n){"object"==typeof exports&&"object"==typeof module?n(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],n):n(CodeMirror)}(function(n){"use strict";function e(e,o,i,t){if(i&&i.call){var l=i;i=null}else l=r(e,i,"rangeFinder");"number"==typeof o&&(o=n.Pos(o,0));var f=r(e,i,"minFoldSize");function d(n){var r=l(e,o);if(!r||r.to.line-r.from.line<f)return null;for(var i=e.findMarksAt(r.from),d=0;d<i.length;++d)if(i[d].__isFold&&"fold"!==t){if(!n)return null;r.cleared=!0,i[d].clear()}return r}var u=d(!0);if(r(e,i,"scanUp"))for(;!u&&o.line>e.firstLine();)o=n.Pos(o.line-1,0),u=d(!1);if(u&&!u.cleared&&"unfold"!==t){var a=function(n,e){var o=r(n,e,"widget");if("string"==typeof o){var i=document.createTextNode(o);(o=document.createElement("span")).appendChild(i),o.className="CodeMirror-foldmarker"}else o&&(o=o.cloneNode(!0));return o}(e,i);n.on(a,"mousedown",function(e){c.clear(),n.e_preventDefault(e)});var c=e.markText(u.from,u.to,{replacedWith:a,clearOnEnter:r(e,i,"clearOnEnter"),__isFold:!0});c.on("clear",function(o,r){n.signal(e,"unfold",e,o,r)}),n.signal(e,"fold",e,u.from,u.to)}}n.newFoldFunction=function(n,o){return function(r,i){e(r,i,{rangeFinder:n,widget:o})}},n.defineExtension("foldCode",function(n,o,r){e(this,n,o,r)}),n.defineExtension("isFolded",function(n){for(var e=this.findMarksAt(n),o=0;o<e.length;++o)if(e[o].__isFold)return!0}),n.commands.toggleFold=function(n){n.foldCode(n.getCursor())},n.commands.fold=function(n){n.foldCode(n.getCursor(),null,"fold")},n.commands.unfold=function(n){n.foldCode(n.getCursor(),null,"unfold")},n.commands.foldAll=function(e){e.operation(function(){for(var o=e.firstLine(),r=e.lastLine();o<=r;o++)e.foldCode(n.Pos(o,0),null,"fold")})},n.commands.unfoldAll=function(e){e.operation(function(){for(var o=e.firstLine(),r=e.lastLine();o<=r;o++)e.foldCode(n.Pos(o,0),null,"unfold")})},n.registerHelper("fold","combine",function(){var n=Array.prototype.slice.call(arguments,0);return function(e,o){for(var r=0;r<n.length;++r){var i=n[r](e,o);if(i)return i}}}),n.registerHelper("fold","auto",function(n,e){for(var o=n.getHelpers(e,"fold"),r=0;r<o.length;r++){var i=o[r](n,e);if(i)return i}});var o={rangeFinder:n.fold.auto,widget:"↔",minFoldSize:0,scanUp:!1,clearOnEnter:!0};function r(n,e,r){if(e&&void 0!==e[r])return e[r];var i=n.options.foldOptions;return i&&void 0!==i[r]?i[r]:o[r]}n.defineOption("foldOptions",null),n.defineExtension("foldOption",function(n,e){return r(this,n,e)})});
|
|
@ -0,0 +1 @@
|
|||
.CodeMirror-foldmarker{color:blue;text-shadow:#b9f 1px 1px 2px,#b9f -1px -1px 2px,#b9f 1px -1px 2px,#b9f -1px 1px 2px;font-family:arial;line-height:.3;cursor:pointer}.CodeMirror-foldgutter{width:.7em}.CodeMirror-foldgutter-open,.CodeMirror-foldgutter-folded{cursor:pointer}.CodeMirror-foldgutter-open:after{content:"\25BE"}.CodeMirror-foldgutter-folded:after{content:"\25B8"}
|
|
@ -0,0 +1 @@
|
|||
!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("./foldcode")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","./foldcode"],t):t(CodeMirror)}(function(t){"use strict";t.defineOption("foldGutter",!1,function(o,e,r){r&&r!=t.Init&&(o.clearGutter(o.state.foldGutter.options.gutter),o.state.foldGutter=null,o.off("gutterClick",a),o.off("changes",d),o.off("viewportChange",u),o.off("fold",l),o.off("unfold",l),o.off("swapDoc",d)),e&&(o.state.foldGutter=new function(t){this.options=t,this.from=this.to=0}(function(t){!0===t&&(t={});null==t.gutter&&(t.gutter="CodeMirror-foldgutter");null==t.indicatorOpen&&(t.indicatorOpen="CodeMirror-foldgutter-open");null==t.indicatorFolded&&(t.indicatorFolded="CodeMirror-foldgutter-folded");return t}(e)),f(o),o.on("gutterClick",a),o.on("changes",d),o.on("viewportChange",u),o.on("fold",l),o.on("unfold",l),o.on("swapDoc",d))});var o=t.Pos;function e(t,e){for(var r=t.findMarks(o(e,0),o(e+1,0)),n=0;n<r.length;++n)if(r[n].__isFold){var i=r[n].find(-1);if(i&&i.line===e)return r[n]}}function r(t){if("string"==typeof t){var o=document.createElement("div");return o.className=t+" CodeMirror-guttermarker-subtle",o}return t.cloneNode(!0)}function n(t,n,f){var a=t.state.foldGutter.options,d=n-1,u=t.foldOption(a,"minFoldSize"),l=t.foldOption(a,"rangeFinder"),c="string"==typeof a.indicatorFolded&&i(a.indicatorFolded),s="string"==typeof a.indicatorOpen&&i(a.indicatorOpen);t.eachLine(n,f,function(n){++d;var i=null,f=n.gutterMarkers;if(f&&(f=f[a.gutter]),e(t,d)){if(c&&f&&c.test(f.className))return;i=r(a.indicatorFolded)}else{var p=o(d,0),m=l&&l(t,p);if(m&&m.to.line-m.from.line>=u){if(s&&f&&s.test(f.className))return;i=r(a.indicatorOpen)}}(i||f)&&t.setGutterMarker(n,a.gutter,i)})}function i(t){return new RegExp("(^|\\s)"+t+"(?:$|\\s)\\s*")}function f(t){var o=t.getViewport(),e=t.state.foldGutter;e&&(t.operation(function(){n(t,o.from,o.to)}),e.from=o.from,e.to=o.to)}function a(t,r,n){var i=t.state.foldGutter;if(i){var f=i.options;if(n==f.gutter){var a=e(t,r);a?a.clear():t.foldCode(o(r,0),f)}}}function d(t){var o=t.state.foldGutter;if(o){var e=o.options;o.from=o.to=0,clearTimeout(o.changeUpdate),o.changeUpdate=setTimeout(function(){f(t)},e.foldOnChangeTimeSpan||600)}}function u(t){var o=t.state.foldGutter;if(o){var e=o.options;clearTimeout(o.changeUpdate),o.changeUpdate=setTimeout(function(){var e=t.getViewport();o.from==o.to||e.from-o.to>20||o.from-e.to>20?f(t):t.operation(function(){e.from<o.from&&(n(t,e.from,o.from),o.from=e.from),e.to>o.to&&(n(t,o.to,e.to),o.to=e.to)})},e.updateViewportTimeSpan||400)}}function l(t,o){var e=t.state.foldGutter;if(e){var r=o.line;r>=e.from&&r<e.to&&n(t,r,r+1)}}});
|
|
@ -0,0 +1 @@
|
|||
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";function n(n,t){var i=n.getLine(t),o=i.search(/\S/);return-1==o||/\bcomment\b/.test(n.getTokenTypeAt(e.Pos(t,o+1)))?-1:e.countColumn(i,null,n.getOption("tabSize"))}e.registerHelper("fold","indent",function(t,i){var o=n(t,i.line);if(!(o<0)){for(var r=null,l=i.line+1,f=t.lastLine();l<=f;++l){var u=n(t,l);if(-1==u);else{if(!(u>o))break;r=l}}return r?{from:e.Pos(i.line,t.getLine(i.line).length),to:e.Pos(r,t.getLine(r).length)}:void 0}})});
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
|||
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";e.defineMode("yaml",function(){var e=new RegExp("\\b(("+["true","false","on","off","yes","no"].join(")|(")+"))$","i");return{token:function(i,t){var r=i.peek(),n=t.escaped;if(t.escaped=!1,"#"==r&&(0==i.pos||/\s/.test(i.string.charAt(i.pos-1))))return i.skipToEnd(),"comment";if(i.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))return"string";if(t.literal&&i.indentation()>t.keyCol)return i.skipToEnd(),"string";if(t.literal&&(t.literal=!1),i.sol()){if(t.keyCol=0,t.pair=!1,t.pairStart=!1,i.match(/---/))return"def";if(i.match(/\.\.\./))return"def";if(i.match(/\s*-\s+/))return"meta"}if(i.match(/^(\{|\}|\[|\])/))return"{"==r?t.inlinePairs++:"}"==r?t.inlinePairs--:"["==r?t.inlineList++:t.inlineList--,"meta";if(t.inlineList>0&&!n&&","==r)return i.next(),"meta";if(t.inlinePairs>0&&!n&&","==r)return t.keyCol=0,t.pair=!1,t.pairStart=!1,i.next(),"meta";if(t.pairStart){if(i.match(/^\s*(\||\>)\s*/))return t.literal=!0,"meta";if(i.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i))return"variable-2";if(0==t.inlinePairs&&i.match(/^\s*-?[0-9\.\,]+\s?$/))return"number";if(t.inlinePairs>0&&i.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/))return"number";if(i.match(e))return"keyword"}return!t.pair&&i.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)?(t.pair=!0,t.keyCol=i.indentation(),"atom"):t.pair&&i.match(/^:\s*/)?(t.pairStart=!0,"meta"):(t.pairStart=!1,t.escaped="\\"==r,i.next(),null)},startState:function(){return{pair:!1,pairStart:!1,keyCol:0,inlinePairs:0,inlineList:0,literal:!1,escaped:!1}},lineComment:"#",fold:"indent"}}),e.defineMIME("text/x-yaml","yaml"),e.defineMIME("text/yaml","yaml")});
|
|
@ -0,0 +1 @@
|
|||
.cm-s-dracula.CodeMirror,.cm-s-dracula .CodeMirror-gutters{background-color:#282a36 !important;color:#f8f8f2 !important;border:0}.cm-s-dracula .CodeMirror-gutters{color:#282a36}.cm-s-dracula .CodeMirror-cursor{border-left:solid thin #f8f8f0}.cm-s-dracula .CodeMirror-linenumber{color:#6d8a88}.cm-s-dracula .CodeMirror-selected{background:rgba(255,255,255,0.10)}.cm-s-dracula .CodeMirror-line::selection,.cm-s-dracula .CodeMirror-line>span::selection,.cm-s-dracula .CodeMirror-line>span>span::selection{background:rgba(255,255,255,0.10)}.cm-s-dracula .CodeMirror-line::-moz-selection,.cm-s-dracula .CodeMirror-line>span::-moz-selection,.cm-s-dracula .CodeMirror-line>span>span::-moz-selection{background:rgba(255,255,255,0.10)}.cm-s-dracula span.cm-comment{color:#6272a4}.cm-s-dracula span.cm-string,.cm-s-dracula span.cm-string-2{color:#f1fa8c}.cm-s-dracula span.cm-number{color:#bd93f9}.cm-s-dracula span.cm-variable{color:#50fa7b}.cm-s-dracula span.cm-variable-2{color:white}.cm-s-dracula span.cm-def{color:#50fa7b}.cm-s-dracula span.cm-operator{color:#ff79c6}.cm-s-dracula span.cm-keyword{color:#ff79c6}.cm-s-dracula span.cm-atom{color:#bd93f9}.cm-s-dracula span.cm-meta{color:#f8f8f2}.cm-s-dracula span.cm-tag{color:#ff79c6}.cm-s-dracula span.cm-attribute{color:#50fa7b}.cm-s-dracula span.cm-qualifier{color:#50fa7b}.cm-s-dracula span.cm-property{color:#66d9ef}.cm-s-dracula span.cm-builtin{color:#50fa7b}.cm-s-dracula span.cm-variable-3,.cm-s-dracula span.cm-type{color:#ffb86c}.cm-s-dracula .CodeMirror-activeline-background{background:rgba(255,255,255,0.1)}.cm-s-dracula .CodeMirror-matchingbracket{text-decoration:underline;color:white !important}
|
Loading…
Add table
Add a link
Reference in a new issue