HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

[hylafax-users] This bin/notify{,.awk} hackery doesnt quite cut it



Greetings Devs & List Members.

  I've a small problem with hacking on a custom sent fax archive
configuration.  What I have basically works okay, it uses some
changes to the bin/notify and bin/notify.awk programs, uses
mimencode, and uses some additional filtering on behalf of a
dedicated fax-log system user.

  The system account receives email with attachments of every
B0ccessfully sent outgoing fax as mimencoded .tiff files.  It
also gets mail for errors and requeues, but these are filtered
out from being stored in the "successfull" sent archive at the
filesystem level.

  A small BASH program is run from the user's .qmail file, which
extracts the .tiff attachment (the sent fax) and saves it to a
unique filename.

  For all the hack that it is, it pretty much does the job.  I'm
aware there might be more elegant/complex/complete systems,
perhaps utilsing MySQL DB for the backend storage, etc.  I'm
not terribly concerned with implementing one of these, so please
no suggestions to look there.  My client setup basically uses
a custom smbfax system, so I've no issues with that part of the
setup either.

  Really the only little irk that I can't figure out, is with
the mimencoded attachment that I manage to pull-out, and then
later play with/track/save.  The thing is, that I only ever
get the main content of the outgoing fax, that is, basically
everything minus the cover page.  Well, most of the time
anyway.

  It does get the cover page when the outgoing job doesnt
complete successfully, for whatever reason.  For all it's
worth and at the end-of-the-day, I think I just might need
a little fix or two to the bin/notify and/or bin/notify.awk
program(s).  So I attach them for you review, could some
person more enlightened than suggestion a solution to the
problem, I'd fully appreciate it.

  There are more comments in the notify file itself as to
my specific dilemma.  Note that the original routine for
the AttachTiffFile stuff was found after digging around
on Google, which some other people have probably run into
if they've looked for stuff along these lines before.
Note also that that function doesnt take a parameter
anymore even though I've not updated the calls to it in
the later sections of notify.awk.  I just kind of hacked
on it all and it ended up where it is now; not too pretty
but almost fully functional for what I need.

  Thanks in advance.
#!/bin/sh
echo DEFANGED.47110
exit
#!/bin/sh
echo DEFANGED.2
exit
#!/bin/sh
echo DEFANGED.47111
exit
#! /bin/sh
#	$Id: notify.sh.in,v 1.1 2001/04/15 03:48:17 darren 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.
#
PATH=${PATH}:/sbin:/usr/sbin:/bin:/usr/bin:

#
# notify qfile why jobtime [nextTry]
#
# Return mail to the submitter of a job when notification is needed.
#
if [ $# != 3 -a $# != 4 ]; then
    echo "Usage: $0 qfile why jobtime [nextTry]"
    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(8C)
command.  Read the documentation on setting up HylaFAX before you
startup a server system.

EOF
    exit 1
}
. etc/setup.cache

QFILE=$1
WHY=$2
JTIME=$3
NEXT=${4:-'??:??'}

#
# Convert the outgoing fax document to a .tiff file.  Then
# run mimencode on the .tiff file so it can be attached to
# a MIME E-Mail message.
#
FAX_FILE=`cat $QFILE | grep '^!postscript' | sed -e 's|!postscript:0::||'`
BASE_FILE=`echo $FAX_FILE | sed -e 's|.*/||'`
TEMP_FILE="$BASE_FILE".ps2fax
/var/spool/fax/bin/ps2fax $FAX_FILE -o docq/$TEMP_FILE
/usr/bin/mimencode docq/$TEMP_FILE -o docq/mimencode.tmp
rm -f docq/$TEMP_FILE
#
# The problem with the above for me, is that I cant figure out
# how to grab the *ENTIRE* fax, every time.  It works, but for
# all sent faxes, 'mimencode.tmp' always ends up being just the
# content of the sent fax (everything minus the cover page).  I've
# noticed that if the outoing fax fails for whatever reason, then
# once it rolls through here, 'mimencode.tmp' *DOES* end up having
# the cover page, and I get the result I want.  So the question
# remains: HOW to change the above to make 'mimencode.tmp' *ALWAYS*
# have the cover page included!  Is it just fixing the FAX_FILE sed
# statement?  I need this to ensure that the fax archive is full
# and complete.  Without cover pages, it's somewhat irritating :(

