diff --git a/pptp/autostart.sh b/pptp/autostart.sh new file mode 100644 index 0000000..a55811f --- /dev/null +++ b/pptp/autostart.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $DIR/env.sh + +if [[ "$EUID" -ne 0 ]]; then + echo "Sorry, you need to run this as root" + exit 1 +fi + +TMPFILE=$(mktemp crontab.XXXXX) +crontab -l > $TMPFILE + +RESTOREPATH=$(which iptables-restore) +RESTORPRESENTS=$(grep iptables-restore $TMPFILE) +if [ $? -ne 0 ]; then + echo "@reboot $RESTOREPATH <$IPTABLES >/dev/null 2>&1" >> $TMPFILE +fi + +PPTPDPRESENTS=$(grep "$CHECKSERVER" $TMPFILE) +if [ $? -ne 0 ]; then + echo "*/5 * * * * $CHECKSERVER >/dev/null 2>&1" >> $TMPFILE +fi + +crontab $TMPFILE > /dev/null +rm $TMPFILE diff --git a/pptp/checkserver.sh b/pptp/checkserver.sh new file mode 100644 index 0000000..cf36582 --- /dev/null +++ b/pptp/checkserver.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +RET=$(pgrep pptpd) + +if [ $? -eq 1 ]; then + /etc/init.d/pptpd restart +fi diff --git a/pptp/env.sh b/pptp/env.sh index 3f2e5e8..aa13dd6 100755 --- a/pptp/env.sh +++ b/pptp/env.sh @@ -6,6 +6,7 @@ PPTPOPTIONS=/etc/ppp/options.pptp CHAPSECRETS=/etc/ppp/chap-secrets IPTABLES=/etc/iptables.rules RCLOCAL=/etc/rc.local +CHECKSERVER=/etc/ppp/checkserver.sh LOCALPREFIX="172.16" LOCALIP="$LOCALPREFIX.0.0" diff --git a/pptp/install.sh b/pptp/install.sh index 6a343ba..1147995 100755 --- a/pptp/install.sh +++ b/pptp/install.sh @@ -10,7 +10,7 @@ fi echo echo "Installing PPTP server..." -apt-get install pptpd +apt-get install pptpd cron ADDUSER="no" ANSUSER="yes" @@ -45,9 +45,13 @@ echo echo "Configuring DNS parameters..." $DIR/dns.sh +echo +echo "Adding cron jobs..." +yes | cp -rf $DIR/checkserver.sh $CHECKSERVER +$DIR/autostart.sh + echo echo "Starting pptpd..." -systemctl enable pptpd service pptpd restart echo diff --git a/pptp/iptables-setup.sh b/pptp/iptables-setup.sh index 063bc06..abc9be8 100755 --- a/pptp/iptables-setup.sh +++ b/pptp/iptables-setup.sh @@ -75,25 +75,5 @@ iptables -A INPUT -p 47 -j ACCEPT iptables -A OUTPUT -p 47 -j ACCEPT iptables-save | awk '($0 !~ /^-A/)||!($0 in a) {a[$0];print}' > $IPTABLES - -IPTABLESRESTOR=$(which iptables-restore) -RESTORPRESENTS=$(grep iptables-restore $RCLOCAL) -if [ $? -ne 0 ]; then - if [[ ! -z $IPTABLESRESTOR ]]; then - sed -i -e "/exit 0/d" $RCLOCAL - echo "$IPTABLESRESTOR < $IPTABLES" >> $RCLOCAL - echo "exit 0" >> $RCLOCAL - else - echo "Cannot save iptables-restore from $IPTABLES to $RCLOCAL." - fi -fi - -RESTORPRESENTS=$(grep iptables-restore $RCLOCAL) -if [ $? -ne 0 ]; then - sed -i -e "/exit 0/d" $RCLOCAL - echo "iptables-restore < $IPTABLES" >> $RCLOCAL - echo "exit 0" >> $RCLOCAL -fi - iptables -F iptables-restore < $IPTABLES