| | |
| | | } |
| | | |
| | | // Get the pieces needed for variable replacement. |
| | | $fu = $RCMAIL->user->get_username(); |
| | | list($u, $d) = explode('@', $fu); |
| | | if ($fu = $RCMAIL->user->get_username()) |
| | | list($u, $d) = explode('@', $fu); |
| | | else |
| | | $d = $this->mail_domain; |
| | | |
| | | $dc = 'dc='.strtr($d, array('.' => ',dc=')); // hierarchal domain string |
| | | |
| | | $replaces = array('%dc' => $dc, '%d' => $d, '%fu' => $fu, '%u' => $u); |
| | |
| | | // we have a search result resource |
| | | if ($this->ldap_result && $this->result->count > 0) |
| | | { |
| | | // sorting still on the ldap server |
| | | if ($this->sort_col && $this->prop['scope'] !== 'base' && !$this->vlv_active) |
| | | ldap_sort($this->conn, $this->ldap_result, $this->sort_col); |
| | | |
| | | // start and end of the page |
| | | $start_row = $this->vlv_active ? 0 : $this->result->first; |
| | | $start_row = $subset < 0 ? $start_row + $this->page_size + $subset : $start_row; |
| | | $last_row = $this->result->first + $this->page_size; |
| | | $last_row = $subset != 0 ? $start_row + abs($subset) : $last_row; |
| | | |
| | | // get all entries from the ldap server |
| | | $entries = ldap_get_entries($this->conn, $this->ldap_result); |
| | | |
| | | // filtering for group members |
| | | if ($this->groups and $this->group_id) |
| | | { |
| | | $count = 0; |
| | | $members = array(); |
| | | foreach ($entries as $entry) |
| | | { |
| | | if ($this->group_members[base64_encode($entry['dn'])]) |
| | | { |
| | | $members[] = $entry; |
| | | $count++; |
| | | } |
| | | } |
| | | $entries = $members; |
| | | $entries['count'] = $count; |
| | | $this->result->count = $count; |
| | | } |
| | | |
| | | // filter entries for this page |
| | | for ($i = $start_row; $i < min($entries['count'], $last_row); $i++) |
| | | $this->result->add($this->_ldap2result($entries[$i])); |
| | | } |
| | | |
| | | // temp hack for filtering group members |
| | | if ($this->groups and $this->group_id) |
| | | { |
| | | $result = new rcube_result_set(); |
| | | while ($record = $this->result->iterate()) |
| | | { |
| | | if ($this->group_members[$record['ID']]) |
| | | { |
| | | $result->add($record); |
| | | $result->count++; |
| | | } |
| | | } |
| | | $this->result = $result; |
| | | } |
| | | |
| | | return $this->result; |
| | | } |
| | | |
| | |
| | | $newdata = array(); |
| | | $replacedata = array(); |
| | | $deletedata = array(); |
| | | |
| | | // flatten composite fields in $record |
| | | if (is_array($record['address'])) { |
| | | foreach ($record['address'] as $i => $struct) { |
| | | foreach ($struct as $col => $val) { |
| | | $record[$col][$i] = $val; |
| | | } |
| | | } |
| | | } |
| | | |
| | | foreach ($this->fieldmap as $col => $fld) { |
| | | $val = $save_cols[$col]; |
| | |
| | | { |
| | | if (!is_array($ids)) { |
| | | // Not an array, break apart the encoded DNs. |
| | | $dns = explode(',', $ids); |
| | | $ids = explode(',', $ids); |
| | | } // end if |
| | | |
| | | foreach ($dns as $id) { |
| | | foreach ($ids as $id) { |
| | | $dn = base64_decode($id); |
| | | $this->_debug("C: Delete [dn: $dn]"); |
| | | // Delete the record. |
| | |
| | | } |
| | | } // end foreach |
| | | |
| | | return count($dns); |
| | | return count($ids); |
| | | } |
| | | |
| | | |
| | |
| | | $filter = $this->filter ? $this->filter : '(objectclass=*)'; |
| | | $function = $this->prop['scope'] == 'sub' ? 'ldap_search' : ($this->prop['scope'] == 'base' ? 'ldap_read' : 'ldap_list'); |
| | | |
| | | $this->_debug("C: Search [".$filter."]"); |
| | | $this->_debug("C: Search [$filter]"); |
| | | |
| | | // when using VLV, we get the total count by... |
| | | if (!$count && $function != 'ldap_read' && $this->prop['vlv']) { |
| | |
| | | } |
| | | else // ...or by fetching all records dn and count them |
| | | $this->vlv_count = $this->_exec_search(true); |
| | | |
| | | |
| | | $this->vlv_active = $this->_vlv_set_controls(); |
| | | } |
| | | |
| | |
| | | $dc = 'dc='.strtr($d, array('.' => ',dc=')); |
| | | $replaces = array('%dc' => $dc, '%d' => $d, '%fu' => $fu, '%u' => $u); |
| | | |
| | | $this->groups_base_dn = strtr($this->groups_base_dn, $replaces);; |
| | | $this->groups_base_dn = strtr($this->groups_base_dn, $replaces); |
| | | } |
| | | |
| | | $base_dn = $this->groups_base_dn; |
| | | $filter = $this->prop['groups']['filter']; |
| | | |
| | | $this->_debug("C: Search [$filter][dn: $base_dn]"); |
| | | |
| | | $res = ldap_search($this->conn, $base_dn, $filter, array('cn','member')); |
| | | if ($res === false) |
| | |
| | | $this->set_error(self::ERROR_SAVING, 'errorsaving'); |
| | | return array(); |
| | | } |
| | | |
| | | $ldap_data = ldap_get_entries($this->conn, $res); |
| | | $this->_debug("S: ".ldap_count_entries($this->conn, $res)." record(s)"); |
| | | |
| | | $groups = array(); |
| | | $group_sortnames = array(); |
| | | for ($i=0; $i<$ldap_data["count"]; $i++) |
| | | { |
| | | $group_name = $ldap_data[$i]['cn'][0]; |
| | | $group_id = base64_encode($group_name); |
| | | $groups[$group_id]['ID'] = $group_id; |
| | | $groups[$group_id]['name'] = $group_name; |
| | | $groups[$group_id]['members'] = $ldap_data[$i]['member']; |
| | | $group_sortnames[] = strtolower($group_name); |
| | | if (!$search || strstr(strtolower($group_name), strtolower($search))) |
| | | { |
| | | $group_id = base64_encode($group_name); |
| | | $groups[$group_id]['ID'] = $group_id; |
| | | $groups[$group_id]['name'] = $group_name; |
| | | $groups[$group_id]['members'] = $ldap_data[$i]['member']; |
| | | $group_sortnames[] = strtolower($group_name); |
| | | } |
| | | } |
| | | array_multisort($group_sortnames, SORT_ASC, SORT_STRING, $groups); |
| | | $this->group_cache = $groups; |
| | |
| | | 'member' => '', |
| | | ); |
| | | |
| | | $this->_debug("C: Add [dn: $new_dn]: ".print_r($new_entry, true)); |
| | | |
| | | $res = ldap_add($this->conn, $new_dn, $new_entry); |
| | | if ($res === false) |
| | | { |
| | |
| | | $this->set_error(self::ERROR_SAVING, 'errorsaving'); |
| | | return false; |
| | | } |
| | | |
| | | $this->_debug("S: OK"); |
| | | |
| | | return array('id' => $new_gid, 'name' => $group_name); |
| | | } |
| | | |
| | |
| | | |
| | | $base_dn = $this->groups_base_dn; |
| | | $group_name = $this->group_cache[$group_id]['name']; |
| | | |
| | | $del_dn = "cn=$group_name,$base_dn"; |
| | | |
| | | $this->_debug("C: Delete [dn: $del_dn]"); |
| | | |
| | | $res = ldap_delete($this->conn, $del_dn); |
| | | if ($res === false) |
| | | { |
| | |
| | | $this->set_error(self::ERROR_SAVING, 'errorsaving'); |
| | | return false; |
| | | } |
| | | |
| | | $this->_debug("S: OK"); |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | $new_rdn = "cn=$new_name"; |
| | | $new_gid = base64_encode($new_name); |
| | | |
| | | $this->_debug("C: Rename [dn: $old_dn] [dn: $new_rdn]"); |
| | | |
| | | $res = ldap_rename($this->conn, $old_dn, $new_rdn, NULL, TRUE); |
| | | if ($res === false) |
| | | { |
| | |
| | | $this->set_error(self::ERROR_SAVING, 'errorsaving'); |
| | | return false; |
| | | } |
| | | |
| | | $this->_debug("S: OK"); |
| | | |
| | | return $new_name; |
| | | } |
| | | |
| | |
| | | foreach (explode(",", $contact_ids) as $id) |
| | | $new_attrs['member'][] = base64_decode($id); |
| | | |
| | | $this->_debug("C: Add [dn: $group_dn]: ".print_r($new_attrs, true)); |
| | | |
| | | $res = ldap_mod_add($this->conn, $group_dn, $new_attrs); |
| | | if ($res === false) |
| | | { |
| | |
| | | $this->set_error(self::ERROR_SAVING, 'errorsaving'); |
| | | return 0; |
| | | } |
| | | |
| | | $this->_debug("S: OK"); |
| | | |
| | | return count($new_attrs['member']); |
| | | } |
| | | |
| | |
| | | foreach (explode(",", $contact_ids) as $id) |
| | | $del_attrs['member'][] = base64_decode($id); |
| | | |
| | | $this->_debug("C: Delete [dn: $group_dn]: ".print_r($del_attrs, true)); |
| | | |
| | | $res = ldap_mod_del($this->conn, $group_dn, $del_attrs); |
| | | if ($res === false) |
| | | { |
| | |
| | | $this->set_error(self::ERROR_SAVING, 'errorsaving'); |
| | | return 0; |
| | | } |
| | | |
| | | $this->_debug("S: OK"); |
| | | |
| | | return count($del_attrs['member']); |
| | | } |
| | | |
| | |
| | | |
| | | $base_dn = $this->groups_base_dn; |
| | | $contact_dn = base64_decode($contact_id); |
| | | $filter = "(member=$contact_dn)"; |
| | | $filter = strtr("(member=$contact_dn)", array('\\' => '\\\\')); |
| | | |
| | | $this->_debug("C: Search [$filter][dn: $base_dn]"); |
| | | |
| | | $res = ldap_search($this->conn, $base_dn, $filter, array('cn')); |
| | | if ($res === false) |
| | |
| | | return array(); |
| | | } |
| | | $ldap_data = ldap_get_entries($this->conn, $res); |
| | | $this->_debug("S: ".ldap_count_entries($this->conn, $res)." record(s)"); |
| | | |
| | | $groups = array(); |
| | | for ($i=0; $i<$ldap_data["count"]; $i++) |