Koozali.org: home of the SME Server

selintra and CID lookup from a local/ldap database

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« on: April 09, 2007, 11:10:42 AM »
Hi all,
I ask for this here instead of writing directly to selintra as it could be interesting for a greater audience..

I wonder if it's possible without too much hassle to have sail to lookup from a database (or even sme's ldap address book?) for external incoming calls, I'd rather see on phones the name of who's calling me instead of an unfriendly number, so friends, clients, colleagues could be answered first and unknow callers could wait longer in the queue.

thanks!

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« Reply #1 on: April 14, 2007, 10:47:41 AM »
well,
seems like it's an already supported feature of asterisk since 1.0 as per
http://www.voip-info.org/tiki-index.php?page=Asterisk%20cmd%20LookupCIDName via asterisk database. they suggest
Code: [Select]
exten => s,X,LookupCIDName and simply adding numbers <-> name via
Code: [Select]
database put cidname 12345 "John Smith" but don't know very well where/how to put the first line (into extensions.conf) with sail..

thanks

Offline SARK devs

  • ****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
selintra and CID lookup from a local/ldap database
« Reply #2 on: April 15, 2007, 09:35:05 PM »
Hi Guys,

As you can see from the above, the asterisk database is capable of holding and looking up numbers but it's a bit of a pain since it's such a non-standard beast - openPBX has dropped it in favour of SQLite which at least makes it open and accessible.  

An LDAP retrieval mechanism would be much more interesting but the only current Asterisk implementations use Perl.  Now, there's nothing wrong with Perl but I shudder to think what overhead it puts onto Asterisk when it's being loaded in real time every time a call arrives....

Snom have a good LDAP directory access mechanism for their phones but unfortunately it won't do a reverse look-up when a call arrives (at least, if it can, then neither we nor the UK distibutor can figure it out).

Aastra have a good central tftp/http directory solution which works well.  You populate a central file on the TFTP of HTTP server and the phones load the directory each time they boot.  The phone will automatically do the reverse look up for you each time a call arrives.  Nice, but limited to one manufacturer.  Others do similar things but there really isn't any standard way of doing it (at least until Microsoft's Universal Media Server becomes endemic, by which time, all the phone manufacturers will certainly have produced an ExchangeServer interface, which will at least bring a measure of uniformity to the proceedings, whatever you may think of Bill and his boys).

So there you go.  Great idea but thin on tools at the moment.

Best

Selintra

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« Reply #3 on: July 07, 2007, 01:05:56 AM »
Quote from: "selintra"

[...]
An LDAP retrieval mechanism would be much more interesting but the only current Asterisk implementations use Perl.  Now, there's nothing wrong with Perl but I shudder to think what overhead it puts onto Asterisk when it's being loaded in real time every time a call arrives....
[...]
So there you go.  Great idea but thin on tools at the moment.


hi again! i just came across this: http://www.mezzo.net/asterisk/app_ldap.html
isn't this the right tool we were thin on since a while ago, a native C app module for asterisk 1.4? :wink:

cheers
b.

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« Reply #4 on: July 09, 2007, 10:13:00 PM »
the app compiles ok, loads fine with "load app_ldap.so" from CLI and is running ("show application LDAPget"), but again i'm stumped at how i should edit extensions.conf to enable the lookup and show names instead of numbers on phone's display without messing everything up.. :(

selintra-sail-2.1.15-483 and smeserver-asterisk-1.4.1-8

thanks again

Offline SARK devs

  • ****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
selintra and CID lookup from a local/ldap database
« Reply #5 on: July 09, 2007, 10:56:35 PM »
How good is your Perl?

We don't have the cycles to look at this until maybe end of the month, but we'd be happy to show you where to make the changes if you want to have a go.

Kind Regards

S

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« Reply #6 on: July 09, 2007, 11:03:51 PM »
my.. what?
ehm, quite bad, but if it doesn't take too long for you to show me, please shoot, i'll enjoy spending some time to figure it out or, as last resort, just wait without hammering if i really can't afford it..

thanks a lot!

Offline SARK devs

  • ****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
selintra and CID lookup from a local/ldap database
« Reply #7 on: July 10, 2007, 11:57:35 AM »
Good man!

OK, we lied about the Perl stuff  :-)....

