Upgrade 3CX to v18 and get it hosted free!

app_rxfax mISDN Asterisk 1.4

Author image

This HOWTO tries to give you a short introduction how to use app_rxfax with mISDN and asterisk.

Versions used:

Asterisk : 1.4.17
mISDN: latest git (1.2 series)
spandsp: 0.0.4-pre15
agx_asterisk_addons (app_rxfax): 1.4.5 (svn)
tiff: 3.8.1

Links to required software:

AGX Extra Addons for Asterisk (use “svn co https://agx-ast-addons.svn.sourceforge.net/svnroot/agx-ast-addons agx-ast-addons”for latest version)

Preparations

  • First of all, you need a working Asterisk installation make sure you can receive normal calls via chan_mISDN.
  • This HOWTO assumes you have a dedicated number that receives your faxes, if not you might take care of normal calls too but that’s nit subject of this HOWTO.
  • Another prerequisite is that you have installed a working MTA eg sendmail,postfix,exim. You need an MTA to transmit the received faxes via email.
  • Building agx_asterisk_addons requires cmake which is available as package in many distributions.

 

WARNING

A mISDN channel is closed as soon as the fax is transmitted, therefore the dialplan execution is stopped right after rxfax returns. This is quite anoying as you can’t send the mail using the asterisk System cmd. To avoid faxes beeing spool forever you need cron or fcron to empty the spool directory and send the emails.

Another solution to handle this is further down

Step by step

Update tiff it’s part of nearly every distribution so make sure your distris libtiff is >= 3.8 but < 4

Download and build spandsp 0.0.4-pre15 (pre16 migth work too)

./configure –prefix=/usr
make
make install

Download and build agx_asterisk_addons (tested svn 1.4.5)

./build.sh

Edit the context which is attached to incoming mISDN calls in extentions.conf

exten => <YOURFAXNUMBER>,1,Answer()
exten => <YOURFAXNUMBER>,2,Set(FAXFILE=/var/spool/asterisk/fax/${STRFTIME(${EPOCH},,%Y%m%M%S)}-${CALLERID(num)}-${EXTEN})
exten => <YOURFAXNUMBER>,3,rxfax(${FAXFILE}.tif)
exten => <YOURFAXNUMBER>,4,Hangup

At this point restart asterisk and do a first test. by now faxes should already be received and saved to /var/spool/asterisk/fax/ as tif files.

Let’s do the submitting.
Download the fax2mail script and put it to /usr/bin. Don’t forget to mark it executable. Don’t forget to change the destination email address in this script.

To avoid faxes being transmitted by email while currently being received our cron script first marks faxes as already seen before sending it per mail on next execution. This is done by a simple lock file mechanism create the directory /var/spool/asterisk/fax/complete and /var/spool/asterisk/fax/transmitted if you want to save all faxes localy.
The cron script is rather simple:

 

  1. !/usr/bin/perl

@ls = `ls -1 /var/spool/asterisk/fax`;

foreach $line (@ls) {
chomp($line);
($name,$ext) = split(‘\.’,$line);
($date,$source,$destination) = split(“-“,$name);

if ($ext eq “tif”) {
if ($TFILE = open(“r”,”/var/spool/asterisk/fax/complete/$name”)) {
close($TFILE);
print “LINE: $date | $source | $destination\n”;
system(“/usr/bin/fax2mail –cid-name \”asterisk\” –cid-number \”$source\” –dest-exten \”$destination\” -f \”/var/spool/asterisk/fax/$name\””);
system(“mv /var/spool/asterisk/fax/$line /var/spool/asterisk/fax/transmitted/”);

  1. system(“rm /var/spool/asterisk/fax/$line”);

system(“rm /var/spool/asterisk/fax/complete/$name”);
}
else {
system(“touch /var/spool/asterisk/fax/complete/$name”);
}
}

}

If you don’t want to save the faxes comment the line moving the files to transmitted and uncomment the line deleting the file.

Now add a cron job to your favourite cron daemon that executes this perl script regularly. I use a interval of 2 minutes but you might be fine with 15 minutes too.

 

Another Fax handle solution

You can create a new context to receive the fax. At the end of this context you can execute any shell script.

Example:

exten => <YOURFAXNUMBER>,1,Answer()
exten => <YOURFAXNUMBER>,n,Set(NumberCalled=${CALLERID(num)})
exten => <YOURFAXNUMBER>,n,Goto(fax,999,1)

fax]
exten => 999,1,Set(FAXFILE=/var/faxes/faxfrom-${NumberCalled}-${UNIQUEID}.tif)
exten => 999,n,rxfax(${FAXFILE})
exten => h,1,system(/usr/bin/handlefax ${FAXFILE} ${NumberCalled})

Related Articles:

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.