Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / pppd / scripts / poff
blob659bfa7f8000291880e25bce4b6f791c945f78e8
1 #!/bin/sh
3 # $Id: poff,v 1.1 2002/11/24 23:30:44 etbe Exp $
4 # Written by John Hasler <john@dhh.gt.org> and based on work
5 # by Phil Hands <phil@hands.com>. Distributed under the GNU GPL
7 if [ -x /usr/bin/kill ]; then
8 KILL="/usr/bin/kill"
9 else
10 KILL="/bin/kill"
12 SIG=TERM
13 DONE="stopped"
14 MODE=""
16 usage ()
18 cat <<!EOF!
19 usage: $0 [option] [provider]
20 options:
21 -r Cause pppd to drop the line and redial.
22 -d Toggle the state of pppd's debug option.
23 -c Cause pppd to renegotiate compression.
24 -a Stop all pppd's. 'provider' will be ignored.
25 -h Print this help summary and exit.
26 -v Print version and exit.
27 none Stop pppd.
29 Options may not be combined.
31 If 'provider' is omitted pppd will be stopped or signalled if and only if
32 there is exactly one running unless the '-a' option was given. If
33 'provider' is supplied the pppd controlling the connection to that
34 provider will be stopped or signalled.
35 !EOF!
38 # Get option. If there are none replace the "?" that getopts puts in
39 # FLAG on error with "null".
40 getopts rdcavh FLAG
41 if [ "$?" -ne 0 ]; then
42 FLAG="null"
45 # Check for additional options. Should be none.
46 getopts :rdcavh DUMMY
47 if [ "$?" -eq 0 ]; then
48 echo "$0: Illegal option -- ${OPTARG}."
49 exit 1
52 case $FLAG in
53 "r") SIG=HUP; DONE=signalled; shift ;;
54 "d") SIG=USR1; DONE=signalled; shift ;;
55 "c") SIG=USR2; DONE=signalled; shift ;;
56 "a") MODE="all"; shift ;;
57 "v") echo "$0$Revision: 1.1 $_TrickToPrint_RCS_Revision"; exit 0 ;;
58 "h") usage; exit 0 ;;
59 "?") exit 1;
60 esac
62 # Get the PIDs of all the pppds running. Could also get these from
63 # /var/run, but pppd doesn't create .pid files until ppp is up.
64 PIDS=`pidof pppd`
66 # poff is pointless if pppd isn't running.
67 if test -z "$PIDS"; then
68 echo "$0: No pppd is running. None ${DONE}."
69 exit 1
72 # Find out how many pppd's are running.
73 N=`echo "$PIDS" | wc -w`
75 # If there are no arguments we can't do anything if there is more than one
76 # pppd running.
77 if test "$#" -eq 0 -a "$N" -gt 1 -a $FLAG != "a" ; then
78 echo "$0: More than one pppd running and no "-a" option and
79 no arguments supplied. Nothing ${DONE}."
80 exit 1
83 # If either there are no arguments or '-a' was specified kill all the
84 # pppd's.
85 if test "$#" -eq 0 -o "$MODE" = "all" ; then
86 $KILL -$SIG $PIDS || {
87 echo "$0: $KILL failed. None ${DONE}."
88 exit 1
90 exit 0
93 # There is an argument, so kill the pppd started on that provider.
94 PID=`ps axw | grep "[ /]pppd call $1 *\$" | awk '{print $1}'`
95 if test -n "$PID" ; then
96 $KILL -$SIG $PID || {
97 echo "$0: $KILL failed. None ${DONE}."
98 exit 1
100 else
101 echo "$0: I could not find a pppd process for provider '$1'. None ${DONE}."
102 exit 1
104 exit 0