143 lines
22 KiB
Plaintext
143 lines
22 KiB
Plaintext
|
#!/usr/bin/perl
|
||
|
# Simple Fax Test
|
||
|
#
|
||
|
#
|
||
|
#
|
||
|
use CGI qw(:standard);
|
||
|
use ESL;
|
||
|
use Data::Dumper;
|
||
|
use Data::UUID;
|
||
|
use XML::Simple;
|
||
|
|
||
|
# Replace Your CID Here
|
||
|
my $cid_num = "1NXXNXXXXXX";
|
||
|
|
||
|
my $q = new CGI;
|
||
|
my $c = new ESL::ESLconnection("127.0.0.1", "8021", "ClueCon");
|
||
|
|
||
|
my $action = $q->param('action');
|
||
|
|
||
|
if($action eq 'log') {
|
||
|
my $uuid = $q->param('uuid');
|
||
|
|
||
|
if($uuid =~ m/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/) {
|
||
|
if(-e "/tmp/$uuid.log") {
|
||
|
print $q->header('text/plain');
|
||
|
open(LOG, "</tmp/$uuid.log");
|
||
|
while (<LOG>) { print $_; }
|
||
|
close(LOG);
|
||
|
} else {
|
||
|
print $q->header();
|
||
|
if(check_call($uuid)) {
|
||
|
my $pages = pages_sent($uuid);
|
||
|
print $q->start_html(-title=> 'FreeSWITCH Fax Results',
|
||
|
-head =>meta({-http_equiv => 'Refresh',
|
||
|
-content => "10;fax.cgi?uuid=$uuid&action=log"})),
|
||
|
font({-color=>'black', -face=>'Arial', -size=>'4'}),
|
||
|
"$pages pages(s) sent , Waiting on fax to complete. Please Wait! Page will reload again in 10 seconds.",br,br,
|
||
|
end_html;
|
||
|
} else {
|
||
|
print $q->start_html(-title=> 'FreeSWITCH Fax Failed'),
|
||
|
font({-color=>'black', -face=>'Arial', -size=>'4'}),
|
||
|
"Fax call appears to have failed.",br,br,
|
||
|
end_html;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} elsif ($action eq 'fax') {
|
||
|
print $q->header;
|
||
|
|
||
|
my $file = '/var/www/fax.tif';
|
||
|
my $fax = $q->param('fax');
|
||
|
my $ecm = $q->param('ecm') || 'false';
|
||
|
my $v17 = $q->param('v17') || 'false';
|
||
|
my $t38 = $q->param('t38') || 'false';
|
||
|
my $large = $q->param('large') || 'false';
|
||
|
my $gateway = $q->param('gateway');
|
||
|
my $refresh = 10;
|
||
|
my $ug = new Data::UUID;
|
||
|
my $buuid = $ug->create();
|
||
|
my $uuid = $ug->to_string( $buuid );
|
||
|
|
||
|
$fax =~ s/\D+//g;
|
||
|
|
||
|
if($fax =~ m/^(1[2-9]\d{2}[2-9]\d{6})$/) {
|
||
|
|
||
|
if($large eq 'true') {
|
||
|
$file = '/var/www/fax_large.tif';
|
||
|
$refresh = 60;
|
||
|
}
|
||
|
|
||
|
my $e = $c->sendRecv("api bgapi originate {fax_ident='FreeSWITCH Test Fax',fax_header='FreeSWITCH Test Fax',api_hangup_hook='system /bin/grep $uuid /usr/local/freeswitch/log/freeswitch.log > /tmp/$uuid.log',origination_uuid=$uuid,fax_disable_v17=$v17,fax_use_ecm=$ecm,origination_caller_id_number=$cid_num,fax_verbose=true,fax_enable_t38=$t38,ignore_early_media=true,fax_enable_t38_request=$t38,t38_passthru=false,absolute_codec_string=PCMU}sofia/gateway/$gateway/$fax &txfax($file)");
|
||
|
my $res = $e->getBody();
|
||
|
print $q->start_html(-title=> 'FreeSWITCH Fax Results',
|
||
|
-head =>meta({
|
||
|
-http_equiv => 'Refresh',
|
||
|
-content => "$refresh;fax.cgi?uuid=$uuid&action=log"})),br
|
||
|
font({-color=>'black', -face=>'Arial', -size=>'4'}),
|
||
|
"API Results: $res",br,br
|
||
|
"Send 10 Pages: $large",br,
|
||
|
"Enable T.38: $t38",br,
|
||
|
"Enable ECM: $ecm",br,
|
||
|
"Disable V17: $v17",br,
|
||
|
"Via Gateway: $gateway", br,br,
|
||
|
"Fax is queued to $fax immediately and will not retry on failure.",br,br
|
||
|
"Your log UUID is $uuid, wait here the page will reload showing you the results once complete",br,br,
|
||
|
end_html;
|
||
|
} else {
|
||
|
print "Invalid Number 1NXXNXXXXXX Only!";
|
||
|
}
|
||
|
} else {
|
||
|
my @gateways = load_gateways();
|
||
|
|
||
|
print $q->header;
|
||
|
|
||
|
print $q->start_html(-title=> 'FreeSWITCH Test Fax'), start_form,
|
||
|
img( {-src => "data:image/png;base64," . <DATA> }),br,br,font({-color=>'black', -face=>'Arial', -size=>'4'}),
|
||
|
"Call will be coming from $cid_num",br,br,
|
||
|
"Customer Fax Number: ", textfield('fax'),br,
|
||
|
br,"Fax options:",br,hidden('action', 'fax'),
|
||
|
br,checkbox(-label => 'Send 10 Pages', -name => "large", -value => 'true', -selected => 0), br,
|
||
|
br,checkbox(-label => 'Enable T.38', -name => "t38", -value => 'true', -selected => 1), br,
|
||
|
br,checkbox(-label => 'Enable ECM', -name => "ecm", -value => 'true', -selected => 1), br,
|
||
|
br,checkbox(-label => 'Disable v.17', -name => "v17", -value => 'true', -selected => 0), br,
|
||
|
br,'Using Gateway:',popup_menu( -name=>'gateway', -values => \@gateways),br,
|
||
|
br,submit('SEND FAX'),end_form,end_html;
|
||
|
}
|
||
|
|
||
|
sub check_call {
|
||
|
my $uuid = shift;
|
||
|
my $e = $c->api("uuid_getvar $uuid uuid");
|
||
|
my $res = $e->getBody();
|
||
|
if($res =~ m/No such channel/) {
|
||
|
return 0;
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
sub pages_sent {
|
||
|
my $uuid = shift;
|
||
|
my $e = $c->api("uuid_getvar $uuid fax_document_transferred_pages");
|
||
|
my $res = $e->getBody();
|
||
|
if ($res =~ /_undef_/) { return 0 };
|
||
|
return $res;
|
||
|
}
|
||
|
|
||
|
# Query FreeSWITCH for gateway list to populate the test rig.
|
||
|
sub load_gateways {
|
||
|
my $e = $c->api('sofia xmlstatus gateways');
|
||
|
my $gwxml = $e->getBody();
|
||
|
|
||
|
my $ref = XMLin($gwxml);
|
||
|
my @gateways;
|
||
|
|
||
|
foreach my $key (keys %{ $ref->{gateway} }) {
|
||
|
push @gateways, $key;
|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