[asterisk-users] SugarAsterisk vs. ________

A J Stiles asterisk_list at earthshod.co.uk
Thu Jun 19 11:10:48 CDT 2014


On Thursday 19 Jun 2014, thufir wrote:
> http://www.voip-info.org/wiki/view/Asterisk+CRM+Integration
> 
> lists a few options.  I'm looking for, literally, the simplest FOSS CRM
> for "click to dial" functionality, but don't know where to start.
> 
> 
> 
> thanks,
> 
> Thufir

The Free version of SugarCRM is no longer officially maintained; but the code 
can still be found if you look hard enough, and cannot easily be suppressed 
since the GPL lasts as long as copyright.  There are also forks based on 
earlier Free SugarCRM versions.


Click-to-dial is pretty easy to implement.  If you can display a link to a CGI 
script, and you have an Apache server running on the Asterisk server, then you 
can set up click-to-dial.  You should be able to modify the Source Code of 
whatever you are using easily enough, so wherever it displays a phone number, 
it will linkify it for you.  The easiest way probably is just to write a 
function to do this.  Example in PHP:

function phone_link($tel) {
    return "<a class=\"click_to_call\"href=\"http://192.168.0.2/cgi-
bin/make_call?tel=$tel">$tel</a>";
};

assuming 192.168.0.2 is your Asterisk server and the script is called 
make_call .

You will need to have a database somewhere relating the IP addresses of 
workstations to their extension numbers  (if using DHCP, you need to place a 
series of host{} declarations in dhcpd.conf to assign a fixed IP to each 
workstation's MAC address -- see man 5 dhcpd.conf) -- the Asterisk server 
itself probably is as good a place as any.  Then in your CGI script, you 
simply look up the IP address of the client  ($_SERVER["REMOTE_ADDR"] in PHP, 
$ENV{"REMOTE_ADDR"} in Perl)  to find the nearest extension number, and 
generate a call file.


In KDE's Kontact application, it is possible to invoke an external command 
when clicking on a phone number, and have the number inserted into the 
command; this originally was meant to launch the toxic, proprietary, anti-
telecommunications tool Skype, but you could use wget to fire off a request to 
the CGI script, like so:
wget -O/dev/null http://192.168.0.2/cgi-bin/make_call?tel=%n


The following CGI script is not quite complete in itself  (it needs the above-
mentioned database relating phone numbers to IP addresses, and a suitable 
context in your dialplan in which to make the outgoing call)  but should give 
you a good starting point to work from:

#########################  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=phones;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"} || "";
$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: autodial
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.\n";
};

$dbh->disconnect;

exit;

#########################  >8  #########################

-- 
AJS

Note:  Originating address only accepts e-mail from list!  If replying off-
list, change address to asterisk1list at earthshod dot co dot uk .



More information about the asterisk-users mailing list