#!/bin/sh
# $OpenBSD: pptp_reconnect,v 1.2 2001/04/12 14:27:12 reinhard Exp $ 
#
# PPTP reconnect script
#
# sample crontab entry: 
# 0,30 * * * * /sbin/ping -c 2 MY_REMOTE_PEER_IP >/dev/null || /usr/local/sbin/pptp-reconnect
#
#
# INSTALL-INSTRUCTIONS: edit following IP and uncomment the line
#MODEMIP=10.0.0.138
 
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin

if [ "$MODEMIP" = "" ]; then
	echo "You have to edit the pptp-reconnect script."
	exit
fi

echo "Killing pppd."
kill -9 `ps -ax|grep pppd|grep -v grep|awk '{print $1}'`
/bin/sleep 3

echo "Killing pptp."
kill -9	`ps -ax|grep pptp|grep -v pptp-reconnect|grep -v grep|awk '{print $1}'`
/bin/sleep 3

if [ -S /var/run/pptp/$MODEMIP ]; then
	/bin/rm -f /var/run/pptp/$MODEMIP
fi

echo "Establishing connection."
echo "=========================================================" >> /var/log/ppp.log 
echo "Establishing connection at `date`." >> /var/log/ppp.log 
/usr/local/sbin/pptp $MODEMIP >> /var/log/ppp.log 2>&1
/bin/sleep 7

echo "Flushing rulesets:"
/sbin/ipf -Fa -f /etc/ipf.rules
/sbin/ipnat -CF -f /etc/ipnat.rules