($AWK -F: -f bin/notify.awk why=$WHY jobTime=$JTIME nextTry=$NEXT $QFILE || {
      echo ""
      echo "Sorry, there was a problem sending notification;"
      echo "something went wrong in the shell script $0."
      echo ""
      exit 1;
  }
) | 2>&1 $SENDMAIL -t -ffax -oi
#!/bin/sh
echo DEFANGED.47112
exit
#!/bin/sh
echo DEFANGED.3
exit
#!/bin/sh
echo DEFANGED.47113
exit
#! /bin/sh
#	$Id: notify.awk,v 1.3 2002/07/20 05:24:17 darren Exp $
#
# HylaFAX Facsimile Software
#
# Copyright (c) 1990-1996 Sam Leffler
# Copyright (c) 1991-1996 Silicon Graphics, Inc.
# 
# 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.
#

#
# Awk support program for notify shell script.  This
# stuff is broken out into a separate file to avoid
# overflowing the exec arg list on some systems like SCO.
#

function printItem(fmt, tag, value)
{
    printf "%14s: " fmt "\n", tag, value;
}

function printBanner(banner)
{
    print "";
    print "    ---- " banner " ----";
    print "";
}

function docType(s)
{
    if (match(s, "\.cover"))
	return "PostScript cover page";
    else if (match(s, "\.ps"))
	return "PostScript";
    else if (match(s, "\.tif"))
	return "TIFF";
    else if (match(s, "\.pdf"))
	return "PDF";
    else if (match(s, "\.pcl"))
	return "PCL";
    else
	return "Unknown document type";
}

#
# Construct a return-to-sender message.
#
function returnToSender()
{
    printBanner("Unsent job status");
    printItem("%s", "Destination", number);
    printItem("%s", "JobID", jobid);
    printItem("%s", "GroupID", groupid);
    printItem("%s", "Sender", sender);
    printItem("%s", "Mailaddr", mailaddr);
    if (commid != "")
	printItem("%s", "CommID", commid);
    if (modem != "any")
	printItem("%s", "Modem", modem);
    printItem("%s", "Submitted From", client);
    if (jobType == "facsimile") {
	printItem("%u (mm)", "Page Width", pagewidth);
	printItem("%.0f (mm)", "Page Length", pagelength);
	printItem("%.0f (lpi)", "Resolution", resolution);
    }
    printItem("%s", "Status", status == "" ? "  (nothing available)" : status);
    printItem("%u (exchanges with remote device)", "Dialogs", tottries);
    printItem("%u (consecutive failed calls to destination)", "Dials", ndials);
    printItem("%u (total phone calls placed)", "Calls", totdials);
    if (jobType == "facsimile") {
	printItem("%u (pages transmitted)", "Pages", npages);
	printItem("%u (total pages to transmit)", "TotPages", totpages);
	printItem("%u (attempts to send current page)", "Attempts", ntries);
	printItem("%u (directory of next page to send)", "Dirnum", dirnum);
	if (nfiles > 0) {
	    printBanner("Documents submitted for transmission");
	    print "The following documents were submitted for transmission and are";
	    print "available on the server for reuse until they are automatically";
	    print "purged when this job is " doneop "d.  Documents may also be manually";
	    print "removed using the faxrm command; consult faxrm(1) for information.";
	    print ""
	    printf "%-20s %8s %s\n", "Filename", "Size", "Type";
	    for (i = 0; i < nfiles; i++) {
		"wc -c " files[i] | getline;
		printf "%-20s %8d %s\n", files[i], $1, docType(files[i]);
		close("wc -c " files[i]);
	     }
	}
    } else if (jobType == "pager") {
	if (npins != 0) {
	    printBanner("Unsent pages submitted for transmission");
	    for (i = 0; i < npins; i++)
		printf "%15s\n",  "PIN " pins[i];
	}
	if (nfiles != 0) {
	    printBanner("Message text");
	    while ((getline <files[0]) > 0)
		print $0;
	    close(files[0]);
	}    
    }
}

