[asterisk-users] Click-to-call software in a hosted environment

A J Stiles asterisk_list at earthshod.co.uk
Thu Aug 30 03:29:27 CDT 2012


On Wednesday 29 August 2012, Carlos Alvarez wrote:
> For any of you doing hosted PBX service on Asterisk, do you have a reliable
> and secure click to dial solution?  Particularly for Outlook, but since
> about 20% of our customers use Mac OS, I'd love to hear about some that
> work on that too.

This is my generic "works-anywhere" click-to-call script.  It should work in 
conjunction with any software that allows you to specify an external command 
to call a number  (we have tried it with Kontact and it works beautifully).  
You just have to issue a wget command to fire a CGI script on the server.

Place this in your Asterisk server's /usr/lib/cgi-bin folder, call it 
"make_call.pl" and chmod 755 make_call.pl:

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

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

my $dbh = DBI->connect("DBI:mysql:database=phonestuff;host=localhost", "root", 
"");
my $sth_get_ext = $dbh->prepare("SELECT ext FROM extensions WHERE pc_ip LIKE 
?");

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"} || "";
unless ($ext = $parameters{"ext"}) {
    $sth_get_ext->execute($ENV{"REMOTE_ADDR"});
    if ($sth_get_ext->rows) {
        ($ext) = $sth_get_ext->fetchrow_array;
    };
    $sth_get_ext->finish;
};

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";
};

$dbh->disconnect;

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

You also need a database `phonestuff` with a table `extensions` relating PC IP 
addresses (in `pc_ip`) to extension numbers (in `ext`).

Now if your software works anything like Kontact, it will want you to specify 
a command to place a call and can substitute placeholders in this command.  
So, give this as the command:

wget -o /dev/null http://ip.of.asterisk.server/cgi-bin/make_call.pl?tel=%N

(Test it in an xterm, omitting the -o /dev/null, with something like your 
mobile number or another extension.)


Licence:  This program is copyright (C) 2012 by A J Stiles.  You are permitted 
and even encouraged to distribute this program, modified or unmodified, in 
Source Code form whether or not accompanied by a binary executable version 
provided that this notice accompanies every copy.  Binary distribution without 
Source Code constitutes a violation of copyright.

-- 
AJS

Answers come *after* questions.



More information about the asterisk-users mailing list