Update mm-scripts.sh
This commit is contained in:
114
mm-scripts.sh
114
mm-scripts.sh
@@ -96,51 +96,49 @@ MMSTART(){
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
|
||||||
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
|
||||||
|
|
||||||
if [ ${GOFORSTART} = true ]; then
|
if [ ${GOFORSTART} = true ]; then
|
||||||
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${zerogw}" != "${defaultgw}" ]; then
|
|
||||||
echo "$(date) - Adding VPN default routes" >> $logfile
|
|
||||||
echo -en "${idsCL[LightCyan]}Adding VPN default routes... ${idsCL[Default]}"
|
|
||||||
/bin/ip route del default via 10.10.0.1
|
|
||||||
/bin/ip route add default dev wg-torguard
|
|
||||||
/bin/ip route add 0.0.0.0/1 dev wg-torguard
|
|
||||||
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
echo -en "${idsCL[LightCyan]}Verifing default network routes... ${idsCL[Default]}"
|
|
||||||
checked=false
|
|
||||||
cc=0
|
|
||||||
until [ "${checked}" = "" ]; do
|
|
||||||
if [ "${zerogw}" = "${defaultgw}" ]; then
|
|
||||||
checked=""
|
|
||||||
fi
|
|
||||||
if [ "${checked}" == "false" ] && [ ${cc} -eq 10 ]; then
|
|
||||||
echo -e "${idsCL[Red]}Could not confirm default routes, restarting system!${idsCL[Default]}"
|
|
||||||
echo "$(date) - Could not confirm default routes, restarting system" >> $logfile
|
|
||||||
[ "${EMAIL_NOTICE}" != "" ] && echo "Default route failure, will try and restart the VPN" | mail -s "Network Failure" ${EMAIL_NOTICE}
|
|
||||||
touch /opt/idssys/mediamanager/mm.vpn.fail
|
|
||||||
MMSTOP
|
|
||||||
sleep 2m
|
|
||||||
"${VPN_START[@]}" >/dev/null 2>&1 &
|
|
||||||
sleep 1m
|
|
||||||
rm -f /opt/idssys/mediamanager/mm.stop*
|
|
||||||
[ $VERBOSE = true ] && DEBUGLOGSTOP
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
((cc=${cc}+1))
|
|
||||||
sleep 1s
|
|
||||||
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
||||||
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
||||||
done
|
|
||||||
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
# if [ "${zerogw}" != "${defaultgw}" ]; then
|
||||||
|
# echo "$(date) - Adding VPN default routes" >> $logfile
|
||||||
|
# echo -en "${idsCL[LightCyan]}Adding VPN default routes... ${idsCL[Default]}"
|
||||||
|
# /bin/ip route del default via 10.10.0.1
|
||||||
|
# /bin/ip route add default dev wg-torguard
|
||||||
|
# /bin/ip route add 0.0.0.0/1 dev wg-torguard
|
||||||
|
# echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
||||||
|
# fi
|
||||||
|
|
||||||
|
|
||||||
|
# echo -en "${idsCL[LightCyan]}Verifing default network routes... ${idsCL[Default]}"
|
||||||
|
# checked=false
|
||||||
|
# cc=0
|
||||||
|
# until [ "${checked}" = "" ]; do
|
||||||
|
# if [ "${zerogw}" = "${defaultgw}" ]; then
|
||||||
|
# checked=""
|
||||||
|
# fi
|
||||||
|
# if [ "${checked}" == "false" ] && [ ${cc} -eq 10 ]; then
|
||||||
|
# echo -e "${idsCL[Red]}Could not confirm default routes, restarting system!${idsCL[Default]}"
|
||||||
|
# echo "$(date) - Could not confirm default routes, restarting system" >> $logfile
|
||||||
|
# [ "${EMAIL_NOTICE}" != "" ] && echo "Default route failure, will try and restart the VPN" | mail -s "Network Failure" ${EMAIL_NOTICE}
|
||||||
|
# touch /opt/idssys/mediamanager/mm.vpn.fail
|
||||||
|
# MMSTOP
|
||||||
|
# sleep 2m
|
||||||
|
# "${VPN_START[@]}" >/dev/null 2>&1 &
|
||||||
|
# sleep 1m
|
||||||
|
# rm -f /opt/idssys/mediamanager/mm.stop*
|
||||||
|
# [ $VERBOSE = true ] && DEBUGLOGSTOP
|
||||||
|
# exit 1
|
||||||
|
# fi
|
||||||
|
# ((cc=${cc}+1))
|
||||||
|
# sleep 1s
|
||||||
|
# zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
||||||
|
# defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
||||||
|
# done
|
||||||
|
# echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
||||||
|
|
||||||
|
|
||||||
echo -en "${idsCL[LightCyan]}Verifing traffic is routing through VPN... ${idsCL[Default]}"
|
echo -en "${idsCL[LightCyan]}Verifing traffic is routing through VPN... ${idsCL[Default]}"
|
||||||
@@ -304,8 +302,8 @@ MMSTOP(){
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "$(ip route show | grep default | cut -d' ' -f 3)" != "10.10.0.1" ] && /bin/ip route add default via 10.10.0.1
|
# [ "$(ip route show | grep default | cut -d' ' -f 3)" != "10.10.0.1" ] && /bin/ip route add default via 10.10.0.1
|
||||||
[ $VERBOSE = true ] && echo "$(date) - Added default route back in" >> $logfile
|
# [ $VERBOSE = true ] && echo "$(date) - Added default route back in" >> $logfile
|
||||||
|
|
||||||
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
echo -e "${idsCL[Green]} done${idsCL[Default]}"
|
||||||
echo "$(date) - Media Management systems stopped" >> $logfile
|
echo "$(date) - Media Management systems stopped" >> $logfile
|
||||||
@@ -350,24 +348,22 @@ MMSTATUS(){
|
|||||||
else
|
else
|
||||||
echo -e "${idsCL[Green]}Running${idsCL[Default]}"
|
echo -e "${idsCL[Green]}Running${idsCL[Default]}"
|
||||||
if [[ ${srvc} == *"vpn"* ]]; then
|
if [[ ${srvc} == *"vpn"* ]]; then
|
||||||
# zerogw=$(netstat -rn | grep '0.0.0.0' | head -1 | awk '{ print $2}')
|
# zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
||||||
# defaultgw=$(netstat -rn | grep 'default' | head -1 | awk '{ print $2}')
|
# defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
||||||
zerogw=$(ip route show | grep 0.0.0.0 | cut -d' ' -f 3)
|
# echo -e " |- 0.0.0.0 gateway --> (${zerogw})"
|
||||||
defaultgw=$(ip route show | grep default | cut -d' ' -f 3)
|
# echo -en " |- DEFAULT gateway --> (${defaultgw}) : "
|
||||||
echo -e " |- 0.0.0.0 gateway --> (${zerogw})"
|
# if [ "${zerogw}" = "${defaultgw}" ]; then
|
||||||
echo -en " |- DEFAULT gateway --> (${defaultgw}) : "
|
# echo -e "${idsCL[Green]}Matches 0.0.0.0 route${idsCL[Default]}"
|
||||||
if [ "${zerogw}" = "${defaultgw}" ]; then
|
# else
|
||||||
echo -e "${idsCL[Green]}Matches 0.0.0.0 route${idsCL[Default]}"
|
# echo -e "${idsCL[Red]}Does not match 0.0.0.0 route${idsCL[Default]}"
|
||||||
else
|
# if [ ! -f /opt/idssys/mediamanager/mm.stop ]; then
|
||||||
echo -e "${idsCL[Red]}Does not match 0.0.0.0 route${idsCL[Default]}"
|
# echo
|
||||||
if [ ! -f /opt/idssys/mediamanager/mm.stop ]; then
|
# echo -e "${idsCL[LightCyan]}Restarting system...${idsCL[Default]}"
|
||||||
echo
|
# MMSTOP
|
||||||
echo -e "${idsCL[LightCyan]}Restarting system...${idsCL[Default]}"
|
# sleep 30s
|
||||||
MMSTOP
|
# MMSTART
|
||||||
sleep 30s
|
# fi
|
||||||
MMSTART
|
# fi
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -en " |- Verify traffic route to VPN -> : "
|
echo -en " |- Verify traffic route to VPN -> : "
|
||||||
scip=$(dig +short sc1.scity.us @9.9.9.9)
|
scip=$(dig +short sc1.scity.us @9.9.9.9)
|
||||||
|
|||||||
Reference in New Issue
Block a user