Sfoglia il codice sorgente

Extracting the onion address from about array

Bob Mottram 6 anni fa
parent
commit
6d66aacf2e
1 ha cambiato i file con 27 aggiunte e 3 eliminazioni
  1. 27
    3
      src/freedombone-controlpanel

+ 27
- 3
src/freedombone-controlpanel Vedi File

@@ -332,15 +332,39 @@ function show_domains {
332 332
 
333 333
     # shellcheck disable=SC2068
334 334
     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)
335
-    if [[ "$selected" != *'.onion'* ]]; then
335
+    if [ ! "$selected" ]; then
336 336
         return
337 337
     fi
338
-    intermediate=$(echo "$selected" | awk -F '.' '{print $2}')
338
+    # obtain the addresses from the key by itterating through
339
+    # the array. This is quite crude and maybe there's a better way
340
+    key_found=
341
+    selected_addresses=
342
+    for key in "${W[@]}";
343
+    do
344
+        if [ $key_found ]; then
345
+            selected_addresses="$key"
346
+            break
347
+        fi
348
+        if [[ "$key" == "$selected" ]]; then
349
+            key_found=1
350
+        fi
351
+    done
352
+    # Was the key matched?
353
+    if [ ! "$selected_addresses" ]; then
354
+        return
355
+    fi
356
+    # addresses were found - is this an onion?
357
+    if [[ "$selected_addresses" != *".onion"* ]]; then
358
+        return
359
+    fi
360
+    # There are two forms of addresses: "x / y.onion" and "x.onion"
361
+    intermediate=$(echo "$selected_addresses" | awk -F '.' '{print $2}')
339 362
     if [[ "$intermediate" == *'/'* ]]; then
340 363
         onion_addr=$(echo "$intermediate" | awk -F ' ' '{print $3}').onion
341 364
     else
342
-        onion_addr="$selected".onion
365
+        onion_addr="$selected_addresses".onion
343 366
     fi
367
+    # show the onion address as a QR code
344 368
     clear
345 369
     echo "$onion_addr"
346 370
     echo -n "$onion_addr" | qrencode -t UTF8