[asterisk-users] click to call

A J Stiles asterisk_list at earthshod.co.uk
Wed Jul 11 08:46:55 CDT 2012


On Wednesday 11 July 2012, alok srivastava wrote:
> dear
> is there any study material for implementing click to call in asterisk.
> plz help.
> 
> thanks
> regards

Dead simple!  You need to install Apache on the Asterisk server if you haven't 
already.  Then use a CGI script like this;

###############  8<  ###############
#!/usr/bin/perl -w
use strict;

my ($web, $input_buffer, $name, $value, %parameters);
my ($ext, $tel);

foreach (split/&/, $ENV{'QUERY_STRING'}) {              #   GET items
    tr/+/ /;
    ($name,$value) = split /=/, $_;
    $name  =~ s/%(..)/pack'c', hex $1/eg;
    $value =~ s/%(..)/pack'c', hex $1/eg;
    $parameters{"$name"} = "$value";
};
read STDIN, $input_buffer, $ENV{"CONTENT_LENGTH"};      #   POST items
foreach (split/&/, $input_buffer) {
    tr/+/ /;
    ($name,$value) = split /=/, $_;
    $name  =~ s/%(..)/pack 'c', hex $1/eg;
    $value =~ s/%(..)/pack 'c', hex $1/eg;
    $parameters{"$name"} = "$value";
};

print "Content-type: text/plain\n\n";

$tel = $parameters{"tel"} || "";
$ext = $parameters{"ext"} || "";
if ($ext) {
    print "Calling from '$ext' to '$tel'.\n";
    open CALLFILE, ">/tmp/asterisk_$$.call";
    print CALLFILE <<"--STOP--";
Channel: SIP/$ext
Context: outgoing
Extension: $tel
Priority: 1
CallerId: $ext
--STOP--
    close CALLFILE;
    system "mv /tmp/asterisk_$$.call 
/var/spool/asterisk/outgoing/${ext}_${tel}.call";
}
else {
    print "Go away, we don't know who you are.  (try &ext=something)\n";
};

exit;
###############  >8  ###############

Then a GET request to /cgi-bin/place_call?tel=018118055&ext=101 will place a 
call from extension 101 to telephone number 018118055 in context outgoing.

With a little extra work, you can determine the correct value for $ext 
automatically from the IP address of the requesting computer. You can find this 
within the script using using
my $ip = $ENV{REMOTE_ADDR};
You will then need some sort of lookup table  (hard-coded in the script or in 
a database)  of PC IPs and the nearest phone.  (Obviously this won't work if 
you are using DHCP to assign IP addresses to workstations.)


In Kontact, you can specify the external action for calling a number as 
something like

/usr/bin/wget -O/dev/null http://192.168.32.214/cgi-
bin/place_call?tel=%n&ext=403

assuming you are on extension 403 and the Asterisk server is 192.168.32.214.

-- 
AJS
Price Engines Ltd.  DDI: 01283 707058.

-- 
AJS

Answers come *after* questions.



More information about the asterisk-users mailing list