Receive faxes with asterisk and Grandstream HT-503 FXO interface

This guide will help you in configuring asterisk plus an FXO interface (in this casa a Grandstream HT-503) to receive faxes from an analog phone line (POTS) and forward it as a PDF email or file stored on the local filesystem)

This guide is not complete, and must be adapted to your setup.

This guide is written for asterisk 18.10 running on Ubuntu 22.04

Asterisk

Here are the two main files of asterisk to be changed

/etc/asterisk/pjsip_wizard.conf, add the following lines at the end of the file
[ht503]
type = wizard
accepts_auth = yes
accepts_registrations = yes
endpoint/context = receivefax
aor/max_contacts = 1
aor/qualify_frequency = 30
endpoint/transport = transport-udp
endpoint/from_user = ht503
endpoint/identify_by = auth_username
endpoint/allow = !all,g722,alaw,ulaw
inbound_auth/username = ht503
inbound_auth/password = _the_ht503_sip_password_
identify/endpoint = ht503
Then edit /etc/asterisk/pjsip.conf and uncomment all the section [transport-udp]

/etc/asterisk/extensions.conf, add the following lines at the end of the file
[receivefax]
exten => ht503,1,Verbose(3,Incoming fax)
        same => n,Set(datetime=${STRFTIME(,,%Y%m%d-%H%M%S)})
        same => n,Set(faxname=fax-${datetime})
        ; where we put the TIF
        same => n,Set(tiffpath=/var/spool/received-faxes/${faxname}.tif)
        ; get the fax and store the given tif file
        same => n,ReceiveFAX(${tiffpath})
        same => n,System(/usr/local/bin/fax_convert_and_send.sh ${tiffpath} ${faxname} '${REMOTESTATIONID}' ${FAXPAGES} ${CALLERID(num)} ${DID})
And this is /usr/local/bin/fax_convert_and_send.sh
#!/bin/bash

fax_file=$1
fax_name=$2
fax_remoteid=$3
fax_pages=$4
fax_caller=$5
fax_callee=$6
# fax_dest_email: space separated list of destinations
fax_dest_email="destination1@mydest.dom destination2@mydest.dom""

# Directory to publish with apache or nginx
outdir=/var/www/html/infaxes

errdie() {
        echo $1
        exit
}


[[ $# -lt 4 ]] && errdie "error: 4 arguments needed"

[ -f "$fax_file" ] || errdie "file not found"

outfile="$outdir/$fax_name.pdf"

dt=`date '+%d/%m/%Y %H:%M:%S'`

convert "$fax_file" -pointsize 30 -draw "text 60,70 'Received $dt from $fax_remoteid ($fax_caller)'" "$outfile"
echo "Attached FAX."  | mutt -a "$outfile" -s "Fax da $fax_remoteid ($fax_caller)" -- $fax_dest_email
Add some other needed system stuff:
mkdir -p /var/www/html/infaxes
mkdir -p /var/spool/received-faxes
chown asterisk:asterisk /var/www/html/infaxes /var/spool/received-faxes
apt install mutt postfix imagemagick

You need also an MTA, postfix for example.

And mutt configuration ~asterisk/.muttrc
set copy=no
set from="FAX Incoming "

Granstream HT 503 fxo side

On FXO port configuration put:

Other projects on github/gitlab

  • TsLsUsers a windows commandline tool to list and disconnect all RDP/RDS/TS users
  • ScreenTextScroller an application for linux/windows/mac to show a scrolling text in fullscreen, with a web management interface.
  • Contacts

    Write me at giodev@panozzo.it