From d33d53746f8966cb7d86a588308d669dd5514c93 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 5 Aug 2024 20:26:11 -0500 Subject: [PATCH] Update nodemgmt-scripts.sh --- nodemgmt-scripts.sh | 60 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index 7b1a8f81..98cb406f 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -25,39 +25,37 @@ fi [ -f ${NM_BACKUP_FOLDER}/templates/*.config ] && rm -f ${NM_BACKUP_FOLDER}/templates/*.config OFFSITE_STATICROUTE_FIX(){ - # [ -f ${NM_TMPFOLDER}/vpn-tunnel.down.sent ] && [ "$(CHECK_HOST_QC 10.5.0.1)" != "true" ] && exit + STSVPN_ADAPTER=$(ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${NM_OFFSITE_GW_IP} ip r | grep '10.5.0.0/20' | awk '{print $7}') + echo "'${STSVPN_ADAPTER}'" - CHECK_HOST_QC 10.10.0.1 - CHECK_HOST_QC ${NM_OFFSITE_GW_IP} - CHECK_HOST_QC 10.5.0.1 - # if [ "$(CHECK_HOST_QC 10.10.0.1)" != "true" ]; then - # if [ "$(CHECK_HOST_QC ${NM_OFFSITE_GW_IP})" != "false" ]; then - # if [ "$(CHECK_HOST_QC 10.5.0.1)" != "false" ]; then - # - # if [ "$(ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${NM_OFFSITE_GW_IP} ip r | grep 10.10.0.0)" = "" ]; then - # RUN=$(ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${NM_OFFSITE_GW_IP} ip r add 10.10.0.0/16 dev ${NM_OFFSITE_VPN_ADAPTER} 2>&1 >/dev/null) - # if [ "${RUN}" == "" ]; then - # SENDNOTICE "Static Route to Homesite Missing" "Re-added the static route onto the Offsite UniFi Gateway" - # else - # SENDNOTICE "ERROR: Static Route to Homesite Missing" "Cannot add the static route onto the Offsite UniFi Gateway" 1 - # fi - # fi - # else - # if [ ! -f ${NM_TMPFOLDER}/vpn-tunnel.down ]; then - # touch ${NM_TMPFOLDER}/vpn-tunnel.down - # elif [ $(expr `date +%s` - $(stat -c %Y ${NM_TMPFOLDER}/vpn-tunnel.down)) -ge 60 ] && [ ! -f ${NM_TMPFOLDER}/vpn-tunnel.down.sent ]; then - # SENDNOTICE "VPN to Homesite Down" "VPN is down, fix your shit first, then I'll fix mine..." - # touch ${NM_TMPFOLDER}/vpn-tunnel.down.sent - # fi - # fi - # fi - # else - # if [ -f ${NM_TMPFOLDER}/vpn-tunnel.down ]; then - # SENDNOTICE "VPN to Homesite is Back Up" "VPN Tunnel is up" - # rm -f ${NM_TMPFOLDER}/vpn-tunnel.down* - # fi - # fi + if [ "$(CHECK_HOST_QC 10.10.0.1)" != "true" ]; then + if [ "$(CHECK_HOST_QC ${NM_OFFSITE_GW_IP})" != "false" ]; then + if [ "$(CHECK_HOST_QC 10.5.0.1)" != "false" ]; then + STSVPN_ADAPTER=$(ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${NM_OFFSITE_GW_IP} ip r | grep '10.5.0.0/20' | awk '{print $7}') + if [ "$(ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${NM_OFFSITE_GW_IP} ip r | grep 10.10.0.0)" = "" ]; then + RUN=$(ssh -q -o ConnectTimeout=3 -o ConnectionAttempts=1 root@${NM_OFFSITE_GW_IP} ip r add 10.10.0.0/16 dev ${NM_OFFSITE_VPN_ADAPTER} 2>&1 >/dev/null) + if [ "${RUN}" == "" ]; then + SENDNOTICE "Static Route to Homesite Missing" "Re-added the static route onto the Offsite UniFi Gateway" + else + SENDNOTICE "ERROR: Static Route to Homesite Missing" "Cannot add the static route onto the Offsite UniFi Gateway" 1 + fi + fi + else + if [ ! -f ${NM_TMPFOLDER}/vpn-tunnel.down ]; then + touch ${NM_TMPFOLDER}/vpn-tunnel.down + elif [ $(expr `date +%s` - $(stat -c %Y ${NM_TMPFOLDER}/vpn-tunnel.down)) -ge 60 ] && [ ! -f ${NM_TMPFOLDER}/vpn-tunnel.down.sent ]; then + SENDNOTICE "VPN to Homesite Down" "VPN is down, fix your shit first, then I'll fix mine..." + touch ${NM_TMPFOLDER}/vpn-tunnel.down.sent + fi + fi + fi + else + if [ -f ${NM_TMPFOLDER}/vpn-tunnel.down ]; then + SENDNOTICE "VPN to Homesite is Back Up" "VPN Tunnel is up" + rm -f ${NM_TMPFOLDER}/vpn-tunnel.down* + fi + fi } BACKUP(){