# /etc/functions-internet # functions to support dialup tasks source /etc/functions-colors Exit_Script () { if [ "$1" = "" ] ; then echo -e "${BOLDYELLOW}Exiting this script.${COLOR_RESET}" else echo -e "${BOLDYELLOW}Exiting the ${BOLDGREEN}$1${BOLDYELLOW} script.${COLOR_RESET}" fi echo exit 1 } Get_Input_File_Name () { # modify this function as necessary for your bookmarks file # INPUTFILE=/location/to/bookmarks.htm INPUTFILE="/mnt/nt_o/Firefox_Shared/Bookmarks/bookmarks.htm" if [ ! -e $INPUTFILE ] ; then # last resort INPUTFILE="`find $HOME/.mozilla -name bookmarks.htm`" fi echo if [ "$INPUTFILE" != "" ] && [ -r $INPUTFILE ] ; then echo -e "Using ${BOLDGREEN}$INPUTFILE${COLOR_RESET} as the input file." echo "$INPUTFILE is readable." echo else echo -e "${BOLDRED}Can't find the bookmarks input file.${COLOR_RESET}" Exit_Script fi } Hang_Up () { # Wait until the ppp daemon stops and then stop everything else. # If the user manually stops kppp, then kppp will stop the ppp daemon # and this script continues as below. However, we watch the # ppd daemon rather than kppp because a user might log out and # that would close the kppp dialer but leave pppd running. # Another user might log on and there is no reason to hang up the modem. # The new user then runs this script and all is well. # If a user logs out without manually stopping kppp then everything will # stop anyway except the ntpd and the pppd. If the last user shuts # down the box then both of those services are stopped from the shutdown scripts. # The following is merely an idling loop watching the ppp daemon. if [ "$PPPD_PID" = "dummy_text" ] ; then # we must be accessing the web through a LAN gateway. PPP daemon is not # running. We watch a different program that is running. WATCH_PID="$ETHAPP" else WATCH_PID="pppd" fi MONITOR_PID=`/sbin/pidof $WATCH_PID` while [ "$MONITOR_PID" != "" ] ; do MONITOR_PID=`/sbin/pidof $WATCH_PID` sleep 2 done echo echo -e "${BOLDRED}The network connection no longer is running.${COLOR_RESET}" echo "Shutting down the dial-up connection." # provide the shutdown sequence in another script in case a user wants # to perform shutdown tasks manually. /usr/local/bin/dialup_exit } No_Connection () { echo -e "${BOLDRED}There seems to be a problem with connecting.${COLOR_RESET}" KPPP_PID=`/sbin/pidof kppp` while [ "$KPPP_PID" != "" ] ; do kppp -k sleep 1 KPPP_PID=`/sbin/pidof kppp` done Hang_Up echo exit 1 } Check_IP_Address () { # Are we online? No need to continue if not. if [ "$1" = "" ] ; then echo "Oops. No ifconfig parameter passed to the Check_IP_Address function." else echo -e "${BOLDWHITE}Looking for your IP address...${COLOR_RESET}" # is variable already set from elsewhere? if [ "$IPADDRESS" = "" ] ; then # assuming a dialup point-to-point connection, otherwise no need for this test IPADDRESS="`/sbin/ifconfig $1 | grep P-t-P | grep inet | awk '{print $2}' | sed 's/^addr://g'`" if [ "$IPADDRESS" = "" ] ; then # variable does not exist echo -e "${BOLDRED}Can't find the IPADDRESS environment variable.${COLOR_RESET}" ifconfig -a Exit_Script else echo -e "${BOLDWHITE}Your IP address:${COLOR_RESET} $IPADDRESS" export IPADDRESS fi fi fi } Ping_Test () { # randomly select a site to ping to test online connection # There is no DNS server if offline. If the IP addresses are not listed in /etc/hosts # then ping responses could take 30 seconds or more. Place the actual IP # addresses of these URLs in the /etc/hosts file to avoid DNS lookup delays. # initialize variables NUMSITES=11 SITENUM=0 let "SITENUM=$RANDOM" # Scale $SITENUM down to within number of sites in array let "SITENUM %= $NUMSITES" PINGURL[0]="www.alltheweb.com" PINGURL[1]="www.altavista.com" PINGURL[2]="www.ask.com" PINGURL[3]="www.excite.com" PINGURL[4]="www.go.com" PINGURL[5]="www.google.com" PINGURL[6]="www.lycos.com" PINGURL[7]="www.metacrawler.com" PINGURL[8]="www.search.com" PINGURL[9]="www.webcrawler.com" PINGURL[10]="www.yahoo.com" TESTURL=${PINGURL[$SITENUM]} GOODPINGTEST="Ping test to ${BOLDGREEN}$TESTURL${COLOR_RESET} is okay." BADPINGTEST="Ping test to ${BOLDGREEN}$TESTURL${COLOR_RESET} failed." echo -e "${BOLDWHITE}Testing online status by pinging ${BOLDGREEN}$TESTURL${COLOR_RESET}." # Any test longer than two seconds probably is a DNS lookup problem. TIMEMARKER1=`date +%s` # ping once and wait one second ping -c 2 -W 2 $TESTURL &> /dev/null PINGERROR=`echo $?` TIMEMARKER2=`date +%s` if [ $(($TIMEMARKER2-$TIMEMARKER1)) -gt 2 ] ; then # let's quit right now echo "Response time was $(($TIMEMARKER2-$TIMEMARKER1)) seconds." echo "The delay time probably was caused by the DNS lookup." echo -e "You probably are not online or the IP address" echo -e " for ${BOLDGREEN}$TESTURL${COLOR_RESET} is not in the /etc/hosts file." echo -e $BADPINGTEST PINGTEST="FAILED" echo else echo -e "IP address for ${BOLDGREEN}$TESTURL${COLOR_RESET} found." #echo "IP address is either in the /etc/hosts file or you have access to a DNS server." #echo if [ "$PINGERROR" = "0" ] ; then echo -e $GOODPINGTEST PINGTEST="PASSED" else # no response, so try again but with more patience echo -e $BADPINGTEST echo echo -e "${BOLDYELLOW}No initial response--trying again.${COLOR_RESET}" ping -c 3 -W 3 $TESTURL PINGERROR=`echo $?` if [ "$PINGERROR" = "0" ] ; then echo -e $GOODPINGTEST PINGTEST="PASSED" else echo -e $BADPINGTEST PINGTEST="FAILED" echo fi fi fi export PINGTEST }