app_rxfax mISDN Asterisk 1.4

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:

Spandsp
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)
fax2mail

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.

Lets 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 beeing transmitted by email while currently beeing 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:

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:

Spandsp
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)
fax2mail

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.

Lets 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 beeing transmitted by email while currently beeing 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:

Created by: sapier, Last modification: Fri 18 of Jul, 2008 (16:58 UTC) by sandlord
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+