Admin Stuff

This is not straight forward. I am using the fax software from I placed the CapiSpFax utitlity on an internal webserver I have running. Sending a fax now consists of two steps. First I need to create the correct tiff file. I was only able to send normal resolution faxes and only if the page has an exact size of 1728x1145 pixels. I already have setup my scanner to scan an A4 page to a pdf file directly. To send this file via fax I use.

 $ gs -sDEVICE=pgmraw -r209x98 -g1728x1145 -sOutputFile=- \
           -dSAFER -dNOPAUSE -dBATCH -dNOINTERPOLATE -q <pdf-file> | \
       pgmtopbm -threshold -value 0.9 | \
       pnmtotiff -g3 - > <webserver-dir>/fax.tiff

The resolution value is not exactly what is defined for fax but this resolution will exactly place an A4 page into the given image size.

<webserver-dir> is the internal web-servers webroot. To send the file from the FritzBox, I telnet to the box and then execute:

 # cd /var
 # wget http://<internal-server>/CapiSpFax
 # chmod 0755 ./CapiSpFax
 # wget http://<internal-server>/fax.tiff
 # ./CapiSpFax -v -l "<meine-fax-id>" -o "<meine-msn>" -d "<ziel-fax-nummer>" -t fax.tiff

Since all this is quite tedious, I wrote some scripts to simplify it. The first is a utility to convert a PDF (or PS) file to a multi-page Fax-tiff-G3 file:

#!/bin/sh -e

OPTS=`getopt -o hbl -n pdftofax -- "$@"`
if [ $? != 0 ] ; then exit 1 ; fi
eval set -- "$OPTS"


while true; do
    case "$1" in
        -h) cat <<EOF
Usage: pdftofax [-b] [-l] [-h] <[pdf-file] >[tiff-file]

Reads a PDF file on standard input and generates a multi-page tiff
file in Fax-G3 encoding on standard output with the correct
(asymetric) resolution.

    -h  Show this help message

    -b  Generate a non-dithered binary tiff. Use this for scanned

    -l  Landscape mode. The pages will be rotated by 90 degrees

            exit 0
            pbmopts="-threshold -value 0.9"
            rotate="pnmflip -ccw"
            shift ; break ;;
            echo "Internal error"; exit 1 ;;

mkdir "$temp"
trap 'cd /; rm -rf "$temp"' 0 1 2 15
cd "$temp"

gs -sDEVICE=pgmraw -r${res} -g${size} -sOutputFile="%d.pgm" -dSAFER -dNOPAUSE -dBATCH -dNOINTERPOLATE -q -

for page in *.pgm; do
    pgmtopbm $pbmopts <$page \
        | ${rotate} \
        | pnmtotiff -g3 - >${page%.pgm}.tiff

tiffcp *.tiff fax.tiff
cat fax.tiff

And next a python script which will transfer a fax to the fritzbox and send it there


fritzhost  = '...'      # Hostname of the fritzbox to telnet to
fritzpwkey = '...'      # Key in the kwallet 'Passwords' group under which the fritzbox password is stored
webdir     = '...'      # Local (possible NFS) directory of the internal webserver
weburl     = '...'      # URL of the internal webserver from the fritzbox
webvhost   = '...'      # Hostname under which the internal webserver is found (vhost)
myfaxid    = '...'      # My own fax ID
mymsn      = '...'      # The MSN to send the fax with

import telnetlib
import pcop
import pydcop
import shutil
import sys

class FritzTelnet:

    def __init__(self, fritzhost, password):
        self.telnet = telnetlib.Telnet(fritzhost)
        self.telnet.read_until('# ')

    def run(self,command):
        return self.telnet.read_until('# ')

if len(sys.argv) != 2:
    print """Usage: fritzfax [faxnr] <[faxfile]

where [faxnr] is the destination number to send the fax tu and
[faxfile] is a Fax-G3 encoded tiff image file.

faxnr = sys.argv[1]

shutil.copyfileobj(sys.stdin, file('%s/fax.tiff' % webdir,"w"))

kded = pydcop.anyAppCalled('kded')
walletid ='kdewallet',0)
fritzpw = kded.kwalletd.readPassword(walletid, 'Passwords', fritzpwkey)

fritz = FritzTelnet(fritzhost, fritzpw)"cd /var")"rm -f CapiSpFax")"wget --header 'Host: %s' '%s/CapiSpFax'" % (webvhost, weburl))"chmod 755 ./CapiSpFax")"rm -f fax.tiff")"wget --header 'Host: %s' '%s/fax.tiff'" % (webvhost, weburl))
print"./CapiSpFax -v -l '%s' -o '%s' -d '%s' -t fax.tiff"
                % (myfaxid, mymsn, faxnr))"rm -f CapiSpFax fax.tiff")
os.unlink('%s/fax.tiff' % webdir)

This script works by copying the fax file to a local webserver and then telneting to the fritzbox, downloading the CapiSpFax tool and the fax from the local webserver and then sending the fax.