Web2Fax Gateway

Fax-Gateway   如果您有數據機,可能想用 PC 作傳真之用。網頁界面可以讓本地網絡的所有使用者使用一部數據機傳真文件。
 

 

在網絡上傳送傳真

有很多軟件也可以利用 Hylafax 伺服器在網絡上送出傳真,伺服器能夠透過特別的用戶端,傳送傳真或讀取外界送來的傳真。

大量的用戶端已有存在,而 SuSE java 用戶端似乎是當中最好的,因為它可以獨立用於任何作業系統。缺點是這個用戶端程式必須安裝在網絡上每部電腦,而管理員要預計使用者會有很多問題,因為程式一點也不易用。

對使用者來說最容易的方法是使用一個簡單的網頁界面,只需輸入文字和電話,其餘的都會自動完成。

 

自製的界面

我們很有野心,自己寫整個網頁界面,而不使用現成的軟件。
在您害怕太多  工作前,可以讓您放心的是,不會需要太多編程。
網頁伺服器及 hylafax 伺服器在同一台電腦執行,您不需要使用 hylafax 伺服器的網絡功能,而可以直接處理傳真。
留意:在下列步驟中,假設您已安裝 hylafax 伺服器。

 

步驟一:網頁

首先,我們要建立一個網頁讓使用者輸入傳真的文字,在網頁伺服器建立一個叫 Fax 的子目錄,在該目錄之下再建立一個叫 cgi-bin 的子目錄,script 就是放在這兒:

>> mkdir /usr/local/httpd/htdocs/Fax
>> mkdir /usr/local/httpd/htdocs/Fax/cgi-bin
(在 SuSE 中,網頁伺服器的目錄在 /usr/local/httpd/htdocs/。目錄位置可能會視乎不同的發行本而有不同,例如 /var/www/ 或 /home/www。)
接著我們會建立一個網上表格如下:

 

/usr/local/httpd/htdocs/Fax/index.html檔案

<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="my@email.de" 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>

 

出來的界面如下:

 

Fax form

當然可以有圖像的裝飾,如果沒有移除 <input>-tags 的話。

步驟二:設定 Apache

為了方便查看,處理傳真伺服器的輸入文字的 cgi script 會在同一個子目錄,因此您需要告訴 Apache 那些  cgi scripts 可能會由該目錄執行。
除了現有的設定,您需要在 /etc/httpd/srm.conf 檔案加上以下記錄:

 

 /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"


您需要重新啟動 Apache 伺服器,才能讓新的設定生效:
(在 SuSE)

>> /sbin/init.d/apache restart
(在 RedHat)
>> /etc/rc.d/init.d/apache restart
如新設定仍未能運作,就需要重新啟動系統 (即使這個做法並不建議)

 

步驟三:cgi script

實際的 script 很快就寫好了,它只是將文字儲存在 /tmp/.fax/  目錄,在下一步,cron job 會將文字從該目錄送往伺服器。
 "faxout.cgi" 這 script 應該在 Fax 目錄下的 "cgi-bin" 子目錄內。

 

/usr/local/httpd/htdocs/Fax/cgi-bin/faxout.cgi 檔案

 #!/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 "Content-type: text/html\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>";


(下載 faxout 並改名為 faxout.cgi)

這個 script 必須讓網頁使用者有所需的權限才能執行 (以 root執行 )

>> chmod og+x /usr/local/httpd/htdocs/Fax/cgi-bin/faxout.cgi
需要建立 /tmp/.fax  子目錄,這就是輸入文字暫時儲存的地方:
>> mkdir /tmp/.fax

 

步驟四:cron job

實際的工作由 cron job 呼叫另一個 script 來完成。
這個 script 會將輸入的文字從 /tmp/.fax 目錄傳送至 Hylafax 伺服器。
基於保安理由,這個 script 應該會放在 /root
您也應該在那兒建立一個 .cron_jobs 子目錄,儲存所有定期由 root 執行的 scripts 。

>> mkdir /root/.cron_jobs
我們會在那兒建立一個名為  htmlfax.sh 的 script。

 

 /root/.cron_jobs/htmlfax.sh  檔案


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



此外還要將這 script 變成可執行:

>> chmod u+x /root/.cron_jobs/htmlfax.sh
這個 script 會定期搜尋 /tmp/.fax/ 目錄,查看有沒有傳真要發送。

要令這個功能運作,您需要將記錄加在 crontab 內:

 

Entry in crontab


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



您可以透過圖像界面如 VCron 或 Kcrontab 修改 crontab,或使用指令也可 (以 root 執行﹗)

>> crontab -e
這項記錄每隔十五分鐘便將所有新的傳真傳送至所有收件者。
再多加一項記錄的話,甚至可以在指定時間 (例如由下午六時開始)發放傳真,那就可以繳交較平的電話費。

步驟五:完成

web2fax gateway 現在可以運作無誤了,可以立刻測試,這個簡單的方法當然並不容易,而且頗為費力。在本例中您可以清楚知道 UNIX 系統的幾個元件如何一同運作。
您只需花很少的編程功夫,就能得到很多的功能。

有些「作業系統」應該以本例作簡單的例子 (特別在伺服器服務方面)。

arrow
arrow
    全站熱搜

    Bluelove1968 發表在 痞客邦 留言(0) 人氣()