Skip to content

Commit

Permalink
minor bug that prevented the browser from loading right. Also fixed a…
Browse files Browse the repository at this point in the history
… bug where the schema browser wasn't working properly with openldap
  • Loading branch information
root committed Oct 4, 2011
1 parent 8663d59 commit 153280f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 108 deletions.
12 changes: 9 additions & 3 deletions controllers/components/ldap.php
Expand Up @@ -168,8 +168,14 @@ function getGroups( $fields = array('cn', 'memberuid', 'uniquemember', 'member')

if(!empty($dn)){
$utmp = $this->Model->find('first', array( 'targetDn'=>$dn, 'scop'=>'base', 'fields'=>array('uid','cn','samaccountname')));
$uid = (isset($utmp[$this->Model->alias]['uid']) ? $utmp[$this->Model->alias]['uid'] :
(isset($utmp[$this->Model->alias]['samacountname']) ? $utmp[$this->Model->alias]['samacountname'] : $utmp[$this->Model->alias]['cn'];
if(isset($utmp[$this->Model->alias]['uid'])){
$uid = $utmp[$this->Model->alias]['uid'];
}elseif(isset($utmp[$this->Model->alias]['samacountname'])){
$uid = $utmp[$this->Model->alias]['samacountname'];
}else{
$uid = $utmp[$this->Model->alias]['cn'];
}

$conditions = '(|(|(uniquemember='.$dn.')(memberuid='.$uid.'))(member='.$dn.'))';
}

Expand Down Expand Up @@ -291,7 +297,7 @@ function hasChildren( $dn ){
function &getModel($name = null) {
$Model = null;
if (!$name) {
$name = $this->Model->alias;
$name = $this->userModel;
}

if (PHP5) {
Expand Down
207 changes: 103 additions & 104 deletions models/datasources/ldap_source.php
Expand Up @@ -110,7 +110,7 @@ class LdapSource extends DataSource {
* @var string
* @access public
*/
var $SchemaFilter;
var $SchemaFilter = '(objectClass=subschema)';

/**
* Result for formal queries
Expand Down Expand Up @@ -763,117 +763,118 @@ function convertTimestamp_ADToUnix($ad_timestamp) {
/* The following was kindly "borrowed" from the excellent phpldapadmin project */
function __getLDAPschema() {
$schemaTypes = array( 'objectclasses', 'attributetypes' );
$this->results = @ldap_read($this->database, $this->SchemaDN, $this->SchemaFilter, $schemaTypes,0,0,0,LDAP_DEREF_ALWAYS);
if( is_null( $this->results ) ) {
$this->log( "LDAP schema filter $schema_filter is invalid!", 'ldap.error');
continue;
}
$this->results = @ldap_read($this->database, $this->SchemaDN, $this->SchemaFilter, $schemaTypes,0,0,0,LDAP_DEREF_ALWAYS);
if( is_null( $this->results ) ) {
$this->log( "LDAP schema filter $schema_filter is invalid!", 'ldap.error');
continue;
}

$schema_entries = @ldap_get_entries( $this->database, $this->results );
$schema_entries = @ldap_get_entries( $this->database, $this->results );

if( $schema_entries ) {
$return = array();
foreach( $schemaTypes as $n ) {
$schemaTypeEntries = $schema_entries[0][$n];
for( $x = 0; $x < $schemaTypeEntries['count']; $x++ ) {
$entry = array();
$strings = preg_split('/[\s,]+/', $schemaTypeEntries[$x], -1, PREG_SPLIT_DELIM_CAPTURE);
$str_count = count( $strings );
for ( $i=0; $i < $str_count; $i++ ) {
switch ($strings[$i]) {
case '(':
break;
case 'NAME':
if ( $strings[$i+1] != '(' ) {
do {
$i++;
if( !isset( $entry['name'] ) || strlen( $entry['name'] ) == 0 )
$entry['name'] = $strings[$i];
else
$entry['name'] .= ' '.$strings[$i];
} while ( !preg_match('/\'$/s', $strings[$i]));
} else {
$i++;
do {
$i++;
if( !isset( $entry['name'] ) || strlen( $entry['name'] ) == 0)
$entry['name'] = $strings[$i];
else
$entry['name'] .= ' ' . $strings[$i];
} while ( !preg_match( '/\'$/s', $strings[$i] ) );
do {
$i++;
} while ( !preg_match( '/\)+\)?/', $strings[$i] ) );
}
if( $schema_entries ) {
$return = array();
foreach( $schemaTypes as $n ) {
$schemaTypeEntries = $schema_entries[0][$n];
for( $x = 0; $x < $schemaTypeEntries['count']; $x++ ) {
$entry = array();
$strings = preg_split('/[\s,]+/', $schemaTypeEntries[$x], -1, PREG_SPLIT_DELIM_CAPTURE);
$str_count = count( $strings );
for ( $i=0; $i < $str_count; $i++ ) {
switch ($strings[$i]) {
case '(':
break;
case 'NAME':
if ( $strings[$i+1] != '(' ) {
do {
$i++;
if( !isset( $entry['name'] ) || strlen( $entry['name'] ) == 0 )
$entry['name'] = $strings[$i];
else
$entry['name'] .= ' '.$strings[$i];
} while ( !preg_match('/\'$/s', $strings[$i]));
} else {
$i++;
do {
$i++;
if( !isset( $entry['name'] ) || strlen( $entry['name'] ) == 0)
$entry['name'] = $strings[$i];
else
$entry['name'] .= ' ' . $strings[$i];
} while ( !preg_match( '/\'$/s', $strings[$i] ) );
do {
$i++;
} while ( !preg_match( '/\)+\)?/', $strings[$i] ) );
}

$entry['name'] = preg_replace('/^\'/', '', $entry['name'] );
$entry['name'] = preg_replace('/\'$/', '', $entry['name'] );
break;
case 'DESC':
do {
$i++;
if ( !isset( $entry['description'] ) || strlen( $entry['description'] ) == 0 )
$entry['description'] = $strings[$i];
else
$entry['description'] .= ' ' . $strings[$i];
} while ( !preg_match( '/\'$/s', $strings[$i] ) );
break;
case 'OBSOLETE':
$entry['is_obsolete'] = TRUE;
break;
case 'SUP':
$entry['sup_classes'] = array();
if ( $strings[$i+1] != '(' ) {
$i++;
array_push( $entry['sup_classes'], preg_replace( "/'/", '', $strings[$i] ) );
} else {
$i++;
do {
$i++;
if ( $strings[$i] != '$' )
array_push( $entry['sup_classes'], preg_replace( "/'/", '', $strings[$i] ) );
} while (! preg_match('/\)+\)?/',$strings[$i+1]));
}
break;
case 'ABSTRACT':
$entry['type'] = 'abstract';
break;
case 'STRUCTURAL':
$entry['type'] = 'structural';
break;
case 'SINGLE-VALUE':
$entry['multiValue'] = 'false';
break;
case 'AUXILIARY':
$entry['type'] = 'auxiliary';
break;
case 'MUST':
$entry['must'] = array();
$i = $this->_parse_list(++$i, $strings, $entry['must']);
$entry['name'] = preg_replace('/^\'/', '', $entry['name'] );
$entry['name'] = preg_replace('/\'$/', '', $entry['name'] );
break;
case 'DESC':
do {
$i++;
if ( !isset( $entry['description'] ) || strlen( $entry['description'] ) == 0 )
$entry['description'] = $strings[$i];
else
$entry['description'] .= ' ' . $strings[$i];
} while ( !preg_match( '/\'$/s', $strings[$i] ) );
break;
case 'OBSOLETE':
$entry['is_obsolete'] = TRUE;
break;
case 'SUP':
$entry['sup_classes'] = array();
if ( $strings[$i+1] != '(' ) {
$i++;
array_push( $entry['sup_classes'], preg_replace( "/'/", '', $strings[$i] ) );
} else {
$i++;
do {
$i++;
if ( $strings[$i] != '$' )
array_push( $entry['sup_classes'], preg_replace( "/'/", '', $strings[$i] ) );
} while (! preg_match('/\)+\)?/',$strings[$i+1]));
}
break;
case 'ABSTRACT':
$entry['type'] = 'abstract';
break;
case 'STRUCTURAL':
$entry['type'] = 'structural';
break;
case 'SINGLE-VALUE':
$entry['multiValue'] = 'false';
break;
case 'AUXILIARY':
$entry['type'] = 'auxiliary';
break;
case 'MUST':
$entry['must'] = array();
$i = $this->_parse_list(++$i, $strings, $entry['must']);

break;
break;

case 'MAY':
$entry['may'] = array();
$i = $this->_parse_list(++$i, $strings, $entry['may']);
case 'MAY':
$entry['may'] = array();
$i = $this->_parse_list(++$i, $strings, $entry['may']);

break;
default:
if( preg_match( '/[\d\.]+/i', $strings[$i]) && $i == 1 ) {
$entry['oid'] = $strings[$i];
break;
default:
if( preg_match( '/[\d\.]+/i', $strings[$i]) && $i == 1 ) {
$entry['oid'] = $strings[$i];
}
break;
}
}
if( !isset( $return[$n] ) || !is_array( $return[$n] ) ) {
$return[$n] = array();
}
//make lowercase for consistency
$return[strtolower($n)][strtolower($entry['name'])] = $entry;
//array_push( $return[$n][$entry['name']], $entry );
}
break;
}
}
if( !isset( $return[$n] ) || !is_array( $return[$n] ) ) {
$return[$n] = array();
}
//make lowercase for consistency
$return[strtolower($n)][strtolower($entry['name'])] = $entry;
//array_push( $return[$n][$entry['name']], $entry );
}
}
}

return $return;
}
Expand Down Expand Up @@ -1415,15 +1416,13 @@ function debugLDAPConnection(){
*/
function setNetscapeEnv(){
$this->OperationalAttributes = 'accountUnlockTime aci copiedFrom copyingFrom createTimestamp creatorsName dncomp entrydn entryid hasSubordinates ldapSchemas ldapSyntaxes modifiersName modifyTimestamp nsAccountLock nsAIMStatusGraphic nsAIMStatusText nsBackendSuffix nscpEntryDN nsds5ReplConflict nsICQStatusGraphic nsICQStatusText nsIdleTimeout nsLookThroughLimit nsRole nsRoleDN nsSchemaCSN nsSizeLimit nsTimeLimit nsUniqueId nsYIMStatusGraphic nsYIMStatusText numSubordinates parentid passwordAllowChangeTime passwordExpirationTime passwordExpWarned passwordGraceUserTime passwordHistory passwordRetryCount pwdExpirationWarned pwdGraceUserTime pwdHistory pwdpolicysubentry retryCountResetTime subschemaSubentry';
$this->SchemaFilter = '(objectClass=subschema)';
$this->SchemaAttributes = 'objectClasses attributeTypes ldapSyntaxes matchingRules matchingRuleUse createTimestamp modifyTimestamp';
}

function setActiveDirectoryEnv(){
//Need to disable referals for AD
ldap_set_option($this->database, LDAP_OPT_REFERRALS, 0);
$this->OperationalAttributes = ' + ';
$this->SchemaFilter = '(objectClass=subschema)';
$this->SchemaAttributes = 'objectClasses attributeTypes ldapSyntaxes matchingRules matchingRuleUse createTimestamp modifyTimestamp subschemaSubentry';
}

Expand Down
7 changes: 7 additions & 0 deletions views/ldap_auths/admin_login.ctp
@@ -0,0 +1,7 @@
<h2>Login</h2>
<?php
echo $form->create('LdapAuth', array('action' => 'login'));
echo $form->input('username');
echo $form->input('password');
echo $form->end('Login');
?>
2 changes: 1 addition & 1 deletion webroot/js/idbroker.js
Expand Up @@ -25,7 +25,7 @@ $(function (){
"json_data" : {
"ajax" : {
"type" : "post",
"url" : "/APS/idbroker/browsers/getnodes/",
"url" : APP+"/idbroker/browsers/getnodes/",
dataType: "json",
"async" : true,
"data" : function (n) {
Expand Down

0 comments on commit 153280f

Please sign in to comment.