Asterisk & FreePBX Faxing Solution with IAXModem + Hylafax + AvantFax

This guide attempts to walk you through installing a faxing solution on top of Asterisk that has FreePBX as it’s frontend GUI/dialplan generator.

So for it to work, you need to be

1) Using Debian (this is a Debian guide btw)
2) Have a working Asterisk
3) Running FreePBX 2.7 or higher (don’t need that if you do manual dialplans tho)

The process is as follows:

1) Install IAXModem – Configure at least one virtual serial port
2) Install Hylafax – “Bind” the modem you just created above into Hylafax
3) Create an IAX extension on FreePBX
4) Install Avantfax, create users and bind users to each virtual modem
5) Use Avantfax to login and retrieve/send faxes

Update apt and fix any broken apt installs

1) # apt-get update
2) # apt-get -f install

Installing IAXmodem

IAXmodem simulates a faxmodem and makes it available to Asterisk via IAX2. All the steps in this chapter must be performed as the root user.

1) # apt-get -y install g++ libtiff-tools libtiff4 libtiff4-dev

2) # cd /usr/src

3) The sources for IAXmodem can be downloaded with any typical web browser from http://iaxmodem.sourceforge.net (the version used in this example is 1.2.0).

4) # tar -xvzf iaxmodem-1.2.0.tar.gz

5) # cd iaxmodem-1.2.0

6) # ./configure && make

7) # cp iaxmodem /usr/bin

8) # mkdir /etc/iaxmodem

9) # touch /etc/iaxmodem/ttyIAX0

10) # nano /etc/iaxmodem/ttyIAX0

device          /dev/ttyIAX0
owner           uucp:uucp
mode            660
port            4570
refresh         60
server          127.0.0.1
peername        201
secret          xxxxxxxx
cidname         IAX Modem 1
cidnumber       201
codec           ulaw

11) # echo “IA00:23:respawn:/usr/bin/iaxmodem ttyIAX0” >> /etc/inittab

12) # echo “mo00:23:respawn:/usr/sbin/faxgetty ttyIAX0” >> /etc/inittab

13) # mkdir /var/log/iaxmodem

14) # touch /var/log/iaxmodem/ttyIAX0

15) # touch /var/log/iaxmodem/iaxmodem

16) # reboot

Installing Hylafax

1) # apt-get install -y hylafax-server

2) # faxsetup

Simply press Enter after the following 2-3 questions. Specify serial port ttyIAX0 when it asks.  Enter your area code and phone number afterward and everything after that can be left with the defaults.  When you are asked if you would like to configure another modem, say no.

3) Create an IAX2 extension in FreePBX.  Make sure to use the same port in the ttyIAX0 file you created earlier. Also, enter the following:

		disallow: all
		allow: ulaw
		requirecalltoken: no

Install and configure AvantFax

1) # apt-get install -y apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libpq5 libsqlite3-0 php5-cli php5-common mysql-server imagemagick libtiff4-dev netpbm libnetpbm10-dev libungif-bin libungif4-dev sudo php-mail php-mail-mime php-file php-db php5-mysql sudo php-mail php-mail-mime php-file php-db php5-mysql

