From 0da1f7ccee9502141f26f0c6ae527a1907cb6969 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Tue, 14 Nov 2023 15:32:00 -0600 Subject: [PATCH] update --- inc/sites.inc | 4 +- nodemgmt-scripts.sh | 89 ++++++++++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/inc/sites.inc b/inc/sites.inc index d33ce376..e461ee7e 100755 --- a/inc/sites.inc +++ b/inc/sites.inc @@ -6,7 +6,7 @@ DELSITE(){ -ssl) DEL_SSL=${2};; -list) DELSITES; exit 0;; -*) - echo "Invalid option: '${1}' requires an argument" 1>&2 + [ "${1}" != "-h" ] && echo "Invalid option: '${1}' requires an argument" 1>&2 echo echo -e "Usage: ${idsCL[Yellow]}[nodemgmt or nmg] delsite${idsCL[Default]} {" width=35 @@ -14,7 +14,7 @@ DELSITE(){ printf "%-${width}s- %s\n" " -ssl {yes or [no]}" "Delete SSL certs as well" printf "%-${width}s- %s\n" " -list" "List sites (same as running nodemgmt delsites)" echo "}" - exit 1;; + exit 0;; esac shift done diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index 2b8cd57c..cc87b1e2 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -499,40 +499,48 @@ ADD_LOGROTATE_CRONTAB(){ } UPDATE_DYNDNS(){ - if [ "${1}" == "q" ]; then - SENDNOTICE "FOUND OLD DYNDNS SERVER" "IP=$(/sbin/ip -o -4 addr list eth0 |grep 255 | awk '{print $4}' | cut -d/ -f1) - HOSTNAME=$(hostname)" - - else - if [ "${2}" != 'q' ]; then - cw_spc=10 - echo -e "${idsCL[Yellow]}Checking for DYNDNS update at ${1^} ... ${idsCL[Default]}" - echo - echo -en "${idsCL[LightCyan]}Old IP ${idsCL[White]}: " - fi - + TESTMODE=0 + while [ $# -gt 0 ]; do + case "$1" in + -t|-test) TESTMODE=1;; + -h | -help | --help) + echo + echo -e "Usage: ${idsCL[LightYellow]}[nodemgmt or nmg] update-dyndns ${idsCL[Yellow]}{location}${idsCL[Default]} {" + width=35 + printf "%-${width}s- %s\n" " {location}" "(site location name to update for)" + printf "%-${width}s- %s\n" " -t|-test" "(tests but does not update records)" + echo "}" + exit 0;; + *) LOCATION=${1};; + esac + shift + done + if [ "${LOCATION}" == "mainsite" ] || [ "${LOCATION}" == "offsite" ] || [ "${LOCATION}" == "kyle" ]; then if [ "${NM_DYNUSER}" == "" ] || [ "${NM_DYNPASS}" == "" ]; then echo "Missing DYNDNS username or password (NM_DYNUSER=${NM_DYNUSER}) (NM_DYNPASS=${NM_DYNPASS})" - SENDNOTICE "${1^^} DYNDNS ERROR" "Missing DYNDNS username or password (NM_DYNUSER=${NM_DYNUSER}) (NM_DYNPASS=${NM_DYNPASS})" + SENDNOTICE "${LOCATION^^} DYNDNS ERROR" "Missing DYNDNS username or password (NM_DYNUSER=${NM_DYNUSER}) (NM_DYNPASS=${NM_DYNPASS})" 1 exit 1 fi - - if [ "${1}" == "home" ]; then + cw_spc=10 + echo -e "${idsCL[Yellow]}Checking for DYNDNS update at ${LOCATION^} ... ${idsCL[Default]}" + echo + echo -en "${idsCL[LightCyan]}Previous WAN IP ${idsCL[White]}: " + + if [ "${LOCATION}" == "mainsite" ]; then OLDIP=`dig +short sc1.scity.us @wdns.scity.us +time=2` - elif [ "${1}" == "offsite" ]; then + elif [ "${LOCATION}" == "offsite" ]; then OLDIP=`dig +short offsite.scity.us @wdns.scity.us +time=2` - elif [ "${1}" == "kyle" ]; then + elif [ "${LOCATION}" == "kyle" ]; then OLDIP=`dig +short wan.pattonfam.com @wdns.scity.us +time=2` fi - if [ "${2}" != 'q' ]; then - echo -e "${idsCL[Cyan]}${OLDIP}" - echo -en "${idsCL[LightCyan]}New IP ${idsCL[White]}: " - fi + echo -e "${idsCL[Cyan]}${OLDIP}" + echo -en "${idsCL[LightCyan]}Current WAN IP ${idsCL[White]}: " NEWIP=`dig +short myip.opendns.com @resolver1.opendns.com +time=2` - [ "${2}" != 'q' ] && echo -e "${idsCL[Green]}${NEWIP}" - + echo -e "${idsCL[Green]}${NEWIP}" + if ([ "${OLDIP}" != "" ] && [ "${NEWIP}" != "" ] && [[ "${OLDIP}" != *";"* ]] && [[ "${NEWIP}" != *";"* ]] && [ "${OLDIP}" != "${NEWIP}" ]) || [ "${2}" == "force" ]; then - [ "${2}" != 'q' ] && echo && echo -en "${idsCL[Green]}${1^} WAN IP has changed, updating records ... " - if [ "${1}" == "home" ]; then + echo && echo -en "${idsCL[Green]}${1^} WAN IP has changed, updating records ... " + if [ "${LOCATION}" == "mainsite" ]; then #external dns /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@wdns.scity.us/nic/update?hostname=sc1.scity.us&myip=${NEWIP}" > /dev/null 2>&1 /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@wdns.scity.us/nic/update?hostname=sc2.scity.us&myip=${NEWIP}" > /dev/null 2>&1 @@ -543,39 +551,36 @@ UPDATE_DYNDNS(){ /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@wdns.scity.us/nic/update?hostname=misfitsmc.com&myip=${NEWIP}" > /dev/null 2>&1 #internal dns /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@dns.scity.us/nic/update?hostname=sc1.scity.us&myip=${NEWIP}" > /dev/null 2>&1 - - elif [ "${1}" == "offsite" ]; then + + elif [ "${LOCATION}" == "offsite" ]; then #external dns /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@wdns.scity.us/nic/update?hostname=offsite.scity.us&myip=${NEWIP}" > /dev/null 2>&1 /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@wdns.scity.us/nic/update?hostname=backup.scity.us&myip=${NEWIP}" > /dev/null 2>&1 #internal dns /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@dns.scity.us/nic/update?hostname=offsite.scity.us&myip=${NEWIP}" > /dev/null 2>&1 /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@dns.scity.us/nic/update?hostname=backup.scity.us&myip=${NEWIP}" > /dev/null 2>&1 - - elif [ "${1}" == "kyle" ]; then + + elif [ "${LOCATION}" == "kyle" ]; then /usr/bin/curl -s "https://${NM_DYNUSER}:${NM_DYNPASS}@wdns.scity.us/nic/update?hostname=wan.pattonfam.com&myip=${NEWIP}" > /dev/null 2>&1 - + fi - SENDNOTICE "${1^^} DYNDNS Updated" "Updated ${1^} WAN IP from '${OLDIP}' to '${NEWIP}'" - [ "${2}" != 'q' ] && echo -e "${idsCL[Green]}done${idsCL[Default]}" + SENDNOTICE "${LOCATION^^} DYNDNS Updated" "Updated ${1^} WAN IP from '${OLDIP}' to '${NEWIP}'" + echo -e "${idsCL[Green]}done${idsCL[Default]}" echo - + elif [[ "${NEWIP}" == *";"* ]] || [[ "${OLDIP}" == *";"* ]]; then - [ "${2}" != 'q' ] && echo -e "${idsCL[Red]}Could not do dns lookup${idsCL[Default]}" + echo -e "${idsCL[Red]}Could not do dns lookup${idsCL[Default]}" # SENDNOTICE "${1^^} DYNDNS Could not Update" "Connection error, could reach any servers" elif [ "${OLDIP}" == "" ]; then - [ "${2}" != 'q' ] && echo -e "${idsCL[Red]}Could not get OLD IP${idsCL[Default]}" + echo -e "${idsCL[Red]}Could not get PREVIOUS WAN IP${idsCL[Default]}" elif [ "${NEWIP}" == "" ]; then - [ "${2}" != 'q' ] && echo -e "${idsCL[Red]}Could not get NEW IP${idsCL[Default]}" + echo -e "${idsCL[Red]}Could not get CURRENT WAN IP${idsCL[Default]}" else - [ "${2}" != 'q' ] && echo -e "${idsCL[Green]}${1^^} WAN IP has not changed${idsCL[Default]}" - fi - - if [ "${2}" != 'q' ]; then - echo - # read -n 1 -s -p "Press any key to continue" - # echo + echo -e "${idsCL[Green]}'${LOCATION^^}' WAN IP has not changed${idsCL[Default]}" fi + echo + else + echo -e "\n${idsCL[Red]}DYNDNS location '${LOCATION}' not recognized" fi }