From 922aa06f9f55e9aead4fc211d12c7d87217740d3 Mon Sep 17 00:00:00 2001 From: Paul M Date: Sun, 1 Nov 2020 21:18:15 -0600 Subject: [PATCH] Add files via upload Added copy of working script --- vpnwatch | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 vpnwatch diff --git a/vpnwatch b/vpnwatch new file mode 100644 index 0000000..50c635a --- /dev/null +++ b/vpnwatch @@ -0,0 +1,55 @@ +#!/bin/bash + +# Standard bash script, requires bash install on OpenWrt +# and monit to be installed and configured + +# We assume a few things when this is called, first +# that the VPN DNS (Expressvpn) is failing second +# that a restart of openvpn will fix it + +# Note the location of OpenVPN startup script assuming +# its already setup and there + +# Note location of startup script is /etc/init.d/openvpn +# We assume the OpenVPN file used to configure this connection +# also has script security set to 2 so we can use the up +# and down scripts to force the DNS to swap. + +# Make sure your wan port isn't setup for DHCP as some DHCP +# setups can cause the DNS to reset from time to time +# Your ISP's DHCP may not be a problem though as I only +# encountered this when I had another router upstream + +# Step one we reset OpenVPN +# /etc/init.d/openvpn restart + +# step two we ping a site and see if it resolves + +# begin hackery + +# Note: The line below does two things first tries to ping +# a domain. Second, causes grep to exit with status code +# 0 if the word "bad" is present otherwise exit 1 + +ping -c 4 expressvpn.com |& grep -q bad + +# note bash supports |& for piping stderr as to where +# the default shell doesn't + +result=${PIPESTATUS[1]} +# echo "result $result" + +# ${PIPESTATUS[1]} reffers to the exit code of one of the +# piped commands in this case the grep + +if [ $result -eq 1 ]; then +# If it is ok log it and move on +logger VPN DNS OK `date` +fi + +if [ $result -eq 0 ]; then +# If we have issue kick a message to syslog and restart +# Ends up in root.log for remote syslog server +logger Restarting OpenVPN `date` +/etc/init.d/openvpn restart # best option to let openvpn handle it +fi