소스 검색

add support for listen 53

rufengsuixing 5 년 전
부모
커밋
1c0ac831c7
3개의 변경된 파일36개의 추가작업 그리고 18개의 파일을 삭제
  1. 1 0
      luasrc/model/cbi/AdGuardHome/base.lua
  2. 4 1
      po/zh-cn/AdGuardHome.po
  3. 31 17
      root/etc/init.d/AdGuardHome

+ 1 - 0
luasrc/model/cbi/AdGuardHome/base.lua

@@ -64,6 +64,7 @@ o.placeholder = "none"
 o:value("none", translate("none"))
 o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
 o:value("redirect", translate("Redirect 53 port to AdGuardHome"))
+o:value("exchange", translate("Use port 53 replace dnsmasq"))
 o.default     = "none"
 
 ---- bin path

+ 4 - 1
po/zh-cn/AdGuardHome.po

@@ -170,4 +170,7 @@ msgid "Fast config"
 msgstr "快速配置"
 
 msgid "Keep database when system upgrade"
-msgstr "系统升级时保留数据"
+msgstr "系统升级时保留数据"
+
+msgid "Use port 53 replace dnsmasq"
+msgstr "使用53端口替换dnsmasq"

+ 31 - 17
root/etc/init.d/AdGuardHome

@@ -94,7 +94,7 @@ clear_iptable()
 	if [ "$ipv6_server" == 0 ]; then
 		return
 	fi
-
+	echo "warn ip6tables nat mod is needed"
 	IPS="`ifconfig | grep "inet6 addr" | grep -v " fe80::" | grep -v " ::1" | grep "Global" | awk '{print $3}'`"
 	for IP in $IPS
 	do
@@ -132,13 +132,24 @@ get_tz()
 	
 	SET_TZ=$tz
 }
-
+exchange_port()
+{
+	dnsmasq_port=$(uci get dhcp.@dnsmasq[0].port)
+	if [ -z "$dnsmasq_port" ]; then
+	dnsmasq_port="53"
+	fi
+	AdGuardHome_PORT=$(awk '/  port:/{printf($2)}' $configpath)
+	config_editor "dns.port" "$dnsmasq_port" "$configpath"
+	uci set dhcp.@dnsmasq[0].port="$AdGuardHome_PORT"
+	uci commit dhcp
+	/etc/init.d/dnsmasq reload
+}
 do_redirect() 
 {
 	config_load "${CONFIGURATION}"
 	local section="$CONFIGURATION"
 	args=""
-	ipv6_server=0
+	ipv6_server=1
 	tcp_server=0
 	enabled=$1
 	config_get configpath $CONFIGURATION configpath "/etc/AdGuardHome.yaml"
@@ -150,18 +161,25 @@ do_redirect()
 	config_get "old_redirect" "$section" "old_redirect" "none"
 	config_get "old_port" "$section" "old_port" "0"
 	config_get "old_enabled" "$section" "old_enabled" "0"
-
+	if [ "$old_redirect" == "exchange" -a "$AdGuardHome_PORT" == "53" ]; then
+		$AdGuardHome_PORT=$(uci get dhcp.@dnsmasq[0].port)
+	fi
+	
 	if [ "$old_redirect" != "$redirect" ] || [ "$old_port" != "$AdGuardHome_PORT" ] || [ "$old_enabled" = "1" -a "$enabled" = "0" ]; then
 		if [ "$old_redirect" != "none" ]; then
-			if [ "$old_port" != "0" ]; then
+			if [  "$old_redirect" == "redirect" -a "$old_port" != "0" ]; then
 				clear_iptable "$old_port" "$ipv6_server"
-			fi
-			if [ "$old_redirect" == "dnsmasq-upstream" ]; then
+			elif [ "$old_redirect" == "dnsmasq-upstream" ]; then
 				stop_forward_dnsmasq "$old_port"
+			elif [ "$old_redirect" == "exchange" ]; then
+				exchange_port
 			fi
 		fi
+	elif [ "$old_enabled" = "1" -a "$enabled" = "1" ]; then
+		if [  "$old_redirect" == "redirect" -a "$old_port" != "0" ]; then
+			clear_iptable "$old_port" "$ipv6_server"
+		fi
 	fi
-	
 	uci delete AdGuardHome.@AdGuardHome[0].old_redirect 2>/dev/null
 	uci delete AdGuardHome.@AdGuardHome[0].old_port 2>/dev/null
 	uci delete AdGuardHome.@AdGuardHome[0].old_enabled 2>/dev/null
@@ -178,16 +196,9 @@ do_redirect()
 		set_iptable $ipv6_server $tcp_server
 	elif [ "$redirect" = "dnsmasq-upstream" ]; then
 		set_forward_dnsmasq "$AdGuardHome_PORT"
+	elif [ "$redirect" == "exchange" -a "$(uci get dhcp.@dnsmasq[0].port)" == "53" ]; then
+		exchange_port
 	fi
-
-	#procd_open_instance "AdGuardHome"
-
-	#get_tz
-	#if [ ! -z "$SET_TZ" ]; then
-	#    procd_set_param env TZ="$SET_TZ"
-	#fi
-	#procd_set_param file "$AdGuardHome_CONF"
-	#procd_close_instance
 }
 get_filesystem()
 {
@@ -349,6 +360,9 @@ reload_service()
 	echo "AdGuardHome reloading"
 	config_get_bool enabled $CONFIGURATION enabled 0
 	procd_send_signal $CONFIGURATION
+	if [ "$enabled" == "0" ]; then
+		do_redirect 0
+	fi
 	start
 	echo "enabled=$enabled"
 }