From 3d327216834a8a71ff271913cd4ac0818bdcc914 Mon Sep 17 00:00:00 2001 From: Gergely Koloszar Date: Thu, 16 Oct 2025 20:50:42 +0200 Subject: [PATCH 1/4] Add availability checker for remote services based on ping and timeout --- dzgui.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dzgui.sh b/dzgui.sh index ae93854..3f02dca 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -495,6 +495,22 @@ stale_symlinks(){ unlink "$l" done } + +check_availability() { + if [[ -z $1 ]]; then + return 1 + fi + local url=$1 + local timeout_sec="3" + if [[ $2 ]]; then + timeout_sec=$2 + fi + if ! ping -w "$timeout_sec" "$url"; then + logger WARN "Failed to reach $url, service may be down." + return 1 + fi +} + local_latlon(){ if [[ -z $(command -v dig) ]]; then local local_ip=$(curl -Ls "https://ipecho.net/plain") From a7c647aa6bd58254c478e165768a0e08e749af59 Mon Sep 17 00:00:00 2001 From: Gergely Koloszar Date: Thu, 16 Oct 2025 20:51:46 +0200 Subject: [PATCH 2/4] Add availability checks for local_latlon function --- dzgui.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/dzgui.sh b/dzgui.sh index 3f02dca..b52012d 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -513,19 +513,30 @@ check_availability() { local_latlon(){ if [[ -z $(command -v dig) ]]; then - local local_ip=$(curl -Ls "https://ipecho.net/plain") + local url_ipecho="https://ipecho.net/plain" + if ! check_availability "ipecho.net"; then + logger WARN "Failed to get external ip address, ipecho.net service may be down." + return 1 + fi + local local_ip=$(curl -Ls "$url_ipecho") else + # todo : implement checking remote local local_ip=$(dig -4 +short myip.opendns.com @resolver1.opendns.com) fi - local url="http://ip-api.com/json/$local_ip" - local res=$(curl -Ls "$url" | jq -r '"\(.lat)\n\(.lon)"') + local url_ip_api="http://ip-api.com/json/$local_ip" + if ! check_availability "ip-api.com"; then + logger WARN "Failed to get local coordinates, ip-api.com service may be down." + return 1 + fi + local res=$(curl -Ls "$url_ip_api" | jq -r '"\(.lat)\n\(.lon)"') if [[ -z "$res" ]]; then logger WARN "Failed to get local coordinates" return 1 fi echo "$res" > "$coords_file" } -lock(){ + +lock [[ ! -f $lock_file ]] && touch $lock_file local pid=$(cat $lock_file) ps -p $pid -o pid= >/dev/null 2>&1 From 0ad6366f0a63a40cbcac290992bfd2dbff9ce1ab Mon Sep 17 00:00:00 2001 From: Gergely Koloszar Date: Thu, 16 Oct 2025 20:53:14 +0200 Subject: [PATCH 3/4] Fix unintended deletion --- dzgui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dzgui.sh b/dzgui.sh index b52012d..7850a4f 100755 --- a/dzgui.sh +++ b/dzgui.sh @@ -536,7 +536,7 @@ local_latlon(){ echo "$res" > "$coords_file" } -lock +lock(){ [[ ! -f $lock_file ]] && touch $lock_file local pid=$(cat $lock_file) ps -p $pid -o pid= >/dev/null 2>&1 From 5654b327d42fc6d8c9e6b65e8106930c26677d06 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Fri, 17 Oct 2025 04:20:13 +0900 Subject: [PATCH 4/4] fix: early abort if local coords are missing --- helpers/funcs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helpers/funcs b/helpers/funcs index c747c82..3f0b44e 100755 --- a/helpers/funcs +++ b/helpers/funcs @@ -425,6 +425,10 @@ local_latlon(){ get_dist(){ shift local given_ip="$1" + if [[ ! -f $_cache_coords ]]; then + printf "Unknown" + return + fi readarray -t coords < "$_cache_coords" readarray -t n < <(<<< "$given_ip" awk 'BEGIN{RS="."}{$1=$1}1')