Personal tools
HylaFAX The world's most advanced open source fax server

Difference between revisions of "Sambafax"

m (Reverted edits by NvvTk7 (Talk); changed back to last version by NdnLc2)
 
Line 44: Line 44:
 
             gsub(/-/,""); \
 
             gsub(/-/,""); \
 
             anfang=match($0,/ ?: ?/); \
 
             anfang=match($0,/ ?: ?/); \
             anfang=anfang match(substr($0,anfang),/[0-9]/)-1; \
+
             anfang=anfang+match(substr($0,anfang),/[0-9]/)-1; \
 
             ende=match(substr($0,anfang),/[^0-9]/)-1; \
 
             ende=match(substr($0,anfang),/[^0-9]/)-1; \
 
             printf ("%s",substr($0,anfang,ende)) \
 
             printf ("%s",substr($0,anfang,ende)) \
Line 64: Line 64:
 
     echo ""
 
     echo ""
 
     echo "Please correct and retry"
 
     echo "Please correct and retry"
     ) | 2>
+
     ) | 2>&1 ${SENDMAIL} -ffax -oi ${MailTo}
 +
else
 +
  ${SENDFAX} -n -D -f ${MailTo} -d ${FAXNUM} ${FAXFILE}
 +
fi
 +
 +
# remove the temp file
 +
rm -f ${FAXFILE}
 +
 +
# end of show
 +
</pre>

Latest revision as of 04:36, 12 July 2007

#!/bin/sh
# constants
SENDMAIL="/usr/sbin/sendmail"
PS2ASCII="/usr/bin/ps2ascii"
AWK="/bin/awk"
SENDFAX="/usr/bin/sendfax"
 
# make up a temporary file
FAXFILE=/tmp/sambafax.$$
 
# retrieve the username and hostname from the paramaters
while :
do
    case "$1" in
        -n) Username="$2"
            shift ; shift
            ;;
        -h) Hostname="$2"
            shift ; shift
            ;;
       -*)  shift
            ;;
        *) break
    esac
done
 
# if the samba user is anonumous then send mails to the postmaster
if [ "$Username" = "nobody" ];
   then
    MailTo="postmaster"
   else
    MailTo=${Username}
fi
 
# now dump the to-be faxewd data (PS fdormat) to the temp file
cat >${FAXFILE}

# retrieve the faxnumber from the printfile
# the silly three x's are added because some awk strugle with an immediate CR
# we use a PS to ascii pipe to strip (most of) the Postscript controls
FAXNUM=`${PS2ASCII} ${FAXFILE} | ${AWK} '{ IGNORECASE=1 } /FAX-Nr ?: ?[0-9-]*/ \
         {  $0=$0 "xxx"; \
            gsub(/-/,""); \
            anfang=match($0,/ ?: ?/); \
            anfang=anfang+match(substr($0,anfang),/[0-9]/)-1; \
            ende=match(substr($0,anfang),/[^0-9]/)-1; \
            printf ("%s",substr($0,anfang,ende)) \
         }' `
 
# if faxnumber is found fax the tempfile
# we donot check the validity of the faxnumber, let sendfax do this...
if [ -z ${FAXNUM} ] ; then
    (echo "To: ${MailTo}"
     echo "From: The HylaFAX Samba dancer "
     echo "Subject: your facsimile request failed"
     echo ""
     echo "The faxnumber is not recognized in your fax of"
     echo `date`
     echo ""
     echo "The faxnumber is recognised via this text:"
     echo "   Fax-Nr : ddd-ddddddd"
     echo "No spaces or characters are allowed between the digits, just a -"
     echo ""
     echo "Please correct and retry"
    ) | 2>&1 ${SENDMAIL} -ffax -oi ${MailTo}
else
   ${SENDFAX} -n -D -f ${MailTo} -d ${FAXNUM} ${FAXFILE}
fi
 
# remove the temp file
rm -f ${FAXFILE}
 
# end of show

This page was last edited on 12 July 2007, at 04:36.

Powered by MediaWiki
Attribution-ShareAlike 2.5

Project hosted by iFAX Solutions