#!/bin/bash
#
# /etc/ppp/service/blocker
#
# Purpose : just a small inspiration, on how to keep your telephone bill
#           a bit under control. Usefull, for restricting someones 
#           online time (read : force your children/husband offline at 
#           bedtime ;> ).

#
# Start of configuration block (you mainly want to change TIME and LUCKYONES)
#

# Just add here the time, when at should terminate the link. NOTE :
# /etc/ppp/service/blocker will shut down the link without mercy. This
# means it won't won't pay any attention to the fact, that your 
# <add a number> MB download is finished 99% by that time.
#
# Also remember, that you (read : root) have to delete the lockfile 
# manually, when you want your users to be able to dial out again.
#
# read the manpage of at(1), to find out, what you can enter for $TIME.

TIME="now + 2 hours"

# Add here the users, who get spared by this script. This is a white-
# space separeted list of loginnames.

LUCKYONES="root patrick"

# Which message would you like to be in the lockfile ? /etc/ppp/ppp
# will print the contents of this file (if present) and then exit
# without trying to dial (of course, you have to delete the lockfile,
# if you want to dial out again).

REASON="\nSorry $LOGNAME, you are no longer allowed to dial out. Please \
ask an\nadministrator, to remove the file :\n\
\n/var/lock/internet/block-ppp.$LOGNAME\n"

# Tell LUCKYONES, that their onlinetime is not restricted

LUCKY="Hello $LOGNAME, you're in my list of lucky users,\n\
therefore you are granted unlimited online time."

# Tell the users, not in $LUCKYONES, that their online time is restricted

NOTLUCKY="Hello $LOGNAME, sorry I can't find your name in my list of lucky \
users, therefore your online time has been restricted. I will shut the link \
down at : \n\n\
$TIME \n\nso be sure, to be finished by then."

#
# End of configuration block, hopefully, you don't need to change anything 
# below
#


TESTGUYS=`/bin/echo $LUCKYONES | /usr/bin/grep $LOGNAME`
if [ "$TESTGUYS" = "$LUCKYONES" ]; then
  /bin/echo $LUCKY
  exit 0
fi

# If someone has an idea of how to mute at, please drop me a line
/bin/echo /etc/ppp/ppp stop | /usr/bin/at $TIME
/bin/echo $NOTLUCKY
/bin/echo $REASON > /var/lock/internet/block-ppp.$LOGNAME
