Callerid:"FaxSender"<1111> Maxretries:maxRetries Waittime:300 Context:faxsend-t38 Extension:faxout RetryTime:50 Priority:1 SetVar: T38CALL=1 Set:RETURNURL={returnUrl} Set:TAGLINE=Fax from CompanyName Set:RECEIVER=Number Of Receiver Set:FAX_ID={faxId} Set:TIFF_2_SEND={faxId}.tif';
<?php define( "STATUS_SUCCESS", "success" ); define( "STATUS_ERROR", "fail" ); $pdfLocation = "//var//tmp//faxes//"; function sendStatus( $statusKind ) { header('Content-type: application/json'); exit( "{\"status\": \"" . $statusKind . "\"}" ); } $fax = $_REQUEST['fax']; $faxId = $_REQUEST['faxId']; $maxRetries = isset( $_REQUEST['maxRetries'] ) ? $_REQUEST['maxRetries'] : 0; $returnUrl = $_REQUEST['returnUrl']; $pdf = $faxId . '.pdf'; if ($fax == '' || $returnUrl == '' || $faxId == '' ) { sendStatus( STATUS_ERROR ); } if(!move_uploaded_file($_FILES['file']['tmp_name'], $pdfLocation . $pdf)) { sendStatus( STATUS_ERROR ); } $callFileBody = 'Channel:SIP/trunkname/{fax} Callerid:"FaxSender"<1111> Maxretries:{maxRetries} Waittime:300 Context:faxsend-t38 Extension:faxout RetryTime:50 Priority:1 SetVar: T38CALL=1 Set:RETURNURL={returnUrl} Set:TAGLINE=Fax from Company Set:RECEIVER={fax} Set:FAX_ID={faxId} Set:TIFF_2_SEND={faxId}.tif'; $callFileBody = str_replace("{fax}", $fax, $callFileBody); $callFileBody = str_replace("{faxId}", $faxId, $callFileBody); $callFileBody = str_replace("{maxRetries}", $maxRetries, $callFileBody); $callFileBody = str_replace("{returnUrl}", $returnUrl, $callFileBody); $callFilename = $faxId . ".call"; file_put_contents($pdfLocation . $callFilename, $callFileBody); if (!file_exists($pdfLocation . $callFilename)) { sendStatus( STATUS_ERROR ); } sendStatus( STATUS_SUCCESS ); ?>
# Apache-level configuration for Elastix administration interface Timeout 300 # Default apache configuration specifies greater limits than these #MaxClients 150 #MaxRequestsPerChild 1000 # Default apache User and Group diretives MUST be commented out # in order for these to take effect. User asterisk Group asterisk <Directory "/var/www/html"> # Redirect administration interface to https #RewriteEngine off #RewriteCond %{HTTPS} off #RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} </Directory>
#!/bin/bash SOURCEDIR="/var/tmp/faxes/" for file in `ls $SOURCEDIR*.pdf `; do callfile="${file/pdf/call}" if [ ! -e "$callfile" ] then continue fi `gs -q -dNOPAUSE -dBATCH -sDEVICE=tiffg4 -sPAPERSIZE=letter -sOutputFile=${file/pdf/tif} $file` mv ${file/pdf/call} /var/spool/asterisk/outgoing rm $file done
/usr/bin/find /var/tmp/faxes -name "*tif" -mtime +2 –delete
t38pt_udptl=yes
[trunkname] username=username type=friend transport=udp secret=password qualify=yes nat=yes insecure=port,invite host=voip.host.com disalow=all directmedia=yes context=from-pstn canreinvite=yes allow=ulaw&alaw
[faxsend-t38] exten => faxout,1,Set(STARTTIME=${SHELL(date +%s)} ) exten => faxout,n,Wait(1) exten => faxout,n,Playback(fax24,skip) exten => faxout,n,Wait(1) exten => faxout,n,NoOp(**** SENDING FAX ****) ; Set FAXOPTs exten => faxout,n,NoOp(**** SETTING FAXOPT ****) exten => faxout,n,Set(FAXFILE=${TIFF_2_SEND}) exten => faxout,n,Set(FAXOPT(ecm)=yes) exten => faxout,n,Set(FAXOPT(headerinfo)=${TAGLINE}) exten => faxout,n,Set(FAXOPT(maxrate)=14400) exten => faxout,n,Set(FAXOPT(minrate)=4800) ; Send the fax exten => faxout,n,NoOp(**** SENDING FAX : ${FAXFILE} ****) exten => faxout,n,SendFAX(/var/tmp/faxes/${FAXFILE},dfzs) ;Calculating Time of Sending exten => faxout,n,Set(ENDTIME=${SHELL(date +%s)} ) exten => faxout,n,Set(TRANSFERTIME=${MATH(${ENDTIME}-${STARTTIME},int)}) ;Actions after sending fax exten => faxout,n,Set(NORMURL=${FAXOPT(error)}) exten => faxout,n,Set(STATUSMESSAGE=${REPLACE(NORMURL, ,+)}) exten => faxout,n,Set(FAXOPTRATE=${FAXOPT(rate)}) exten => faxout,n,Hangup ;Actions if no answer or busy exten => failed,1,Set(FAXSTATUS=FAILED) exten => failed,2,Set(STATUSMESSAGE=number+no+answer+or+busy) exten => failed,3,Set(FAXOPTRATE=none) exten => h,1,NoOP(------------------- FAX to ${EXTEN} with ${FAXSTATUS} -----------------) exten => h,2,Set(CURLRESULT=${CURL(${RETURNURL}?fax=${RECEIVER}&faxId=${FAX_ID}&status=${FAXSTATUS}&message=${STATUSMESSAGE})}) exten => h,4,Set(LOGFAXOUT=${SHELL(echo "${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)} : ${FAX_ID} : ${RECEIVER} : ${FAXSTATUS} : ${STATUSMESSAGE} : ${TRANSFERTIME}s : ${FAXOPTRATE}" >> /var/log/asterisk/faxout.log)}) exten => h,3,NoOp(${RECEIVER}:${FAX_ID}:${FAXSTATUS}:${STATUSMESSAGE}:${FAXOPTRATE})
Source: https://habr.com/ru/post/183584/
All Articles