Hack90.Turn Your Linux Box into a Fax Machine

Hack 90. Turn Your Linux Box into a Fax Machine

Have you ever wished you could handle fax traffic with your Linux machine?

Asterisk offers a built-in fax-detection mechanism. This allows you to handle faxes that are sent to your Asterisk box on a Plain Old Telephone Service (POTS) line connected via a Zaptel interface. It's Asterisk's Answer( ) command that triggers the fax detection. If an incoming fax is detected, Asterisk automatically transfers the call to the special extension called fax, if it exists.

To use this special extension, you'll need to compile and install the spandsp package. Download the latest version from ftp://ftp.opencall.org, and unzip the file into /usr/src/spandsp. To compile it, issue these commands:

 # ./configure --prefix=/usr # make; make install # cp app_rxfax.c /usr/src/asterisk/apps # cp app_txfax.c /usr/src/asterisk/apps # cp Makefile.patch /usr/src/asterisk/apps # cd /usr/src/asterisk/apps # patch <Makefile.patch 

If you're worried about the security concerns associated with compiling as root, you can use a nonroot account to compile spandsp.

These commands compile the spandsp package, which provides a source code patch for Asterisk. As such, you'll need to recompile Asterisk now:

 # cd  /pathtoasterisksource/  asterisk  # make clean ; make install  

The next step to faxing with Asterisk is to enable fax detection on the Zaptel channel you want to use for faxing. This doesn't stop the channel from being used for normal voice calls; it just enables the channel to discern fax calls from normal calls. To enable this function, be sure that the channel's section in /etc/asterisk/zapata.conf has this entry:


The valid parameters for the faxdetect option are incoming, outgoing, both, and no. By default, fax detection is disabled.

7.4.1. Receiving Faxes

Now, consider the following snippet from a dial plan:

 [incoming-local] exten => s,1,Answer exten => s,2,Dial(SIP/202,45,rm) exten => s,3,Voicemail(202) exten => fax,1,SetVar(TIFFILE=/var/spool/faxes/thisfax.tif) exten => fax,2,rxfax(${TIFFILE}) 

In this context, the Answer() command triggers fax detection. If the call isn't a fax, the dial plan calls for a call to SIP peer 202. If it is a fax, the fax extension takes over, saving the fax image into a TIFF file located in /var/spool/faxes. Another script can then process the file in any way you see fit, perhaps printing it immediately, like this:

 exten => fax,1,SetVar(TIFFILE=/var/spool/faxes/thisfax.tif) exten => fax,2,rxfax(${TIFFILE}) ; dump the FAX file to the default printer and remove the FAX file exten => fax,3,System('tiff2ps ${TIFFILE} | lpr') exten => fax,4,System('rm ${TIFFILE}') 

tiff2PS is a utility provided in the libtiff package, a library for dealing with TIFF files. It's a standard part of many Linux distributions, Red Hat included.

7.4.2. Sending Faxes

Receiving faxes with Asterisk is quite a bit easier than sending them, because when receiving them, the work of scanning them into digital form is done already. This is the part neither Asterisk nor spandsp addresses. However, these packages can very easily fax a TIFF file. So it's up to you to get that TIFF file in a path where spandsp can grab it.

This can happen in any number of ways. You can create a simple web interface that allows you to upload TIFF files to the server, or, if you have the right software, you can just scan them directly using the Linux machine. I don't recommend either of these approaches, however, because neither of them provides a straightforward way of telling Asterisk where to send the fax from the outside application or script that's handling the scanning and packaging.

Without a lot of hacking, Asterisk just doesn't make a good day-to-day, occasional-use fax server for outbound fax transmittals. There are better solutions to this need already. One of them is HylaFAX, a freely available fax server for Linux and BSD operating systems. HylaFAX can use standard fax/modems, which also makes it cheaper to implement than Asterisk with (comparatively expensive) Digium voice cards. You can obtain HylaFAX from http://www.hylafax.org/.

VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net