#!/bin/bash ######################################################################## # filename: star69 # description: IRLP Script to play: # Last Call Waiting # Last Outgoing Call # Last Incoming Call # # NOTE: Once you have this script tested and working it is strongly # advises that you come back and delete all of the comment lines. # Comment lines are those that begin with the # symbol. # # NOTE: There is still a known bug in the last call waiting code # A fix to be released soon. # # This script is the playcwg script modified to add the last # incomming and outgoing calls. It will also announce how long # ago the call came in, within the hour or upto 8 hours ago. # Calls older than 8 hours are announced simply as over 8 hours # ago. Will play only when enabled and not in an active connection. # It will skip an announcement if no information can be found in # the logs. The optional callwaiting environment variable must be # setup in /home/irlp/custom/enviroment for the call waiting # feature to be enabled. The last callwaiting data is stored in # a the ram disk /home/irlp/local and will be lost upon a reboot. # # Most of the code has been copied from existing IRLP scripts. # # history: # 20020709 WA2DCI rev 1 # Added search for GSM connections # Added search for Reflector connections # Added new wav files and code to say "to" # # 20021117 WA2DCI rev 2 # Modified for 4 digit node numbers # # 20021118 KC6HUR rev 3 # Fixed 4-digit node handling # Fixed Date parsing # Streamlined some code sections to keep within # shell instead of calling out to other programs. # star69 now goes in $CUSTOM, the audio files go # in ${AUDIO}/custom/S69 # Fixed so only loads environment if needed and # does it instead of just complaining about it. # # 20030503 KC6HUR rev 4 # Now uses ${CUSTOM}/playwav to play the audio # files. # Removed the playing of the nodes ID file. # (I got tired of listening to the ID file # followed by the node number. Node numbers are # enough. If you want to hear the ID files, # change commenting of lines. # # 20030606 KC6HUR rev 5 # Fixed new log format parsing. Optimized the # mainline code. Removed the CALLERID files from # the speak routine. Now uses my playwav script # rather than the wavplay script. (Mine is more # efficient). Changed referrences for audio file # locations and placed the files in a subdirectory # of the $AUDIO directory. Now only uses fields # 1,2 and 4 to compute the date. If 3 was left in, # there needed to be a comma after field 2. This # mod was needed for RH 6.2 nodes, 7.3 nodes # handled the date OK. This new way is backwards # compatible. # # 20040125 KC6HUR rev 6 # Fixed problem arrising from Year rollover. # # 20040207 KC6HUR rev 7 # Fixed problem handling reflectors and echo # reflectors. Will now report 999x for the "echo" # reflector and the full 4-digit node number for # a reflector and it's channel number. # # 20040208 KC6HUR rev 8 # Fixed handling of last Call Waiting. star69 now # works with RH 6.2 - RH 9.0 # # 20070811 KC6HUR rev 9 # Fixed problem in handling dates. # ######################################################################## # Define Constants ################################################## S69AUD="custom/S69/" CALLWTG="${S69AUD}callwtg" CALLIN="${S69AUD}incomming" CALLOUT="${S69AUD}outgoing" WITHIN="${S69AUD}within_the" MORETHAN="${S69AUD}more_than" HOURS="${S69AUD}hours" HOUR="${S69AUD}hour" HOURAGO="${S69AUD}hour_ago" FROM="${S69AUD}from" TO="${S69AUD}to" # # By setting VERBOSE=1, a very detailed diagnostic printout is # generated. # VERBOSE=0 if [ ${VERBOSE} -eq "1" ] ; then ECHO="echo" else ECHO=":" fi # Common Routines ################################################### # Play the results # called by mainline code function speak () { # Convert difference in seconds to an integer in hours let DIFF=$DIFF/3600 # Select correct wav files upto 8 hours ago case $DIFF in 0) WAS=$WITHIN; HR=$HOUR; DIFF=1;; 1) WAS=$MORETHAN; HR=$HOURAGO;; 2|3|4|5|6|7|8) WAS=$MORETHAN; HR=$HOURS;; *) WAS=$MORETHAN; HR=$HOURS; DIFF=8;; esac # Parse node number TEMP=${CALLERID#*???} # Strip the stn/ref NUM1=${TEMP%???} # Get the 1st number TEMP=${CALLERID#*????} NUM2=${TEMP%??} # Get the 2nd number TEMP=${CALLERID#*?????} NUM3=${TEMP%?} # Get the 3rd number NUM4=${CALLERID#*??????} # Get the 4th number # Play the audio files ${PLAYER} $1 $WAS $DIFF $HR $2 nodenum $NUM1 $NUM2 $NUM3 $NUM4 } # Search the logfiles for connection records # called by mainline code searchlogs () { REFLECTOR="FALSE" # Find the last ADPCM entry findentry "$1 ADPCM" ADPCM=$LOGENTRY # Find the last GSM entry findentry "$1 GSM" GSM=$LOGENTRY # Do we have both entry types? if [ -n "$ADPCM" -a -n "$GSM" ] ; then # Find latest entry ADPCMTIME=`echo ${ADPCM} | cut -d " " -f 1,2` ADPCMTIME="${ADPCMTIME} `echo ${ADPCM} | cut -d " " -f 3,4`" GSMTIME=`echo ${GSM} | cut -d " " -f 1,2` GSMTIME="${GSMTIME} `echo ${GSM} | cut -d " " -f 3,4`" timediff "$ADPCMTIME" "$GSMTIME" if [ $DIFF -gt 0 ] ; then $ECHO "DIAG: Latest call was the ADPCM call" LOGENTRY=$ADPCM else $ECHO "DIAG: Latest call was the GSM call" LOGENTRY=$GSM fi else # the following two lines re commented out only used for debug # if [ -n "$ADPCM" ] ; then LOGENTRY=$ADPCM ; echo "ADPCM" ; fi # if [ -n "$GSM" ] ; then LOGENTRY=$GSM ; echo "GSM" ; fi if [ -n "$ADPCM" ] ; then LOGENTRY=$ADPCM ; fi if [ -n "$GSM" ] ; then LOGENTRY=$GSM ; fi fi # If outgoing then search for a reflector call if [ $1 = "connectok" ] ; then # Save node entry found CALLENTRY=$LOGENTRY CALLTIME=`echo ${CALLENTRY} | cut -d " " -f 1,2` CALLTIME="${CALLTIME} `echo ${CALLENTRY} | cut -d " " -f 3,4`" findentry "Connected to reflector" if [ -n "$LOGENTRY" ] ; then $ECHO "DIAG: Check if reflector most recent call..." LOGTIME=`echo ${LOGENTRY} | cut -d " " -f 1,2` LOGTIME="${LOGTIME} `echo ${LOGENTRY} | cut -d " " -f 3,4`" timediff "$LOGTIME" "$CALLTIME" if [ $DIFF -lt 0 ] ; then $ECHO "DIAG: Reflector was not the most recent call" call_time "$CALLENTRY" else $ECHO "DIAG: Reflector was most recent call" REFLECTOR="TRUE" call_time "$LOGENTRY" fi else # Outgoing no reflector calls found call_time "$CALLENTRY" fi else # Incoming call call_time "$LOGENTRY" fi } # Find a particular type of log entry # called by searchlogs () findentry () { # Find last entry $ECHO "DIAG: searching ${LOG}/messages..." LOGENTRY="" LOGENTRY=`grep "$1" ${LOG}/messages | tail -1` # Not found, search prior month (usually only after rotate logs) if [ -z "${LOGENTRY}" ] ; then if [ -f ${LOG}/messages.1 ] ; then $ECHO "DIAG: searching ${LOG}/messages.1..." LOGENTRY=`grep "$1" ${LOG}/messages.1 | tail -1` fi fi $ECHO "DIAG: LOGENTRY = ${LOGENTRY}" } # Calculate differnce in seconds (spans a month or year change) # called by mainline code and searchlogs () timediff () { # Convert input date/times to timestamps TIMESTAMP1=`date -d "$1" --iso-8601="seconds" +%s` TIMESTAMP2=`date -d "$2" --iso-8601="seconds" +%s` $ECHO "DIAG: TIMESTAMP1 = $1 ($TIMESTAMP1 seconds)" $ECHO "DIAG: TIMESTAMP2 = $2 ($TIMESTAMP2 seconds)" # Calculate difference in seconds let DIFF=$TIMESTAMP1-$TIMESTAMP2 $ECHO "DIAG: timediff = $DIFF seconds" } # Extract ID and Time # called by searchlogs call_time () { if [ $REFLECTOR = "TRUE" ] ; then # Because of the bullshit of calling the echo reflector "echo" # instead of a node number AND for calling reflector, reflectors # with a channel number instead of just a node number, we have # go through all sorts of BS to reconstitute a node number for # outbound. CALLERID=`echo "$1" | cut -d " " -f 10` if [ ${CALLERID} == "echo" ] ; then CALLERID=ref9990 # Change "echo" to "ref9990" fi # Add the channel number back into the reflector base CALLERID=${CALLERID%?}`echo "$1" | cut -d " " -f 13` else CALLERID=`echo "$1" | cut -d " " -f 6` fi if [ ${#CALLERID} = "6" ] ; then CALLERID=${CALLERID}0 fi LOGTIME=`echo "$1" | cut -d " " -f 1,2` LOGTIME="${LOGTIME}, `echo "$1" | cut -d " " -f 3,4`" $ECHO "DIAG: NODE=$CALLERID TIME=$LOGTIME" } # Begin Mailine Code ############################################### # # Load common functions # [ -z "$CUSTOM" ] && CUSTOM=/home/irlp/custom source ${CUSTOM}/irlp_common.sh # Get parm 0=play 1-3=call if [ "$1" = "" ] ; then PARM="0" else PARM="$1" fi # Figure out which player to user if [ -f ${CUSTOM}/playwav ] ; then PLAYER="${CUSTOM}/playwav" else echo "Don't like the carrier dropping between messages?" echo "Get playwav from http://irlp.kc6hur.net/irlp_scripts/" PLAYER="${SCRIPT}/wavplay" fi if [ ! -f "$LOCAL"/enable -o -f "$LOCAL"/active ] ; then exit 1 fi # COS & PTT Test - wait for COS unkey while [ TRUE ] ; do if ${BIN}/cosstate ; then if ${BIN}/pttstate ; then break fi fi usleep 5000 done ${BIN}/key usleep ${TXDELAY:-500000} # Default .5 second CURTIME=`date +"%b %d %Y %T"` $ECHO "DIAG: CURTIME = $CURTIME" # Last Call Waiting if [ $PARM = "0" -o $PARM = "1" -o $PARM = "4" ] ; then $ECHO "DIAG: ========================================" $ECHO "DIAG: processing Last Call Waiting..." findentry "Call Waiting" CWREC=$LOGENTRY if [ -n "$CWREC" ] ; then CALLERID=`echo ${CWREC} | cut -d " " -f 8` # 4-digit fix 11/18/02 if [ ${#CALLERID} = "6" ] ; then CALLERID=${CALLERID}0 fi if [ $PARM = "0" -o $PARM = "4" ] ; then CWTIME=`echo ${CWREC} | cut -d " " -f 1,2` CWTIME="${CWTIME} `echo ${CWREC} | cut -d " " -f 3,4`" timediff "$CURTIME" "$CWTIME" speak $CALLWTG $FROM else call $CALLERID exit 0 fi fi fi # Last Incomming Call if [ $PARM = "0" -o $PARM = "2" -o $PARM = "5" ] ; then $ECHO "DIAG: ========================================" $ECHO "DIAG: processing Last Incomming Call..." searchlogs "connect" if [ $CALLERID ] ; then if [ $PARM = "0" -o $PARM = "5" ] ; then timediff "$CURTIME" "$LOGTIME" speak $CALLIN $FROM else call $CALLERID exit 0 fi else $ECHO "DIAG: No incomming calls found!" fi fi # Last Outgoing Call if [ $PARM = "0" -o $PARM = "3" -o $PARM = "6" ] ; then $ECHO "DIAG: ========================================" $ECHO "DIAG: processing Last Outgoing Call..." searchlogs "connectok" if [ $CALLERID ] ; then if [ $PARM = "0" -o $PARM = "6" ] ; then timediff "$CURTIME" "$LOGTIME" speak $CALLOUT $TO else if [ $REFLECTOR = "TRUE" ] ; then connect_to_reflector $CALLERID else call $CALLERID exit 0 fi fi fi fi usleep 500000 ${BIN}/unkey exit 0