From d96a0528e3f0f28f616c5032e8da12c7d9dfe553 Mon Sep 17 00:00:00 2001 From: "github@kiekerjan.isdronken.nl" Date: Fri, 12 Nov 2021 21:12:10 +0100 Subject: [PATCH] fixes to dynamic dns tool --- tools/dyndns/dyndns.cfg | 3 ++- tools/dyndns/dyndns.sh | 56 +++++++++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/tools/dyndns/dyndns.cfg b/tools/dyndns/dyndns.cfg index ddbe0513..67fd63cd 100644 --- a/tools/dyndns/dyndns.cfg +++ b/tools/dyndns/dyndns.cfg @@ -1 +1,2 @@ -user = ":" +USER_NAME="" +USER_PASS="" diff --git a/tools/dyndns/dyndns.sh b/tools/dyndns/dyndns.sh index 2cbf8bc6..cea3d369 100755 --- a/tools/dyndns/dyndns.sh +++ b/tools/dyndns/dyndns.sh @@ -15,7 +15,8 @@ #----- Contents of dyndns.cfg file below ------ #----- user credentials ----------------------- -#user = "admin@mydomain.com:MYADMINPASSWORD" +#USER_NAME="admin@mydomain.com" +#USER_PASS="MYADMINPASSWORD" #----- Contents of dyndns.domain below -------- # #------ Contents of dyndns.dynlist below ------ @@ -35,6 +36,8 @@ CATCMD="/bin/cat" OATHTOOLCMD="/usr/bin/oathtool" DYNDNSNAMELIST="$MYNAME.dynlist" +IGNORESTR=";; connection timed out; no servers could be reached" + if [ ! -x $DIGCMD ]; then echo "$MYNAME: dig command $DIGCMD not found. Check and fix please." exit 99 @@ -66,24 +69,43 @@ if [ ! -f $DYNDNSNAMELIST ]; then exit 99 fi +source $CFGFILE +AUTHSTR="Authorization: Basic $(echo $USER_NAME:$USER_PASS | base64 -w 0)" + MYIP="`$DIGCMD +short myip.opendns.com @resolver1.opendns.com`" -if [ -z "MYIP" ]; then +if [ -z "$MYIP" ]; then MYIP="`$DIGCMD +short myip.opendns.com @resolver2.opendns.com`" fi -if [ -z "MYIP" ]; then +if [ "$MYIP" = "$IGNORESTR" ]; then + MYIP="" +fi + +if [ -z "$MYIP" ]; then MYIP="`$DIGCMD +short myip.opendns.com @resolver3.opendns.com`" fi -if [ -z "MYIP" ]; then +if [ "$MYIP" = "$IGNORESTR" ]; then + MYIP="" +fi + +if [ -z "$MYIP" ]; then MYIP="`$DIGCMD +short myip.opendns.com @resolver4.opendns.com`" fi +if [ "$MYIP" = "$IGNORESTR" ]; then + MYIP="" +fi + if [ -z "$MYIP" ]; then MYIP=$($DIGCMD -4 +short TXT o-o.myaddr.l.google.com @ns1.google.com | tr -d '"') fi +if [ "$MYIP" = "$IGNORESTR" ]; then + MYIP="" +fi + if [ ! -z "$MYIP" ]; then for DYNDNSNAME in `$CATCMD $DYNDNSNAMELIST` do @@ -97,7 +119,7 @@ if [ ! -z "$MYIP" ]; then else echo "$MYNAME: $DYNDNSNAME changed (previously: $PREVIP, now: $MYIP)" - STATUS="`$CURLCMD -X PUT -K $CFGFILE -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME/A`" + STATUS="`$CURLCMD -X PUT -u $USER_NAME:$USER_PASS -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME/A`" case $STATUS in "OK") echo "$MYNAME: mailinabox API returned OK, cmd succeeded but no update.";; @@ -116,7 +138,7 @@ if [ ! -z "$MYIP" ]; then source $TOTPFILE TOTP="X-Auth-Token: $(oathtool --totp -b -d 6 $TOTP_KEY)" - STATUST="`$CURLCMD -X PUT -K $CFGFILE -H "$TOTP" -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME/A`" + STATUST="`$CURLCMD -X PUT -u $USER_NAME:$USER_PASS -H "$TOTP" -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME/A`" case $STATUST in "OK") echo "$MYNAME: mailinabox API returned OK, cmd succeded but no update.";; @@ -137,16 +159,28 @@ fi # Now to do the same for ipv6 -MYIP="`$DIGCMD AAAA @resolver1.ipv6-sandbox.opendns.com myip.opendns.com +short -6`" +MYIP="`$DIGCMD +short AAAA @resolver1.ipv6-sandbox.opendns.com myip.opendns.com -6`" -if [ -z "MYIP" ]; then - MYIP="`$DIGCMD AAAA @resolver2.ipv6-sandbox.opendns.com myip.opendns.com +short -6`" +if [ "$MYIP" = "$IGNORESTR" ]; then + MYIP="" +fi + +if [ -z "$MYIP" ]; then + MYIP="`$DIGCMD +short AAAA @resolver2.ipv6-sandbox.opendns.com myip.opendns.com -6`" +fi + +if [ "$MYIP" = "$IGNORESTR" ]; then + MYIP="" fi if [ -z "$MYIP" ]; then MYIP=$($DIGCMD -6 +short TXT o-o.myaddr.l.google.com @ns1.google.com | tr -d '"') fi +if [ "$MYIP" = "$IGNORESTR" ]; then + MYIP="" +fi + if [ ! -z "$MYIP" ]; then for DYNDNSNAME in `$CATCMD $DYNDNSNAMELIST` do @@ -160,7 +194,7 @@ if [ ! -z "$MYIP" ]; then else echo "$MYNAME: $DYNDNSNAME changed (previously: $PREVIP, now: $MYIP)" - STATUS="`$CURLCMD -X PUT -K $CFGFILE -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME/AAAA`" + STATUS="`$CURLCMD -X PUT -u $USER_NAME:$USER_PASS -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME/AAAA`" case $STATUS in "OK") echo "$MYNAME: mailinabox API returned OK, cmd succeeded but no update.";; @@ -179,7 +213,7 @@ if [ ! -z "$MYIP" ]; then source $TOTPFILE TOTP="X-Auth-Token: $(oathtool --totp -b -d 6 $TOTP_KEY)" - STATUST="`$CURLCMD -X PUT -K $CFGFILE -H "$TOTP" -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME/AAAA`" + STATUST="`$CURLCMD -X PUT -u $USER_NAME:$USER_PASS -H "$TOTP" -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME/AAAA`" case $STATUST in "OK") echo "$MYNAME: mailinabox API returned OK, cmd succeded but no update.";;