#! /bin/sh
#$Id:
faxrcvd.sh,v 1.1.1.1 1998/10/12 20:47:48 root Exp $
#
# HylaFAX Facsimile Software
#
# Copyright (c) 1990-1996 Sam Leffler
# Copyright (c) 1991-1996 Silicon Graphics, Inc.
# HylaFAX is a trademark of Silicon Graphics
#
# Permission to use, copy, modify, distribute, and sell this software and
# its documentation for any purpose is hereby granted without fee,
provided
# that (i) the above copyright notices and this permission notice appear
in
# all copies of the software and related documentation, and (ii) the
names of
# Sam Leffler and Silicon Graphics may not be used in any advertising
or
# publicity relating to the software without the specific, prior
written
# permission of Sam Leffler and Silicon Graphics.
#
# THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY
KIND,
# EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
# WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
#
# IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
# ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
KIND,
# OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS,
# WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY
OF
# LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
# OF THIS SOFTWARE.
#
#
#
#######################################
# LEAVE THIS AT TOP OF THE FILE!!!
# Automatically Print to the CUPS printing system to the printer
PrinterPG
# There is a weekly CRON job defined to cleanup the print queue
jobs
###/usr/bin/tiff2ps -a1 $1 | /usr/bin/lpr -PHaywardFax
# HAD TO ADD FLAGS TO SET WIDTH AND HEIGHT OF IMAGES
# OTHERWISE SOME FAXES DIDN"T PRINT PROPERLY and the TSID header
info
# wouldn't print out. Laser printers have a maximum printable area
and
# some sender's faxes are set to A4 paper size!!!
/usr/bin/tiff2ps -a -1 -h10.675 -w8.25 $1 | /usr/bin/lpr -PHaywardFax
#######################################
# faxrcvd file devID commID error-msg
#
if [ $# != 4 ]; then
echo "Usage: $0 file devID commID
error-msg"
exit 1
fi
test -f etc/setup.cache || {
SPOOL=`pwd`
cat<<EOF
FATAL ERROR: $SPOOL/etc/setup.cache is missing!
The file $SPOOL/etc/setup.cache is not present. This
probably means the machine has not been setup using the
faxsetup(1M)
command. Read the documentation on setting up HylaFAX before
you
startup a server system.
EOF
exit 1
}
. etc/setup.cache
##########################
##### Set Variables ######
##########################
INFO=$SBIN/faxinfo
FAX2PS=$TIFFBIN/fax2ps
TOADDR=FaxMaster
HOSTNAME=`hostname`#
XXX no good way to find FQDN
PORT=4559#
XXX no good way to lookup service
FILE="$1"
DEVICE="$2"
COMMID="$3"
MSG="$4"
# Parse out the fax tif filename alone, strip the log folder name
FILENAME=`echo $1 | awk -F\/ '{print $2}'`
# If you don't have a matchfile, lookups will not occur
MATCHFILE=/home/neomail/fax/nametofax.txt
# If you want to do the WEB link stuff, set to YES, else original links
previal
WEBNOTIFY=YES
WEBSITE="http://linux-2"
WEBFOLDER=/home/neomail/fax
WEBCGIFILE=/cgi-bin/viewfaxfolder.cgi
WEBFAXPATH=/fax
##########################
####### START MAIN #######
##########################
# Check the sender's TSI and setup to dispatch
# facsimile received from well-known senders.
#
SENDER="`$INFO $FILE | $AWK -F: '/Sender/ { print
$2 }' 2>/dev/null`"
#############################################################
############## ALTERNATE SENDER RETRIEVAL METHOD
############
#############################################################
# I WROTE MY OWN SCRIPT TO GET THE SENDER INFO FROM
THE JOB CONVERSATION -
# ON FAILED JOBS THE FILE DOES NOT EXIST
##### This doesn't work well for my modem...
#####SENDER2=`cat log/c$COMMID | awk -F\"
''/FTSI/' {print $2}' | \
##### sed -e 's/[ ]*//g'`
# If SENDER2 returns nothing, use SENDER
instead. Else, if BOTH are
# blank change value to UNSPECIFIED.
if [ "`echo $SENDER2 | sed -e 's/[ ]*//g'`"
= "" ]; then if [
"`echo $SENDER | sed -e 's/[ ]*//g'`" = "" ];
then SENDER2="-
UNSPECIFIED -" else #
Strip out spaced from SENDER so same format to later #
compare with text database for email details. SENDER2="`echo
$SENDER | sed -e 's/[
]*//g'`" fi
fi
# Now use the resulting SENDER2 variable and compare
it to the compare
# file that is formatted "CUSTOMER
NAME;555-111-1234" in each line entry.
# The filename is based on MATCHFILE such as
/var/spool/fax/bin/namefax
# Only do this is the MATCHFILE has been set up.
if [ -f $MATCHFILE ]; then
# Initialize MATCH
MATCH=""
# Compare SENDER2 with each
line in MATCHFILE # Note:
The AWK just finds the LINE with the search text - this does # not
guarantee a correct match. You may have multiple numbers on # the
right of the semicolon. MATCH="`cat
$MATCHFILE | awk -F\; '/'$SENDER2'/ { print $1 }' \ 2>/dev/null`"
# If there is a match then
change SENDER2 to the matching text # so it
will show in the subject line instead of the telno.
if [ "$MATCH" !=
"" ]; then
SENDER2=$MATCH
fi
fi
#############################################################
########## END ALTERNATE SENDER RETRIEVAL METHOD
############
#############################################################
if [ -f $FILE ]; then
# A fax was received, since a TIF file came in.
#######################################
# COPY FAX FILE TO WEB FOLDER. ALSO, MODIFIED SCRIPTS BELOW
TO SHOW HTTP:
# REFERENCE FTP REFERENCE BECAUSE FTP REFERENCES DONT WORK
PROPERLY.
if [ $WEBNOTIFY ]; then
# Copy the fax files to the
destination folder in the Apache server
# Copy the TIF file there
first
cp $1 $WEBFOLDER # Copy the
LOG file there next cp log/c$3
$WEBFOLDER # Set the
permissions so they can be read. Folder must be writable! chmod 755
$WEBFOLDER/*
fi
################################
SENDTO=
if [ -f etc/FaxDispatch ]; then .
etc/FaxDispatch#
NB: FaxDispatch sets SENDTO based on $SENDER
fi
(echo "To: $TOADDR"
echo "From: The HylaFAX Receive Agent
<fax>"
if [ "$MSG" ]; then
echo "Subject:
(Partial) Facsimile received from $SENDER2";
else
echo "Subject:
Facsimile received from $SENDER2";
fi
echo ""
if [ $WEBNOTIFY ]; then
echo "The following fax may or may not be yours... view it to
see."
echo
""
echo
"$FILE ($WEBSITE$WEBFAXPATH/$FILENAME):"; $INFO -n $FILE
else
echo
"$FILE
(ftp://$HOSTNAME:$PORT/$FILE):";
$INFO -n $FILE
fi
echo "ReceivedOn: $DEVICE"
if [ "$MSG" ]; then echo
"" echo
"The full document was not received because:" echo
"" echo
" $MSG" echo
"" echo
" ---- Transcript of session follows
----" echo
"" if [ -f
log/c$COMMID ]; then
$SED -e '/-- data/d' \
-e '/start.*timer/d' -e '/stop.*timer/d' \ log/c$COMMID elif [ -n "$COMMID" ]; then echo " No transcript available (CommID c$COMMID)." else echo " No transcript available." fi
else if [ $WEBNOTIFY ]; then #echo "$FILE ($WEBSITE$WEBFAXPATH/c$COMMID):"; $INFO -n $FILE echo "$FILE ($WEBSITE$WEBFAXPATH/c$COMMID):" echo echo "To manage fax logs and tifs on the web server," echo "click here: ($WEBSITE/$WEBCGIFILE)"; else
echo "CommID: c$COMMID (ftp://$HOSTNAME:$PORT/log/c$COMMID)" fi
fi
if [ -n "$SENDTO" ]; then echo "" echo "The facsimile was automatically dispatched to: $SENDTO."
fi
) | 2>&1 $SENDMAIL -ffax -oi $TOADDR
if [ -n "$SENDTO" ]; then (MIMEBOUNDARY="NextPart$$" echo "Mime-Version: 1.0" echo "Content-Type: Multipart/Mixed; Boundary=\"$MIMEBOUNDARY\"" echo "Content-Transfer-Encoding: 7bit"
echo "To: $SENDTO" echo "From: The HylaFAX Receive Agent <fax>"
if [ "$MSG" ]; then
echo "Subject: (Partial) Facsimile received from $SENDER2";
else
echo "Subject: Facsimile received from $SENDER2";
fi echo "" echo "--$MIMEBOUNDARY" echo "Content-Type: text/plain; charset=us-ascii" echo "Content-Transfer-Encoding: 7bit" echo ""
if [ $WEBNOTIFY ]; then
echo "The following fax may or may not be yours... view it to see."
echo ""
echo "$FILE ($WEBSITE$WEBFAXPATH/$FILENAME):"; $INFO -n $FILE
else
echo "$FILE (ftp://$HOSTNAME:$PORT/$FILE):"; $INFO -n $FILE
fi echo "ReceivedOn: $DEVICE" if [ "$MSG" ]; then echo "" echo "The full document was not received because:" echo "" echo " $MSG" echo "" echo " ---- Transcript of session follows ----" echo "" if [ -f log/c$COMMID ]; then $SED -e '/-- data/d' \ -e '/start.*timer/d' -e '/stop.*timer/d' \ log/c$COMMID elif [ -n "$COMMID" ]; then echo " No transcript available (CommID c$COMMID)." else echo " No transcript available." fi else
if [ $WEBNOTIFY ]; then
#echo "$FILE ($WEBSITE$WEBFAXPATH/c$COMMID):"; $INFO -n $FILE
echo "$FILE ($WEBSITE$WEBFAXPATH/c$COMMID):"
echo echo "To manage fax logs and tifs on the web server," echo "click here: ($WEBSITE/$WEBCGIFILE)";
else
echo "CommID: c$COMMID (ftp://$HOSTNAME:$PORT/log/c$COMMID)"
fi fi echo "" echo "--$MIMEBOUNDARY" echo "Content-Type: application/postscript" echo "Content-Description: FAX document" echo "Content-Transfer-Encoding: 7bit" echo "" $FAX2PS $FILE 2>/dev/null echo "" echo "--$MIMEBOUNDARY--" ) | 2>&1 $SENDMAIL -ffax -oi $SENDTO
fi
else
#
# Generate notification mail for a failed attempt.
#
SENDER="`$INFO $FILE | $AWK -F: '/Sender/ { print $2 }' 2>/dev/null`"
(echo "To: $TOADDR"
echo "From: The HylaFAX Receive Agent <fax>"
echo "Subject: Facsimile FAILED from $SENDER2";
echo ""
echo "An attempt to receive facsimile on $DEVICE failed because:"
echo ""
echo " $MSG"
echo ""
echo ""
echo " ---- Transcript of session follows ----"
echo ""
if [ -f log/c$COMMID ]; then $SED -e '/-- data/d' \ -e '/start.*timer/d' -e '/stop.*timer/d' \ log/c$COMMID
elif [ -n "$COMMID" ]; then echo " No transcript available (CommID c$COMMID)."
else echo " No transcript available."
fi
) | 2>&1 $SENDMAIL -ffax -oi $TOADDR
fi
I'm new to the list, but I figured *someone* might appreciate and benefit from the scripting changes I have made to MY faxrcvd script.
FYI: I am running Mandrake Linux 8.0, Postfix, Apache on a Celeron 600mhz. box with 128 mb ram. Seems like an overkill, but our two fax modems (Multitech 1932zdx w/ fax patch #54) are very busy receiving sometimes. I found that the P133 w/64 mb tram I had been using had trouble performing the TIFF2PS conversions properly, sometimes corrupting them. Not good. That problem went away with this box, so I will stick with it. The print jobs pump out real fast with it which is good. FYI: Multitech is a GREAT company, really supports their products. They will send out free PROM updates to their modems - they updated 10 modems I had at work at no charge for this fax fix.
The following features I scripted may not be written real efficiently, but at least they work :>
1. Better TSID ID
I saw that in some cases I got no TSID in the message - that the default SENDER variable was based upon info stored in the actual resulting TIF file and not the log. Since there is no TIF file on a failed fax, I devised an alternate SENDER2 variable which is parsed from the cxxxx log file, then I compare the two, and if one is blank the other takes priority. I this way I can see who is having problems faxing me.
2. Display Company Name instead of Fax Number
I added some comparison testing to "Match" the TSID against a simple semicolon (;) delimited text file to a company name so the reception email displays the company name instead of the TSID. This way I can see who the fax is from rather than the fax number usually in there. If both variables are null I display - UNSPECIFIED -.
3. Web Fax Viewing
The default FTP pointers in the email messages didn't work for me so I wanted to set up a web-based fax retrieval system. I as the sysadmin want to be able to review and reprint faxes that are automatically printed via CUPS to an HP laserjet here, and this was the easiest way for me to do it. For my personal server I wanted to be able to retrieve faxes from anywhere I might be, so web based fax access made sense.
I set up Apache on my Mandrake Linux 8.0 system and set up the script to copy the fax TIF and Cxxx log files to the web folder. The script emails me a fax reception message that includes web links to cgi scripts which simply display the fax or log, respectively, or delete the copies in that folder.
Hope I have been of help!
Mark Tilles
____________________ HylaFAX(tm) Users Mailing List _______________________
To unsub: mail -s unsubscribe hylafax-users-request@hylafax.org < /dev/null