function returnTranscript()
{
    printBanner("Transcript of session follows");
    comFile = "log/c" commid;
    if ((getline <comFile) > 0) {
	do {
	    if (index($0, "-- data") == 0)
		print $0
	} while ((getline <comFile) > 0);
	close(comFile);
    } else {
	printf "    No transcript available";
	if (commid != "")
	    printf "(CommID c" commid ")";
	print ".";
    }
}

function printStatus(s)
{
    if (s == "")
	print "<no reason recorded>";
    else
	print s
}

function putHeaders(subject)
{
    print "To: " mailaddr;
    print "Subject: " subject;
    print "";
    printf "Your " jobType " job to " number;
}

function putMimeHeaders(subject)
{
    print "Mime-Version: 1.0"
    print "Content-Type: Multipart/Mixed\; Boundary=\"NextPart7738\"";
    print "Content-Transfer-Encoding: 7bit";
    print "To: " mailaddr;
    print "Bcc: fax-log";
    print "Subject: " subject;
    print "";
    print  "--NextPart7738";
    print "";
    printf "Your " jobType " job to " number " name " qfile;
}
#
# this function inserts a tiff file into stdout
# you could use another conversion (tiff2ps) if you choose
# added yan seiner nov 1999 yan@seiner.com
# 
function attachTiffFile(file)
{
    print  "--NextPart7738";
    print "Content-Type: image/tiff";
    print "Content-Description: FAX document; name=fax.tiff";
    print "Content-Disposition: inline;";
    print "Content-Transfer-Encoding: base64";
    print "";
    system("/bin/cat docq/mimencode.tmp" );
    print "";
    print  "--NextPart7738--";
    print "";
}

BEGIN		{ nfiles = 0;
		  npins = 0;
		  pagewidth = 0;
		  pagelength = 0;
		  resolution = 0;
		  jobType = "facsimile";
		  signalrate = "unknown";
		  dataformat = "unknown";
		  doneop = "default";
                pagernum = "unknown";
		  commid = "";
		}
/^jobid/	{ jobid = $2; }
/^groupid/	{ groupid = $2; }
/^state/	{ state = $2+0; }
/^doneop/	{ doneop = $2; }
/^number/	{ number = $2; }
/^external/	{ number = $2; }		# override unprocessed number
/^sender/	{ sender = $2; }
/^mailaddr/	{ mailaddr = $2; }
/^jobtag/	{ jobtag = $0; sub("jobtag:", "", jobtag); }
/^jobtype/	{ jobType = $2; }
/^status/	{ status = $0; sub("status:", "", status);
		  if (status ~ /\\$/) {
		      sub("\\\\$", "\n", status);
		      while (getline > 0) {
			  status = status $0;
			  sub("\\\\$", "\n", status);
			  if ($0 !~ /\\$/)
			      break;
		      }
		  }
		}
