Author Topic: ldap as default addressbook  (Read 8313 times)

Offline em

  • Newbie
  • *
  • Posts: 9
ldap as default addressbook
« on: May 30, 2007, 11:12:16 AM »
Hello,

I would like that when user type in address field a ldap request was made(instead of personal addressbook), is it possible?

thanks for your answers

Offline ckmandli

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #1 on: May 30, 2007, 04:14:56 PM »
Yes, it is. I searched because I was in this same boat, and came across this. This has worked very well for me and beta2
http://trac.roundcube.net/trac.cgi/attachment/ticket/1483899/compose_391.inc.diff

Offline em

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #2 on: May 31, 2007, 06:14:15 AM »
thanks, this is not working with RC1 because ldap functions was changed, but I will try to adapt... If I found I will post the code here.

Offline em

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #3 on: May 31, 2007, 08:59:40 AM »
this is working for me on RC1.
changes have been made at the end of program/steps/mail/compose.inc
changes are between "//Add for LDAP search" and "//End of LDAP search"

Code: [Select]
/****** get contacts for this user and add them to client scripts ********/

require_once('include/rcube_contacts.inc');

$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
$CONTACTS->set_pagesize(1000);

if ($result = $CONTACTS->list_records())
 {
 $a_contacts = array();
 while ($sql_arr = $result->iterate())
  if ($sql_arr['email'])
   $a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));


//Add for LDAP search
foreach ($CONFIG['ldap_public'] as $ldapserv_config)
{
 $ldapfields = array($ldapserv_config['mail_field'],$ldapserv_config['name_field']);
 $cLdap = new rcube_ldap($ldapserv_config);
 $cLdap->connect ();
 $cLdap->bind($ldapserv_config['base_dn'],'');     //second field is for password if required
 $results = $cLdap->search ($ldapfields,
               "mydomain",          //field for search criteria, can't be empty,* is not a Wildcard character
               true);
 $cLdap->close ();
}

while ($ldap_arr = $results->next())
{
 if ($ldap_arr['email'])
   $a_contacts[] = format_email_recipient($ldap_arr['email'], JQ($ldap_arr['name']));
}
//End of LDAP search


$OUTPUT->set_env('contacts', $a_contacts);
}

parse_template('compose');
?>

Offline rtomanek

  • Newbie
  • *
  • Posts: 8
Re: ldap as default addressbook
« Reply #4 on: May 31, 2007, 10:02:43 AM »
Hi,

 a cleaned up diff version of the above, modified slightly, with current (RC1) version of config parameters:
