diff --git a/Makefile b/Makefile index b76f8eb..97c152f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/luasrc/model/cbi/mosdns/basic.lua b/luasrc/model/cbi/mosdns/basic.lua index 4a04b38..0542775 100644 --- a/luasrc/model/cbi/mosdns/basic.lua +++ b/luasrc/model/cbi/mosdns/basic.lua @@ -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("View the Custom YAML Configuration file used by this MosDNS. You can edit it as you own need.") 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 diff --git a/luasrc/model/cbi/mosdns/update.lua b/luasrc/model/cbi/mosdns/update.lua index 32c75e5..30c75a2 100644 --- a/luasrc/model/cbi/mosdns/update.lua +++ b/luasrc/model/cbi/mosdns/update.lua @@ -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 diff --git a/root/etc/config/mosdns b/root/etc/config/mosdns index 141163e..da0e147 100644 --- a/root/etc/config/mosdns +++ b/root/etc/config/mosdns @@ -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' diff --git a/root/etc/init.d/mosdns b/root/etc/init.d/mosdns index c72aa5f..8767469 100755 --- a/root/etc/init.d/mosdns +++ b/root/etc/init.d/mosdns @@ -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 diff --git a/root/etc/mosdns/def_config.yaml b/root/etc/mosdns/config.yaml similarity index 92% rename from root/etc/mosdns/def_config.yaml rename to root/etc/mosdns/config.yaml index 33953a0..9c630ff 100644 --- a/root/etc/mosdns/def_config.yaml +++ b/root/etc/mosdns/config.yaml @@ -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 }} diff --git a/root/etc/mosdns/cus_config.yaml b/root/etc/mosdns/config_custom.yaml similarity index 95% rename from root/etc/mosdns/cus_config.yaml rename to root/etc/mosdns/config_custom.yaml index db9d6be..19ab0c0 100644 --- a/root/etc/mosdns/cus_config.yaml +++ b/root/etc/mosdns/config_custom.yaml @@ -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 diff --git a/root/etc/mosdns/ad_domain.sh b/root/usr/share/mosdns/ad_domain.sh similarity index 100% rename from root/etc/mosdns/ad_domain.sh rename to root/usr/share/mosdns/ad_domain.sh diff --git a/root/etc/mosdns/dns.sh b/root/usr/share/mosdns/dns.sh similarity index 89% rename from root/etc/mosdns/dns.sh rename to root/usr/share/mosdns/dns.sh index a5a5c5c..7aed934 100755 --- a/root/etc/mosdns/dns.sh +++ b/root/usr/share/mosdns/dns.sh @@ -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" diff --git a/root/etc/mosdns/library.sh b/root/usr/share/mosdns/library.sh similarity index 100% rename from root/etc/mosdns/library.sh rename to root/usr/share/mosdns/library.sh diff --git a/root/etc/mosdns/mosupdater.sh b/root/usr/share/mosdns/update_geodat.sh similarity index 91% rename from root/etc/mosdns/mosupdater.sh rename to root/usr/share/mosdns/update_geodat.sh index 8761ab6..9a9911e 100755 --- a/root/etc/mosdns/mosupdater.sh +++ b/root/usr/share/mosdns/update_geodat.sh @@ -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