Avantfax-Hylafax-Iaxmodem - TB Faxing with web interface

trixbox-2.6.1.13, Postfix, Iaxmodem 1.1.1, Hylafax+ 5.2.5, Avantfax 3.1.3

Ref:
http://trixbox.org/forums/trixbox-forums/share-your-trixbox-succe...
http://www.trixbox.org/forums/trixbox-forums/open-discussion/hyla...
http://groups.google.co.il/group/fa.hylafax/search?hl=iw&group=fa...
http://www.trixbox.org/forums/trixbox-forums/help/postfix-error
http://www.hylafax.org/content/Desktop_Client_Software

Acknowledgement:
I owe a lot to the guides of Lamarmora, Kspare & Giuliano for this compilation.

BASICS:
avantfax = web interface
hylafax = fax software
iaxmodem = software modem

My starting point was a SOHO functional TB 2.6.1

As always, please don't use my step-by-step guide straight on your working box, but try it first on a spare one! Differences in hardware may account for appropriate adjustments.

Major steps of installations:
1. Install necessary packages
2. Install POSTFIX if not your default, skip if you prefer SENDMAIL
a. Configure postfix
3. UPGRADE TO PHP5 if necessary
4. Update system to the latest stable versions (Don't do that unless you're a master in passwords changes)
5. Install Hylafax +
6. Install IAXMODEM
a. Configure Trixbox
i. Configure Asterisk IAX2 fax Extension
ii. Configure asterisk to use this extension for faxes
iii. Configure route
b. Configure IAXModem
c. Configure Hylafax
7. Verifying functionality
8. Install Avanfax
9. Avantfax configuration
10. Testing

1) Install necessary packages

Can be done in a single row writings: yum -y install package package ….
For clarity they are written separately.

yum -y install ghostscript
yum -y install sharutils
yum -y install mgetty-voice
yum -y install gcc*
yum -y install make
yum -y install iaxmodem
yum -y install ImageMagick
yum -y install libtiff
yum -y install netpbm-progs
yum -y install netpbm
yum -y install libungif
yum -y install sudo
yum -y install a2ps
yum -y install psutils
yum -y install expect
yum -y install php-pecl-Fileinfo
yum -y install php-devel
pear install MDB2_driver_mysql
pear install db mail Mail_Mime
pear upgrade-all
pear channel-update pear.php.net

ln -s /usr/share/fonts/default/ghostscript/ /usr/share/ghostscript/fonts

2) INSTALL POSTFIX INSTEAD OF SENDMAIL (easier to configure)
Skip this step if you have working Sendmail.
Skip this step if you have Posfix installed.
rpm -e --nodeps sendmail (removal of sendmail)
yum -y install postfix

Configure postfix

Can be done manually, or via webmin
vi /etc/postfix/main.cf
insert this line:
relayhost = mail.your_provider.com (use your smtp server)
check that all the other lines with "relayhost=xyz...." are commented out.
close an save /etc/postfix/main.cf
service postfix start

Authentication in Postfix the simplest way

http://www.trixbox.org/forums/trixbox-forums/help/postfix-error [by Vrillusions]
For those that need to authenticate.
Go to the trixbox admin then choose Settings -> General Settings.
Enter all the mail information there: your-SMTP-server .
FQDN: your-FQDN
Authorization name your-mail-user-name
Password: your-mail-password
After it saves go into console and type the following:
postmap /etc/postfix/saslpasswd
This will build the /etc/postfix/saslpasswd.db file that postfix needs.
Then do
/etc/init.d/postfix restart
to restart postfix which will trigger it trying to send all messages in its queue.
Just remember if you change something in the general settings you have to rerun postmap

