#!/bin/sh - ################################################# ## ## ## Silly little script to connect an Indy ## ## to a dynamically-addressing modem pool. ## ## ## ## By: Bri Hatch, bri@ifokr.org ## ## ## ## Released under the GPL ## ## ## ## Last updated on 9/01/95 ## ## ## ################################################# force="no" mach="lucky" success_string="Your IP address" failure_string="NoSUCHString" default_route="129.105.9.0" netmask="255.255.255.0" BLIP_BLURB="/usr/local/lib/blip.blurb" BLIP="/usr/local/bin/blip" CONFILE="/tmp/blip.connections" TMPFILE="/tmp/connections.out" MACHINEFILE="/var/tmp/blip.machine" # All connections show something distinctive. For me it's acns or ais. CON_STRING="ais|acns" umask 077 command=$1 IPADD=$2 chk () { rm -f $CONFILE 2> /dev/null # Put netstat output into $CONFILE netstat -f inet | grep tcp | egrep "$CON_STRING" \ | awk '{ print $4 " " $5 " " $6}' > $CONFILE ; } Check () { # Set blip.connections file chk connections=`wc $CONFILE| awk '{print $1 }'` if [ "$connections" = "0" ] then echo "\nNo Live Connections\n" > $CONFILE fi if [ $interactive = "no" ] then cat $CONFILE else xconfirm -c -name Connections -file $CONFILE \ > /dev/null fi unset iconic; } Connect () { # Remove trash files, and /tmp/.slip files /bin/rm -f $TMPFILE /tmp/.slip* # Check for active connections ps -ef | egrep -v "egrep" | egrep -s "/usr/etc/slip" # If no active connections: if [ $? -ne 0 ] then /usr/etc/slip -dd -cp cslip -m $netmask -u $mach 1>/dev/null \ 2>&1 & slippid=$! datestring=`date|awk '{print $2 "[ ]*" $3}'` # Wait for huge-ass Banner to go by. Don't waste my time. sleep 9 while # Got connected one way or other egrep "$failure_string|$success_string" /var/adm/SYSLOG | \ egrep "slip\[$slippid\]" | egrep "$datestring" > $TMPFILE [ $? = "1" -o $? = "2" ] do sleep 2 done egrep "$success_string" $TMPFILE | egrep $slippid | \ egrep -s "$datestring" # It made a successful connection, and all is well if [ $? = "0" ] # This will take tweeking depending on the output of your specific server. # I get a string that says "Your IP address is 129.105.9.XXX # Where XXX is the only differing portion, so I only need the last number. # Your mileage will vary. then node=`egrep "Your IP address" $TMPFILE \ | awk -F. '{ print $5 }'` exec $BLIP config 129.105.9.$node # It didn't, due to busy signal, line noise, etc... else $BLIP disconn exec $BLIP conn fi # Nope - a connection is still alive. else if [ $interactive = "yes" ] then trash=`xconfirm -c -name "Connect" -t \ "Current connection active" -t "" -t \ "Please hang up any live connections first"\ -t "" -B "Continue"` else exec echo "Current connection active." fi fi unset iconic ; } Configure () { # Make our machine masquerade as the IP we recieved. # Again, this is what I need, change the 129.105.9.$node to whatever you need, # In coordination with the grepping above, etc... /usr/etc/ifconfig sl0 $IPADD netmask $netmask # remove any old default route, add the current one. # You may or may not want these lines. # remove=`netstat -r | grep default | awk '{print $1 " " $2}'` # su - root -c "/usr/etc/route delete $remove" su - root -c "/usr/etc/route add net default $default_route 1 " # My personal additions for NU configuration. See the documentation at # http://www.ais.net/bri/blip/bri's-mods.html to learn what they # do before un-commenting these. # Determine the lucky/aragorn/elvex terminal we are attached to and fix the # sendmail.cf to recognize it. # machine=`nslookup $IPADD|grep Name|awk '{ print $IPADD }'` # echo $machine > $MACHINEFILE # chmod 644 $MACHINEFILE # /bin/rm -f /etc/sendmail.cf # ( cat /etc/sendmail.cf.top ; echo \ # 'R$*<@'$machine'>$*'\\t'$@$1<@@$j>$2'; \ # cat /etc/sendmail.cf.bot ) > /etc/sendmail.cf # su - root -c "/etc/init.d/mail start" # keepalive & # announce $machine # echo "readdress kami $machine 129.0.0.0" > $HOME/.ytalkrc ; } Minimize () { iconic="-iconic" ; } killit () { killall keepalive killall -INT slip & killall -9 slip rm -f /tmp/.slip*; } Hangup () { chk connections=`wc $TMPFILE| awk '{print $1}'` # If no connections, or we're sure we want to kill it anyway if [ "$connections" = "0" -o $force = "yes" ] then killit # We found connections still active, and aren't forcing a hang up. # What should we do? else /bin/rm -f $TMPFILE # Set up output file echo "The Following Connections are still active:\n" \ > $TMPFILE cat $CONFILE >> $TMPFILE echo "\nKill Connection anyway?" >> $TMPFILE if [ $interactive = "no" ] then cat $TMPFILE read cont else cont=`xconfirm -c -B "Nope" -b "Hangup" -file \ $TMPFILE -header \ "Really Hang Up???"` fi # We're abso-smurfly sure we want to kill the connection if [ "$cont" = "yes" -o $cont = "Hangup" ] then killit fi fi unset iconic ; } Quit () { exit 0 ; } # Main code schtuff # If somethin' specified on the command line. if [ $command ] then interactive="no" case $command in check|chk) command=Check;; conn|connect) command=Connect;; disconnect|disconn|hangup|hang) command=Hangup;; DISCONNECT|DISCONN|HANGUP|HANG) force="yes" command=Hangup;; config|configure) command=Configure;; esac $command # Command line blip supports only one command at a time. Exit. exit 0 fi interactive="yes" # Repeat until the cows come home. while [ true ] do command=`xconfirm -header "BLIP" -file $BLIP_BLURB -c $iconic \ -font '-*-utopia-medium-r-normal--17-*-*-*-p-91-iso8859-1' \ -B "Check" -b "Connect" -b "Hangup" -b "Minimize" -b "Quit"` $command done