Daily Archives: May 15, 2012

sendFax Over SIP , SpanDSP, Asterisk


#!/usr/bin/perl -w
use strict;
use warnings;
sub random_name_generator($);

# usage: faxout.pl number filename
# example: faxout.pl 5555551212 myfax.pdf

if ($#ARGV != 1) {
print qq(FAIL: 2 Arguments needed\n);
exit(0);
}

my ($callto,$pdfname,$callfile,$filename);

$callto = $ARGV[0];
$pdfname = $ARGV[1];

my $tifname = $pdfname;
$tifname =~ s/.pdf/.tif/i;

system(“gs -q -dNOPAUSE -dBATCH -sDEVICE=tiffg4 -sOutputFile=$tifname $pdfname”);

if ($callto) {
$filename = &random_name_generator(12).”.call”;
open (MYFILE, “>>/tmp/$filename”) or die $!;
$callfile = “Channel: SIP/2000/$callto\n”;
$callfile = $callfile . “MaxRetries: 1\n”;
$callfile = $callfile . “RetryTime: 60\n”;
$callfile = $callfile . “WaitTime: 60\n”;
$callfile = $callfile . “Archive: yes\n”;
$callfile = $callfile . “Context: send-fax”;
$callfile = $callfile . “Extension: 100\n”;
$callfile = $callfile . “Priority: 1\n”;
$callfile = $callfile . “Set: FAX_FILE_NAME=$tifname\n”;
$callfile = $callfile . “Set: FAX_HEADER=Testing Fax\n”;
$callfile = $callfile . “Set: FAX_ID=1\n”;
$callfile = $callfile . “Set: FAXFILE=$tifname\n”;
print MYFILE $callfile;
close (MYFILE);
system(“mv /tmp/$filename /var/spool/asterisk/outgoing”);
}

sub random_name_generator($) {
my ($namelength, $randomstring, @chars);
$namelength = shift;
@chars = (‘a’..’z’,’A’..’Z’,’0′..’9′);
foreach (1..$namelength) {
$randomstring .= $chars[rand @chars];
}
return $randomstring;
}

 

extensions.conf

[send-fax]
exten => 100,1,NoOP(“Sending FAX, ID:${FAX_ID}, File:${FAX_FILE_NAME}”)
exten => 100,n,Set(FAXOPT(localstationid)=${FAX_HEADER})
exten => 100,n,Set(FAXOPT(headerinfo)=${FAX_HEADER})
exten => 100,n,sendFax(${FAX_FILE_NAME})

exten => failed,1,Set(FAXSTATUS=DIALFAIL)
exten => failed,n,Set(FAXERROR=No Answer)
exten => failed,n,Set(FAXPAGES=0)
exten => failed,n,Hangup

exten => h,1,NoOp(“Fax Status: ${FAXSTATUS}”)
exten => h,n,NoOp(“Fax Error : ${FAXERROR}”)
exten => h,n,NoOp(“Fax Pages : ${FAXPAGES}”)
exten => h,n,GoToIf($[“${FAXSTATUS}”=”SUCCESS”]?send-fax-success,1,1)
exten => h,n,GoToIf($[“${FAXSTATUS}”=”FAILED”]?send-fax-failed,1,1)
exten => h,n,GoToIf($[“${FAXSTATUS}”=”DIALFAIL”]?send-fax-dial-failed,1,1)

[send-fax-success]
exten => 1,1,NoOp(“FAX SUCCESS”)
exten => 1,n,MYSQL(Connect connid localhost ${FAX_DB_USER} ${FAX_DB_PASS} ${FAX_DB_NAME})
exten => 1,n,MYSQL(Query resultid ${connid} UPDATE ${FAX_DB_TABLE_OUT} SET sent_status=’S’, sent_message=’${FAXSTATUS}’,sent_retry=sent_retry+1, sent_time=NOW() where id=’${FAX_ID}’)
exten => 1,n,MYSQL(Disconnect ${connid})

[send-fax-failed]
exten => 1,1,NoOp(“FAX FAILED”)
exten => 1,n,MYSQL(Connect connid localhost ${FAX_DB_USER} ${FAX_DB_PASS} ${FAX_DB_NAME})
exten => 1,n,MYSQL(Query resultid ${connid} UPDATE ${FAX_DB_TABLE_OUT} SET sent_status=’F’, sent_message=’${FAXERROR}’, sent_retry=sent_retry+1, sent_time=NOW() where id=’${FAX_ID}’)
exten => 1,n,MYSQL(Disconnect ${connid})

[send-fax-dial-failed]
exten => 1,1,NoOp(“FAX DIAL FAILED: ${MAX_RETRY}”)
exten => 1,n,MYSQL(Connect connid localhost ${FAX_DB_USER} ${FAX_DB_PASS} ${FAX_DB_NAME})
exten => 1,n,MYSQL(Query resultid ${connid} UPDATE ${FAX_DB_TABLE_OUT} SET sent_status= if(sent_retry >= ${MAX_RETRY},’F’,’Q’), sent_message=’${FAXERROR}’, sent_retry=sent_retry+1, sent_time=NOW() where id=’${FAX_ID}’)
exten => 1,n,MYSQL(Disconnect ${connid})

SIP TRUNK ANTAR ASTERISK


sip trunk antar asterisk

shisdew

Listens until think alike

moses.spaceku@yahoo.com / voip ipbx

Hosted PBX, IP-PBX SOHO/ CALL CENTER, VOICE GATEWAY, VOICE CARD, COST EFECTIVE SOLUTIONS (LCR), GSM/CDMA GATEWAY

%d bloggers like this: