User Tools

Site Tools


articles:cupsprinting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
articles:cupsprinting [2009/02/16 12:13] timallenarticles:cupsprinting [2010/02/08 08:54] (current) timallen
Line 150: Line 150:
  
 ===== Putting It All Together ===== ===== Putting It All Together =====
 +
  
  
 ==== Sambafax ==== ==== Sambafax ====
-Sambafax uses Hylafax to send a document to a recipient, based on a fax number embedded in a Postscript document. Sambafax was originally written by Ignace Suy. {{articles:sambafax.txt|This modified version}} works under CUPS, using the CUPS Postscript drivers described above. It also uses pstotext, which does a better job of extracting the fax number from the Postscript file, as well as handling fax numbers which may be split over a number of lines. +Sambafax uses Hylafax to send a document to a recipient, based on a fax number embedded in a Postscript document. Sambafax was originally written by Ignace Suy. The modified version below works under CUPS, using the CUPS Postscript drivers described above. It also uses pstotext, which does a better job of extracting the fax number from the Postscript file, as well as handling fax numbers which may be split over a number of lines. 
 + 
 +<file> 
 +#!/bin/sh 
 +#  
 +# Faxing with HylaFax through a faxprinter 
 +# Heavily modified from original version. Supports CUPS and LPR 
 +#  
 +# $Id: sambafax,v 1.9 2009-06-30 08:43:41 tda Exp $ 
 + 
 + 
 +# Printer spool type (LPR or CUPS) 
 +PRINTSYSTEM="CUPS" 
 + 
 +# Constants 
 +SENDMAIL="/usr/sbin/sendmail" 
 + 
 +# Make up a temporary file using PID 
 +FAXFILE=/tmp/sambafax.$$ 
 + 
 +# Fax number format 
 +# Match FAX : '01234 567890' 
 +# Deals with newlines in string and 0xad as hyphen 
 +PARSE=" 
 +b testfirst 
 +: appendnext 
 +
 +y/FAX\n\xad\xa3/fax - / 
 +: testfirst 
 +s/.*fax *: *'\([0-9 ][0-9 ,-]*[0-9 ]\)'.*/\1/ 
 +T appendnext 
 +s/[ -]//g 
 +
 +
 +
 + 
 +# Retrieve the username and hostname from the parameters 
 +if [ $PRINTSYSTEM = "LPR" ]; then 
 +  while : 
 +  do 
 +    case "$1" in 
 +        -n) Username="$2" 
 +            shift ; shift 
 +            ;; 
 +        -h) Hostname="$2" 
 +            shift ; shift 
 +            ;; 
 +        -*) shift 
 +            ;; 
 +         *) break 
 +    esac 
 +  done 
 +  cat >${FAXFILE} 
 +else 
 +# CUPS 
 +  Username="$2" 
 +  cat "$6" >${FAXFILE} 
 +fi 
 + 
 +# If the samba user is anonymous then send mails to the postmaster 
 +if [ "${Username}" = "nobody" ]; then 
 +  MailTo="postmaster@fleet.dcallen.co.uk" 
 +else 
 +  MailTo="${Username}@fleet.dcallen.co.uk" 
 +fi 
 + 
 +# Retrieve the faxnumber from the printfile 
 +FAXNUM=`pstotext ${FAXFILE} | sed -n "${PARSE}"
 + 
 +# If faxnumber is found fax the tempfile 
 +# We do not check the validity of the faxnumber, let sendfax do this... 
 +if [ "${FAXNUM}" = "" ]; then 
 +  (echo "To: ${MailTo}" 
 +   echo "From: The HylaFAX Samba print service <fax>" 
 +   echo "Subject: Your facsimile request failed" 
 +   echo ""                                                                  
 +   echo -n "The faxnumber is not recognized in your fax of "  
 +   echo -n `date` 
 +   echo "." 
 +   echo "The faxnumber is recognised by this text:" 
 +   echo ""                                                                  
 +   echo "   Fax: 'd,ddd-dd ddddd'" 
 +   echo ""                                                                  
 +   echo "Only spaces, ',' or '-' characters are allowed between the digits." 
 +   echo "" 
 +   echo "Please correct and retry." 
 +  ) | 2>&1 $SENDMAIL -ffax -oi ${MailTo} 
 +else 
 +  sendfax -n -D -m -f ${MailTo} -d ${FAXNUM} ${FAXFILE} 
 +fi 
 + 
 +# Remove the temp file 
 +# rm -f ${FAXFILE} 
 + 
 +# End of file 
 +</file> 
 + 
  
 First, copy the sambafax script to ''/usr/lib/cups/backend'', then First, copy the sambafax script to ''/usr/lib/cups/backend'', then
articles/cupsprinting.1234786437.txt.gz · Last modified: 2009/02/16 12:13 by timallen