2) # cd /usr/src
3) # wget http://downloads.sourceforge.net/project/avantfax/avantfax-3.3.3.tgz
4) # tar -zxvf avantfax-3.3.3.tgz
5) # cd avantfax-3.3.3
6) # mv /usr/src/avantfax-3.3.3/avantfax /var/www
7) # chmod -R 777 /var/www/avantfax/tmp /var/www/avantfax/faxes
8) # cd /var/spool/hylafax/bin
9) # mv faxrcvd faxrcvd.old
10) # mv notify notify.old
11) # ln -s /var/www/avantfax/includes/faxrcvd.php /var/spool/hylafax/bin/faxrcvd
12) # ln -s /var/www/avantfax/includes/notify.php /var/spool/hylafax/bin/notify
13) # mv /usr/bin/faxcover /usr/bin/faxcover.old
14) # ln -s /var/www/avantfax/includes/faxcover.php /usr/bin/faxcover
15) # cd /usr/src/avantfax-3.3.3
16) # nano create_tables.sql
17) on top of this file add “USE avantfax;” without quotes
18) # nano debian-prefs.txt (IMPORTANT!: Ensure the settings here are correct, e.g. ROOTMYSQLPWD is the root MySQL user, supply its password, pay attention to the httpuser and httpgroup (you can do a ps –ef |grep apache and see what user apache2 is running)
19) Fix some apache logging requirements for Avantfax
20) # mkdir /etc/apache2/logs
21) # touch /etc/apache2/logs/avantfax-error_log
22) # /etc/init.d/apache2 start
Start install script.
23) # ./debian-install.sh (if you do not want to use postfix because you already have an email server, like exim, edit the file and remove the existence of the word postfix normally found at the line that says apt-get install, then, start. Install will start downloading packages, configuring postfix (if enabled), getting some pear perl stuff, (YOU SHOULD NOT SEE ANY ERRORS!) 
You can now login to the WebUI at http(s)://[ipaddress]/avantfax/admin. Login with ‘admin’ for the username and ‘password’ for the password. You will be asked to change the password, please do that!

AvantFax setup done

Creating new users

Firstly, create a category, e.g. Engineering Team, using the pulldown menu.

For each modem you create (iaxmodem), create it also in AvantFax. Modems can be mapped to users, which is what we will do now. Under the pull-down menu, select modems. Create the modem when you configured iaxmodem above.

image_thumb[1]

Now, you need to create a new user:

Under the pull-down menu, select new user: create a user and make sure you map him/her to a modem like below;

image_thumb[4]

IMPORTANT! – When you create a new user, there’s a “bug” in hylafax that you also need to manually do it over the cli. So in this case, I’ve created user sanjay and must delete this user and recreate via cli like below; YOU MUST FOLLOW THE ORDER IN WHICH IS SHOWN AFTER CREATING A USER IN AVANTFAX UI ABOVE.

# faxdeluser sanjay
# faxadduser sanjay

image_thumb[7]

It should not have any other objects/characters after the @ for the newly created regular users! as seen corrected above by the faxadduser command.. Make sure the name you created in Avantfax is similar and unique and match that name with the faxadduser command.

Restart hylafax

# /etc/init.d/hylafax restart

Now, you should be able to send the fax in to this user/extension and log on to the WebUI or you can receive an fax-to-email email.

Regular users can login to: http(s)://[ipaddress]/avantfax/ and start receiving and sending faxes.

Here’s a test fax i just received without any modification to the graphics and what not:

image_thumb[9]

To create more users:

1) Create a FreePBX extension like shown above (make sure you use unique port numbers, like 4801….4802….4803…etc)
2) Create an IAX modem (you can copy the ttyIAX0 config file to another file, say #cp ttyIAX0 ttyIAX1, modify that 1 file to match the FreePBX extension info you just created on FreePBX), follow the rest of the steps there to restart and create the inittab entry, like below (for ttyIAX1) : NOTICE the underlined values go up as we add new modems.

# Load modem
IA00:23:respawn:/usr/bin/iaxmodem ttyIAX0
IA01:23:respawn:/usr/bin/iaxmodem ttyIAX1

# Faxgetty
m0:2345:respawn:/usr/sbin/faxgetty ttyIAX0
m1:2345:respawn:/usr/sbin/faxgetty ttyIAX1

3) # /etc/init.d/iaxmodem restart && tellinit q
4) Add hylafax, faxmodem, #faxaddmodem, choose ttyIAX1 now and so on..
5) # /etc/init.d/hylafax restart
6) Create modem in AvantFax called ttyIAX1, create user, say john and map to ttyIAX1
7) # faxdeluser john
8) # faxadduser john
9) # /etc/init.d/hylafax restart
10) That user can log in to http(s)://[ipaddress]/avantfax

References

http://www.the-asterisk-book.com/unstable/faxserver-mit-iaxmodem-und-hylafax.html
http://highsecurity.blogspot.com/2011/01/asterisk-freepbx-iaxmodem-hylafax.html