Create a custom app and set the span to external.  Call it whatever you like.  In your inbound trunk, point the Open route to your custom app.  When a call arrives, SAIL will deliver it to your custom app.  You can now do whatever you like with it (including dial statements etc etc).

Custom app flow will be something like (in pseudocode)

Code: [Select]
exten=>s,1,{do LDAP lookup and assign to CALLERID}
exten=>s,2,{dial an extension}
exten=>s,3,Hangup


If you want to properly integrate your code into SAIL itself you can ask SAIL to do the Dial for you with something like...

Code: [Select]
exten=>s,1,{do LDAP lookup and assign to CALLERID}
exten => s,2,agi(selintra,InCall,{extension or Alias you want to call})
exten=>s,3,Hangup


Kind Regards

S

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« Reply #8 on: July 10, 2007, 11:34:26 PM »
Hi again,
thanks for the tips.. and for the excellent news about Perl not being involved! :D

i promised i won't hammer on this, just some good/bad news from the lookup side..

i COULD lookup from ldap, and that's really good, but something goes bang when it's time to route calls to phones with the piece of code you gave me, with and w/o brackets.

Quote

exten => s,2,agi(selintra,InCall,{extension or Alias you want to call})


7000 is an alias for "5001 5002 5003", 3 SIP users i have around.
boobee telephoneNumber into local ldap is '1234567890'
public numbers/names are not real.

Code: [Select]
CLI>
    -- Starting simple switch on 'Zap/2-1'
    -- Executing [s@mainmenu:1] GotoIf("Zap/2-1", "0?s-Zap1-1|1") in new stack
    -- Executing [s@mainmenu:2] GotoIf("Zap/2-1", "1?s-Zap2-1|1") in new stack
    -- Goto (mainmenu,s-Zap2-1,1)
    -- Executing [s-Zap2-1@mainmenu:1] AGI("Zap/2-1", "selintra|Inbound|Zap2-1") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/selintra
    -- AGI Script Executing Application: (Background) Options: (silence/2)
    -- <Zap/2-1> Playing 'silence/2' (language 'en')
    -- AGI Script selintra completed, returning 0
    -- Executing [s@ldapcid:1] LDAPget("Zap/2-1", "CALLERID=lookupcid/||) exten=>s|2|agi(selintra|InCall|{7000}") in new stack
    -- LDAPget: varname=CALLERID, config-section=lookupcid, keys=||) exten=>s|2|agi(selintra|InCall|{7000}
  == Parsing '/etc/asterisk/ldap.conf': Found
       > LDAPget: ldap://localhost/dc=localhost,dc=localdomain?cn?sub?(&(objectClass=*)(telephoneNumber=${CALLERID(number)}))
    -- LDAPget: ldap://localhost/dc=localhost,dc=localdomain?cn?sub?(&(objectClass=*)(telephoneNumber=1234567890))
    -- LDAPget: bind to localhost anonymously
    -- LDAPget: cn=boobee
    -- LDAPget: convert: UTF-8 -> ISO-8859-1
    -- LDAPget: set CALLERID='boobee'
  == Auto fallthrough, channel 'Zap/2-1' status is 'UNKNOWN'
    -- Hungup 'Zap/2-1'


my /etc/asterisk/ldap.conf

Code: [Select]
[lookupcid]
host = localhost
version = 3
base = dc=localhost,dc=localdomain
convert = UTF-8, ISO-8859-1


and my custom app 'ldapcid'

Code: [Select]
exten=>s,1,LDAPget(CALLERID=cidname/${CALLERIDNUM},${CALLERIDNUM},${CALLERIDNUM})
exten=>s,2,agi(selintra,InCall,{7000})
exten=>s,3,Hangup


if i change the destination for inbound calls back to alias 7000 instead of my app, all works fine again.

Offline SARK devs

  • ****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
selintra and CID lookup from a local/ldap database
« Reply #9 on: July 11, 2007, 12:40:23 AM »
Hi,

Sorry - bad notation on our part.  The curly brackets were just to show an optional parameter... Try....
Code: [Select]
exten=>s,2,agi(selintra,InCall,7000)

..should work  -  If it doesn't, we'll think of something else ;-)

