Improved dnsmasq confdir check.

This commit is contained in:
gSpot
2025-02-09 18:35:41 +03:00
parent fa5a7fac87
commit 5c3c1c125d
7 changed files with 54 additions and 29 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=ruantiblock
PKG_VERSION:=2.1.3
PKG_VERSION:=2.1.4
PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
+10 -10
View File
@@ -8,12 +8,12 @@ APP_EXEC="/usr/bin/${APP_NAME}"
VAR_DIR="/tmp"
get_dnsmasq_confdir() {
local _first_instance_dir
local _current_dir="$1" _first_instance_dir
if [ -d "${VAR_DIR}/dnsmasq.d" ]; then
printf "${VAR_DIR}/dnsmasq.d"
return 0
else
_first_instance_dir=`ubus call service list | jsonfilter -e "VAR=$.dnsmasq.instances.*.mount" | awk '
_first_instance_dir=`ubus call service list | jsonfilter -e "VAR=$.dnsmasq.instances.*.mount" | awk -v CUR_DIR="$_current_dir" '
BEGIN {
RS = " ";
}
@@ -25,7 +25,7 @@ get_dnsmasq_confdir() {
};
}
END {
print a[0];
print (CUR_DIR in a) ? CUR_DIR : a[0];
}'`
if [ -n "$_first_instance_dir" ]; then
printf "$_first_instance_dir"
@@ -36,18 +36,18 @@ get_dnsmasq_confdir() {
}
start() {
local _update_at_startup _dnsmasq_confdir
local _update_at_startup _dnsmasq_confdir_cur _dnsmasq_confdir
config_load $APP_NAME
config_get _update_at_startup config update_at_startup
config_get _dnsmasq_confdir config dnsmasq_confdir ""
if [ -z "$_dnsmasq_confdir" ]; then
_dnsmasq_confdir=`get_dnsmasq_confdir`
if [ $? -eq 0 -a -n "$_dnsmasq_confdir" ]; then
config_get _dnsmasq_confdir_cur config dnsmasq_confdir ""
_dnsmasq_confdir=`get_dnsmasq_confdir "$_dnsmasq_confdir_cur"`
if [ $? -eq 0 -a -n "$_dnsmasq_confdir" ]; then
if [ "$_dnsmasq_confdir" != "$_dnsmasq_confdir_cur" ]; then
uci set "${APP_NAME}.config.dnsmasq_confdir"="$_dnsmasq_confdir"
uci commit ruantiblock
else
exit 1
fi
else
exit 1
fi
$APP_EXEC start
if [ $? -eq 0 -a "$_update_at_startup" = "1" ]; then
+36 -11
View File
@@ -643,7 +643,6 @@ CheckStatus() {
GetVpnRouteStatus() {
local _inst _i=1 _ret_val=0
for _inst in $USER_INSTANCES_VPN_FNAMES
do
if ! NftRouteStatus $(($VPN_ROUTE_TABLE_ID_START + $_i)); then
_ret_val=1
@@ -662,16 +661,24 @@ ClearDataFiles() {
if [ -d "$DATA_DIR" ]; then
if [ -z "$_arg" -o "$_arg" = "main_instance" ]; then
printf "" > "$IP_DATA_FILE"
printf "" > "$DNSMASQ_DATA_FILE"
printf "0 0 0" > "$UPDATE_STATUS_FILE"
fi
if [ -z "$_arg" -o "$_arg" = "user_instances" ]; then
printf "" > "$IP_DATA_FILE_USER_INSTANCES"
printf "" > "$DNSMASQ_DATA_FILE_USER_INSTANCES"
printf "" > "$USER_ENTRIES_STATUS_FILE"
fi
if [ -z "$_arg" ]; then
printf "" > "$IP_DATA_FILE_BYPASS"
fi
fi
if [ -d "$DNSMASQ_CONFDIR" ]; then
if [ -z "$_arg" -o "$_arg" = "main_instance" ]; then
printf "" > "$DNSMASQ_DATA_FILE"
fi
if [ -z "$_arg" -o "$_arg" = "user_instances" ]; then
printf "" > "$DNSMASQ_DATA_FILE_USER_INSTANCES"
fi
if [ -z "$_arg" ]; then
printf "" > "$DNSMASQ_DATA_FILE_BYPASS"
fi
fi
@@ -681,9 +688,11 @@ PreStartCheck() {
[ -d "$DATA_DIR" ] || mkdir -p "$DATA_DIR"
[ "$ENABLE_HTML_INFO" = "1" -a ! -d "$HTML_DIR" ] && mkdir -p "$HTML_DIR"
### Костыль для старта dnsmasq
[ -e "$DNSMASQ_DATA_FILE" ] || printf "" > "$DNSMASQ_DATA_FILE"
[ -e "$DNSMASQ_DATA_FILE_BYPASS" ] || printf "" > "$DNSMASQ_DATA_FILE_BYPASS"
[ -e "$DNSMASQ_DATA_FILE_USER_INSTANCES" ] || printf "" > "$DNSMASQ_DATA_FILE_USER_INSTANCES"
if [ -d "$DNSMASQ_CONFDIR" ]; then
[ -e "$DNSMASQ_DATA_FILE" ] || printf "" > "$DNSMASQ_DATA_FILE"
[ -e "$DNSMASQ_DATA_FILE_BYPASS" ] || printf "" > "$DNSMASQ_DATA_FILE_BYPASS"
[ -e "$DNSMASQ_DATA_FILE_USER_INSTANCES" ] || printf "" > "$DNSMASQ_DATA_FILE_USER_INSTANCES"
fi
}
AddBypassEntries() {
@@ -1056,6 +1065,14 @@ MakeToken() {
date +%s > "$TOKEN_FILE"
}
CheckDnsmasqConfDir() {
if [ ! -d "$DNSMASQ_CONFDIR" ]; then
echo " Error! DNSMASQ_CONFDIR (${DNSMASQ_CONFDIR}) does not exists." >&2
return 1
fi
return 0
}
Update() {
local _arg="$1" _return_code=0
if CheckStatus; then
@@ -1287,9 +1304,13 @@ case "$1" in
;;
update|force-update)
Init
Update "$1"
return_code=$?
StatusOutput
if CheckDnsmasqConfDir; then
Update "$1"
return_code=$?
StatusOutput
else
return_code=1
fi
;;
blacklist-files)
Init
@@ -1297,8 +1318,12 @@ case "$1" in
echo " ${NAME} - Error! Another instance of update is already running" >&2
exit 2
else
GetBlacklistFiles
return_code=$?
if CheckDnsmasqConfDir; then
GetBlacklistFiles
return_code=$?
else
return_code=1
fi
fi
;;
status)