3) UPGRADE TO PHP5
Skip if you've PHP5 ( e.g. TB 2.6.xx)
vi /etc/yum.repos.d/CentOS-Base.repo
Go to " and centosplus" and change "enable=0" to enable=1
yum upgrade php
ln -s /usr/lib/php/modules/* /usr/lib/php4/
mysql_fix_privilege_tables --user=root --password=passw0rd
chown -R asterisk:asterisk /var/lib/php/session
vi /etc/yum.repos.d/CentOS-Base.rep
Go to " and centosplus" and set back "enable=1" to enable=0
Reboot

4) Update system to the latest stable versions
Again you're forewarned, don't do that unless familiar with the intricate password system and knows how to revert to your passwords, as updating creates havoc with the system passwords which are dispersed all over, several of them return to defaults!!!
yum –y update
reboot

5) INSTALL HYLAFAX PLUS
Anyone who follows this tutorial, if you are prone to doing yum updates you must exclude hylafax because the box may try to over write hylafax+
Now download the latest binaries
cd /usr/src
wget http://packages.sw.be/hylafax/hylafax-5.2.5-1.el5.rf.i386.rpm
rpm -i hylafax-5.2.5-1.el5.rf.i386.rpm

6) INSTALL IAXMODEM
cd /usr/src
Now download the latest binaries
wget http://voxel.dl.sourceforge.net/sourceforge/iaxmodem/iaxmodem-1.1...
tar zxvf iaxmodem-1.1.1.tar.gz
cd iaxmodem-1.1.1
./build static
cd /usr/sbin
mv iaxmodem iaxmodemold
cp /usr/src/iaxmodem-1.1.1/iaxmodem iaxmodem
ln -s /usr/share/fonts/default/ghostscript/ /usr/share/ghostscript/fonts

Configurations done in Trixbox:
Configure Asterisk Extension
Edit the iax.conf (through FreePBX) web GUI
Log into the FreePBX control panel with your browser and Click:
Setup -> Extensions -> IAX2 (create a new IAX2 extension)
And enter the following:
Extension Number: 9001 ( 9001 [my chosen number, chose what's suitable for you] and go up to as many extensions as you need.)
Display Name: Digital Modem 1 (chose whatever name which suits you)
Record Incoming: Never
Record Outgoing: Never
Secret: extension-password

Perform this step once for each channel on which you wish to receive faxes changing the extension number each time. The example above uses a single channel and a single extension: 9001
Don't Forget Click Submit and then the red bar at the top!

Finishing this step the Fax extension should show as follows:
Display Name: Digital Modem 1
Extension Number: 9001
secret your_password
notransfer yes
context from-internal
host dynamic
type friend
port 4570 (should be entered/changed in accordance with IAXMODEN settings, explained there)
qualify yes
disallow all
allow slinear (or alaw, must match IAXMODEN configuration)
dial IAX2/9001
accountcode
mailbox 9001@device
Record Incoming: Never
Record Outgoing: Never

Configure asterisk to use this extension for faxes:
PBX Settings -> Setup -> General Settings -> Fax Machine -> Extension of fax machine Extension of fax machine for receiving faxes: Digital Modem 1 <9001>
Don't Forget Click Submit Changes and then the red bar at the top!

Configure route
In my case the simplest – any DID / any CID
Fax extension 9001
Fax email (blank)
Fax detection type None
Clear destination IVR MainMenu

Configure IAXModem
You need a config file for each Zaptel channel on which you wish to receive faxes. The iaxmodem RPM sets up only one config file by default.
Edit Config Files (using vi nano or from shell through WinSCP )
device /dev/ttyIAX1 (edit each file to reflect the device, IE. ttyIAX1 would go in iaxmodem-cfg.ttyIAX1 etc.
cd /etc/iaxmodem
nano iaxmodem-cfg.ttyIAX
owner uucp:uucp
mode 660
port 4570 (should be the same on the corresponding IAX2 fax extension)
refresh 60 (you can leave 300 but you'll get nasty messages on"/var/log/asterisk/full")
server 127.0.0.1
peername 9001 (change this to your corresponding IAX2 extension # )
secret your-password (iax2 password you used when you created the extension)
cidname CUSTOMER (Customer name)
cidnumber CUSTOMER-NUMBER (Customer fax number)
codec slinear (leave this recommended but for some countries you can use alaw, don't forget to put the same codec in the IAX2 fax extension in your TrixBox!

cd /etc/iaxmodem
(copy default base configuration to iaxmodem devices as many as defined
cp iaxmodem-cfg.ttyIAX iaxmodem-cfg.ttyIAX1
cp iaxmodem-cfg.ttyIAX iaxmodem-cfg.ttyIAX2
cp iaxmodem-cfg.ttyIAX iaxmodem-cfg.ttyIAX3
...
edit each for suitable corresponding parameters:
peername (change this to your corresponding IAX2 extension # etc)
secret (iax2 password you used when you created the extension)
cidname (Customer name)
cidnumber (Customer fax number)

nano /etc/iaxmodem/iaxmodem-cfg.ttyIAX1
nano /etc/iaxmodem/iaxmodem-cfg.ttyIAX2
nano /etc/iaxmodem/iaxmodem-cfg.ttyIAX3
...
Setup Logs
make sure it can log properly:

mkdir /var/log/iaxmodem
touch /var/log/iaxmodem/iaxmodem-cfg.ttyIAX1
touch /var/log/iaxmodem/iaxmodem-cfg.ttyIAX2
touch /var/log/iaxmodem/iaxmodem-cfg.ttyIAX3
...
Add faxgetty to /etc/inittab
These correspond to the device lines in the /etc/iaxmodem/* config files. (see previous step, above).
You need one of these for each channel, so a T1/PRI would require 23 lines. The last argument to faxgetty ('ttyIAX' in this case) is the device name (i.e. /dev/ttyIAX) on which to connect to iaxmodem.
I put these at the very bottom:

nano /etc/inittab
t0:23:respawn:/usr/sbin/faxgetty ttyIAX1
t1:23:respawn:/usr/sbin/faxgetty ttyIAX2
t2:23:respawn:/usr/sbin/faxgetty ttyIAX3
...

Configure Hylafax

There are a number of important files used by Hylafax. Most of them reside in the /var/spool/hylafax/etc directory.

Create the necessary files and permissions for incoming fax reporting:
cd /var/spool/hylafax/etc
touch xferfaxlog
chown uucp:uucp xferfaxlog

Faxsetup
Enter appropriate parameters, mostly yes or default to:
Do you want to run faxaddmodem to configure a modem [yes]? no
/usr/sbin/faxsetup

It can be done also by editing the hylafax iax settings. You only need to edit the top to reflect your fax numbers in the base file and copy it out the suitable number of times.
nano /var/spool/hylafax/etc/config.ttyIAX

CountryCode: 1 (put your country code)
AreaCode: 306 (put your area code, omit preceding zero)
FAXNumber: +1.306.555.1212 (put your fax number)
LongDistancePrefix: 1 (put your NDD Prefix (National Direct Dialing))
InternationalPrefix: 011 (put your appropriate IDD Prefix (International Direct Dialing))
DialStringRules: etc/dialrules
ServerTracing: 0xFFF
SessionTracing: 0xFFF
RecvFileMode: 0600
LogFileMode: 0600
DeviceMode: 0600
RingsBeforeAnswer: 1
SpeakerVolume: off
GettyArgs: "-h %l dx_%s"
LocalIdentifier: "Your Customer"
TagLineFont: etc/lutRS18.pcf
TagLineFormat: "From %%l|%c|Page %%P of %%T"
MaxRecvPages: 200

cd /var/spool/hylafax/etc
nano config.ttyIAX
cp config.ttyIAX config.ttyIAX1
cp config.ttyIAX config.ttyIAX2
cp config.ttyIAX config.ttyIAX3
...

chown uucp:uucp config.ttyIAX1
chown uucp:uucp config.ttyIAX2
chown uucp:uucp config.ttyIAX3
...

FaxDispatch file
One of the most important files is the FaxDispatch script.
Edit fax dispatch file to control where the faxes are emailed to, you've to create it as it doesn't exist in the default installation. This file is not needed if you intend to install Avantfax
nano /var/spool/hylafax/etc/FaxDispatch

SENDTO=faxes@customer.ca; # by default email to FaxMaster
FILETYPE=pdf; # in PDF format
## and/or by device
#case "$DEVICE" in
# ttyS1) SENDTO=john;; # all faxes received on ttyS1
# ttyLT0) SENDTO=mary@home;; # all faxes received on ttyLT0
#esac

You can also edit it to forward faxes based on the device.
Simple single E-Mail FaxDispatch example
Here is a simple example that routes faxes to my email address:

# ---------------- Start FaxDispatch Example 1 --------------------
FILETYPE=pdf;
SENDTO=your-email-destination;
# ---------------- Stop FaxDispatch Example 1 ---------------------

More complex examples, such as inbound DID routing to separate email addresses can be tailored.

chown uucp:uucp FaxDispatch

Modify how faxes are sent
chkconfig iaxmodem on
nano /var/spool/hylafax/bin/faxrcvd
INFO=$SBIN/faxinfo
FAX2PS=$TIFFBIN/fax2ps
TIFF2PS=tiff2ps
TOADDR=support@yourcompany.com (address errors are sent to)
FROMADDR=fax@yourcompany.com (address faxes appear to come from
TIFFINFO=tiffinfo
NOTIFY_FAXMASTER=errors
/usr/sbin/faxsetup
Finish Up

7) Verifying functionality
Start Up IAXModem:
service iaxmodem start
check the log:
tail -f /var/log/iaxmodem/iaxmodem
tail -f /var/log/iaxmodem/iaxmodem-cfg.ttyIAX1

Start Up Faxgetty:
telinit q
tail -f /var/log/messages

Verify E-Mail Traffic
You can also check the sendmail log to verify that emails are being sent as expected:
tail -f /var/log/maillog
Reporting
Now test some fax calls and you're done! You can use the following command to view a report of the faxes you receive:

recvstats - will display some fax stats

8) INSTALL AVANTFAX

DOWNLOAD AND UNTAR AVANTFAX
cd /anywhere_you_untarred_the_sources/avantfax-3.1.3 (download the latest version)
chown -R asterisk:asterisk avantfax
mv avantfax /var/www/html/
mysql -uroot -ppassw0rd < create_user.sql
mysql -uavantfax -pd58fe49 avantfax < create_tables.sql
cd /var/www/html/avantfax/includes/
cp -a local_config-example.php local_config.php
vi local_config.php
and change "$dft_config_lang = "en";" to your language
chmod -R 777 /var/www/html/avantfax/tmp
chmod -R 777 /var/www/html/avantfax/faxes
cd /var/spool/hylafax/bin
mv faxrcvd faxrcvd.old
mv notify notify.old
ln -s /var/www/html/avantfax/includes/faxrcvd.php /var/spool/hylafax/bin/faxrcvd
ln -s /var/www/html/avantfax/includes/notify.php /var/spool/hylafax/bin/notify
mv /usr/bin/faxcover /usr/bin/faxcover.old
ln -s /var/www/html/avantfax/includes/faxcover.php /usr/bin/faxcover
/usr/sbin/faxadduser -a your-asterisk-password asterisk
/usr/sbin/faxdeluser localhost
/usr/sbin/faxdeluser 127.0.0.1
echo 127.0.0.1 >> /var/spool/hylafax/etc/hosts.hfaxd
vi /etc/sudoers
and add the following line (all on one line, best - cut and past):
asterisk ALL = NOPASSWD: /sbin/reboot, /sbin/halt, /usr/sbin/faxdeluser, /usr/sbin/faxadduser -u * -p * *

vi /etc/crontab
and add the following 2 lines:
0 * * * * /var/www/html/avantfax/includes/phb.php
0 0 * * * /var/www/html/avantfax/includes/remold.php

To avoid "Fatal error: Call to a member function get_name() on a non-object in /var/www/html/avantfax/sendfax.php on line …"
You must set register_globals to off ( php.ini )
Edit both of your php.ini
/etc/php.ini
/var/trixbox_load/php.ini
and change:
register_globals=On
to
register_globals=Off
and restart apache
apachectl restart

To access Avantfax for the first time use
user: admin
password: password (you'll be asked to change it to a strong password on first logging)
Now point your browser to:
"http://where_your_FreePBX_is/avantfax/admin"
and configure a user for AVANTFAX
and then to
"http://where_your_FreePBX_is/avantfax"
to login with the user you just created.

Important
Using Avantfax you can only attach PostScript (.ps), PDF (.pdf), and TIFF (.tif) files for faxing, otherwise you've to convert to either of these formats or use some other solution such as Hylafax client or Sambafax.
http://www.hylafax.org/content/Desktop_Client_Software