Home > Trixbox > Ldap directory for Cisco 7941 / 7961 IP Phones

Ldap directory for Cisco 7941 / 7961 IP Phones

Since a few weeks I’m having a few Cisco 7941 IP Phones. Although they look pretty similar to the 7940 models, it turns out configuring them is totally different.
Once provisioned and registered, I discovered that the ldap directory script I use for the 7960 phone didn’t work any longer.

I finally found a solution for this problem today, by just using some of the code from the pre-installed Trixbox xmlservices scripts.

Rather than using the original directory.php script, I now use the below updated SearchDirectory.php script, and renamed it to ldapSearchDirectory.php.

ldapSearchDirectory.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
//Copyright (C) 2006 Fonality Inc. (fonality.com)
 
//
 
//This program is free software; you can redistribute it and/or
 
//modify it under the terms of the GNU General Public License
 
//as published by the Free Software Foundation; either version 2
 
//of the License, or (at your option) any later version.
 
//
 
//This program is distributed in the hope that it will be useful,
 
//but WITHOUT ANY WARRANTY; without even the implied warranty of
 
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
//GNU General Public License for more details.
 
 
require '/var/www/html/xmlservices/libs/Smarty.class.php';
 
$smarty = new Smarty;
 
require '/var/www/html/xmlservices/include/xmlservices_libs.php';
require '/var/www/html/xmlservices/include/xmlservices_config.php';
 
$smarty->compile_check = true;
 
// $smarty->debugging = true; 
 
$smarty->assign('PageTitle','Search by last name');
$smarty->assign('Prompt','Enter the first few letters');
 
$smarty->display('ldapsearchDirectory_'.$content_format.'.tpl');
?>

ldapsearchDirectory_ciscoxml4.tpl in the templates directory looks like this:

1
2
3
4
5
6
7
8
9
10
11
<CiscoIPPhoneInput>
<Title>{$PageTitle}</Title>
<Prompt>{$Prompt}</Prompt>
<URL>{$Server}/result.php</URL>
<InputItem>
<DisplayName>Filter</DisplayName>
<QueryStringParam>filter</QueryStringParam>
<DefaultValue></DefaultValue>
<InputFlags>A</InputFlags>
</InputItem>
</CiscoIPPhoneInput>

Lastly, the result.php script has been updated a little:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php 
// This XML-PHP page searches contacts in LDAP and display it on CISCO directory service 
// Script Provided by Gael Marronnier From Simstream Company www.simstream.com gael_asterisk@simstream.com
// Modified by Arnaud Croes (arnaud@croesnet.eu) to make it work properly in a 3CX environment
// 
// Get parameter from directory script
 
require '/var/www/html/xmlservices/libs/Smarty.class.php';
 
$smarty = new Smarty;
 
require '/var/www/html/xmlservices/include/xmlservices_libs.php';
require '/var/www/html/xmlservices/include/xmlservices_config.php';
 
$directoryRowCount=30;
 
$smarty->compile_check = true;
 
//$smarty->debugging = true; 
 
# This sets the offset for the LIMIT portion of the query
$NextStartingRow = $_GET['NextGroup']*$directoryRowCount;
 
 
$filter = $_REQUEST["filter"]; 
 
// LDAP server characteristics 
$ds=ldap_connect("192.168.1.2"); 
if (ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3))
{
    echo "Using LDAP v3";
}else{
    echo "Failed to set version to protocol 3";
}
$myldap="ou=addressbook,dc=croesnet,dc=eu"; 
 
// Phone entries on my LDAP server are in the format +1 (800) 5551234, the way outlook likes it.
// Names on the server (cn) are not supposed to have special characters like &
// The script replaces the + by 00 , because 3CX doesn't like the + character in the dial string.
// Also removing space, ( and ) characters.
// Removing the ( and ) characters is just cosmetic, they do not cause functionality problems.
// Phone number format change variables
$patterns[0] = '/\+/';
$patterns[1] = '/\(|\)|-|\s+/';
$replacements[0] = '00';
$replacements[1] = '';
 
