📜 ⬆️ ⬇️

Implementation of work with faxes in asterisk

There is a need to configure the reception and sending of faxes on asterisk. According to the technical task, receiving and sending faxes should take place with the participation of operators and the possibility of a preliminary conversation.
I found examples of implementation on the Internet, but in them, as a rule
1) there was an automatic sending of faxes to a specific number without first talking to the operator;
2) different bundles of iaxmodem or t38modem + hylafax were used, in which, in my opinion, there is no special need in this case. Asterisk can work with faxes via SpanDSP (must be compiled with SpanDSP support).

In the end, it all came down to the following:
1) any operator of the company must have the functionality to receive and send faxes from his workplace, using a PC and telephone;
2) to receive a fax, you need to transfer the call to the number 5555. The system should convert the received document from tiff to pdf, put it in the FAX common folder and duplicate it to the secretary's mailbox.
3) when sending a fax, it should be possible to send any electronic document or document on paper (through a scanner). The operator must first be able to tell who and what the document transmits, then, just as at admission, transfer to a specific number corresponding to this document.

Asterisk is installed on a gentoo assembly.

To avoid user involvement in translating a document in tiff format, it was decided to use the cups-pdf network virtual printer.
')
Install:

emerge -va cups-pdf 


To put the printer and folder for received faxes into the network use the samba package.

 emerge -va samba 


I have it already installed net-fs / samba-3.6.12

The cups package is also required, and the samba itself must be built with the support of this package. Let's install our virtual printer via cups web interface, let's call it fax.

We share the printer by adding the following lines to /etc/samba/smb.conf

 [global] printing = cups printcap name = /etc/printcap [fax] comment =  public = yes printable = yes writable = yes create mode = 0666 


Windows 7 is installed on the operator computers. The network printer is installed, as usual, it will only ask for the driver, I chose the HP LaserJet 2300 Series PS (any PostScript driver should fit)

When printing to this printer, the document itself must go to the printer in a suitable format, and the user must receive a four-digit number during the transfer, to which the transfer of this document will occur.

First, let's look at the settings of this virtual printer nano /etc/cups/cups-pdf.conf
And change the following settings:

 Out /var/spool/cups-pdf #     AnonDirName /var/spool/cups-pdf Spool /var/spool/cups-pdf TitlePref 1 #      UserUMask 0000 #     PostProcessing /opt/pdf_to_tiff #     pdf  DecodeHexStrings 1 #      


The / opt / pdf_to_tiff script reads the current value of ext_num (four-digit fax number) adds one and transfers the pdf file to the / usr / dumps folder as ext_num.
Next, it converts the file to the tiff format and sends it to the user who sent the document with a four-digit number to the post office.

Cups-pdf will run / opt / pdf_to_tiff with two parameters:
file name is $ ARGV [0]
username is $ ARGV [1]
In an organization, the domain (samba-3.6) and mailboxes (corporate mail on postfix) correspond to user names (here and there we had to add a couple of mail aliases).

The script itself:

 srv d # cat /opt/pdf_to_tiff 


 #!/usr/bin/perl -w use strict; use File::Copy; #     $ENV{PATH} = '/bin:/usr/bin:/sbin:/usr/sbin'; #  my $debug=0; #     chdir '/'; my $ext=" "; my $num=0; open(ext_num,"/opt/ext_num"); $ext=<ext_num>; $num=int($ext); close(ext_num); if ($num > 499) { $num=1; } else { $num=$num+1; } open(ext_num,">/opt/ext_num"); print ext_num "$num\n"; close(ext_num); $num=$num+5000; move("$ARGV[0]","/usr/dumps/$num.pdf"); system("/usr/bin/gs -dSAFER -dBATCH -dQUIET -sDEVICE=tiffg3 -sPAPERSIZE=a4 -r204x196 -dNOPAUSE -sOutputFile=/usr/dumps/$num.tiff /usr/dumps/$num.pdf"); chmod(0644,"/usr/dumps/$num.tiff"); system("/usr/bin/sendEmail -f asterisk_fax\@name.ru -t $ARGV[1]\@name.ru -u FAX -o message-charset=utf-8 -m     :$num -s localhost"); 