/^resolution/	{ resolution = $2; }
/^npages/	{ npages = $2; }
/^totpages/	{ totpages = $2; }
/^dirnum/	{ dirnum = $2; }
/^commid/	{ commid = $2; }
/^ntries/	{ ntries = $2; }
/^ndials/	{ ndials = $2; }
/^pagewidth/	{ pagewidth = $2; }
/^pagelength/	{ pagelength = $2; }
/^signalrate/	{ signalrate = $2; }
/^dataformat/	{ dataformat = $2; }
/^modem/	{ modem = $2; }
/^totdials/	{ totdials = $2; }
/^tottries/	{ tottries = $2; }
/^client/	{ client = $2; }
/^[!]*post/	{ files[nfiles++] = $4; }
/^[!]*tiff/	{ files[nfiles++] = $4; }
/^[!]*pcl/	{ files[nfiles++] = $4; }
/^page:/	{ pins[npins++] = $4; }
/^[!]page:/   { pagernum = $4; }
/^data:/	{ files[nfiles++] = $4; }
/^poll/		{ poll = " -p"; }
END {
    if (jobtag == "")
	jobtag = jobType " job " jobid;;
    if (doneop == "default")
	doneop = "remove";
    if (jobType == "pager")
      number = pagernum;
    if (why == "done") {
#	putHeaders(jobtag " to " number " completed");
	putMimeHeaders(jobtag " to " number " completed");
	print " was completed successfully.";
	print "";
	if (jobType == "facsimile") {
	    printItem("%u", "Pages", npages);
	    if (resolution == 196)
		printItem("%s", "Quality", "Fine");
	    else
		printItem("%s", "Quality", "Normal");
	    printItem("%u (mm)", "Page Width", pagewidth);
	    printItem("%.0f (mm)", "Page Length", pagelength);
	    printItem("%s", "Signal Rate", signalrate);
	    printItem("%s", "Data Format", dataformat);
	}
	if (tottries != 1)
	    printItem("%s (exchanges with remote device)", "Dialogs", tottries);
	if (totdials != 1)
	    printItem("%s (total phone calls placed)", "Calls", totdials);
	if (modem != "any")
	    printItem("%s", "Modem", modem);
	printItem("%s", "Submitted From", client);
	printItem("%s", "JobID", jobid);
	printItem("%s", "GroupID", groupid);
	printItem("%s", "CommID", "c" commid);
	printf "\nProcessing time was " jobTime ".\n";
	if (status != "") {
	    print "  Additional information:\n    " status;
	    returnTranscript();
	}
	attachTiffFile($4);
    } else if (why == "failed") {
#	putHeaders(jobtag " to " number " failed");
	putMimeHeaders(jobtag " to " number " failed");
	printf " failed because:\n    ";
	printStatus(status);
	returnTranscript();
	attachTiffFile($4);
	returnToSender();
    } else if (why == "rejected") {
	putHeaders(jobtag " to " number " failed");
	printf " was rejected because:\n    ";
	printStatus(status);
	returnToSender();
    } else if (why == "blocked") {
#	putHeaders(jobtag " to " number " blocked");
	putMimeHeaders(jobtag " to " number " blocked");
	printf " is delayed in the scheduling queues because:\n    ";
	printStatus(status);
	print "";
	print "The job will be processed as soon as possible."
	attachTiffFile($4);
    } else if (why == "requeued") {
#	putHeaders(jobtag " to " number " requeued");
	putMimeHeaders(jobtag " to " number " requeued");
	printf " was not sent because:\n    ";
	printStatus(status);
	print "";
	print "The job will be retried at " nextTry "."
	returnTranscript();
	attachTiffFile($4);
    } else if (why == "removed" || why == "killed") {
	putHeaders(jobtag " to " number " removed from queue");
	print " was deleted from the queue.";
	if (why == "killed")
	    returnToSender();
    } else if (why == "timedout") {
#	putHeaders(jobtag " to " number " failed");
	putMimeHeaders(jobtag " to " number " failed");
	print " could not be completed before the appointed deadline.";
	attachTiffFile($4);
	returnToSender();
    } else if (why == "format_failed") {
	putHeaders(jobtag " to " number " failed");
	print " was not sent because document conversion"
	print "to facsimile failed.  The output from the converter program was:\n";
	print status "\n";
	printf "Check any PostScript documents for non-standard fonts %s.\n",
	    "and invalid constructs";
	returnToSender();
    } else if (why == "no_formatter") {
	putHeaders(jobtag " to " number " failed");
	print " was not sent because";
	print "the document conversion script was not found.";
	returnToSender();
    } else if (match(why, "poll_*")) {
	putHeaders("Notice about " jobtag);
	printf ", a polling request,\ncould not be completed because ";
	if (why == "poll_rejected")
	    print "the remote side rejected your request.";
	else if (why == "poll_no_document")
	    print "no document was available for retrieval.";
	else if (why == "poll_failed")
	    print "an unspecified problem occurred.";
	print "";
	printf "Processing time was %s.\n", jobTime;
	returnTranscript();
    } else {
	putHeaders("Notice about " jobtag);
	print " had something happen to it."
	print "Unfortunately, the notification script was invoked",
	    "with an unknown reason"
	print "so the rest of this message is for debugging:\n";
	print "why: " why;
	print "jobTime: " jobTime;
	print "nextTry: " nextTry;
	print  "";
	print "This should not happen, please report it to your administrator.";
	returnTranscript();
	returnToSender();
    }
}



Project hosted by iFAX Solutions