My purpose is send and receive faxes using the lines provided by the Asterisk FreePBX voip server.
Asterisk can be configured to receive fax calls, but cannot send faxes, so I need to install some software to manage the fax send job.
The iaxmodem to be used as a modem for Hilafax and as a extension in Asterisk FreePBX, and the Hylafax to handle the fax jobs.
Software
To get both installed run:
apt-get install iaxmodem apt-get install hylafax-client hylafax-doc hylafax-server
Configure iaxmodem for Asterisk FreePBX and Hylafax
ls /etc/iaxmodem
Configure the iaxmodem in file /etc/iaxmodem/ttyIAX0
device /dev/ttyIAX0 owner uucp:uucp mode 660 port 4570 refresh 60 server 127.0.0.1 peername 201 secret 1234 cidname Fax cidnumber 97X554211012 codec ulaw
Change the peername, secret, cidname and cidnumber to the desired values.
Copy the file to setup another iaxmodem.
cp /etc/iaxmodem/ttyIAX0 /etc/iaxmodem/ttyIAX1
Configure the iaxmodem in file /etc/iaxmodem/ttyIAX1
Change the port (important), peername, secret, cidname and cidnumber to the desired values.
Each iax device shoud have this own port. If we put two iaxmodems in the same port, we can get problems.
Restart iaxmodem service
service iaxmodem restart
We also can do it with: /etc/init.d/iaxmodem restart
Configure Hylafax to Asterisk FreePBX and iaxmodem
After configured the iaxmodem we need to run faxsetup utility to begin configuring hylafax.
faxsetup
yes…. enter.
The setup continue and write some configuration files, after ask you to allow stop the faxq process.
yes…. enter.
The setup continue and ask you to allow restart the hylafax server process.
yes…. enter.
The setup continue and as we dont have any modem configured it ask you to run ‘faxaddmodem’.
yes…. enter.
Use ttyUSB0 in config dialog
Finished the modem configuration without much worries (we change that later) you’ll be prompted for some more configuration settings values.
You need to change some of them for the contry and area, and your preferences. Bellow you find the configuration needed and the defaults.
* Country code (1 for USA)
* Area code (fill in with your area code)
* Phone number of fax modem (in +1.xxx.xxx.xxxx format, for the US)
* Local identification string (this should be something similar ‘My Fax Server’ as it is printed on the tag line of outgoing faxes)
* Long distance dialing prefix (1 in US)
* International dialing prefix (011 in US)
* Dial string rules file (accept the default)
* Tracing during normal server operation (accept the default)
* Tracing during send and receive operations (accept the default)
There are a lot more, but just accept the default for them.
When asked to confirm the values that you entered, just accept them.
yes…. enter.
It continues with fax-modem setup to determine the best speed to talk to it, and the fax classes that it supports.
If any errors was show you may ignore then.
When it ask if you want to configure another modem say no.
no…. enter
When it ask to run faxmodem in the new configured fax say yes.
yes…. enter.
The setup process is done. Lets change some files manualy.
Edit file: /var/spool/hylafax/etc/config.ttyIAX0
If that file dont exist make a copy from /var/spool/hylafax/config/iaxmodem.
For receive only fax modem
Add the following to the end of the file:
RingsBeforeAnswer: 1
For send only fax modem
Add the following to the end of the file:
RingsBeforeAnswer: 0
For debug you need to add (also at the end of the file):
ServerTracing: 0x201 SessionTracing: 0x4f
For send only fax modem set:
Copy: /var/spool/hylafax/etc/config.ttyIAX0
To: /var/spool/hylafax/etc/config.ttyIAX1
Restart the Hylafax server
service hylafax restart
Test, Monitoring and troubleshooting
With the software installation and configuration done we need to test.
Sending a fax
We now can test sending with the command
sendfax -n -d 92XXXXX51 /etc/issue.net
The fax is added to the hylafax job queue.
Monitoring hylafax
We can check the modem status and fax queue with
watch faxstat -s
View a verbose modem status with:
faxstat -v
View fax queue
faxstat -ds
or
ll /var/spool/hylafax/sendq/q*
Delete a fax job
faxrm jobnr
Delete a fax job from another user
su -s /bin/sh -c "faxrm 87" Debian-exim
Script to delete all fax jobs.
#!/bin/sh Q=/var/spool/hylafax/sendq cd $Q for x in `ls -1 q* | cut -d q -f 2` ; do faxrm $x done
Hylafax Log files
/var/log/daemon.log
/var/spool/hylafax/log/xferfaxlog
/var/spool/hylafax/log/*
/var/log/iaxmodem/ttyIAX0
/var/log/iaxmodem/ttyIAX1
Configure hfaxd to log its operation by setting the ServerTracing in the hfaxd.conf file: ServerTracing: 0x3 # enable protocol tracing.
Service or in initab
As far as i know configuring this is optional. Its automatic for me.
It is possible to run faxgetty and yaxmodem as service or in initab.
The above setup is done using it as service.
- The faxgetty instances are handle by Hylafax service;
- The iaxmodem instances are handle by Iaxmodem service;
Check if Hylafax is configured to use faxgetty in initab.
cat /etc/default/hylafax
check for USE_FAXGETTY=YES
if not, make sure it is uncomented or active, to use as service.
If you cant, you should use initab configuration bellow.
if the iaxmodems are not working as a service.
You should use initab configuration bellow.
In both situations remove the # on desired lines.
cat /etc/inittab
# Prepare iaxmodem for Hylafax with Asterisk plus FreePBX
#
# iaxmodem is handled by Iaxmodem service
#IA00:23:respawn:/usr/bin/iaxmodem ttyIAX0
#IA01:23:respawn:/usr/bin/iaxmodem ttyIAX1
#faxgetty is handled by Hylafax service
#mo00:23:respawn:/usr/sbin/faxgetty ttyIAX0
#mo00:23:respawn:/usr/sbin/faxgetty ttyIAX1
To restart inittab
init q
Email to Fax
Using exim4 with virtual domains for faxnumber@domain.zorg
Edit file /etc/exim4/virtual/domain.zorg and add a catchall to the script:
* : "|/usr/local/bin/mail2fax.sh"
Update exim4 config, restart and flush queue.
update-exim4.conf invoke-rc.d exim4 restart exim4 -qff
Create file /usr/local/bin/mail2fax.sh and add:
RANDOMFAX=/tmp/mail2fax.$$ mkdir $RANDOMFAX cat >> $RANDOMFAX/_message_ # Uncomment the following three lines for debugging. #set -x #exec > /tmp/mail2faxlog.$$ 2>&1 #cp $RANDOMFAX/_message_ /tmp/mail2faxmail.$$ JOBID=`grep -e "^subject:" -i $RANDOMFAX/_message_ | sed q | sed 's/^[^:]*: *//g'` TOLINE=`grep -e "^to:" -i $RANDOMFAX/_message_ | sed q` FROMLINE=`grep -e "^from:" -i $RANDOMFAX/_message_ | sed q` if [ "`echo $TOLINE | grep '<.*>'`" != "" ]; then TONUMBER=`echo $TOLINE| sed -e 's/.*<\(.*[^@]*\)@.*>.*/\1/'` else TONUMBER=`echo $TOLINE| sed -e 's/^[Tt]o://g' -e 's/[ ]*\(.*[^@]*\)@.*/\1/'` fi if [ "`echo $FROMLINE | grep '<.*>'`" != "" ]; then FROMPATH=`echo $FROMLINE| sed -e 's/.*<\(.*\).*>.*/\1/'` else FROMPATH=`echo $FROMLINE| sed -e 's/^[Ff]rom://g' -e 's/[ ]*\([^ ]*\).*/\1/'` fi echo "faxmail -v -T $TONUMBER | sendfax -vv -n -D -f "$FROMPATH" -i "$JOBID" " > /var/log/mail2fax.log cat $RANDOMFAX/_message_ | faxmail -v -T $TONUMBER | sendfax -vv -n -D -f "$FROMPATH" -i "$JOBID" rm -rf $RANDOMFAX exit 0
Give execute permissions
chmod a+x /usr/local/bin/mail2fax.sh
email 2 fax log
/var/log/mail2fax.log
Test local
cat email.txt | /usr/local/bin/mail2fax.sh
cat email.txt | faxmail -v -T 960000001 | sendfax -vv -n -D -f email@gmail.xcom -i Subject
Asterisk configuration for fax
Testing
/etc/asterisk/udptl_custom.conf
added
T38FaxUdpEC=t38UDPRedundancy
changed for original
t38pt_udptl=yes
t38pt_rtp=no
t38pt_tcp=no
Asterisk CLI fax module commands
fax set debug {on|off} — Enable/Disable FAX debugging on new FAX sessions
fax show capabilities — Show the capabilities of the registered FAX technology modules
fax show session — Show the status of the named FAX sessions
fax show sessions — Show the current FAX sessions
fax show settings — Show the global settings and defaults of both the FAX core and technology modules
fax show stats — Summarize FAX session history
fax show version — Show versions of FAX For Asterisk components
Usefull Iinks
http://enginx.com/blog/hylafax-iaxmodem-pure-asteriskfreepbx-replacing-rtfax/
http://www.dslreports.com/forum/r25113228-HOW-TO-Ubuntu-10-04-Asterisk-Hylafax-iaxmodem
http://the-asterisk-book.com/1.6/faxserver-mit-iaxmodem-und-hylafax.html
https://wiki.debian.org/HylaFax
http://www.hylafax.org/site1/man/hylafax-config.html
http://www.hylafax.org/site1/troubleshooting.html
http://hylafax.sourceforge.net/howto/faxing.php
http://hylafax.sourceforge.net/howto/tweaking.php