Location: PHPKode > projects > LDAP Navigator > ldapnavigator-0.9.6/modules/authent.old/logon.php
<?php

/*
	check login form parameters and start the session
	host & port are check using a ldap_connect()
	registered connexion parameters are in the session var $ldapmanager[]
*/



while( 1 ) 
{	
	
	if( ! isset($host) or ! isset($port) ) {
			$errorMsg = "Host and port required";
			break;
	}

	$ds = ldap_connect( $host, $port );
	if( ! $ds ) {
		$errorMsg = "Bad host or port";
		break;
	}

	if( $binddn ) {
		
		if( ! strstr( $binddn, "=" ) ) {
			$sr = ldap_search( $ds, $basedn, "uid=$binddn" );
			$tmp = ldap_get_entries( $ds, $sr );
			if( is_array($tmp) && $tmp['count'] == 1 ) {
				$binddn = $tmp[0]['dn'];
			} else {
				$errorMsg = "Bad username";
				break;
			}
		}
	}
	
	// try to bind
	if( isset($binddn) && isset($bindpw) ) {
		$ret = ldap_bind( $ds, $binddn, $bindpw );
		if( ! $ret ) {
			$errorMsg = "Bad password";
			break;
		}
	}
	
	ldap_close($ds);
	
	// si un basedn libre est saisi, prend celui-ci
	( $custombasedn != "" ) && $basedn = $custombasedn;
	// silently ignore bad input
	( $maxTreeItems <= 0 ) && $maxTreeItems = $config->maxtreeitems;
	
	// save connexion params in session
	$ldapmanager = array(
		"basedn" => $basedn,
		"custombasedn" => $custombasedn,
		"host" => $host,
		"port" => $port,
		"filter" => 'objectclass=*',
		"binddn" => $binddn,
		"bindpw" => $bindpw,
		"convertCharset" => $convertCharset,
		"maxTreeItems" => $maxTreeItems,
	);
	
	session_register( "ldapmanager" );
	$statusMsg = "Welcome to LDAP Navigator ! You are logged on the LDAP server <b>$ldapmanager[host]:$ldapmanager[port]</b>";
	break;
}

if( $errorMsg ) {
	include_once( "./modules/authent/login.php" );
	exit;
}
	

?>
Return current item: LDAP Navigator