Best

S[/quote]

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« Reply #10 on: July 11, 2007, 12:20:22 PM »
Quote from: "selintra"
Sorry - bad notation on our part. The curly brackets were just to show an optional parameter... Try....
Code: [Select]

exten=>s,2,agi(selintra,InCall,7000)

..should work - If it doesn't, we'll think of something else


Quote from: "boobee"
[...]something goes bang when it's time to route calls to phones with the piece of code you gave me, with and w/o brackets.


already tried with no braces, but it's still claiming about Zap/2-1 status UNKNOWN and then it hangs up immediately..

maybe that Perl approach is now required? :wink:

regards
b.

Offline SARK devs

  • ****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
selintra and CID lookup from a local/ldap database
« Reply #11 on: July 11, 2007, 12:50:57 PM »
Sorry Boobee

We gave you some bad info. You use InCall if you are only ringning a single SIP extension.  If you want to ring a group (Alias) you use...

Code: [Select]
exten => 288,1,agi(selintra,Alias,SIP/6044 SIP/6035 SIP/6042,${EXTEN})


So, for your call you can do...

Code: [Select]
exten=>s,1,LDAPget(CALLERID=cidname/${CALLERIDNUM},${CALLERIDNUM},${CALLERIDNUM})
exten=>s,2,GoTo(7000,1)

exten=>7000,1,agi(selintra,Alias,SIP/nnnn SIP/nnnn SIP/nnnnn,${EXTEN})
exten=>7000,2,Hangup


The SIP/nnnn entries should be substituted with the real extension numbers you want to call... e.g. SIP/6004 SIP/6005...  and so on.

Wouldn't it be nice if we knew how our own product worked?  Heigh ho...

Try that.

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« Reply #12 on: July 11, 2007, 07:07:35 PM »
Quote from: "selintra"

Wouldn't it be nice if we knew how our own product worked?  Heigh ho...

Try that.


happens to me everyday for most stupid things, stress and too little sleep don't help me that much though.

anyway, still out of luck..

there must be something wrong with the ldap lookup or its exit code i suppose.. i tried  BTW the InCall bit again with a single sip extension in place of an alias, but it won't change a single line of the error.

always
Code: [Select]
== Auto fallthrough, channel 'Zap/2-1' status is 'UNKNOWN'
    -- Hungup 'Zap/2-1'


thanks very much guys for your time spent here

PS: meanwhile, i drained my gsm credit because of the initial fax detection on the 30+ test calls i did  :?

Offline SARK devs

  • ****
  • 2,806
  • +1/-0
    • http://sarkpbx.com
selintra and CID lookup from a local/ldap database
« Reply #13 on: July 11, 2007, 08:25:41 PM »
We think it might be because the LDAP lookup adds +101 to the linecounter.

Try this...

Code: [Select]
exten=>s,1,LDAPget(CALLERID=cidname/${CALLERIDNUM},${CALLERIDNUM},${CALLERIDNUM})
exten=>s,2,GoTo(7000,1)
exten->s,102,GoTo(7000,1)

exten=>7000,1,agi(selintra,Alias,SIP/nnnn SIP/nnnn SIP/nnnnn,${EXTEN})
exten=>7000,2,Hangup


Best

S

Offline boobee

  • *
  • 32
  • +0/-0
selintra and CID lookup from a local/ldap database
« Reply #14 on: July 11, 2007, 08:42:31 PM »
hey, you did it!

now calls are incoming correctly, while the name is still not presented, just the number, the classic way, on ip phone and softphones.

we are approaching the goal..

i promise a little howto/wiki page (for what it's worth) for the weekend if you can fix this, should be a piece of cake right now, shouldn't it?  :wink: