No, I do not use the distro. I’m using FreePBX 2.9.0.7 + Asterisk 1.6.2.9 on Debian squeeze (see the initial post).
I tried Superfecta, but the ldap source says it is unable to bind. My script however, running from the same box, is able to connect. I tried with both ldap and ldaps, but to no avail.
But your script did show me how the HTTP method works. So I’ve adapted my script (mostly deletions, a few changes), and now it uses HTTP as the delivery method. The whole LDAP part is unchanged, but see for yourself:
#!/usr/bin/perl
use strict; # be picky with the synatax
use Net::LDAP;
use CGI::Simple;
use constant LDAPSERVER => “ldaps://ldapserver.domain.tld”; # ldap URI
use constant LDAPTIMEOUT=> 2; # timeout in seconds
use constant BASEDN => “dc=domain,dc=tld”;
use constant BINDDN => “uid=clid2name,ou=roles,dc=domain,dc=tld”;
use constant BINDPW => “averystrongsecret”;
use constant FILTER => ‘(|(mobile=%s)(telephoneNumber=%s)(homePhone=%s))’; # filter to search for
use constant LOOKUP => ‘callerid’; # the variable to use
use constant MAXNATNUM => 10; # maximum digits in national number (no country code)
use constant THISCOUNTRY=> 31; # country code
use constant LOCALPREFIX=> 0; # local prefix code (replaces country code)
use constant DEBUG => 1; # 0=no debug, 1=debug output to STDERR (asterisk console)
$|=1; # no buffer for the output
my $name; # to hold the resulting name
my $q = new CGI::Simple; # get options from query
sub normalizeclid { # To convert different types of CLI to type in LDAP
my ($res) = @_;
my $x = THISCOUNTRY;
my $y = LOCALPREFIX;
(DEBUG) && print STDERR “NormalizeCLID: input is $res\n”;
if (length($res) > MAXNATNUM ) {
$res =~ s/^$x/$y/;
}
(DEBUG) && print STDERR “NormalizeCLID: output is $res\n”;
return($res);
}
my $id = $q->param(LOOKUP);
if (!$id) { # check if callerid is available
$id = “UNKNOWN” ; # a default value (when missing/empty);
} else {
$id=&normalizeclid ($id); # replace ‘31’ prefix with '0’
my @filterargs;
my $filtervars = FILTER =~ tr/%/%/;
for (my $i = 0; $i < $filtervars; $i++) { $filterargs[$i] = $id }
my $ldap = Net::LDAP->new(LDAPSERVER, timeout => LDAPTIMEOUT) or die “$@”;
my $mesg = $ldap->bind(BINDDN, password => BINDPW) or die “$@”;
my $filter = sprintf(FILTER,@filterargs);
(DEBUG) && print STDERR “FILTER=$filter\n”;
$mesg = $ldap->search(base => BASEDN, filter => $filter, attrs => [‘cn’,‘o’] );
$mesg->code && die $mesg->error;
if ($mesg->count >0) {
my $result = $mesg->entry(0);
$name = $result->get_value(‘cn’) ." (".$result->get_value(‘o’).")";
} else {
$name=“UNKNOWN”;
}
$mesg = $ldap->unbind;
}
printf ("%s%s", $q->header(), $name);
The whole AGI-interface handling is removed. It is also easy to supply all settings in the query (just use the q->param method a few more times), but for me this will do.
Hope this is helpfull for others. It works in my setup.
Marcel