Code: [Select]
--- compose.inc.orig  2007-05-18 15:11:22.000000000 +0200
+++ compose.inc 2007-05-31 15:57:50.000000000 +0200
@@ -867,6 +867,7 @@ $OUTPUT->add_handlers(array(
 /****** get contacts for this user and add them to client scripts ********/

 require_once('include/rcube_contacts.inc');
+require_once('include/rcube_ldap.inc');

 $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
 $CONTACTS->set_pagesize(1000);
@@ -877,7 +878,23 @@ if ($result = $CONTACTS->list_records())
  while ($sql_arr = $result->iterate())
   if ($sql_arr['email'])
    $a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
-
+
+ foreach ($CONFIG['ldap_public'] as $ldapserv_config)
+ {
+  $ldapfields = array($ldapserv_config['email_field'],$ldapserv_config['name_field']);
+  $cLdap = new rcube_ldap($ldapserv_config);
+  $cLdap->connect ();
+  $cLdap->bind($ldapserv_config['bind_dn'], $ldapserv_config['bind_pass']);
+  $results = $cLdap->search ($ldapfields, "@" /* God, forgive me this nasty hack */, true);
+  $cLdap->close ();
+ }
+
+ while ($ldap_arr = $results->next())
+ {
+  if ($ldap_arr['email'])
+    $a_contacts[] = format_email_recipient($ldap_arr['email'], JQ($ldap_arr['name']));
+ }
+
  $OUTPUT->set_env('contacts', $a_contacts);
  }

Offline ckmandli

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #5 on: June 01, 2007, 11:52:35 AM »
Thanks, this helps. Will try it out.

Offline em

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #6 on: July 06, 2007, 10:00:23 AM »
in the composer, I have only the 10 first address found in the ldap:( in adress book I can see all my ldap entries

anyone have an idea?

Offline em

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #7 on: July 10, 2007, 07:42:25 AM »
this is this variable that limits the list...
 
in "include/rcube_ldap.inc"
var $page_size = 10;

I change to 100 and I've got all the addresses but I don't know if there was other effect...


Offline em

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #8 on: July 10, 2007, 09:19:26 AM »
little improvement : sorting the list

add before this line
Code: [Select]
$results = $cLdap->search.......
this :
Code: [Select]
$cLdap->sort_col = 'mail';
change 'mail' by the ldap field you want ;)


Offline nariz

  • Newbie
  • *
  • Posts: 1
Re: ldap as default addressbook
« Reply #9 on: July 30, 2007, 08:21:02 PM »
i too try this...
but not work

Offline em

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #10 on: August 09, 2007, 08:38:02 AM »
What did you try? give me more informations, if I can help you....

Offline jay

  • Jr. Member
  • **
  • Posts: 10
Re: ldap as default addressbook
« Reply #11 on: August 21, 2007, 06:48:31 PM »
I'm trying to implement this ldap-autofill too, but without success.
my code of compose.inc looks like this at the end.

Code: [Select]
/****** get contacts for this user and add them to client scripts ********/

require_once('include/rcube_contacts.inc');
require_once('include/rcube_ldap.inc');

$CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
$CONTACTS->set_pagesize(1000);
                 
if ($result = $CONTACTS->list_records())
 {    
 $a_contacts = array();
 while ($sql_arr = $result->iterate())
  if ($sql_arr['email'])
   $a_contacts[] = format_email_recipient($sql_arr['email'], JQ($sql_arr['name']));
 
//Add for LDAP search
foreach ($CONFIG['ldap_public'] as $ldapserv_config)
{
$ldapfields = array($ldapserv_config['email_field'],$ldapserv_config['name_field']);
$cLdap = new rcube_ldap($ldapserv_config);
$cLdap->connect ();
$cLdap->bind($ldapserv_config['bind_dn'], $ldapserv_config['bind_pass']);
$results = $cLdap->search ($ldapfields, "@" /* God, forgive me this nasty hack */, true);
$cLdap->close ();
}

while ($ldap_arr = $results->next())
{
if ($ldap_arr['email'])
  $a_contacts[] = format_email_recipient($ldap_arr['email'], JQ($ldap_arr['name']));
}
//End of LDAP search

 $OUTPUT->set_env('contacts', $a_contacts);
 }


parse_template('compose');

the ldap-addressbook is working fine
but if I type in the to: filed some names no email appears except the one address of the normal addressbook.

any idea what's wrong?
btw: if I change to the ldap-addressbook RC shows "loading..." but nothing will be displayed, I have to use the search for seeing some addresses. is this normal? or could this be a similar problem?

thanks for any help
jay

Offline em

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #12 on: August 23, 2007, 03:40:40 AM »
sorry, no ideas... perhaps look in ldap logs

which version of RC do you use? I test this code on RC1, now I use on svn version of the 18 june

for me in ldap-addressbook nothing is displaying whereas I make a search

Offline jay

  • Jr. Member
  • **
  • Posts: 10
Re: ldap as default addressbook
« Reply #13 on: August 31, 2007, 11:16:33 AM »
I found where it's not working!! on this line
Code: [Select]
$results = $cLdap->search ($ldapfields, "@" /* God, forgive me this nasty hack */, true);I never get a result. If I replace "@" with some text e.g. the beginning of a name there is a result. I don't know why but the email field is not searchable (see also my post http://roundcubeforum.net/forum/index.php?topic=2084.0).

Do you have an idea why the email field is not searchable?

BTW:
1) In main.inc.php I configured the ldap email filed like this
Code: [Select]
'email_field'  => 'mail', // this field represents the contact's e-mail
2) I installed the latest roundcube svn version (675)

Thanks
jay

Offline em

  • Newbie
  • *
  • Posts: 9
Re: ldap as default addressbook
« Reply #14 on: September 03, 2007, 02:14:07 AM »
I try with "@" and it is working for me... I use my domain name in search criteria because I only have users of my network into my ldap.
maybe "@" doesn't work for you because of your character encoding is your file compose.inc, your web server and your browser use the same character encoding? For me I install roundcube on a Debian with Apache and all character encoding is UTF8.