Faxing in the 21st Century

So, people have been using fax machines for decades. But being the 21st century I’ve actually gotten rid of mine. To my surprise one of the vendors I work with required me to fax them my credit card information. They wouldn’t accept it in email form (I wouldn’t either) or over the phone. So, I needed a way to get faxing working with my Asterisk setup.

Asterisk has an internal fax application. But I’ve found that it isn’t supported in Asterisk 13. After asking around I found that we can use Hylafax as a solution. Plus I wouldn’t have to write the tricky code to get fax to email and email to fax working. They’ve got numerous clients for it already. I wouldn’t have posted anything if it was that easy. I mean you can find countless articles online just googling for Hylafax and Asterisk (this one helped me a lot)

But there is a missing piece. Iaxmodem. This is the glue between Asterisk and Hylafax. Hylafax sees it as a modem… er fax machine… and Asterisk sees it as an extension using their IAX protocol. But there are no packages for Centos 6. I have to roll my own… Not a problem.

I talked before about my personal RPM build scripts that let me build things quickly (here). So, all we need to do is create a spec file and we are good to go.

We’ll skip the header stuff. There isn’t anything in there of value. The fun part is in the install section of the spec file.


%prep
%setup

%install
./build static

mkdir -p $RPM_BUILD_ROOT/usr/sbin
cp iaxmodem $RPM_BUILD_ROOT/usr/sbin/iaxmodem
mkdir -p $RPM_BUILD_ROOT/usr/share/doc/iaxmodem

for i in CHANGES FAQ README TODO VERSION; do
cp $i $RPM_BUILD_ROOT/usr/share/doc/iaxmodem
done

# Copy over the man file
mkdir -p $RPM_BUILD_ROOT/usr/share/man/man1
gzip -c iaxmodem.1 > $RPM_BUILD_ROOT/usr/share/man/man1/iaxmodem.1.gz

# Init
mkdir -p $RPM_BUILD_ROOT/etc/init.d
sed 's;/usr/local/sbin;/usr/sbin;g' iaxmodem.init.fedora > $RPM_BUILD_ROOT/etc/init.d/iaxmodem

# Logrotate - doesn't come from the tar ball, but is our own file
mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d
cp %{_sourcedir}/logrotate $RPM_BUILD_ROOT/etc/logrotate.d/iaxmodem

# IAXModem config file
mkdir -p $RPM_BUILD_ROOT/etc/iaxmodem
sed s/ttyIAX/ttyIAX0/ iaxmodem-cfg.ttyIAX > $RPM_BUILD_ROOT/etc/iaxmodem/ttyIAX0

# Log directory
mkdir -p $RPM_BUILD_ROOT/var/log/iaxmodem
touch $RPM_BUILD_ROOT/var/log/iaxmodem/iaxmodem
touch $RPM_BUILD_ROOT/var/log/iaxmodem/ttyIAX0

%files
%attr( 755, root, root ) /usr/sbin/iaxmodem
%attr( 755, root, root ) /etc/init.d/iaxmodem
%attr( 644, root, root ) /etc/logrotate.d/iaxmodem
%dir %attr( 755, root, root ) /etc/iaxmodem
%config %attr( 644, root, root ) /etc/iaxmodem/ttyIAX0
%dir %attr( 755, uucp, uucp ) /var/log/iaxmodem
%attr( 660, uucp, uucp ) /var/log/iaxmodem/ttyIAX0
%attr( 660, uucp, uucp ) /var/log/iaxmodem/iaxmodem
%doc /usr/share/doc/iaxmodem
%doc /usr/share/man/man1/iaxmodem.1.gz

The first line where I build it is the most important. This will compile IAXmodem and create the executable. It doesn’t install it. To install it, I create a bunch of directories and copy things into it. Some fun bits to notice… I actually create the first device in my package. So I can’t just copy the supplied config, I have to use it to create ttyIAX0 device. I also need to tell the init script where the proper iaxmodem location is. Sed is cool.

Once built (on a completely separate build machine) the RPM installs everything… Configuring it was a bit fun. So, lets do that now… The documents cover most things, but are a bit out of date… We’ll need to do a bit more

  • Add requirecalltoken=no to the iax.conf block for the new IAX peer.
  • Use host=dynamic. For some reason I couldn’t get it to work setting a hostname. And using deny/permit doesn’t work either. This is doing everything on the same server. So the IP was 127.0.0.1

Once we got that done, everything seemed to work nice.