update config

This commit is contained in:
sbwml 2022-04-09 09:32:06 +08:00
parent 73e884fa45
commit d8882bafee
11 changed files with 35 additions and 49 deletions

View File

@ -9,7 +9,7 @@ LUCI_PKGARCH:=all
LUCI_DEPENDS:=+mosdns +jsonfilter +bash +v2ray-geoip +v2ray-geosite
define Package/$(PKG_NAME)/conffiles
/etc/mosdns/cus_config.yaml
/etc/mosdns/config_custom.yaml
/etc/config/mosdns
endef

View File

@ -12,22 +12,22 @@ enable = s:option(Flag, "enabled", translate("Enable"))
enable.rmempty = false
configfile = s:option(ListValue, "configfile", translate("MosDNS Config File"))
configfile:value("./def_config.yaml", translate("Def Config"))
configfile:value("./cus_config.yaml", translate("Cus Config"))
configfile.default = "./def_config.yaml"
configfile:value("/etc/mosdns/config.yaml", translate("Def Config"))
configfile:value("/etc/mosdns/config_custom.yaml", translate("Cus Config"))
configfile.default = "/etc/mosdns/config.yaml"
loglv = s:option(ListValue, "loglv", translate("Log Level"))
loglv:value("debug")
loglv:value("info")
loglv:value("warn")
loglv:value("error")
loglv.default = "error"
loglv:depends( "configfile", "./def_config.yaml")
loglevel = s:option(ListValue, "log_level", translate("Log Level"))
loglevel:value("debug")
loglevel:value("info")
loglevel:value("warn")
loglevel:value("error")
loglevel.default = "error"
loglevel:depends( "configfile", "/etc/mosdns/config.yaml")
logfile = s:option(Value, "logfile", translate("MosDNS Log File"))
logfile.placeholder = "/dev/null"
logfile.default = "/dev/null"
logfile:depends( "configfile", "./def_config.yaml")
logfile:depends( "configfile", "/etc/mosdns/config.yaml")
dnsforward = s:option(Value, "dns_forward", translate("Remote DNS"))
dnsforward.default = "tls://8.8.4.4"
@ -36,7 +36,7 @@ dnsforward:value("tls://8.8.8.8", "8.8.8.8 (Google DNS)")
dnsforward:value("tls://8.8.4.4", "8.8.4.4 (Google DNS)")
dnsforward:value("208.67.222.222", "208.67.222.222 (Open DNS)")
dnsforward:value("208.67.220.220", "208.67.220.220 (Open DNS)")
dnsforward:depends( "configfile", "./def_config.yaml")
dnsforward:depends( "configfile", "/etc/mosdns/config.yaml")
cache_size = s:option(Value, "cache_size", translate("DNS Cache Size"))
cache_size.datatype = "and(uinteger,min(0))"
@ -52,26 +52,26 @@ maximum_ttl.datatype = "and(uinteger,min(1))"
maximum_ttl.rmempty = false
redirect = s:option(Flag, "redirect", translate("Enable DNS Redirect"))
redirect:depends( "configfile", "./def_config.yaml")
redirect:depends( "configfile", "/etc/mosdns/config.yaml")
redirect.default = true
adblock = s:option(Flag, "adblock", translate("Enable DNS ADblock"))
adblock:depends( "configfile", "./def_config.yaml")
adblock:depends( "configfile", "/etc/mosdns/config.yaml")
adblock.default = true
config = s:option(TextValue, "manual-config")
config.description = translate("<font color=\"ff0000\"><strong>View the Custom YAML Configuration file used by this MosDNS. You can edit it as you own need.</strong></font>")
config.template = "cbi/tvalue"
config.rows = 25
config:depends( "configfile", "./cus_config.yaml")
config:depends( "configfile", "/etc/mosdns/config_custom.yaml")
function config.cfgvalue(self, section)
return nixio.fs.readfile("/etc/mosdns/cus_config.yaml")
return nixio.fs.readfile("/etc/mosdns/config_custom.yaml")
end
function config.write(self, section, value)
value = value:gsub("\r\n?", "\n")
nixio.fs.writefile("/etc/mosdns/cus_config.yaml", value)
nixio.fs.writefile("/etc/mosdns/config_custom.yaml", value)
end
return m

View File

@ -30,7 +30,7 @@ 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("/etc/mosdns/mosupdater.sh &> /dev/null &")
luci.sys.exec("/usr/share/mosdns/update_geodat.sh &> /dev/null &")
end
return m

View File

