From cd9466410439f17f47340535fd5f8ba9996e4519 Mon Sep 17 00:00:00 2001 From: Navid <51497406+Navid200@users.noreply.github.com> Date: Fri, 4 Nov 2022 15:20:59 -0400 Subject: [PATCH] Dialogs added --- ConfigureFreedns.sh | 128 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 6 deletions(-) diff --git a/ConfigureFreedns.sh b/ConfigureFreedns.sh index ca3e3bba5a4..7beda5e89cd 100755 --- a/ConfigureFreedns.sh +++ b/ConfigureFreedns.sh @@ -1,20 +1,135 @@ #!/bin/bash + if [ "`id -u`" != "0" ] then -echo "Script needs root - execute bootstrap.sh or use sudo bash installation.sh" -echo "Cannot continue.." +echo "Script needs root - use sudo bash ConfigureFreedns.sh" +echo "Cannot continue." exit 5 fi sudo apt-get install bind9-dnsutils -y echo -echo "Move to use free dns instead of noip.com" +echo "Move to use free dns instead of noip.com" - tzachi-dar echo -read -rep "Please enter host name (for example mynightscoute.mooo.com) "$'\n'"hostname: " hostname -read -rep "please enter direct url. Should look like https://freedns.afraid.org/dynamic/update.php?d005WVNjWkE3aDhyWkJpa1h1cFZiOUV5OjIwNzQ4NTY1 "$'\n'" direct_url: " directurl +got_them=0 +while [ $got_them -lt 1 ] +do +go_back=0 +clear +exec 3>&1 +Values=$(dialog --colors --ok-label "Submit" --form " \Zr Developed by the xDrip team \Zn\n\n\n\ +Enter your FreeDNS userID and password." 12 50 0 "User ID:" 1 1 "$user" 1 14 25 0 "Password:" 2 1 "$pass" 2 14 25 0 2>&1 1>&3) +response=$? +if [ $response = 255 ] || [ $response = 1 ] # cancled or escaped +then +clear +exit 5 +fi + +exec 3>&- +user=$(echo "$Values" | sed -n 1p) +pass=$(echo "$Values" | sed -n 2p) + +if [ "$user" = "" ] || [ "$pass" = "" ] # At least one parameter is blank. +then + go_back=1 + clear + dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\ + You need to enter both userID and password. Try again." 8 50 +fi +clear + +if [ $go_back -lt 1 ] # if 7 +then + arg1="https://freedns.afraid.org/api/?action=getdyndns&v=2&sha=" + arg2=$(echo -n "$user|$pass" | sha1sum | awk '{print $1;}') + arg="$arg1$arg2" + + wget -O /tmp/hosts "$arg" +if [ ! "`grep 'Could not authenticate' /tmp/hosts`" = "" ] # Failed to log in +then + dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\n\ + Failed to authenticate. Try again." 8 50 + go_back=1 +fi + +if [ $go_back -lt 1 ] # if 6 +then + Lines=$(awk 'END{print NR}' /tmp/hosts) + if [ $Lines -eq 0 ] # No hostnames # if 5 + then + dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\ + No subdomains found. Ensure you have one in your Free DNS account, and try again." 9 50 + go_back=1 + + elif [ $Lines -gt 1 ] # More than one hostname + then + clear + exec 3>&1 + subvalue=$(dialog --colors --ok-label "Submit" --form " \Zr Developed by the xDrip team \Zn\n\n\n\ + You have more than one subdomain. Enter the subdomain you want to use. \n\ + It should look like mine.strangled.net" 12 50 0 "Subdomain:" 1 1 "$subd" 1 14 25 0 2>&1 1>&3) + response2=$? + if [ $response2 = 255 ] || [ $response2 = 1 ] # canceled or escaped + then + go_back=1 + fi + + exec 3>&- + subd=$(echo "$subvalue" | sed -n 1p) + if [ $go_back -lt 1 ] # if 4 + then + if [ "$subd" = "" ] # Nothing entered + then + go_back=1 + clear + dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\n\ + You need to enter a subdomain. Try again." 8 50 + fi + + if [ $go_back -lt 1 ] # if 3 + then + grep $subd /tmp/hosts > /tmp/FullLine # Find the lines that match and put them in FullLine. + if [ ! -s /tmp/FullLine ] # Not found + then + go_back=1 + dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\n\ + The subdomain you entered is not one of the ones we found. Try again." 9 50 + fi + if [ $go_back -lt 1 ] # if 2 + then + Lines2=$(wc -l < /tmp/FullLine) + if [ $Lines2 -gt 1 ] # More than one found if 1 + then + go_back=1 + dialog --colors --msgbox " \Zr Developed by the xDrip team \Zn\n\n\n\ + The value you entered matches more than one of your subdomains. Try again and enter a unique value." 11 50 + else + FLine=$( /etc/free-dns.sh<