Web2Fax gatewayIf 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:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Homepage</title> </head> <body> <form METHOD=POST action="/Fax/cgi-bin/faxout.cgi"> <pre> Recipient <input type="text" name="ToName" size=30> Fax number <input type="text" name="ToNumber" size=20> <input type="hidden" name="ToCompany" value=" " size=20> <input type="hidden" name="FromName" value="firstname.lastname@example.org" size=30> <hr> Subject <input type="text" name="Regarding" size=30> <center> Text: <textarea name="Comments" rows=10 cols=60></textarea> </center> </pre> <center> <input type="submit" value="Send fax!"> <input type="reset" value="Delete"> </center> </body> </html>
The resulting frontend will look like:
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:
#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:
>> /sbin/init.d/apache restart(In RedHat)
>> /etc/rc.d/init.d/apache restartor, 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
The script "faxout.cgi" should reside in the subdirectory "cgi-bin" in the directory Fax.
#!/usr/bin/perl require "flush.pl"; $| = 1; $tmpfaxcover="/tmp/.fax/faxcover.$$"; $faxcover='faxcover'; # location of faxcover binary use CGI; $query = new CGI; require "ctime.pl"; $tt = &ctime(time()); chop($tt); $sendfax = "/usr/bin/sendfax"; print STDOUT "\n\n"; print $query->dump; print"<pre>"; @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"; close(TEST); open(LOG, ">>/var/spool/fax/log/sendlog"); print LOG "$tt web $sendfax @args\n"; close(LOG); open(SCR, ">>/tmp/.fax/fax_script.$$"); print SCR "#!/bin/sh\n"; print SCR "$sendfax @args\n"; close(SCR); &flush(STDOUT); system("chmod og+x /tmp/.fax/fax_script.$$"); &flush(STDOUT); print "</pre>"; print "<p><hr><p><center><h1>Fax was sent!</h1></center>";
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.cgiThe 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_jobsThere, we create a script named htmlfax.sh
Addtionally, this script must be made executable:
>> chmod u+x /root/.cron_jobs/htmlfax.shThis 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|
The crontab can be edited with graphical frontends like VCron or Kcrontab or with the command-line instruction (run as root!)
>> crontab -eThis 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.
Enter Own Comment