From 6d66aacf2ef0747ce00634c4def7e3b83c4bc416 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Tue, 8 May 2018 13:45:18 +0100
Subject: [PATCH] Extracting the onion address from about array

---
 src/freedombone-controlpanel | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel
index 402a3a67c..ce06b3bf2 100755
--- a/src/freedombone-controlpanel
+++ b/src/freedombone-controlpanel
@@ -332,15 +332,39 @@ function show_domains {
 
     # shellcheck disable=SC2068
     selected=$(dialog --backtitle $"Freedombone Control Panel" --title $"Domains" --menu $"Use Shift+cursors to select and copy onion addresses" $((height-4)) $((width-4)) $((height-4)) "${W[@]}" 3>&2 2>&1 1>&3)
-    if [[ "$selected" != *'.onion'* ]]; then
+    if [ ! "$selected" ]; then
         return
     fi
-    intermediate=$(echo "$selected" | awk -F '.' '{print $2}')
+    # obtain the addresses from the key by itterating through
+    # the array. This is quite crude and maybe there's a better way
+    key_found=
+    selected_addresses=
+    for key in "${W[@]}";
+    do
+        if [ $key_found ]; then
+            selected_addresses="$key"
+            break
+        fi
+        if [[ "$key" == "$selected" ]]; then
+            key_found=1
+        fi
+    done
+    # Was the key matched?
+    if [ ! "$selected_addresses" ]; then
+        return
+    fi
+    # addresses were found - is this an onion?
+    if [[ "$selected_addresses" != *".onion"* ]]; then
+        return
+    fi
+    # There are two forms of addresses: "x / y.onion" and "x.onion"
+    intermediate=$(echo "$selected_addresses" | awk -F '.' '{print $2}')
     if [[ "$intermediate" == *'/'* ]]; then
         onion_addr=$(echo "$intermediate" | awk -F ' ' '{print $3}').onion
     else
-        onion_addr="$selected".onion
+        onion_addr="$selected_addresses".onion
     fi
+    # show the onion address as a QR code
     clear
     echo "$onion_addr"
     echo -n "$onion_addr" | qrencode -t UTF8
-- 
GitLab