I have an ajax code where i call a Perl script through querysting with GET method.
Ajax code
if(ajaxRequest != null)
{
ajaxRequest.open("GET", "dial1.pl" + queryString , true);
ajaxRequest.onreadystatechange = handler;
//console.log(queryObj.fund);
ajaxRequest.send(null);
}
Perl Code
#!/usr/bin/perl -w
# Dial Script for asterisk
# date: 25 July 2013
use strict;
use CGI;
use Fcntl;
use CGI::Carp qw(fatalsToBrowser);
my $cgi = new CGI;
my ($request,$agent_id,@agent_details_url,$agent_name,$agent_terminal_id);
if ($ENV{'REQUEST_METHOD'} eq "GET")
{ # if we're receiving a GET
$request = $ENV{'QUERY_STRING'}; # the request is passed in the
} # environment variable
# QUERY_STRING
# else ...
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
{ # if receiving a POST request
# the length of the posted data
# is passed in CONTENT_LENGTH,
# and it is read from stdin
#$request = $ENV{'QUERY_STRING'};
read(STDIN, $request,$ENV{'CONTENT_LENGTH'}) || die "Could not get query\n";
}
my $context="Test";
my $query_string="$request";
$query_string=~ s/&//;
my @new_query_string = split(/=/,$query_string);
my $phone=$new_query_string[1];
print "<p>alert($phone)</p>";
print $cgi->header();
print $cgi->start_html('Asterisk Caller');
print '<center><p>call</p>';
sysopen( FH,"/var/spool/asterisk/outgoing/meeting_user$$.call", O_RDWR|O_EXCL|O_CREAT, 0777);
#print FH "Channel: GSM/1/xxxxxxxxx\n";
#print FH "Channel: GSM/1/$phone\n";
print FH "Callerid: 4006\n";
print FH "RetryTime: 60\n";
print FH "WaitTime: 30\n";
print FH "Context: $context\n";
print FH "Extension: s\n";
#printf "<p><b>$dest_nmbr<\/b> über <b>$src_nmbr<\/b><\/p>";
close FH;
When i run Perl program manually it is working fine on other hand i got an error through ajax(with browser)
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 62.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 64.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 65.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 66.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 67.
[Sun Nov 23 11:36:19 2014] -e: print() on closed filehandle FH at /var/www/perl/dial1.pl line 68.
Please let me know where I'm doing wrong and will appreciate your suggestion.