Crmgo Blog

Konfiguracja faksu

Konfiguracja faksu

Konfiguracja faksu (odbieranie) W idealnym świecie chciałbym zarówno odbierać, jak i wysyłać faksy za pomocą wbudowanego faksu w Asterisku, jednak wysyłka wciąż budzi wiele kwestii organizacyjnych (np. jak podawać numer, konwertować formaty itd.). W tym artykule omówię konfigurację odbierania faksów. Samą firmą Digium…

Konfiguracja faksu

Konfiguracja faksu (odbieranie)

W idealnym świecie chciałbym skonfigurować zarówno odbieranie, jak i wysyłanie faksów za pomocą wbudowanego modułu faksowego Asteriska, jednak wysyłanie wciąż budzi wiele pytań organizacyjnych (np. jak podawać numer, konwertować formaty itp.). W tym artykule omówię konfigurację odbierania faksów.

Firma Digium opracowała i sprzedaje oprogramowanie faksowe dla Asteriska. Można je pobrać i przetestować w trybie darmowym (z ograniczeniem do jednej linii) lub dokupić linie po 40 dolarów, co jest całkiem niską ceną (w porównaniu do tradycyjnych faksów).

Spróbujmy skonfigurować faks tak, aby odbierane dokumenty były automatycznie przesyłane na wybrany przez nas adres e-mail.

Instalacja faksu Digium

Najpierw pobieramy sam program. Użyłem narzędzia yum:

yum install asterisk18-res_fax_digium
ponieważ kompilowałem Asteriska ręcznie, pobrałem moduł ze strony producenta, korzystając z oryginalnej instrukcji:
Uwagi:
W wersji 1.8 moduł res_fax jest już zainstalowany, instalujemy tylko res_fax_digium poprzez skopiowanie go do katalogu z modułami.

Następnie kupujemy licencję lub uzyskujemy darmową dla jednego połączenia, uruchamiamy narzędzie /usr/sbin/register i rejestrujemy nasz faks.

Tworzymy plik /etc/asterisk/res_fax.conf (przyjąłem wszystkie parametry z przykładowego pliku):

[general] maxrate=14400 minrate=2400 statusevents=no modems=v17,v27,v29 ecm=yes

Przeładowujemy Asteriska i sprawdzamy, czy moduł faksowy został załadowany.

Moduł można załadować bez restartu za pomocą polecenia module load res_fax_digium

asterisk*CLI> module show like res_fax Module                         Description                              Use Count res_fax.so                     Generic FAX Applications                 1 res_fax_digium.so              Digium G.711 and T.38 FAX Technologies ( 0

 

Konfiguracja dialplanu

W poprzednim artykule opisałem „zalążek” kontekstu dla faksu. Czas go dokończyć.

Część pliku wziąłem z dokumentacji faksu, część uzupełniłem samodzielnie. Zwracam uwagę, że Asterisk musi mieć prawa do zapisu w katalogu, który wyznaczysz do odbierania faksów.

777 - wewnętrzny numer faksu
....
; from-fax exten => 777,1,GoTo(fromfax,fax,1)
...
fromfax] ; kontekst faksu programowego. exten => fax,1,NoOp(group_rittal_softfax from ${CALLERID(NUM)})

; pobierzemy nazwę pliku w formacie fax-[numer_faksu].tif
exten => fax,n,Set(GLOBAL(FAXCOUNT)=${IF($["${GLOBAL(FAXCOUNT)}"=""]?0:${GLOBAL(FAXCOUNT)})})
exten => fax,n,Set(GLOBAL(FAXCOUNT)=$[${GLOBAL(FAXCOUNT)} + 1])
exten => fax,n,Set(FAXCOUNT=${GLOBAL(FAXCOUNT)})
exten => fax,n,Set(FAXFILE=/tmp/faxes/fax-${FAXCOUNT}.tif)

; odbierzemy faks do pliku
exten => fax,n,ReceiveFax(${FAXFILE})
exten => fax,n,Hangup()

; gdy faks rozłączy się, zajmiemy się analizą tego,
; co zostało odebrane
exten => h,1,NoOp(fax hangup)
; pobierzemy status odbioru
exten => h,n,GotoIF($["${FAXOPT(status)}" != "SUCCESS" ]?finish)

; status of reception - successful.
; now it is necessary to pass this file name to the script with the action description
; the script accepts the following parameters:
; -f=file name -m=action -p=parameter
; -m=del - delete file
; -m=mail -p="address" - send via email
; -m=print -p="printer name" - print
; at the first stage we will execute all three, then we will choose

; printing
exten => h,n,NoOp(${SHELL(php /var/lib/asterisk/rittal/fax_work.php -f ${FAXOPT(filename)} -m print -p printer1)})
; sending
exten => h,n,NoOp(${SHELL(php /var/lib/asterisk/rittal/fax_work.php -f ${FAXOPT(filename)} -m mail -p user@rittal.ru)})
; deleting
exten => h,n,NoOp(${SHELL(php /var/lib/asterisk/rittal/fax_work.php -f ${FAXOPT(filename)} -m del)})
; finishing
exten => h,n(finish),NoOp(finish fax hangup)

 

create the file /var/lib/asterisk/rittal/fax_work.php

<?php date_default_timezone_set('Europe/Moscow'); $args=getopt("f:m:p:");// check that the "file" parameter is set and the file exists if(!isset($args['f'])) die("use -f to give file name\n"); if(!file_exists($args['f'])) die("file '".$args['f']."' is not exists\n");

// check that the mode parameter is set
if(!isset($args['m'])) die("use -m to give mode name\n");

switch ($args['m'])
{
case 'del':
// file deletion
unlink($args['f']);
break;
case 'mail':
// sending email
if( (!isset($args['p'])) || ($args['p']=='')) die("use -p to give dest mail\n");

$to=$args['p']; // to whom
$subject="Fax received ".date("d.m.Y H:i:s"); // subject
$random_hash = md5(date('r', time()));
// Headers
$headers = "From: fax@rittal.ru\r\nReply-To: postmaster@rittal.ru";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents($args['f'])));

$body="";
$body .="\r\n".'--PHP-mixed-'.$random_hash;
$body .="\r\n".'Content-Type: multipart/alternative; boundary="PHP-alt-'.$random_hash.'"';
$body .="\r\n";
$body .="\r\n".'--PHP-alt-'.$random_hash;
$body .="\r\n".'Content-Type: text/plain; charset="iso-8859-1"';
$body .="\r\n".'Content-Transfer-Encoding: 7bit';
$body .="\r\n";
$body .="\r\n".'Please, see fax message in attachment';
$body .="\r\n";
$body .="\r\n".'--PHP-alt-'.$random_hash.'--';
$body .="\r\n".'--PHP-mixed-'.$random_hash;
$body .="\r\n".'Content-Type: application/tiff; name="fax.tiff"';
$body .="\r\n".'Content-Transfer-Encoding: base64';
$body .="\r\n".'Content-Disposition: attachment';
$body .="\r\n";
$body .="\r\n".$attachment;
$body .="\r\n".'--PHP-mixed-'.$random_hash.'--';
$body .="\r\n";

mail( $to, $subject, $body, $headers );

break;
case 'print':
// printing file on printer
if( (!isset($args['p'])) || ($args['p']=='')) die("use -p to give printer name\n");
exec('tiff2ps "'.$args['f'].'" | lpr -P'.$args['p']);
break;

default:
die("wrong mode!\n");

}
?>

article taken

Uwaga: wpis mógł powstać z pomocą AI i redakcji. Odpowiedzialny: Dmytro Lomaka, Kaltenkirchen.