#!/bin/bash # #!F:isdn.dial # #!P:/usr/local/sbin # #!D:ISDN Dial trigger # #!C:Copyright 1997-1998 Peter Bieringer # #!V:Version 2.26 11.05.1998 # Changes to # 2.11: Deleting default route at stop is switched to delete all routes # through ISDN device to preserve automatic dial-up # 2.20: Changes for DLD 5.3, switching of resolver config files improved # 2.21: Named-config-changer # 2.22: Check online before hangup # 2.23: Info display, minor changes # 2.24: Now compatible to bind8 # 2.25: Displays BIND version # 2.26: 'Stop' independed from being online to presere auto-dial-up, undo of 2.22 # Also delete routes first, than hangup. # Script file to delete all IPv4 routes through a specified interface DELALLIP4ROUTES="/usr/local/sbin/delip4routes" ## Info for switching configuration files # Switching named enabled? NAMEDB_SWITCH=yes # Get path of named NAMEDPATH=`which named` # Get major version number of named (4 or 8) NAMEDMAJORVERSION=`strings $NAMEDPATH | grep "^@(#)named" | cut -d " " -f2 | cut -d "." -f1` # Switching resolver enabled? RESOLV_SWITCH=yes RESOLV_ONLINE=/etc/resolv.conf.online RESOLV_OFFLINE=/etc/resolv.conf HOST_SWITCH=yes HOST_ONLINE=/etc/host.conf.online HOST_OFFLINE=/etc/host.conf ## Functions # Display information info() { grep "^#!D" $0 | awk -F: '{ print $2}' grep "^#!C" $0 | awk -F: '{ print " " $2}' grep "^#!V" $0 | awk -F: '{ print " " $2}' echo } # Check online checkonline() { if imontty | grep -i "outgoing" >/dev/null ; then # Online return 0 else # Offline return 1 fi } showdialup() { echo -n " Dial-up info:" imontty | grep -i "outgoing" } ## Start info # Resource files if [ "$NAMEDMAJORVERSION" = "4" ]; then NAMEDB_ONLINE=/etc/namedb/named.boot.online NAMEDB_OFFLINE=/etc/namedb/named.boot NAMEDB_ROOT=/etc/named.boot echo " Running BIND is version 4" elif [ "$NAMEDMAJORVERSION" = "8" ]; then NAMEDB_ONLINE=/etc/namedb/named.conf.online NAMEDB_OFFLINE=/etc/namedb/named.conf NAMEDB_ROOT=/etc/named.conf echo " Running BIND is version 8" fi # Get options OPTION_DEBUG=`echo $* | grep "\ -d" >/dev/null && echo 1` OPTION_DEVICE=`echo $* | awk -F "-i " '{ print $2 }' | awk '{ print $1 }'` if [ "$OPTION_DEBUG" = "1" ]; then echo " You choosed the DEBUG option - no real isdnctrl is done!" fi # Source function library. [ -f /etc/init.d/functions ] || exit 0 . /etc/init.d/functions # Source networking configuration. [ -f /etc/sysconfig/network ] || exit 0 . /etc/sysconfig/network # Source daemon configuration. [ -f /etc/sysconfig/runservices ] || exit 0 . /etc/sysconfig/runservices # Check that networking is up. [ "$NETWORKING" = "yes" ] || exit 0 # Check that ISDN is up. [ "$ISDN" = "yes" -o "$ISDN" = "YES" ] || exit 0 # Source ISDN [ -f /etc/sysconfig/isdn ] || exit 0 . /etc/sysconfig/isdn [ -x /usr/sbin/isdnctrl ] || exit 0 # Check if ISDN is configured (isdn.init start) if ! [ -f /var/lock/subsys/isdn ] ; then echo -e "\aNo ISDN Is Configured And Initialized Well!" exit 1 fi # Choose Dial Device if [ "$OPTION_DEVICE" = "" ] ; then DIALDEVICE=$ISDNDEV else DIALDEVICE=$OPTION_DEVICE fi # Set dial tries ISDNDIALMAX=$DIALMAX # Reset in ipppd configuration if ! [ "$OPTION_DEBUG" = "1" ]; then isdnctrl dialmax ${ISDNDEV} 1 >/dev/null 2>&1 fi case "$1" in start) echo "Dial ISDN Device $DIALDEVICE" START=0 TRIES=0 DIALWAIT=10 # seconds echo -n " Dial Up With $ISDNDIALMAX Tries:" while ! [ $TRIES = $ISDNDIALMAX ] ; do # Trigger DialUp if ! [ "$OPTION_DEBUG" = "1" ]; then isdnctrl dial $DIALDEVICE fi echo -n " Wait $DIALWAIT seconds" TRIES=$[ TRIES + 1 ] WAIT=0 while ! [ $WAIT = $DIALWAIT ] ; do sleep 1 WAIT=$[ WAIT + 1 ] echo -n "." # Check if online if checkonline; then START=1 if [ $START = 1 ] ; then break; fi; fi; done if [ $START = 1 ] ; then break; fi; echo "[$TRIES/$ISDNDIALMAX]" done if ! [ $START = 1 ] ; then echo -e "\a Dial Up Without Success!" if ! [ "$OPTION_DEBUG" = "1" ]; then isdnctrl hangup $DIALDEVICE exit 1; fi fi; echo -e "\n Dial Up Succeeded!" if [ $DIALDEVICE = $ISDNDEV ] ; then echo " Set Default-Route to ISDN" route add default netmask 0.0.0.0 dev $DIALDEVICE # Change software link to another resolv.conf, # which has other DNS entries if [ -f $RESOLV_ONLINE -a "$RESOLV_SWITCH" = "yes" ]; then # Make backup of the existing file if [ -f /etc/resolv.conf ]; then mv /etc/resolv.conf /etc/resolv.conf.bak fi echo " Change 'resolv.conf' to PPP usage" # Create new link ln -f -s $RESOLV_ONLINE /etc/resolv.conf fi # Change software link to another host.conf, # which has other settings if [ -f $HOST_ONLINE -a "$HOST_SWITCH" = "yes" ]; then # Make backup of the existing file if [ -f /etc/host.conf ]; then mv /etc/host.conf /etc/host.conf.bak fi echo " Change 'host.conf' to PPP usage" # Create new link ln -f -s $HOST_ONLINE /etc/host.conf fi # Change software link to another named.boot, # which has other settings and reload named if [ "$NAMEDB_SWITCH" = "yes" ]; then if [ -f $NAMEDB_ONLINE ]; then # Make backup of the existing file if [ -f $NAMEDB_ROOT ]; then mv $NAMEDB_ROOT $NAMEDB_ROOT.bak1 fi echo " Change '$NAMEDB_ONLINE' to PPP usage" # Create new link ln -f -s $NAMEDB_ONLINE $NAMEDB_ROOT fi # Reload named echo " Reload BIND:" ndc reload fi fi showdialup echo "ISDN Device $DIALDEVICE Is Dialed Up" ;; stop) echo "Hang Up ISDN Device $DIALDEVICE" if [ $DIALDEVICE = $ISDNDEV ] ; then echo " Delete all routes to ISDN device" $DELALLIP4ROUTES $DIALDEVICE fi echo -n " Hangup:" # HangUp if ! [ "$OPTION_DEBUG" = "1" ]; then isdnctrl hangup $DIALDEVICE fi echo -e "\n" if [ $DIALDEVICE = $ISDNDEV ] ; then # Change software link to another resolv.conf, # which has other DNS entries if [ "$RESOLV_SWITCH" = "yes" ]; then if [ -f $RESOLV_OFFLINE -a ! "$RESOLV_OFFLINE" = "/etc/resolv.conf" ]; then echo " Change 'resolv.conf' to non-PPP usage" if [ -L /etc/resolv.conf ]; then # Create new link ln -f -s $RESOLV_OFFLINE /etc/resolv.conf fi else # Copy backup back if [ -f /etc/resolv.conf.bak ]; then rm /etc/resolv.conf cp /etc/resolv.conf.bak /etc/resolv.conf fi fi fi # Change software link to another host.conf, # which has other settings if [ "$HOST_SWITCH" = "yes" ]; then if [ -f $HOST_OFFLINE -a ! "$HOST_OFFLINE" = "/etc/host.conf" ]; then echo " Change 'host.conf' to non-PPP usage" if [ -L /etc/host.conf ]; then # Create new link ln -f -s $HOST_OFFLINE /etc/host.conf fi else # Copy backup back if [ -f /etc/host.conf.bak ]; then rm /etc/host.conf cp /etc/host.conf.bak /etc/host.conf fi fi fi # Change software link to another named.boot, # which has other settings if [ "$NAMEDB_SWITCH" = "yes" ]; then if [ -f $NAMEDB_OFFLINE ]; then # Make backup of the existing file if [ -f $NAMEDB_ROOT ]; then mv $NAMEDB_ROOT $NAMEDB_ROOT.bak2 fi echo " Change '$NAMEDB_ROOT' to non-PPP usage" # Create new link ln -f -s $NAMEDB_OFFLINE $NAMEDB_ROOT fi # Reload named echo " Reload BIND" ndc reload fi fi echo "ISDN Device $DIALDEVICE Is Hanged Up" ;; sleep) echo "Hang Up ISDN Device $DIALDEVICE, but route to ISDN is up (autodial)" # HangUp if ! [ "$OPTION_DEBUG" = "1" ]; then isdnctrl hangup $DIALDEVICE fi echo "ISDN Device $DIALDEVICE Is Sleeping" ;; *) echo "Syntax: isdn.dial {start|stop|sleep} <-i isdn-device> -d" exit 1 esac exit 0