diff --git a/luci-app-openclash/root/usr/share/openclash/openclash_custom_domain_dns.sh b/luci-app-openclash/root/usr/share/openclash/openclash_custom_domain_dns.sh index 59073ede69..c3962e1647 100644 --- a/luci-app-openclash/root/usr/share/openclash/openclash_custom_domain_dns.sh +++ b/luci-app-openclash/root/usr/share/openclash/openclash_custom_domain_dns.sh @@ -13,7 +13,13 @@ del_lock() { set_lock -DNSMASQ_CONF_DIR=$(uci -q get dhcp.@dnsmasq[0].confdir || echo '/tmp/dnsmasq.d') +# Get the default DNSMasq config ID from the UCI configuration +DEFAULT_DNSMASQ_CFGID=$(uci show dhcp.@dnsmasq[0] | awk -F '.' '{print $2}' | awk -F '=' '{print $1}' | head -1) +# Locate the dnsmasq.conf file that contains the conf-dir option +DNSMASQ_CONF_PATH=$(grep -l "^conf-dir=" "/tmp/etc/dnsmasq.conf.${DEFAULT_DNSMASQ_CFGID}") +# Extract the directory path from the conf-dir line +DNSMASQ_CONF_DIR=$(grep '^conf-dir=' "$DNSMASQ_CONF_PATH" | cut -d'=' -f2 | head -n 1) +# Check if a conf-dir value was found and set variables accordingly DNSMASQ_CONF_DIR=${DNSMASQ_CONF_DIR%*/} rm -rf ${DNSMASQ_CONF_DIR}/dnsmasq_openclash_custom_domain.conf >/dev/null 2>&1 if [ "$(uci get openclash.config.enable_custom_domain_dns_server 2>/dev/null)" = "1" ] && [ "$(uci get openclash.config.enable_redirect_dns 2>/dev/null)" = "1" ]; then