AGI Ldap CallerId Lookup for Asterisk

heimi666

Neuer User
Mitglied seit
14 Feb 2007
Beiträge
29
Punkte für Reaktionen
3
Punkte
3
Hab grad dieses Script fertiggestellt, was ich nicht vorenthalten möchte:

Code:
#!/usr/bin/perl -w

# AGI Ldap CallerId Lookup for Asterisk
# LDAP schema is mozillaAbPersonAlpha, Number format "0894711"
# use exten => s,1,AGI(ldaplookupphone.agi) in extensions.conf
#
# V 0.01 2010-09-02 Reimer Prochnow, reimerp at gmx dot net
# Credits to Matt Schmandt and duese
# use as CC-BY-SA 3.0
#
# Done in Perl as Shell is not powerful enough for parsing output

use strict;

# far too slow: use Net::LDAP;
use MIME::Base64 qw(decode_base64);
use Encode qw(decode);

$|=1;

my $agi_callerid;
my $num;
if ($#ARGV >= 0) {
    $agi_callerid=$ARGV[0];         # for test
    $num="*$agi_callerid*";         # also allow wildcards around number
} else {

# Setup some variables
my %AGI;

while(<STDIN>) {
    chomp;
    last unless length($_);
    if (/^agi_(\w+)\:\s+(.*)$/) {
        $AGI{$1} = $2;
    }
}

#print STDERR "AGI Environment Dump:\n";
#foreach my $i (sort keys %AGI) {
#    print STDERR " -- $i = $AGI{$i}\n";
#}

$agi_callerid=$AGI{'callerid'};
$num=$agi_callerid;
}

my $cn='';

my $ldapcmd="/usr/bin/ldapsearch -h server -x -D cn=asterisk,dc=xxx,dc=yyy -w ***** " .
        "-b ou=personal,dc=xxx,dc=yyy -LLL -s one " .
        "\"(&(objectClass=mozillaAbPersonAlpha)(|(homePhone=$num)(mobile=$num)(pager=$num)(telephoneNumber=$num)))\"" .
        ' | sed -n -e "H;\${g;s/\n //g;p}"';    # does unfold, not that easy in perl

open (LDAP, "$ldapcmd |") || die ("Unable to open $ldapcmd: $!");
while (<LDAP>){
    chop;
    if (/([^:]*):: (.*)/) {
        $_="$1: " . Encode::decode('utf8', decode_base64($2));  # decodes UTF-8 for :: vars
    }
    if (/^dn[^=]*=([^,]*).*/) { $cn=$1; }
    elsif (/^([^:]*): .*$agi_callerid/) { $cn.='/'.substr($1,0,3);}     # builds: "peter falk/mob"
    #elsif (/^$/) { print "$cn\n"; }
    #print "$cn\n";
}

print 'SET CALLERID "' . $cn . '"<' . $agi_callerid . '>' . "\n";
#exit 0;
 
Zuletzt bearbeitet:
Hola.

War gerade auf der Suche, wie ich wohl meinen asterisk-1.8.0 mit ldap verheiraten könnte. Kein app-ldap in Sicht, also flugs mal das perl script probiert und man glaubt es nicht, nach geringfügigen Anpassungen läuft das. Danke.

cheers
t.
 
Kostenlos!

Statistik des Forums

Themen
248,886
Beiträge
2,303,960
Mitglieder
378,564
Neuestes Mitglied
warumdas