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
+3 -3
View File
@@ -10,9 +10,9 @@ LUCI_APP=1
HTTPS_DNS_PROXY=1 HTTPS_DNS_PROXY=1
OWRT_VERSION="current" OWRT_VERSION="current"
RUAB_VERSION="2.1.3-r1" RUAB_VERSION="2.1.4-r1"
RUAB_MOD_LUA_VERSION="2.1.3-r1" RUAB_MOD_LUA_VERSION="2.1.4-r1"
RUAB_LUCI_APP_VERSION="2.1.3-r2" RUAB_LUCI_APP_VERSION="2.1.4-r1"
BASE_URL="https://raw.githubusercontent.com/gSpotx2f/packages-openwrt/master" BASE_URL="https://raw.githubusercontent.com/gSpotx2f/packages-openwrt/master"
PKG_DIR="/tmp" PKG_DIR="/tmp"
+2 -2
View File
@@ -5,8 +5,8 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-ruantiblock PKG_NAME:=luci-app-ruantiblock
PKG_VERSION:=2.1.3 PKG_VERSION:=2.1.4
PKG_RELEASE:=2 PKG_RELEASE:=1
LUCI_TITLE:=LuCI support for ruantiblock LUCI_TITLE:=LuCI support for ruantiblock
LUCI_DEPENDS:=+ruantiblock LUCI_DEPENDS:=+ruantiblock
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
+1 -1
View File
@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=ruantiblock-mod-lua PKG_NAME:=ruantiblock-mod-lua
PKG_VERSION:=2.1.3 PKG_VERSION:=2.1.4
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt> PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
+1 -1
View File
@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=ruantiblock-mod-py PKG_NAME:=ruantiblock-mod-py
PKG_VERSION:=2.1.3 PKG_VERSION:=2.1.4
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt> PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
+1 -1
View File
@@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=ruantiblock PKG_NAME:=ruantiblock
PKG_VERSION:=2.1.3 PKG_VERSION:=2.1.4
PKG_RELEASE:=1 PKG_RELEASE:=1
PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt> PKG_MAINTAINER:=gSpot <https://github.com/gSpotx2f/ruantiblock_openwrt>
+8 -8
View File
@@ -8,12 +8,12 @@ APP_EXEC="/usr/bin/${APP_NAME}"
VAR_DIR="/tmp" VAR_DIR="/tmp"
get_dnsmasq_confdir() { get_dnsmasq_confdir() {
local _first_instance_dir local _current_dir="$1" _first_instance_dir
if [ -d "${VAR_DIR}/dnsmasq.d" ]; then if [ -d "${VAR_DIR}/dnsmasq.d" ]; then
printf "${VAR_DIR}/dnsmasq.d" printf "${VAR_DIR}/dnsmasq.d"
return 0 return 0
else 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 { BEGIN {
RS = " "; RS = " ";
} }
@@ -25,7 +25,7 @@ get_dnsmasq_confdir() {
}; };
} }
END { END {
print a[0]; print (CUR_DIR in a) ? CUR_DIR : a[0];
}'` }'`
if [ -n "$_first_instance_dir" ]; then if [ -n "$_first_instance_dir" ]; then
printf "$_first_instance_dir" printf "$_first_instance_dir"
@@ -36,19 +36,19 @@ get_dnsmasq_confdir() {
} }
start() { start() {
local _update_at_startup _dnsmasq_confdir local _update_at_startup _dnsmasq_confdir_cur _dnsmasq_confdir
config_load $APP_NAME config_load $APP_NAME
config_get _update_at_startup config update_at_startup config_get _update_at_startup config update_at_startup
config_get _dnsmasq_confdir config dnsmasq_confdir "" config_get _dnsmasq_confdir_cur config dnsmasq_confdir ""
if [ -z "$_dnsmasq_confdir" ]; then _dnsmasq_confdir=`get_dnsmasq_confdir "$_dnsmasq_confdir_cur"`
_dnsmasq_confdir=`get_dnsmasq_confdir`
if [ $? -eq 0 -a -n "$_dnsmasq_confdir" ]; then 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 set "${APP_NAME}.config.dnsmasq_confdir"="$_dnsmasq_confdir"
uci commit ruantiblock uci commit ruantiblock
fi
else else
exit 1 exit 1
fi fi
fi
$APP_EXEC start $APP_EXEC start
if [ $? -eq 0 -a "$_update_at_startup" = "1" ]; then if [ $? -eq 0 -a "$_update_at_startup" = "1" ]; then
$APP_EXEC update $APP_EXEC update
+28 -3
View File
@@ -643,7 +643,6 @@ CheckStatus() {
GetVpnRouteStatus() { GetVpnRouteStatus() {
local _inst _i=1 _ret_val=0 local _inst _i=1 _ret_val=0
for _inst in $USER_INSTANCES_VPN_FNAMES for _inst in $USER_INSTANCES_VPN_FNAMES
do do
if ! NftRouteStatus $(($VPN_ROUTE_TABLE_ID_START + $_i)); then if ! NftRouteStatus $(($VPN_ROUTE_TABLE_ID_START + $_i)); then
_ret_val=1 _ret_val=1
@@ -662,16 +661,24 @@ ClearDataFiles() {
if [ -d "$DATA_DIR" ]; then if [ -d "$DATA_DIR" ]; then
if [ -z "$_arg" -o "$_arg" = "main_instance" ]; then if [ -z "$_arg" -o "$_arg" = "main_instance" ]; then
printf "" > "$IP_DATA_FILE" printf "" > "$IP_DATA_FILE"
printf "" > "$DNSMASQ_DATA_FILE"
printf "0 0 0" > "$UPDATE_STATUS_FILE" printf "0 0 0" > "$UPDATE_STATUS_FILE"
fi fi
if [ -z "$_arg" -o "$_arg" = "user_instances" ]; then if [ -z "$_arg" -o "$_arg" = "user_instances" ]; then
printf "" > "$IP_DATA_FILE_USER_INSTANCES" printf "" > "$IP_DATA_FILE_USER_INSTANCES"
printf "" > "$DNSMASQ_DATA_FILE_USER_INSTANCES"
printf "" > "$USER_ENTRIES_STATUS_FILE" printf "" > "$USER_ENTRIES_STATUS_FILE"
fi fi
if [ -z "$_arg" ]; then if [ -z "$_arg" ]; then
printf "" > "$IP_DATA_FILE_BYPASS" 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" printf "" > "$DNSMASQ_DATA_FILE_BYPASS"
fi fi
fi fi
@@ -681,9 +688,11 @@ PreStartCheck() {
[ -d "$DATA_DIR" ] || mkdir -p "$DATA_DIR" [ -d "$DATA_DIR" ] || mkdir -p "$DATA_DIR"
[ "$ENABLE_HTML_INFO" = "1" -a ! -d "$HTML_DIR" ] && mkdir -p "$HTML_DIR" [ "$ENABLE_HTML_INFO" = "1" -a ! -d "$HTML_DIR" ] && mkdir -p "$HTML_DIR"
### Костыль для старта dnsmasq ### Костыль для старта dnsmasq
if [ -d "$DNSMASQ_CONFDIR" ]; then
[ -e "$DNSMASQ_DATA_FILE" ] || printf "" > "$DNSMASQ_DATA_FILE" [ -e "$DNSMASQ_DATA_FILE" ] || printf "" > "$DNSMASQ_DATA_FILE"
[ -e "$DNSMASQ_DATA_FILE_BYPASS" ] || printf "" > "$DNSMASQ_DATA_FILE_BYPASS" [ -e "$DNSMASQ_DATA_FILE_BYPASS" ] || printf "" > "$DNSMASQ_DATA_FILE_BYPASS"
[ -e "$DNSMASQ_DATA_FILE_USER_INSTANCES" ] || printf "" > "$DNSMASQ_DATA_FILE_USER_INSTANCES" [ -e "$DNSMASQ_DATA_FILE_USER_INSTANCES" ] || printf "" > "$DNSMASQ_DATA_FILE_USER_INSTANCES"
fi
} }
AddBypassEntries() { AddBypassEntries() {
@@ -1056,6 +1065,14 @@ MakeToken() {
date +%s > "$TOKEN_FILE" 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() { Update() {
local _arg="$1" _return_code=0 local _arg="$1" _return_code=0
if CheckStatus; then if CheckStatus; then
@@ -1287,9 +1304,13 @@ case "$1" in
;; ;;
update|force-update) update|force-update)
Init Init
if CheckDnsmasqConfDir; then
Update "$1" Update "$1"
return_code=$? return_code=$?
StatusOutput StatusOutput
else
return_code=1
fi
;; ;;
blacklist-files) blacklist-files)
Init Init
@@ -1297,8 +1318,12 @@ case "$1" in
echo " ${NAME} - Error! Another instance of update is already running" >&2 echo " ${NAME} - Error! Another instance of update is already running" >&2
exit 2 exit 2
else else
if CheckDnsmasqConfDir; then
GetBlacklistFiles GetBlacklistFiles
return_code=$? return_code=$?
else
return_code=1
fi
fi fi
;; ;;
status) status)