0
     ˆ¿Ã„€ëÀÆ /+    #! /bin/bash
#
# ifup-ippp
# 
# This script is normally called from the ifup script when it detects a ippp device. 

. /etc/init.d/functions

cd /etc/sysconfig/network-scripts
. ./network-functions

# Get global network configuration
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network

GATEWAY=""

# set device
CONFIG=$1
[ -f "${CONFIG}" ] || CONFIG=ifcfg-${1}
source_config

if [ "${2}" = "boot" -a "${ONBOOT}" = "no" ]; then
    exit
fi

if [ ! -f /var/lock/subsys/isdn ] && [ -x /etc/init.d/isdn ] ; then
    /etc/init.d/isdn start
fi

# check that ipppd is available for syncppp 
if [ "$ENCAP" = "syncppp" ]; then
    if [ ! -x /sbin/ipppd ] && [ ! -x /usr/sbin/ipppd ] ; then
        /usr/bin/logger -p daemon.info -t ifup-ippp "ipppd does not exist or is not executable"
        exit 1
    fi
fi

# check that isdnctrl is available
if [ ! -x /sbin/isdnctrl ] && [ ! -x /usr/sbin/isdnctrl ] ; then
    /usr/bin/logger -p daemon.info -t ifup-ippp "isdnctrl does not exist or is not executable"
    exit 1
fi

# check all ISDN devices
if ! isdnctrl list all >/dev/null 2>&1 ; then
    /usr/bin/logger -p daemon.info -t ifup-ippp "cannot list ISDN devices"
    exit 1
fi

# check if device already is configured
isdnctrl list $DEVICE >/dev/null 2>&1 && exit 0

function log_echo()
{
    /usr/bin/logger -p daemon.info -t ifup-ippp $"$*"
}

function log_isdnctrl()
{
    /usr/bin/logger -p daemon.info -t ifup-ippp isdnctrl $*
    isdnctrl $* >/dev/null 2>&1 || exit 1
}

function create_option_file()
{
    umask 066
    echo "$1" > /etc/ppp/ioption-secret-$DEVICE
    umask 022
}

function start_ibod()
{
    # don't start ibod, if it's running
    [ -f /var/lock/subsys/ibod ] && return

    device=$1
    if [ -f /etc/isdn/ibod.cf ] && [ -x /usr/sbin/ibod ] ; then
        ibod $device &
        pid=$(pidof ibod)
        [ -n "$pid" ] && touch /var/lock/subsys/ibod
    fi
}

function addprovider()
{
    options=
    if [ -z "$PHONE_OUT" ]; then
        log_echo "Error: $1: no outgoing phone number set"
        return 1
    fi

    # set the encapsulation mode
    [ -z "$ENCAP" ] && ENCAP="syncppp"

    # set the dial mode
    [ -z "$DIALMODE" ] && DIALMODE="off"

    [ "$AUTH" = "none" -o "$AUTH" = "noauth" -o -z "$AUTH" ] && AUTH="-pap -chap"

    # set layer-2/3 protocol 
    [ -z "$L2_PROT" ] && L2_PROT="hdlc"
    [ -z "$L3_PROT" ] && L3_PROT="trans"

    # check local/remote IP
    [ -z "$IPADDR" ] && IPADDR="0.0.0.0"
    [ -z "$GATEWAY" ] && GATEWAY="0.0.0.0"

    # set default route
    [ "$DEFROUTE" = "yes" ] && options="$options defaultroute deldefaultroute"

    # set authentication
    _auth=$(echo "$AUTH" | sed 's/[a-z -]*//g')
    if [ -n "$_auth" ]; then
        if [ -z "$USER" -a "$DIALIN" != "on" ]; then
            log_echo " Error: $1 (syncppp) user is not set"
            return 1
        fi
        if [ "$DIALIN" != "on" ]; then
            # we should hide the user name, so i add user name to option file.
            if [ "$AUTH" = "-pap +chap" ]; then
                create_option_file "name \"$USER\""
            else
                create_option_file "user \"$USER\""
            fi
            options="$options file /etc/ppp/ioption-secret-$DEVICE"
        fi

        # authentication options:
        # +pap and/or +chap does not work correct by dialout - remove
        # them if it's configured as dialout
        [ "$DIALIN" = "on" ] || AUTH=$(echo "$AUTH" | sed 's/+[a-z]*//g')
    fi

    # add ISDN device 
    log_isdnctrl addif $DEVICE

    # set local MSN
    [ -z "$MSN" ]  || log_isdnctrl eaz $DEVICE $MSN

    # set dialout numbers
    if echo $COUNTRYCODE | grep ":" >/dev/null 2>&1 ; then
        COUNTRYCODE="$(echo $COUNTRYCODE | cut -f 2 -d ':')"
        [ "$COUNTRYCODE" = "0" ] && COUNTRYCODE=
    else
        COUNTRYCODE=
    fi
    for i in $PHONE_OUT; do
        log_isdnctrl addphone $DEVICE out $COUNTRYCODE$PREFIX$AREACODE$i
    done
    for i in $PHONE_IN; do
        log_isdnctrl addphone $DEVICE in $i
    done

    # set layer-2/3 protocol
    log_isdnctrl l2_prot $DEV