home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / fax.lzh / fax (.txt)
Microsoft Windows Help File Content  |  1990-05-06  |  8KB  |  205 lines

  1. : This is a shar archive.  Extract with sh, not csh.
  2. echo x - README
  3. cat > README << '!Funky!Stuff!'
  4. This is an el-cheapo way to implement outgoing-only text-only e-mail to
  5. We use a $198 fax card ("The Complete FAX") in an old IBM-PC.  The PC
  6. is set up as needed by the fax card, with the AUTOEXEC.BAT file set up
  7. to cd into the CFAX directory (where all the fax stuff is stored),
  8. start the fax background process, and then execute the AUTOFAX.BAT file
  9. included in this distribution.
  10. On our Sun mailserver, a dedicated serial line (on /dev/tty0d in our
  11. case) runs from the Sun to the serial port on the PC.
  12. When someone sends mail to 12345@fax.ucsd.edu, we run the mail through
  13. the 'faxmailer' shell script, which extracts the phone number (after
  14. applying some sanity and security checks), and then queues it into a
  15. fax job in /var/spool/fax.
  16. Every 15 minutes or so (from crontab), we run the 'faxq' script, which
  17. fetches previous fax transmission history files from the PC, examines
  18. them to determine whether the transmission was successful, whether to
  19. requeue the message for retransmission, or to return it to the sender
  20. as undeliverable.
  21. It then transfers the outgoing text files to the PC, and then finally
  22. transfers a batch script 'QUEUE.BAT' which performs the actual
  23. transmission and then loops back to the 'AUTOFAX' batch script.
  24. For $200 and an old PC, we have the ability for E-mail users to send
  25. mail to Fax machines on campus (at last estimate, there were around
  26. 200-400 or so fax machines around UCSD).
  27. This is an incredible hack that I dreamed up one afternoon, but it's
  28. been working fine for about two months, and it has demonstrated that
  29. people want the capability.  We're looking into getting some more
  30. sophisticated FAX capability for our E-mail system, but the low demand
  31. (we handle maybe two to five E-Fax messages a day now) doesn't justify
  32. the expense of the available commercial solutions.
  33. You'll need Kermit on both the mail server and the PC.  Or maybe you can
  34. get fancy and use some Ethernet mechanism, but I didn't think it was
  35. worth the cost of putting an Ethernet card into the PC and we had lots
  36. of leftover ports on the Ariel card in our Sun.
  37. Enjoy.  Hack on it; it'll do you good.
  38. (BTW: this is the only document on this there is.  You're on your own
  39. now, son.)
  40.     - Brian Kantor, UCSD, Nov 1989
  41. !Funky!Stuff!
  42. echo x - autofax.bat
  43. cat > autofax.bat << '!Funky!Stuff!'
  44. del queue.bat
  45. del *.txt
  46. del *.0*
  47. kermit server
  48. queue
  49. !Funky!Stuff!
  50. echo x - faxmailer
  51. cat > faxmailer << '!Funky!Stuff!'
  52. #!/bin/sh
  53. cd /var/spool/fax
  54. # make a copy of the file
  55. echo "==============================================================" > f$$.txt
  56. echo "==============================================================" >> f$$.txt
  57. echo "    Wonderous Electronic Mail to FAX System " `date` >> f$$.txt
  58. echo "==============================================================" >> f$$.txt
  59. echo "==============================================================" >> f$$.txt
  60. echo " " >> f$$.txt
  61. echo " " >> f$$.txt
  62. echo " " >> f$$.txt
  63. head -200 >> f$$.txt
  64. # find the phone number in the Subject: line
  65. PH=`awk -f /usr/local/lib/faxnumber f$$.txt`
  66. if [ $PH ] ; then
  67.     echo "No valid fax number found in To: or Subject: line"
  68.     rm f$$.txt
  69.     # ( error 65 is "data error" to sendmail)
  70.     exit 65
  71. # put out the actual command to be run
  72. echo "cfaxsend f$$.txt $PH /x /f > f$$.err" > f$$.q
  73. exit 0
  74. !Funky!Stuff!
  75. echo x - faxnumber
  76. cat > faxnumber << '!Funky!Stuff!'
  77. BEGIN    { for (i=1; i <= 5; i++)  number[i] = "" }
  78. /^To: / { 
  79.     number[1] = substr($0,5);
  80.         if (q = index(number[1], "@"))
  81.             number[1]=substr(number[1], 1, (q-1));
  82. /^Subject: / {
  83.     if (p = index($0, "["))
  84.         if (q = index($0, "]"))
  85.             number[2]=substr($0, p+1, (q-p-1));
  86.     if (p = index($0, "("))
  87.         if (q = index($0, ")"))
  88.             number[3]=substr($0, p+1, (q-p-1));
  89.     if (p = index($0, "<"))
  90.         if (q = index($0, ">"))
  91.             number[4]=substr($0, p+1, (q-p-1));
  92.     if (p = index($0, "{"))
  93.         if (q = index($0, "}"))
  94.             number[5]=substr($0, p+1, (q-p-1));
  95. END    {
  96.     for (i=1; i <= 5; i++)
  97.         p = index(number[i],"%");
  98.         if (p > 1)
  99.             number[i] = substr(number[i], 1, p-1);
  100.         # check for illegal first digit - campus phones start 3,4,5
  101.         fd = substr(number[i],1,1);
  102.         if ( fd != 3 && fd != 4 && fd != 5 )
  103.             number[i] = "";
  104.     print number[1] number[2] number[3] number[4] number[5]
  105. !Funky!Stuff!
  106. echo x - faxq
  107. cat > faxq << '!Funky!Stuff!'
  108. #!/bin/sh
  109. # this one dequeues the messages from where they're spooling and
  110. # moves them over to the PC.
  111. cd /var/spool/fax
  112. # following stuffed in to prevent more than one of these running at a
  113. # time 
  114. # Note that shlock compares
  115. # pids so it doesn't matter if a process dies and leaves a lock sitting
  116. #        - Brian
  117. if /usr/lib/news/shlock -p $$ -f FAXLOCK ; then
  118.     echo ${pname}: "[$$]" already running "[`cat FAXLOCK`]"
  119.     exit 0
  120. nfiles=`find . -name '*.q*' -print | wc -l`
  121. if [ $nfiles = "0" ] ; then
  122.     rm FAXLOCK
  123.     exit 0;
  124. # zap commands left over from last time
  125. rm queue.bat
  126. # following grabs all the error files from the last go-round,
  127. /usr/local/bin/kermit << EOF
  128. set line /dev/tty0d
  129. set baud 9600
  130. get f*.err
  131. # analyze the .err files we got, and add the appropriate
  132. # deletes to the outgoing batch file.  Successful faxes get deleted
  133. # from the current spool directory here too; unsuccessful ones get
  134. # requeued
  135. for f in *.err ; do
  136.     if [ ! -r $f ] ; then
  137.         continue;
  138.     fb=`basename $f .err`
  139.     echo $f $fb ;
  140.     # we got the errors file, blow it away on the PC
  141.     echo "DEL $f" >> queue.bat ;
  142.     # see if it was sent ok
  143.     if ( egrep -i 'Sent successfully' $f ) ; then
  144.         rm $fb.* ;
  145.         continue ;
  146.     # see if it failed miserably
  147.     if ( egrep -i 'error' $f ) ; then
  148.         frm=`egrep From: $fb.txt | sed -e 's/From: //'` ;
  149.         more FAXERR $fb.* | Mail -s "Fax mail error" $frm brian ;
  150.         rm $fb.* ;
  151.         continue ;
  152.     # otherwise, requeue and remove the errors file
  153.     cat $fb.q.o >> queue.bat ;
  154.     rm $f ;
  155. # cat all the new queue files onto the batch file
  156. nq=`find . -name '*.q' -print | wc -l`
  157. if [ $nq -gt 0 ] ; then
  158.     for f in *.q ; do
  159.         cat $f >> queue.bat ;
  160.         mv $f $f.o ;
  161.     done ;
  162.     # ship over the current text files
  163.     /usr/local/bin/kermit << EOF
  164. set line /dev/tty0d
  165. set baud 9600
  166. send f*.txt
  167. # make sure that the last thing in the batch restarts the PC script
  168. echo "AUTOFAX" >> queue.bat
  169. # ship over batch list of things to do
  170. # 'finish' makes the PC kermit exit and execute the queue.bat file
  171. # we just delivered
  172. /usr/local/bin/kermit << EOF
  173. set line /dev/tty0d
  174. set baud 9600
  175. send queue.bat
  176. finish
  177. echo "===================================================" >> /var/log/fax
  178. date >> /var/log/fax
  179. cat queue.bat >> /var/log/fax
  180. rm -f  FAXLOCK
  181. exit 0
  182. !Funky!Stuff!
  183. echo x - sendmail.stuff
  184. cat > sendmail.stuff << '!Funky!Stuff!'
  185. This goes in Ruleset Zero:
  186. # resolve the FAX mailer
  187. R$*<@$*fax>$*        $#FAX$@$2$:$1$3            user@fax
  188. R$*<@$*fax.$D>$*    $#FAX$@$2$:$1$3            user@fax.ucsd.edu
  189. And this goes wherever you stuff your mailer definitions
  190. ############################################################
  191. ############################################################
  192. #####        FAX Mailer specification
  193. ############################################################
  194. ############################################################
  195. Mfax,    P=/usr/local/lib/faxmailer, F=rsDFMmnC, S=17, R=27,
  196.     A=faxmailer $u
  197. #null
  198. #null
  199. !Funky!Stuff!
  200. echo x - usr.lib.aliases
  201. cat > usr.lib.aliases << '!Funky!Stuff!'
  202. fax:fax@fax.ucsd.edu
  203. !Funky!Stuff!
  204. exit 0
  205.