From 47a78f33381d5fdb3c6d2df6a3b95f4952f4371e Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Mon, 5 Aug 2024 19:55:40 -0500 Subject: [PATCH] update --- defaults.inc | 12 ++++++++++ nodemgmt-scripts.sh | 56 +++++++++++++++++++++++---------------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/defaults.inc b/defaults.inc index bd0ff2c9..6b737667 100755 --- a/defaults.inc +++ b/defaults.inc @@ -210,6 +210,18 @@ DISP_HEADER(){ echo } +CHECK_HOST_NM(){ + if [ ! -z ${1+x} ]; then + if [ "$(nmap ${1} -p 22,80,443 -n | grep 'open ')" != "" ] || [ "$(nmap -sU ${1} -p 161 -n | grep 'open ')" != "" ]; then + echo true + else + echo false + fi + else + echo false + fi +} + SENDNOTICE(){ if [ "${PUSHOVER_USER_TOKEN}" != "" ]; then SN_TIT="$(echo -e "${1}" | sed "s/\%/\%25 /g")" diff --git a/nodemgmt-scripts.sh b/nodemgmt-scripts.sh index e903b5b5..fda5c379 100755 --- a/nodemgmt-scripts.sh +++ b/nodemgmt-scripts.sh @@ -26,35 +26,37 @@ fi OFFSITE_STATICROUTE_FIX(){ if [ -f ${NM_TMPFOLDER}/vpn-tunnel.down.sent ]; then - [ "$(CHECK_HOST 10.5.0.1)" != "true" ] && exit + [ "$(CHECK_HOST_NM 10.5.0.1)" != "true" ] && exit fi - # if [ "$(CHECK_HOST 10.10.0.1)" != "true" ]; then - # if [ "$(CHECK_HOST ${NM_OFFSITE_GW_IP})" != "false" ]; then - # if [ "$(CHECK_HOST 10.5.0.1)" != "false" ]; then - # if [ -f ${NM_TMPFOLDER}/vpn-tunnel.down ]; then - # SENDNOTICE "VPN to Homesite is Back Up" "VPN Tunnel is up" - # fi - # 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 - # rm -f ${NM_TMPFOLDER}/vpn-tunnel* - # fi + + + if [ "$(CHECK_HOST_NM 10.10.0.1)" != "true" ]; then + if [ "$(CHECK_HOST ${NM_OFFSITE_GW_IP})" != "false" ]; then + if [ "$(CHECK_HOST_NM 10.5.0.1)" != "false" ]; then + if [ -f ${NM_TMPFOLDER}/vpn-tunnel.down ]; then + SENDNOTICE "VPN to Homesite is Back Up" "VPN Tunnel is up" + fi + 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 + rm -f ${NM_TMPFOLDER}/vpn-tunnel* + fi } BACKUP(){