@ -1,16 +1,14 @@
config mosdns 'mosdns'
option not_first_start '0'
option enabled '0'
option geo_auto_update '0'
option geo_update_week_time 'all'
option geo_update_day_time '2'
option redirect '1'
option autoconf '1'
option update_adlist '1'
option adblock '0'
option configfile './def_config.yaml'
option loglv 'error'
option configfile '/etc/mosdns/config.yaml'
option log_level 'error'
option logfile '/tmp/mosdns.log'
option dns_forward 'tls://8.8.4.4'
option cache_size '1024'

View File

@ -53,13 +53,13 @@ reload_service() {
}
setcron() {
sed -i '/mosupdater.sh/d' $CRON_FILE 2>/dev/null
[ "$(uci -q get mosdns.mosdns.geo_auto_update)" -eq 1 ] && echo "0 $(uci -q get mosdns.mosdns.geo_update_day_time) * * $(uci -q get mosdns.mosdns.geo_update_week_time) /etc/mosdns/mosupdater.sh" >>$CRON_FILE
sed -i '/update_geodat.sh/d' $CRON_FILE 2>/dev/null
[ "$(uci -q get mosdns.mosdns.geo_auto_update)" -eq 1 ] && echo "0 $(uci -q get mosdns.mosdns.geo_update_day_time) * * $(uci -q get mosdns.mosdns.geo_update_week_time) /usr/share/mosdns/update_geodat.sh" >>$CRON_FILE
crontab $CRON_FILE
}
delcron() {
sed -i '/mosupdater.sh/d' $CRON_FILE 2>/dev/null
sed -i '/update_geodat.sh/d' $CRON_FILE 2>/dev/null
crontab $CRON_FILE
}
@ -67,15 +67,7 @@ start_service() {
# Reading config
inital_conf
if [ "$enabled" -eq 0 ]; then
firstblood=$(uci -q get mosdns.mosdns.not_first_start)
[ "${firstblood}" = "0" ] && restore_setting
[ "${firstblood}" = "0" ] && reload_others
uci set mosdns.mosdns.not_first_start='1'
uci commit mosdns
echo "MosDNS has turned off"
return 1
fi
[ $enabled != 1 ] && return 1
delcron
setcron
procd_open_instance mosdns
@ -87,25 +79,21 @@ start_service() {
procd_close_instance mosdns
configfile=$(uci -q get mosdns.mosdns.configfile)
if [ "${configfile}" = "./def_config.yaml" ]; then
if [ "${configfile}" = "/etc/mosdns/config.yaml" ]; then
restore_setting
redirect_setting
reload_others
fi
echo "MosDNS turn on"
echo "enabled=$enabled"
}
stop_service() {
pgrep -f /usr/bin/mosdns | xargs kill -9
echo "MosDNS turn off"
echo "enabled=$enabled"
configfile=$(uci -q get mosdns.mosdns.configfile)
if [ "${configfile}" = "./def_config.yaml" ]; then
if [ "${configfile}" = "/etc/mosdns/config.yaml" ]; then
config_load "mosdns"
enabled=$(uci -q get mosdns.mosdns.enabled)
[ "${enabled}" = "0" ] && restore_setting

View File

@ -1,5 +1,5 @@
log:
level: ${{ uci -q get mosdns.mosdns.loglv }}
level: ${{ uci -q get mosdns.mosdns.log_level }}
file: ${{ uci -q get mosdns.mosdns.logfile }}
plugin:
@ -73,8 +73,8 @@ plugin:
type: fast_forward
args:
upstream:
- addr: ${{ ./dns.sh 0 }}
- addr: ${{ ./dns.sh 1 }}
- addr: ${{ /usr/share/mosdns/dns.sh 0 }}
- addr: ${{ /usr/share/mosdns/dns.sh 1 }}
- tag: query_is_whitelist_domain
type: query_matcher
@ -111,4 +111,4 @@ plugin:
type: query_matcher
args:
domain:
- ${{ ./ad_domain.sh }}
- ${{ /usr/share/mosdns/ad_domain.sh }}

View File

@ -53,8 +53,8 @@ plugin:
type: fast_forward
args:
upstream:
- addr: ${{ ./dns.sh 0 }}
- addr: ${{ ./dns.sh 1 }}
- addr: ${{ /usr/share/mosdns/dns.sh 0 }}
- addr: ${{ /usr/share/mosdns/dns.sh 1 }}
- tag: forward_remote
type: fast_forward

View File

@ -1,6 +1,6 @@
#!/bin/bash -e
# shellcheck source=/etc/mosdns/library.sh
source /etc/mosdns/library.sh
source /usr/share/mosdns/library.sh
if [ "$(ifconfig | grep -c wan)" = 0 ]; then
bakdns "$1"

View File

@ -2,7 +2,7 @@
# shellcheck source=/etc/mosdns/library.sh
set -o pipefail
source /etc/mosdns/library.sh
source /usr/share/mosdns/library.sh
TMPDIR=$(mktemp -d) || exit 1
getdat geoip.dat