summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mcrute@gmail.com>2017-07-16 16:58:22 +0000
committerMike Crute <mcrute@gmail.com>2017-07-16 16:58:22 +0000
commit232681e150432aa962ad8544407a6cf91d149de3 (patch)
treea0a55d25e6b5bfd4759094ad3255b7dd89de696b
parentbe794d825cff203f3ca943eba7b2e37de9b60b56 (diff)
downloadserver_bin-232681e150432aa962ad8544407a6cf91d149de3.tar.bz2
server_bin-232681e150432aa962ad8544407a6cf91d149de3.tar.xz
server_bin-232681e150432aa962ad8544407a6cf91d149de3.zip
Add VPN reset script
-rwxr-xr-xvpn_reset.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/vpn_reset.sh b/vpn_reset.sh
new file mode 100755
index 0000000..0905927
--- /dev/null
+++ b/vpn_reset.sh
@@ -0,0 +1,33 @@
1#!/bin/bash
2#
3# Script to reset VPN tunnels on Vyatta based routers. Under some odd
4# circumstances that I don't yet understand these will collapse and not come
5# back up without some help. This will reset them if they don't come back up
6# but do nothing otherwise. It's designed to run as a all-stars cron.
7#
8# Fixes: https://bugs.crute.me/show_bug.cgi?id=70
9#
10
11IPSEC=/usr/sbin/ipsec
12ACTIVE_CONNECTIONS=$($IPSEC status | awk '/INSTALLED/ { split($1, i, "{"); items[i[1]] += 1 } END { for (k in items) { c += items[k]; } print c}')
13ACTIVE_CONNECTIONS=${ACTIVE_CONNECTIONS:-0}
14TOTAL_CONNECTIONS=( $(awk '/^conn/ { if ($2 != "%default" ) print $2 }' /etc/ipsec.conf) )
15
16# Not sure if this is always true but seems that single-tunnel systems
17# only have a single tunnel whereas systems with multiple tunnels have
18# two of each
19if (( ${#TOTAL_CONNECTIONS[@]} > 1 )); then
20 TUNNEL_MULTIPLIER=2
21else
22 TUNNEL_MULTIPLIER=1
23fi
24
25if (( ${ACTIVE_CONNECTIONS} != (${#TOTAL_CONNECTIONS[@]} * $TUNNEL_MULTIPLIER) )); then
26 echo "$(date '+%Y-%m-%d %H:%M:%S') Resetting IPSEC connections ${ACTIVE_CONNECTIONS} of ${#TOTAL_CONNECTIONS[@]}" >> /var/log/vpn_reset.log
27
28 for conn in "${TOTAL_CONNECTIONS[@]}"; do
29 $IPSEC down "$conn"
30 $IPSEC up "$conn"
31 done
32fi
33