We check the work by sending a document to print (you may have to create and correct the rights to access the / usr / dumps / folder)

Next, configure Asterisk to receive and send faxes:

The main thing is to disable faxdetect:

 /etc/asterisk/sip.conf 


 [general] faxdetect=no ;faxdetect=yes t38pt_udptl=no ;t38pt_udptl=yes 


 /etc/asterisk/extensions.conf 


 [internal] exten => 5555,1,NoOp(-------------------Call from ${CALLERID(number)} to ${EXTEN}------------------) same => n,Goto(fax-rx,receive,1) exten => _5[0-4]XX,1,NoOp(-------------------Call from ${CALLERID(number)} to ${EXTEN}------------------) same => n,Set(FAXFILENAME=${EXTEN}) same => n,Goto(fax-tx,send,1) [fax-rx] exten => receive,1,NoOP(------------------- FAX from ${CALLERID(number)} ------------------) same => n,Answer() same => n,Set(DT=${TIMESTAMP}-${CALLERIDNUM}-${UNIQUEID}) same => n,Set(FAXOPT(headerinfo)=Received by ${CALLERID(number)} ${STRFTIME(${EPOCH},,%Y-%m-%d %H-%M)}) same => n,Set(FAXOPT(localstationid)=Name) same => n,Set(FAXOPT(maxrate)=14400) same => n,Set(FAXOPT(minrate)=2400) same => n,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)}) same => n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)}) same => n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)}) same => n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)}) same => n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)}) same => n,NoOp(**** RECEIVING FAX : ${DT} ****) same => n,ReceiveFax(/var/spool/asterisk/fax/${FAXOPT(headerinfo)}.tif) same => n,System(/usr/bin/tiff2pdf "/var/spool/asterisk/fax/${FAXOPT(headerinfo)}.tif" -o "/var/spool/asterisk/fax/${FAXOPT(headerinfo)}.pdf") same => n,System(/bin/cp "/var/spool/asterisk/fax/${FAXOPT(headerinfo)}.pdf" /mnt/public/samba/public/FAX ) same => n,System(/usr/bin/sendEmail -f asterisk_fax@name.ru -t office@name.ru -u FAX -o message-charset=utf-8 -m   -s localhost -a "/var/spool/asterisk/fax/${FAXOPT(headerinfo)}.pdf") same => n,HangUp() [fax-tx] exten => send,1,NoOp(------------------- FAX from ${CALLERID(number)} ------------------) same => n,Wait(1) same => n,Set(DT=${TIMESTAMP}-${CALLERIDNUM}-${UNIQUEID}) same => n,Set(FAXOPT(headerinfo)=Received by ${CALLERID(number)} ${STRFTIME(${EPOCH},,%Y-%m-%d %H-%M)}) same => n,Set(FAXOPT(localstationid)=Name) same => n,Set(FAXOPT(maxrate)=14400) same => n,Set(FAXOPT(minrate)=2400) same => n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)}) same => n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)}) same => n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)}) same => n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)}) same => n,NoOp(**** RECEIVING FAX : ${DT} ****) same => n,SendFAX(/usr/dumps/${FAXFILENAME}.tiff,d) same => n,NoOp(${FAXSTATUS}) same => n,NoOp(number is ${CALLERID(number)}) same => n,System(/usr/bin/sendEmail -f asterisk_fax@name.ru -t office@name.ru -u 'Fax message Sent' -o message-charset=utf-8 -m ':${CALLERID(number)}\nStatus:${FAXSTATUS}' -s localhost -l /var/log/fax.log) same => n,HangUp() 


That's all. As a result, no additional software is needed and it is easier to train operators to work with faxes.

Source: https://habr.com/ru/post/185260/


All Articles