From 90d7c60fcbc5aff99c1b03aa6a851dae03f286c2 Mon Sep 17 00:00:00 2001 From: Ivan K Date: Sun, 30 Mar 2025 14:46:03 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(podkop):=20Handle=20DNS=20ch?= =?UTF-8?q?eck=20errors=20and=20timeouts=20properly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/view/podkop/podkop.js | 36 +++++++++++++------ podkop/files/usr/bin/podkop | 11 +++--- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js index ae89987..83e2b82 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/podkop.js @@ -813,20 +813,34 @@ function checkDNSAvailability() { return new Promise(async (resolve) => { try { const dnsStatusResult = await safeExec('/usr/bin/podkop', ['check_dns_available']); - const dnsStatus = JSON.parse(dnsStatusResult.stdout || '{"dns_type":"unknown","dns_server":"unknown","is_available":0,"status":"unknown","local_dns_working":0,"local_dns_status":"unknown"}'); + if (!dnsStatusResult || !dnsStatusResult.stdout) { + return resolve({ + remote: createStatus('error', 'DNS check timeout', 'WARNING'), + local: createStatus('error', 'DNS check timeout', 'WARNING') + }); + } - const remoteStatus = dnsStatus.is_available ? - createStatus('available', `${dnsStatus.dns_type.toUpperCase()} (${dnsStatus.dns_server}) available`, 'SUCCESS') : - createStatus('unavailable', `${dnsStatus.dns_type.toUpperCase()} (${dnsStatus.dns_server}) unavailable`, 'ERROR'); + try { + const dnsStatus = JSON.parse(dnsStatusResult.stdout); - const localStatus = dnsStatus.local_dns_working ? - createStatus('available', 'Router DNS working', 'SUCCESS') : - createStatus('unavailable', 'Router DNS not working', 'ERROR'); + const remoteStatus = dnsStatus.is_available ? + createStatus('available', `${dnsStatus.dns_type.toUpperCase()} (${dnsStatus.dns_server}) available`, 'SUCCESS') : + createStatus('unavailable', `${dnsStatus.dns_type.toUpperCase()} (${dnsStatus.dns_server}) unavailable`, 'ERROR'); - return resolve({ - remote: remoteStatus, - local: localStatus - }); + const localStatus = dnsStatus.local_dns_working ? + createStatus('available', 'Router DNS working', 'SUCCESS') : + createStatus('unavailable', 'Router DNS not working', 'ERROR'); + + return resolve({ + remote: remoteStatus, + local: localStatus + }); + } catch (parseError) { + return resolve({ + remote: createStatus('error', 'DNS check parse error', 'WARNING'), + local: createStatus('error', 'DNS check parse error', 'WARNING') + }); + } } catch (error) { return resolve({ remote: createStatus('error', 'DNS check error', 'WARNING'), diff --git a/podkop/files/usr/bin/podkop b/podkop/files/usr/bin/podkop index abeb9bc..c6fa55d 100755 --- a/podkop/files/usr/bin/podkop +++ b/podkop/files/usr/bin/podkop @@ -2049,14 +2049,15 @@ check_dns_available() { fi fi elif [ "$dns_type" = "dot" ]; then - nc $dns_server 853 /dev/null 2>&1 & pid=$! - (sleep 3; kill $pid 2>/dev/null) & killpid=$! - wait $pid >/dev/null 2>&1 - if [ $? -eq 0 ]; then + (nc "$dns_server" 853 /dev/null 2>&1) & pid=$! + sleep 2 + if kill -0 $pid 2>/dev/null; then + kill $pid 2>/dev/null + wait $pid 2>/dev/null + else is_available=1 status="available" fi - kill $killpid 2>/dev/null elif [ "$dns_type" = "udp" ]; then if nslookup -timeout=2 itdog.info $dns_server >/dev/null 2>&1; then is_available=1