if ($ds) { 
  $r=ldap_bind($ds); 
  $filterldap="(|(givenname=*".$filter."*)(sn=*".$filter."*)(cn=*".$filter."*)(mail=*".$filter."*))";
  $sr=ldap_search($ds, $myldap, $filterldap); 
  // Lets start displaying XML infos 
  echo "<CiscoIPPhoneDirectory>\n"; 
  echo "<Title>IP Telephony Directory</Title>\n"; 
  $info = ldap_get_entries($ds, $sr); 
  echo "<Prompt>"; 
  echo $info["count"]; 
  echo " Reachable person(s)</Prompt>\n"; 
  for ($i=0; $i<$info["count"]; $i++) {
     if ($info[$i]["mobile"][0]) { 
     echo "<DirectoryEntry>\n"; 
     echo "<Name>" . iconv("UTF-8","ISO-8859-1",$info[$i]["cn"][0]) . " (mobile)</Name>\n"; 
     echo "<Telephone>" .preg_replace($patterns, $replacements, $info[$i]["mobile"][0]) ."</Telephone>\n"; 
     echo "</DirectoryEntry>\n"; 
     } 
     if ($info[$i]["homephone"][0]) { 
     echo "<DirectoryEntry>\n"; 
     echo "<Name>" . iconv("UTF-8","ISO-8859-1",$info[$i]["cn"][0]) . " (home)</Name>\n"; 
     echo "<Telephone>" .preg_replace($patterns, $replacements, $info[$i]["homephone"][0]) ."</Telephone>\n"; 
     echo "</DirectoryEntry>\n"; 
     } 
     if ($info[$i]["telephonenumber"][0]) { 
     echo "<DirectoryEntry>\n"; 
     echo "<Name>" . iconv("UTF-8","ISO-8859-1",$info[$i]["cn"][0]) . " (business)</Name>\n"; 
     echo "<Telephone>" .preg_replace($patterns, $replacements, $info[$i]["telephonenumber"][0]) ."</Telephone>\n"; 
     echo "</DirectoryEntry>\n"; 
     } 
   } 
   echo"</CiscoIPPhoneDirectory>"; 
   ldap_close($ds); 
} else { 
  echo "error"; 
} 
 
?>
Categories: Trixbox Tags:
  1. zzbo
    December 14th, 2009 at 16:40 | #1

    line 8-20 is changed ? you got this directory to show under the directory button ?

  2. December 14th, 2009 at 16:52 | #2

    Hi, I coped lines 8 – 20 from the standard scripts on the trixbox. With this, the script is working, however only under the services button. Not under the directory button. Is it now working for you? What did you change?
    To copy code into the comment, please use the b-quote option.

  3. zzbo
    December 15th, 2009 at 10:14 | #3

    hmm.. It’s just “requesting…” but no result. Working on 7940/7960.
    Have you got 7936 to work on SIP ?

  4. December 15th, 2009 at 10:35 | #4

    @zzbo
    Hi, no I don’t. I only use (for the moment) the 7960 and 7941 models.

  5. zzbo
    December 15th, 2009 at 14:09 | #5

    found the error. It was requesting because of it could not resolve the OU via LDAP. Now it’s working, I just need 7936 to work if it’s possible, and make the directory visible under the directory button. Please give me a hint if you make yours work here

  6. zzbo
    December 15th, 2009 at 14:31 | #6

    Got it :)

    Now I have the directory under directorybutton (has to be xml) and I can do search.. now I can use my servicebutton for something else.

  7. Eddie
    August 26th, 2010 at 17:47 | #7

    zzbo – what do you mean that the directorybutton has to be xml? The reason I ask is because I am trying to get my 7961 working pointing towards a .php script using “directoryURL”, but with no success. Does anyone have any pointers they could provide?

  8. feiyu
    September 12th, 2010 at 05:04 | #8

    Hi There,

    Anyone knows how to get this script working on a XAMPP instead?

    Where can I get the following 2 files working in XAMPP?
    require ‘/var/www/html/xmlservices/include/xmlservices_libs.php’;
    require ‘/var/www/html/xmlservices/include/xmlservices_config.php’;

  1. No trackbacks yet.