Posts Tagged document collection

Automated Document Collection via Fax using HylaFax

I. Our OS of choice is CentOS (latest release 5.1) since a HylaFAX rpm is widely available. Assuming we already have a working OS with its network properly configured to reach outside world.

II. Secondly we need to install our modem of choice, in this case a Conexant based data/fax modem. To support the fax capability we need to use the paid version of the linuxant.org HSF softmodem driver. Their website (linuxant.org) provides and simple and easy way to install the driver as well as activating the purchased license.

III. For more convenience we will create a middle user or utility user called ‘faxman’ using whatever password plus we also generate an rsa private key pair. Assuming an rsa key pair has been generated copy the private key to the $POOL/etc/ directory as ‘faxman_id_rsa’

# cp /home/faxman/.ssh/id_rsa /var/spool/hylafax/etc/faxman_id_rsa
# chown uucp.uucp /var/spool/hylafax/etc/faxman_id_rsa
# chmod 0600 /var/spool/hylafax/etc/faxman_id_rsa

Another requirement is that the faxman user should be able to login to localhost using his private key so we do:

faxman@localhost ~$ cat .ssh/id_rsa.pub > .ssh/authorized_keys2
faxman@localhost ~$ chmod 0600 .ssh/*

So when you do:

faxman@localhost ~$ ssh localhost

faxman should login without a fuzz.

IV. Our next step is HylaFax, searching over rpm.pbone.net we found a compatible rpm version 4.4.4 (http://rpm.pbone.net/index.php3/stat/4/idpl/6051053/com/hylafax-4.4.4-1rhel5.i386.rpm.html). Make sure before you install that you satisfied the dependencies (sharutils, gcc, ghostscript(optional)). Once the RPM has been installed faxsetup will automatically execute, accept all defaults except set the correct country code, area code and the phone number the modem will be attached to. Afterwards you will be prompted to configure your modem via faxaddmodem, same as faxsetup, accept defaults except country code, area code and phone number.

V. Next we customize some scripts that comes with hylafax, first up $SPOOL/etc/FaxDispatch . Normally this file sends out email notification to the faxmaster (in our case faxman user) but we will add some values and procedures to scp in and call some external notication script.

## These values will determine to what server and directory the inbound facsimile is to be sent to.
SSH_HOST=jhive.net;
SSH_USER=<user>;
SSH_PASS=<pass>;
SSH_PREFIX=/home/hylafax/web;
NOTIFY=http://www.jhive.net/hylafax/notify.php

Where:
SSH_HOST : the remote host where we will scp our converted facsimiles to
SSH_USER : the remote user
SSH_PASS : optional, but keep here
SSH_PREFIX : the remote directory to send the files to
NOTIFY : an http based service that will be called with an attached querystring with the name of the scp’ed folder.

Another important requirement:
Our ‘faxman’ user must be able to login to SSH_HOST as SSH_USER using only private key pair so you must set this up as well before attempting anything.

Our next script will be $SPOOL/bin/faxrcvd , this script handles whatever it is you want to do with RAW INBOUND (tiff) facsimiles. Open the faxrvcd script and replace the MailWithFAX procedure with this:

MailWithFAX ()
{
    template="etc/templates/$TEMPLATE/faxrcvd-$1.txt"
    files_1=$FILE;
    filetype_1=TIFF;
    nfiles=1;
    for ft in $FILETYPE
    do
        ATTACH_ARGS="$ATTACH_ARGS "`BuildAttachArgs $ft`
    done
    eval CreateMailMessage $template $ATTACH_ARGS \
        2>$ERRORSTO | $SENDMAIL -f"$FROMADDR" -oi "$SENDTO"
    SSHDispatch
}

SSHDispatch ()
{
    IPAY_DATE=`date '+%Y%m%d%H%M%S'`
    if [ -d $TMPDIR ]
    then
        /bin/chmod -R 0777 $TMPDIR
        /usr/bin/ssh -i etc/faxman_id_rsa faxman@localhost "/usr/bin/scp -p -r $TMPDIR $SSH_USER@$SSH_HOST:$SSH_PREFI
X/$IPAY_DATE" 1>>log/scp.log 2>>log/scp.log
        export LYNX_TEMP_SPACE=/tmp; /usr/bin/lynx -dump "$NOTIFY?$SSH_HOST:$SSH_PREFIX/$DATE" 1>>log/lynx.log 2
>>log/lynx.log
        /bin/chmod -R 0700 $TMPDIR
    fi
}

Lastly for this step, we create some additional logs $SPOOL/log/lynx.log and $SPOOL/log/scp.log

touch /var/spool/hylafax/log/scp.log
touch /var/spool/hylafax/log/lynx.log
chown uucp.uucp touch /var/spool/hylafax/log/scp.log
chown uucp.uucp touch /var/spool/hylafax/log/lynx.log

VI. Open up /etc/aliases and add the following:

# alias for notification messages from HylaFAX servers
faxman: <a valid email address where you want notifications sent out to>
FaxMaster: faxman

Close the aliases file and commit by:

# newliases

VII. You should be all set, fire up:

/usr/sbin/faxgetty <your modem device i.e. ttySHSF0>

… and fax away!

VIII. Troubleshooting:

Wondering why your faxes aren’t being sent to remote server or your notify script not being called or failing? Check $SPOOL/log/lynx.log and $SPOOL/log/scp.log

, , ,

No Comments