mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-31 21:59:17 +03:00
Merge pull request #72 from itdoginfo/feature/no-more-cache
🐛 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'),
|
||||||
|
|||||||
@@ -2029,6 +2029,13 @@ check_dns_available() {
|
|||||||
local status="unavailable"
|
local status="unavailable"
|
||||||
local local_dns_working=0
|
local local_dns_working=0
|
||||||
local local_dns_status="unavailable"
|
local local_dns_status="unavailable"
|
||||||
|
|
||||||
|
# Mask NextDNS ID if present
|
||||||
|
local display_dns_server="$dns_server"
|
||||||
|
if echo "$dns_server" | grep -q "\.dns\.nextdns\.io$"; then
|
||||||
|
local nextdns_id=$(echo "$dns_server" | cut -d'.' -f1)
|
||||||
|
display_dns_server="$(echo "$nextdns_id" | sed 's/./*/g').dns.nextdns.io"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$dns_type" = "doh" ]; then
|
if [ "$dns_type" = "doh" ]; then
|
||||||
# Different DoH providers use different endpoints and formats
|
# Different DoH providers use different endpoints and formats
|
||||||
@@ -2049,14 +2056,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
|
||||||
@@ -2070,7 +2078,7 @@ check_dns_available() {
|
|||||||
local_dns_status="available"
|
local_dns_status="available"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "{\"dns_type\":\"$dns_type\",\"dns_server\":\"$dns_server\",\"is_available\":$is_available,\"status\":\"$status\",\"local_dns_working\":$local_dns_working,\"local_dns_status\":\"$local_dns_status\"}"
|
echo "{\"dns_type\":\"$dns_type\",\"dns_server\":\"$display_dns_server\",\"is_available\":$is_available,\"status\":\"$status\",\"local_dns_working\":$local_dns_working,\"local_dns_status\":\"$local_dns_status\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
sing_box_add_secure_dns_probe_domain() {
|
sing_box_add_secure_dns_probe_domain() {
|
||||||
|
|||||||
Reference in New Issue
Block a user