From 64980655f48af7b22cfa4fc42d10a737d9be211d Mon Sep 17 00:00:00 2001
From: Daniel Gibbs <me@danielgibbs.co.uk>
Date: Mon, 24 Feb 2025 22:28:37 +0000
Subject: [PATCH] feat: bypass termbin if site is down

---
 lgsm/modules/command_postdetails.sh | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/lgsm/modules/command_postdetails.sh b/lgsm/modules/command_postdetails.sh
index 61d537440..7f5f67304 100644
--- a/lgsm/modules/command_postdetails.sh
+++ b/lgsm/modules/command_postdetails.sh
@@ -58,18 +58,27 @@ else
 fi
 
 fn_print_dots "termbin.com"
-link=$(cat "${postdetailslog}" | nc termbin.com 9999 | tr -d '\n\0')
-fn_print_ok_nl "termbin.com for 30D"
-fn_script_log_pass "termbin.com for 30D"
-pdurl="${link}"
+link=$(cat "${postdetailslog}" | {
+	nc -w 3 termbin.com 9999
+	echo $? > /tmp/nc_exit_status
+} | tr -d '\n\0')
+nc_exit_status=$(cat /tmp/nc_exit_status)
+if [ "${nc_exit_status}" -ne 0 ]; then
+	fn_print_error_nl "Failed to post to termbin.com"
+	fn_script_log_error "Failed to post to termbin.com"
+else
+	fn_print_ok_nl "termbin.com for 30D"
+	fn_script_log_pass "termbin.com for 30D"
+	pdurl="${link}"
 
-if [ "${firstcommandname}" == "POST-DETAILS" ]; then
-	echo -e ""
-	echo -e "Please share the following url for support: "
-	echo -e "${italic}${pdurl}${default}"
+	if [ "${firstcommandname}" == "POST-DETAILS" ]; then
+		echo -e ""
+		echo -e "Please share the following url for support: "
+		echo -e "${italic}${pdurl}${default}"
+	fi
+	fn_script_log_info "${pdurl}"
+	alerturl="${pdurl}"
 fi
-fn_script_log_info "${pdurl}"
-alerturl="${pdurl}"
 
 if [ -z "${exitbypass}" ]; then
 	core_exit.sh