home   articles   archive   forum   masthead  
Published at 22.6.2000
Author: Ronny Ziegler
Translator: Andy Ziegler
Languages: de nl cn
Printer printer-version
Support Us!

Web2Fax gateway

Fax-Gateway If you own a modem, you might want to send faxes with your PC. A web frontend is the solution for allowing all users in the local network to send faxes with one modem .

Sending faxes over the network

There are many software solutions to to send faxes out of the whole network with a Hylafax server. The server is able, via special clients, to send a fax or to read an incoming one.

A huge number of clients already exists, and a SuSE java client seems to be one of the best solutions because it can be used independently of any operating system. The disadvantage is that this client program must be installed on every computer in the network and the admin should be expecting questions from the users because the program will not win a prize for ease of use.

The most uncomplicated solution for the user is a simple web frontend in which you only have to enter the text and phone number and the rest is done automatically.

A selfmade frontend

We are ambitious enough to write such a web frontend entirely by ourselves and do not use already written solutions.
Before you get terrified of so much work, we can calm you down because we will not need much code.
When the webserver and the hylafax server are running on the same computer, you do not have to use the network abilities of the hylafax server; you can hand over the fax directly.
Note: In the following instructions, we assume that a working hylafax server is already installed.

Step I: The web page

First of all, we create a web page the user shall access to enter his fax text. You create a subdirectory named Fax on the web server and beneath that one, a second one named cgi-bin, where the script shall be placed:

  >> mkdir /usr/local/httpd/htdocs/Fax
  >> mkdir /usr/local/httpd/htdocs/Fax/cgi-bin
(In SuSE, the directory of the web server resides in /usr/local/httpd/htdocs/. This may vary in other distributions, such as /var/www/ or /home/www.)
We then create a web form looking like:

File /usr/local/httpd/htdocs/Fax/index.html
     <meta http-equiv="Content-Type" content="text/html;
  <form METHOD=POST action="/Fax/cgi-bin/faxout.cgi">
               Recipient  <input type="text" name="ToName" size=30>
              Fax number  <input type="text" name="ToNumber" size=20>
                          <input type="hidden" name="ToCompany" value=" "
                          <input type="hidden" name="FromName"
  value="my@email.de" size=30>
               Subject    <input type="text" name="Regarding" size=30>
  <textarea name="Comments" rows=10 cols=60></textarea>
  <input type="submit" value="Send fax!"> <input type="reset"

The resulting frontend will look like:

Fax form

Graphical decoration is allowed, of course, unless the <input>-tags are not removed.

Step II: Adjusting Apache

Because the cgi script that hands over the entered text to the fax server resides in the same subdirectory for better overview, you have to tell Apache that cgi scripts may also be started out of that directory.
You need the following entry in the file /etc/httpd/srm.conf in addition to the existing ones:

File /etc/httpd/srm.conf
   #ScriptAlias: This controls which directories contain server scripts.
   #Format: ScriptAlias fakename realname
   ScriptAlias /cgi-bin/ "/usr/local/httpd/cgi-bin/"
   ScriptAlias /Fax/cgi-bin/ "/usr/local/httpd/htdocs/Fax/cgi-bin"

Restarting the Apache server is necessary to execute the new preferences:
(In SuSE)

  >> /sbin/init.d/apache restart
(In RedHat)
  >> /etc/rc.d/init.d/apache restart
or, if that does not work: Reboot (even if it hurts to recommend this)

Step III: The cgi script

The actual script is quickly written and it only causes the written text to be stored in the directory /tmp/.fax/, from where the text will be handed over to the server by a cron job in the next step.
The script "faxout.cgi" should reside in the subdirectory "cgi-bin" in the directory Fax.

File /usr/local/httpd/htdocs/Fax/cgi-bin/faxout.cgi
   require "flush.pl";
   $| = 1;
   $faxcover='faxcover';	# location of faxcover binary
   use CGI;
   $query = new CGI;
   require "ctime.pl";
   $tt = &ctime(time());
   $sendfax = "/usr/bin/sendfax";
   print STDOUT "\n\n";
   print $query->dump;
   @fax = $query->param('fax');
   $to = $query->param('ToName');
   $phone = $query->param('ToNumber');
   $company = $query->param('ToCompany');
   $from = $query->param('FromName');
   $cover = $query->param('Cover');
   $regard = $query->param('Regarding');
   $comments = $query->param('Comments');
   $comment =~ s/\n//g;
   $comment =~ s/\r//g;
   push(@args, '-P', 'high');
   push(@args, '-m', '-D');
   push(@args, '-f', "$from");
   push(@args, '-d', "$phone");
   push(@args, '-n');
   push(@args, "@fax");
   push(@args, "/tmp/.fax/fax_test.$$");
   print"Performing $sendfax @args\n";
   open(TEST, ">>/tmp/.fax/fax_test.$$");
   print TEST "$comments";
   open(LOG, ">>/var/spool/fax/log/sendlog");
   print LOG "$tt web $sendfax @args\n";
   open(SCR, ">>/tmp/.fax/fax_script.$$");
   print SCR "#!/bin/sh\n";
   print SCR "$sendfax @args\n";
   system("chmod og+x /tmp/.fax/fax_script.$$");
   print "</pre>";
   print "<p><hr><p><center><h1>Fax was 

(download faxout rename to faxout.cgi)

This script must own the necessary permissions to be able to be executed by the web users. (Run as root)

  >> chmod og+x /usr/local/httpd/htdocs/Fax/cgi-bin/faxout.cgi
The subdirectory /tmp/.fax must be created; it's where the written texts are temporarily saved:
  >> mkdir /tmp/.fax

Step IV: The cron job

The actual work is done by another script called from a cron job.
With this script, the written texts get transferred from the directory /tmp/.fax to the Hylafax server.
This script should reside in /root for security means.
You should also create the subdiretory .cron_jobs in there, where we will store all the scripts that must be started by root regularly.

  >> mkdir /root/.cron_jobs
There, we create a script named htmlfax.sh

File /root/.cron_jobs/htmlfax.sh

#!/bin/sh /tmp/.fax/fax_script.* sleep 2 rm /tmp/.fax/fax_script.* rm /tmp/.fax/fax_test.* #END

Addtionally, this script must be made executable:

  >> chmod u+x /root/.cron_jobs/htmlfax.sh
This script will regularly search the directory /tmp/.fax/ for faxes to send.

For this to work, you need an entry in the crontab:

Entry in crontab

0-55/15 * * * * /root/.cron_scripts/htmlfax.sh > /dev/null

The crontab can be edited with graphical frontends like VCron or Kcrontab or with the command-line instruction (run as root!)

  >> crontab -e
This entry sends all new faxes to their recipients every 15 minutes.
With an alternative entry, it is even possible to send the faxes only at particular times (e.g. from 6 p.m.) to use a cheaper telephone rate.

Schritt V: Enjoy

The web2fax gateway is now ready to work without any problems and can be tested at once. Of course, this simple solution does not provide much comfort; but it is very robust. In this example you can see clearly how several components of a UNIX system can work together.
You only have a minimal expenditure of programming effort to get huge functionality.

Some "operating systems" should take this lesson in simplicity (especially in the server services field) as an example.


Talkback Area

Enter Own Comment