| | |
| | | |
| | | foreach ($p as $prop => $value) |
| | | if (preg_match('/^(.+)_field$/', $prop, $matches)) |
| | | $this->fieldmap[$matches[1]] = strtolower($value); |
| | | $this->fieldmap[$matches[1]] = $this->_attr_name(strtolower($value)); |
| | | |
| | | foreach ($this->prop['required_fields'] as $key => $val) |
| | | $this->prop['required_fields'][$key] = $this->_attr_name(strtolower($val)); |
| | | |
| | | $this->sort_col = $p['sort']; |
| | | |
| | |
| | | $filter = $this->prop['filter']; |
| | | $this->set_search_set($filter); |
| | | } |
| | | |
| | | |
| | | // exec LDAP search if no result resource is stored |
| | | if ($this->conn && !$this->ldap_result) |
| | | $this->_exec_search(); |
| | |
| | | $res = null; |
| | | if ($this->conn && $dn) |
| | | { |
| | | $this->ldap_result = ldap_read($this->conn, base64_decode($dn), "(objectclass=*)", array_values($this->fieldmap)); |
| | | $this->ldap_result = ldap_read($this->conn, base64_decode($dn), '(objectclass=*)', array_values($this->fieldmap)); |
| | | $entry = @ldap_first_entry($this->conn, $this->ldap_result); |
| | | |
| | | if ($entry && ($rec = ldap_get_attributes($this->conn, $entry))) |
| | |
| | | $newentry['objectClass'] = $this->prop['LDAP_Object_Classes']; |
| | | foreach ($save_cols as $col => $val) { |
| | | $fld = $this->_map_field($col); |
| | | if ($fld != '') { |
| | | if ($fld && $val) { |
| | | // The field does exist, add it to the entry. |
| | | $newentry[$fld] = $val; |
| | | } // end if |
| | |
| | | $deletedata = array(); |
| | | foreach ($save_cols as $col => $val) { |
| | | $fld = $this->_map_field($col); |
| | | if ($fld != '') { |
| | | if ($fld) { |
| | | // The field does exist compare it to the ldap record. |
| | | if ($record[$col] != $val) { |
| | | // Changed, but find out how. |
| | |
| | | } // end if |
| | | } // end foreach |
| | | |
| | | // Update the entry as required. |
| | | $dn = base64_decode($id); |
| | | |
| | | // Update the entry as required. |
| | | if (!empty($deletedata)) { |
| | | // Delete the fields. |
| | | $res = ldap_mod_del($this->conn, $dn, $deletedata); |
| | | if ($res === FALSE) { |
| | | if (!ldap_mod_del($this->conn, $dn, $deletedata)) |
| | | return false; |
| | | } // end if |
| | | } // end if |
| | | |
| | | if (!empty($replacedata)) { |
| | | // Handle RDN change |
| | | if ($replacedata[$this->prop['LDAP_rdn']]) { |
| | | $newdn = $this->prop['LDAP_rdn'].'='.$replacedata[$this->prop['LDAP_rdn']].','.$this->prop['base_dn']; |
| | | if ($dn != $newdn) { |
| | | $newrdn = $this->prop['LDAP_rdn'].'='.$replacedata[$this->prop['LDAP_rdn']]; |
| | | unset($replacedata[$this->prop['LDAP_rdn']]); |
| | | } |
| | | } |
| | | // Replace the fields. |
| | | $res = ldap_mod_replace($this->conn, $dn, $replacedata); |
| | | if ($res === FALSE) { |
| | | return false; |
| | | if (!empty($replacedata)) { |
| | | if (!ldap_mod_replace($this->conn, $dn, $replacedata)) |
| | | return false; |
| | | } // end if |
| | | } // end if |
| | | |
| | | if (!empty($newdata)) { |
| | | // Add the fields. |
| | | $res = ldap_mod_add($this->conn, $dn, $newdata); |
| | | if ($res === FALSE) { |
| | | if (!ldap_mod_add($this->conn, $dn, $newdata)) |
| | | return false; |
| | | } // end if |
| | | } // end if |
| | | |
| | | // Handle RDN change |
| | | if (!empty($newrdn)) { |
| | | if (@ldap_rename($this->conn, $dn, $newrdn, NULL, TRUE)) |
| | | return base64_encode($newdn); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | |
| | | * |
| | | * @access private |
| | | */ |
| | | function _exec_search() |
| | | private function _exec_search() |
| | | { |
| | | if ($this->ready && $this->filter) |
| | | if ($this->ready) |
| | | { |
| | | $filter = $this->filter ? $this->filter : '(objectclass=*)'; |
| | | $function = $this->prop['scope'] == 'sub' ? 'ldap_search' : ($this->prop['scope'] == 'base' ? 'ldap_read' : 'ldap_list'); |
| | | $this->ldap_result = $function($this->conn, $this->prop['base_dn'], $this->filter, array_values($this->fieldmap), 0, 0); |
| | | $this->ldap_result = $function($this->conn, $this->prop['base_dn'], $filter, array_values($this->fieldmap), 0, 0); |
| | | return true; |
| | | } |
| | | else |
| | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _ldap2result($rec) |
| | | private function _ldap2result($rec) |
| | | { |
| | | global $RCMAIL; |
| | | |
| | | $out = array(); |
| | | |
| | | if ($rec['dn']) |
| | |
| | | |
| | | foreach ($this->fieldmap as $rf => $lf) |
| | | { |
| | | if ($rec[$lf]['count']) |
| | | $out[$rf] = $rec[$lf][0]; |
| | | if ($rec[$lf]['count']) { |
| | | if ($rf == 'email' && !strpos($rec[$lf][0], '@')) |
| | | $out[$rf] = sprintf('%s@%s', $rec[$lf][0] , $RCMAIL->config->mail_domain($_SESSION['imap_host'])); |
| | | else |
| | | $out[$rf] = $rec[$lf][0]; |
| | | } |
| | | } |
| | | |
| | | return $out; |
| | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function _map_field($field) |
| | | private function _map_field($field) |
| | | { |
| | | return $this->fieldmap[$field]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | private function _attr_name($name) |
| | | { |
| | | // list of known attribute aliases |
| | | $aliases = array( |
| | | 'gn' => 'givenname', |
| | | 'rfc822mailbox' => 'mail', |
| | | 'userid' => 'uid', |
| | | 'emailaddress' => 'email', |
| | | 'pkcs9email' => 'email', |
| | | ); |
| | | return isset($aliases[$name]) ? $aliases[$name] : $name; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @static |
| | | */ |
| | | function quote_string($str) |