luci-app-mosdns: cleanup shell script

This commit is contained in:
sbwml 2022-08-11 02:06:28 +08:00
parent 624b3979d2
commit d67faae180
9 changed files with 70 additions and 92 deletions

View File

@ -26,9 +26,9 @@ function act_status()
end end
function get_log() function get_log()
luci.http.write(luci.sys.exec("cat $(/usr/share/mosdns/log_path.sh)")) luci.http.write(luci.sys.exec("cat $(/usr/share/mosdns/mosdns.sh logfile)"))
end end
function clear_log() function clear_log()
luci.sys.call("cat /dev/null > $(/usr/share/mosdns/log_path.sh)") luci.sys.call("cat /dev/null > $(/usr/share/mosdns/mosdns.sh logfile)")
end end

View File

@ -28,7 +28,7 @@ data_update = s:option(Button, "geo_update_database", translate("Database Update
data_update.inputtitle = translate("Check And Update") data_update.inputtitle = translate("Check And Update")
data_update.inputstyle = "reload" data_update.inputstyle = "reload"
data_update.write = function() data_update.write = function()
luci.sys.exec("/usr/share/mosdns/update_geodat.sh &> /dev/null &") luci.sys.exec("/usr/share/mosdns/mosdns.sh geodata &> /dev/null &")
end end
return m return m

View File

@ -38,11 +38,11 @@ init_yaml() {
cache_survival_time=$(uci -q get mosdns.mosdns.cache_survival_time) cache_survival_time=$(uci -q get mosdns.mosdns.cache_survival_time)
minimal_ttl_custom=$(uci -q get mosdns.mosdns.minimal_ttl) minimal_ttl_custom=$(uci -q get mosdns.mosdns.minimal_ttl)
maximum_ttl_custom=$(uci -q get mosdns.mosdns.maximum_ttl) maximum_ttl_custom=$(uci -q get mosdns.mosdns.maximum_ttl)
local_dns1=$(/usr/share/mosdns/dns.sh 0) local_dns1=$(/usr/share/mosdns/mosdns.sh dns 0)
local_dns2=$(/usr/share/mosdns/dns.sh 1) local_dns2=$(/usr/share/mosdns/mosdns.sh dns 1)
remote_dns1=$(uci -q get mosdns.mosdns.remote_dns1) remote_dns1=$(uci -q get mosdns.mosdns.remote_dns1)
remote_dns2=$(uci -q get mosdns.mosdns.remote_dns2) remote_dns2=$(uci -q get mosdns.mosdns.remote_dns2)
adblock=$(/usr/share/mosdns/ad_domain.sh) adblock=$(/usr/share/mosdns/mosdns.sh ad)
enable_pipeline=$(uci -q get mosdns.mosdns.enable_pipeline) enable_pipeline=$(uci -q get mosdns.mosdns.enable_pipeline)
[ $enable_pipeline = 0 ] && enable_pipeline=false [ $enable_pipeline = 0 ] && enable_pipeline=false
[ $enable_pipeline = 1 ] && enable_pipeline=true [ $enable_pipeline = 1 ] && enable_pipeline=true
@ -98,13 +98,13 @@ reload_service() {
} }
setcron() { setcron() {
sed -i '/update_geodat.sh/d' $CRON_FILE 2>/dev/null sed -i '/mosdns.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 [ "$(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/mosdns.sh geodata" >>$CRON_FILE
crontab $CRON_FILE crontab $CRON_FILE
} }
delcron() { delcron() {
sed -i '/update_geodat.sh/d' $CRON_FILE 2>/dev/null sed -i '/mosdns.sh/d' $CRON_FILE 2>/dev/null
crontab $CRON_FILE crontab $CRON_FILE
} }
@ -114,7 +114,7 @@ start_service() {
delcron delcron
setcron setcron
[ "${CONF}" = "/etc/mosdns/config.yaml" ] && init_yaml [ "${CONF}" = "/etc/mosdns/config.yaml" ] && init_yaml
cat /dev/null > $(/usr/share/mosdns/log_path.sh) cat /dev/null > $(/usr/share/mosdns/mosdns.sh logfile)
procd_open_instance mosdns procd_open_instance mosdns
procd_set_param command $PROG start -c "$CONF" procd_set_param command $PROG start -c "$CONF"
procd_set_param user root procd_set_param user root

View File

@ -1,8 +0,0 @@
#!/bin/sh
adblock=$(uci -q get mosdns.mosdns.adblock)
if [ "$adblock" -eq 1 ];then
echo "provider:geosite:category-ads-all"
else
echo "full:disable-category-ads-all.null"
fi

View File

@ -1,18 +0,0 @@
#!/bin/sh
source /usr/share/mosdns/library.sh
if [ "$(ifconfig | grep -c wan)" = 0 ]; then
bakdns "$1"
exit 0
fi
if [ $1 ]; then
if [[ "$(getdns 0)" =~ ^127\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
getdns "$1" inactive
elif [[ "$(getdns "$1")" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
getdns "$1"
else
bakdns "$1"
fi
fi

View File

@ -1,29 +0,0 @@
#!/bin/sh
bakdns() {
if [ "$1" == "0" ]; then
echo "119.29.29.29"
elif [ "$1" == "1" ]; then
echo "114.114.114.114"
fi
}
exist() {
command -v "$1" >/dev/null 2>&1
}
getdat() {
curl --connect-timeout 60 -m 900 -fSLo "$TMPDIR/$1" "https://github.cooluc.com/https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/$1"
}
getdns() {
if [ "$2" == "inactive" ]; then
ubus call network.interface.wan status | jsonfilter -e "@['inactive']['dns-server'][$1]"
else
ubus call network.interface.wan status | jsonfilter -e "@['dns-server'][$1]"
fi
}
pid() {
pgrep -f "$1"
}

View File

@ -1,9 +0,0 @@
#!/bin/sh
configfile=$(uci -q get mosdns.mosdns.configfile)
if [ "$configfile" = "/etc/mosdns/config.yaml" ]; then
uci -q get mosdns.mosdns.logfile
else
[ ! -f /etc/mosdns/config_custom.yaml ] && exit 1
cat /etc/mosdns/config_custom.yaml | grep -A 3 log | grep file | awk -F ":" '{print $2}' | sed 's/\"//g;s/ //g'
fi

View File

@ -0,0 +1,60 @@
#!/bin/sh
logfile_path() (
configfile=$(uci -q get mosdns.mosdns.configfile)
if [ "$configfile" = "/etc/mosdns/config.yaml" ]; then
uci -q get mosdns.mosdns.logfile
else
[ ! -f /etc/mosdns/config_custom.yaml ] && exit 1
cat /etc/mosdns/config_custom.yaml | grep -A 4 log | grep file | awk -F ":" '{print $2}' | sed 's/\"//g;s/ //g'
fi
)
interface_dns() (
peerdns=$(uci -q get network.wan.peerdns)
if [ "$peerdns" -eq 0 ]; then
ubus call network.interface.wan status | jsonfilter -e "@['dns-server'][$1]"
else
ubus call network.interface.wan status | jsonfilter -e "@['inactive']['dns-server'][$1]"
fi
[ $? -ne 0 ] && echo 119.29.29.29
)
ad_block() (
adblock=$(uci -q get mosdns.mosdns.adblock)
if [ "$adblock" -eq 1 ]; then
echo "provider:geosite:category-ads-all"
else
echo "full:disable-category-ads-all.null"
fi
)
geodat_update() (
geodat_download() (
google_status=$(curl -I -4 -m 3 -o /dev/null -s -w %{http_code} http://www.google.com/generate_204)
[ $google_status -ne "204" ] && mirror="https://github.cooluc.com/"
echo -e "\e[1;32m"$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/$1\e[0m"
curl --connect-timeout 60 -m 900 -fSLo "$TMPDIR/$1" ""$mirror"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/$1"
)
TMPDIR=$(mktemp -d) || exit 1
geodat_download geoip.dat
geodat_download geosite.dat
if [ "$(grep -o CN "$TMPDIR"/geoip.dat | wc -l)" -eq "0" ]; then
rm -rf "$TMPDIR"/geoip.dat
elif [ "$(grep -o .com "$TMPDIR"/geosite.dat | wc -l)" -lt "1000" ]; then
rm -rf "$TMPDIR"/geosite.dat
fi
cp -f "$TMPDIR"/* /usr/share/v2ray
rm -rf "$TMPDIR"
)
if [ "$1" == "dns" ]; then
[ -z $2 ] && exit 0
interface_dns $2
elif [ "$1" == "ad" ]; then
ad_block
elif [ "$1" == "geodata" ]; then
geodat_update
elif [ "$1" == "logfile" ]; then
logfile_path
fi

View File

@ -1,18 +0,0 @@
#!/bin/sh
set -o pipefail
source /usr/share/mosdns/library.sh
TMPDIR=$(mktemp -d) || exit 1
getdat geoip.dat
getdat geosite.dat
if [ "$(grep -o CN "$TMPDIR"/geoip.dat | wc -l)" -eq "0" ]; then
rm -rf "$TMPDIR"/geoip.dat
fi
if [ "$(grep -o .com "$TMPDIR"/geosite.dat | wc -l)" -lt "1000" ]; then
rm -rf "$TMPDIR"/geosite.dat
fi
cp -rf "$TMPDIR"/* /usr/share/v2ray
rm -rf "$TMPDIR"
exit 0