Hetz Ben Hamo wrote:

Hi,

I have a situation which is well known to people - your machine is connected (PPTP) to the net, but sometimes there's disconnection between your home and ISP, but the PPP0 interface stays up, which means you'll need to kill it and redial..

I have a small script which deals with the situation where the PPP0 interface is down, then it tries to connect until it connects, but my script doesn't handle the situation above..

So, I was thinking - has anyone written such a script? (for PPTP connection, not PPPOE) and willing to share it please?

Thanks,
Hetz


Hi,
I have such scripts, which I managed to write during the time (and based on other scripts which I found on the internet. - sorry, but i don't remember who should get the credit for them)

attached files are:
/etc/init.d/adsl
/etc/ppp/ip-up
/etc/ppp/ip-down

you will also need  a script:
/etc/ppp/firewall.sh
which will do all the firewall stuff (and nat if necessary)
all it needs to get as a parameter is the interface (usually ppp0)

Noam


#! /bin/sh
#
# adsl          Start/Stop ADSL link.
#
# chkconfig: 2345 15 85
# description: ADSL connection start/stop script.
# processname: pptp
# config: /etc/adsl.conf
# pidfile: /var/run/adsl.pid

# ADSL connection parameters
 /etc/adsl.conf

RETVAL=0

start () {
        echo -n "Starting ADSL connection: "
        # Remove our special sign file and leftover socket sometimes left behind by 
pptp call manager
        rm -f /tmp/adsl.is.stopping /var/run/pptp/"${ADSL_IP}"
        # Bring up the pptp & ppp
        if /usr/local/sbin/pptp "${ADSL_IP}" user "$USER_NAME" remotename "${ADSL_IP} 
RELAY_PPP1" defaultroute noauth 2>/dev/null; then
                RETVAL=$?
                echo "ADSL went up successfully..."
                touch /var/lock/subsys/adsl
        else 
                RETVAL=$?
        echo "ADSL didn't go up successfully..."
        fi
        # waitforconnect waits 2 minutes, and then tries to re-connect. It gets killed 
by ip-connect when the
        # link is properly brought up. This is a race condition here, in case ip-up is 
called BEFORE we get here,
        # but in reality I don't think it can happen that fast.
        $0 waitforconnect >/dev/null &
        echo
}


stop () {
        # this is a special sign for ip-down.local NOT to redial when the line is 
dropped.
        touch /tmp/adsl.is.stopping
        echo -n "Stopping ADSL connection: "
        killall -q -INT pppd
        killall -q -INT pptp
        sleep 5
        killall -q -INT pppd
        killall -q -INT pptp
        rm /var/run/pptp/${ADSL_IP}
        rm /var/run/ppp*
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/adsl
}


case "$1" in 
  start)
        start
        ;;
  stop)
        stop
        # we kill ourselves here, but kill 'adsl waitforconnect' too!
        killall -q adsl
        ;;
  restart)
        stop
        start
        RETVAL=$?
        ;;
  waitforconnect)
        # Save our pid so /etc/ppp/ip-up.local will be able to kill us
        echo $$ >/var/run/adsl-waitforconnect
        # We are going to re-try to reconnect every 2 minutes
        sleep 120
        stop
        start
        RETVAL=$?
        ;;
  *)
        echo "Usage: adsl {start|stop|restart}"
        exit 1
        ;;
esac

exit $RETVAL
#!/bin/sh

# Set up PATH
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

if [ -f /tmp/adsl.is.stopping ]; then
        logger -p local1.info -t adsl "Orderly disconnect"
else
        ERRMSG="Unexpected disconnect, trying to re-connect"
        logger -p local1.error -t adsl "$ERRMSG"
        echo "$ERRMSG" | mail root -s "ADSL log"
        /etc/init.d/adsl restart
fi

#!/bin/bash

# This script is executed when the  link  is  available for  sending and
# receiving IP packets (that is, IPCP has come up).
# It is executed with these parameters:
# interface-name tty-device speed local-IP-address  remote-IP-address ipparam

# Put the arguments from the command-line into vars.
IFNAME=${1}
TTYDEV=${2}
SPEED=${3}
LOCALIP=${4}
REMOTEIP=${5}
IPPARAM=${6}

# Make sure we have a good path.
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11"

# The reconnect waiting proccess file name.
WAITPROC="/var/run/adsl-waitforconnect"

logger -p local1.notice -t adsl "link established, local ip is: $LOCALIP"
ddclient -daemon=0 -syslog -use=if -if=${1} > /dev/null 2>&1
echo $LOCALIP | mail [EMAIL PROTECTED] -s "new ip"

# Kill the waiting process
kill -9 `cat $WAITPROC`
rm $WAITPROC

# Execute the firewall
if ! /etc/ppp/firewall.sh $IFNAME; then 
        # Something wrong happened. Log it.
        logger -p local1.crit -t adsl "Cannot configure firewall"
        echo "Cannot configure firewall" | mail root -s "ADSL critical log"
fi

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to