summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
authorsvncommit <devs@roundcube.net>2006-01-08 07:15:44 +0000
committersvncommit <devs@roundcube.net>2006-01-08 07:15:44 +0000
commitd1d2c4fb1d0e9b7a46693e617835850b0edc0fd5 (patch)
tree038a14713ddb3005c1ba33926094b13e15bb012e /program/include
parent3baec23206671623a6a011f323775e0dd897d538 (diff)
adding files and modifications for public ldap search
Diffstat (limited to 'program/include')
-rw-r--r--program/include/main.inc51
-rw-r--r--program/include/rcube_ldap.inc259
2 files changed, 296 insertions, 14 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 24110d343..c64ac7d38 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -924,6 +924,8 @@ function rcube_xml_command($command, $str_attrib, $a_attrib=NULL)
'recordscountdisplay' => 'rcmail_rowcount_display',
'contactdetails' => 'rcmail_contact_details',
'contacteditform' => 'rcmail_contact_editform',
+ 'ldappublicsearch' => 'rcmail_ldap_public_search_form',
+ 'ldappublicaddresslist' => 'rcmail_ldap_public_list',
// USER SETTINGS
'userprefs' => 'rcmail_user_prefs_form',
@@ -1110,7 +1112,7 @@ function rcube_menu($attrib)
-function rcube_table_output($attrib, $sql_result, $a_show_cols, $id_col)
+function rcube_table_output($attrib, $table_data, $a_show_cols, $id_col)
{
global $DB;
@@ -1128,21 +1130,44 @@ function rcube_table_output($attrib, $sql_result, $a_show_cols, $id_col)
$table .= "</tr></thead>\n<tbody>\n";
$c = 0;
- while ($sql_result && ($sql_arr = $DB->fetch_assoc($sql_result)))
+
+ if (!is_array($table_data))
{
- $zebra_class = $c%2 ? 'even' : 'odd';
+ while ($table_data && ($sql_arr = $DB->fetch_assoc($table_data)))
+ {
+ $zebra_class = $c%2 ? 'even' : 'odd';
- $table .= sprintf('<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", $sql_arr[$id_col]);
+ $table .= sprintf('<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", $sql_arr[$id_col]);
- // format each col
- foreach ($a_show_cols as $col)
- {
- $cont = rep_specialchars_output($sql_arr[$col]);
- $table .= '<td class="'.$col.'">' . $cont . "</td>\n";
+ // format each col
+ foreach ($a_show_cols as $col)
+ {
+ $cont = rep_specialchars_output($sql_arr[$col]);
+ $table .= '<td class="'.$col.'">' . $cont . "</td>\n";
+ }
+
+ $table .= "</tr>\n";
+ $c++;
}
+ }
+ else
+ {
+ foreach ($table_data as $row_data)
+ {
+ $zebra_class = $c%2 ? 'even' : 'odd';
+
+ $table .= sprintf('<tr id="rcmrow%d" class="contact '.$zebra_class.'">'."\n", $row_data[$id_col]);
+
+ // format each col
+ foreach ($a_show_cols as $col)
+ {
+ $cont = rep_specialchars_output($row_data[$col]);
+ $table .= '<td class="'.$col.'">' . $cont . "</td>\n";
+ }
- $table .= "</tr>\n";
- $c++;
+ $table .= "</tr>\n";
+ $c++;
+ }
}
// complete message table
@@ -1420,7 +1445,6 @@ function rcmail_charset_selector($attrib)
}
-
function rcube_timer()
{
list($usec, $sec) = explode(" ", microtime());
@@ -1442,5 +1466,4 @@ function rcube_print_time($timer, $label='Timer')
console(sprintf("%s: %0.4f sec", $label, $diff));
}
-
-?> \ No newline at end of file
+?>
diff --git a/program/include/rcube_ldap.inc b/program/include/rcube_ldap.inc
new file mode 100644
index 000000000..7cb9dee53
--- /dev/null
+++ b/program/include/rcube_ldap.inc
@@ -0,0 +1,259 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/include/rcube_ldap.inc |
+ | |
+ | This file is part of the RoundCube Webmail client |
+ | Copyright (C) 2005, RoundCube Dev. - Switzerland |
+ | Licensed under the GNU GPL |
+ | |
+ | PURPOSE: |
+ | Manage an LDAP connection |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Jeremy Jongsma <jeremy@jongsma.org> |
+ +-----------------------------------------------------------------------+
+
+ $Id$
+
+*/
+
+require_once("bugs.inc");
+
+class rcube_ldap
+ {
+ var $conn;
+ var $host;
+ var $port;
+ var $protocol;
+ var $base_dn;
+ var $bind_dn;
+ var $bind_pass;
+
+ // PHP 5 constructor
+ function __construct()
+ {
+ }
+
+ // PHP 4 constructor
+ function rcube_ldap()
+ {
+ $this->__construct();
+ }
+
+ function connect($hosts, $port=389, $protocol=3)
+ {
+ if (!function_exists('ldap_connect'))
+ raise_error(array("type" => "ldap",
+ "message" => "No ldap support in this installation of php."),
+ TRUE);
+
+ if (is_resource($this->conn))
+ return TRUE;
+
+ if (!is_array($hosts))
+ $hosts = array($hosts);
+
+ foreach ($hosts as $host)
+ {
+ if ($lc = @ldap_connect($host, $port))
+ {
+ @ldap_set_option($lc, LDAP_OPT_PROTOCOL_VERSION, $protocol);
+ $this->host = $host;
+ $this->port = $port;
+ $this->protocol = $protocol;
+ $this->conn = $lc;
+ return TRUE;
+ }
+ }
+
+ if (!is_resource($this->conn))
+ raise_error(array("type" => "ldap",
+ "message" => "Could not connect to any LDAP server, tried $host:$port last"),
+ TRUE);
+ }
+
+ function close()
+ {
+ if ($this->conn)
+ {
+ if (@ldap_unbind($this->conn))
+ return TRUE;
+ else
+ raise_error(array("code" => ldap_errno($this->conn),
+ "type" => "ldap",
+ "message" => "Could not close connection to LDAP server: ".ldap_error($this->conn)),
+ TRUE);
+ }
+ return FALSE;
+ }
+
+ // Merge with connect()?
+ function bind($dn=null, $pass=null)
+ {
+ if ($this->conn)
+ {
+ if ($dn)
+ if (@ldap_bind($this->conn, $dn, $pass))
+ return TRUE;
+ else
+ raise_error(array("code" => ldap_errno($this->conn),
+ "type" => "ldap",
+ "message" => "Bind failed for dn=$dn: ".ldap_error($this->conn)),
+ TRUE);
+ else
+ if (@ldap_bind($this->conn))
+ return TRUE;
+ else
+ raise_error(array("code" => ldap_errno($this->conn),
+ "type" => "ldap",
+ "message" => "Anonymous bind failed: ".ldap_error($this->conn)),
+ TRUE);
+ }
+ else
+ raise_error(array("type" => "ldap",
+ "message" => "Attempted bind on nonexistent connection"), TRUE);
+ return FALSE;
+ }
+
+ function count($base, $filter=null, $attributes=null, $scope="sub")
+ {
+ if ($this->conn)
+ {
+ if ($scope === 'sub')
+ $sr = @ldap_search($this->conn, $base, $filter, $attributes, 0, $limit);
+ else if ($scope === 'one')
+ $sr = @ldap_list($this->conn, $base, $filter, $attributes, 0, $limit);
+ else if ($scope === 'base')
+ $sr = @ldap_read($this->conn, $base, $filter, $attributes, 0, $limit);
+ if ($sr)
+ return @ldap_count_entries($this->conn, $sr);
+ }
+ else
+ raise_error(array("type" => "ldap",
+ "message" => "Attempted count search on nonexistent connection"), TRUE);
+ return FALSE;
+ }
+
+ function search($base, $filter=null, $attributes=null, $scope='sub', $sort=null, $limit=0)
+ {
+ if ($this->conn)
+ {
+ if ($scope === 'sub')
+ $sr = @ldap_search($this->conn, $base, $filter, $attributes, 0, $limit);
+ else if ($scope === 'one')
+ $sr = @ldap_list($this->conn, $base, $filter, $attributes, 0, $limit);
+ else if ($scope === 'base')
+ $sr = @ldap_read($this->conn, $base, $filter, $attributes, 0, $limit);
+ if ($sr)
+ {
+ if ($sort && $scope !== "base")
+ {
+ if (is_array($sort))
+ {
+ // Start from the end so first sort field has highest priority
+ $sortfields = array_reverse($sort);
+ foreach ($sortfields as $sortfield)
+ @ldap_sort($this->conn, $sr, $sortfield);
+ }
+ else
+ @ldap_sort($this->conn, $sr, $sort);
+ }
+ return @ldap_get_entries($this->conn, $sr);
+ }
+ }
+ else
+ raise_error(array("type" => "ldap",
+ "message" => "Attempted search on nonexistent connection"), TRUE);
+ return FALSE;
+ }
+
+ function add($dn, $object)
+ {
+ if ($this->conn)
+ {
+ if (@ldap_add($this->conn, $dn, $object))
+ return TRUE;
+ else
+ raise_error(array("code" => ldap_errno($this->conn),
+ "type" => "ldap",
+ "message" => "Add object failed: ".ldap_error($this->conn)),
+ TRUE);
+ }
+ else
+ raise_error(array("type" => "ldap",
+ "message" => "Add object faile: no connection"),
+ TRUE);
+ return FALSE;
+ }
+
+ function modify($dn, $object)
+ {
+ if ($this->conn)
+ {
+ if (@ldap_modify($this->conn, $dn, $object))
+ return TRUE;
+ else
+ raise_error(array("code" => ldap_errno($this->conn),
+ "type" => "ldap",
+ "message" => "Modify object failed: ".ldap_error($this->conn)),
+ TRUE);
+ }
+ else
+ raise_error(array("type" => "ldap",
+ "message" => "Modify object failed: no connection"),
+ TRUE);
+ return FALSE;
+ }
+
+ function rename($dn, $newrdn, $parentdn)
+ {
+ if ($this->protocol < 3)
+ {
+ raise_error(array("type" => "ldap",
+ "message" => "rename() support requires LDAPv3 or above "),
+ TRUE);
+ return FALSE;
+ }
+
+ if ($this->conn)
+ {
+ if (@ldap_rename($this->conn, $dn, $newrdn, $parentdn, TRUE))
+ return TRUE;
+ else
+ raise_error(array("code" => ldap_errno($this->conn),
+ "type" => "ldap",
+ "message" => "Rename object failed: ".ldap_error($this->conn)),
+ TRUE);
+ }
+ else
+ raise_error(array("type" => "ldap",
+ "message" => "Rename object failed: no connection"),
+ TRUE);
+ return FALSE;
+ }
+
+ function delete($dn)
+ {
+ if ($this->conn)
+ {
+ if (@ldap_delete($this->conn, $dn))
+ return TRUE;
+ else
+ raise_error(array("code" => ldap_errno($this->conn),
+ "type" => "ldap",
+ "message" => "Delete object failed: ".ldap_error($this->conn)),
+ TRUE);
+ }
+ else
+ raise_error(array("type" => "ldap",
+ "message" => "Delete object failed: no connection"),
+ TRUE);
+ return FALSE;
+ }
+
+ }
+
+// vi: et ts=2 sw=2
+?>