mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 19:46:52 +03:00
🐛 fix(podkop): Handle DNS check errors and timeouts properly
This commit is contained in:
@@ -813,20 +813,34 @@ function checkDNSAvailability() {
|
|||||||
return new Promise(async (resolve) => {
|
return new Promise(async (resolve) => {
|
||||||
try {
|
try {
|
||||||
const dnsStatusResult = await safeExec('/usr/bin/podkop', ['check_dns_available']);
|
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 ?
|
try {
|
||||||
createStatus('available', `${dnsStatus.dns_type.toUpperCase()} (${dnsStatus.dns_server}) available`, 'SUCCESS') :
|
const dnsStatus = JSON.parse(dnsStatusResult.stdout);
|
||||||
createStatus('unavailable', `${dnsStatus.dns_type.toUpperCase()} (${dnsStatus.dns_server}) unavailable`, 'ERROR');
|
|
||||||
|
|
||||||
const localStatus = dnsStatus.local_dns_working ?
|
const remoteStatus = dnsStatus.is_available ?
|
||||||
createStatus('available', 'Router DNS working', 'SUCCESS') :
|
createStatus('available', `${dnsStatus.dns_type.toUpperCase()} (${dnsStatus.dns_server}) available`, 'SUCCESS') :
|
||||||
createStatus('unavailable', 'Router DNS not working', 'ERROR');
|
createStatus('unavailable', `${dnsStatus.dns_type.toUpperCase()} (${dnsStatus.dns_server}) unavailable`, 'ERROR');
|
||||||
|
|
||||||
return resolve({
|
const localStatus = dnsStatus.local_dns_working ?
|
||||||
remote: remoteStatus,
|
createStatus('available', 'Router DNS working', 'SUCCESS') :
|
||||||
local: localStatus
|
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) {
|
} catch (error) {
|
||||||
return resolve({
|
return resolve({
|
||||||
remote: createStatus('error', 'DNS check error', 'WARNING'),
|
remote: createStatus('error', 'DNS check error', 'WARNING'),
|
||||||
|
|||||||
@@ -2049,14 +2049,15 @@ check_dns_available() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ "$dns_type" = "dot" ]; then
|
elif [ "$dns_type" = "dot" ]; then
|
||||||
nc $dns_server 853 </dev/null >/dev/null 2>&1 & pid=$!
|
(nc "$dns_server" 853 </dev/null >/dev/null 2>&1) & pid=$!
|
||||||
(sleep 3; kill $pid 2>/dev/null) & killpid=$!
|
sleep 2
|
||||||
wait $pid >/dev/null 2>&1
|
if kill -0 $pid 2>/dev/null; then
|
||||||
if [ $? -eq 0 ]; then
|
kill $pid 2>/dev/null
|
||||||
|
wait $pid 2>/dev/null
|
||||||
|
else
|
||||||
is_available=1
|
is_available=1
|
||||||
status="available"
|
status="available"
|
||||||
fi
|
fi
|
||||||
kill $killpid 2>/dev/null
|
|
||||||
elif [ "$dns_type" = "udp" ]; then
|
elif [ "$dns_type" = "udp" ]; then
|
||||||
if nslookup -timeout=2 itdog.info $dns_server >/dev/null 2>&1; then
|
if nslookup -timeout=2 itdog.info $dns_server >/dev/null 2>&1; then
|
||||||
is_available=1
|
is_available=1
|
||||||
|
|||||||
Reference in New Issue
Block a user