Location: PHPKode > projects > LDAPted > ldapted/login.php
<?php
/***************************************************************************
 *
 *                                  login.php
 *                              -------------------
 *
 *   begin                : Friday, Jul 5, 2002
 *   copyright            : (C) 2002 The Kabramps Team
 *   email                : hide@address.com,
 *                          hide@address.com
 *
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *   See the GNU General Public License for more details.
 *   (http://www.gnu.org/licenses/gpl.html)
 *
 ***************************************************************************/

include("includes/XMLDocument.php");
include("includes/Config.php");
include("includes/smarty/Smarty.class.php");

$config = new Config("config.xml");
$options = $config->get_options();

if (!$_REQUEST["login"])
{
  $skin_folder = $options['templates'].$options['defskin'];
 
  $tmpls = new Smarty;
  $tmpls->template_dir = $skin_folder;
  $tmpls->assign(array(
		       "PAGETITLE"   => "LDAPted: Login",
		       "USER"        => gettext("bind DN"),
		       "PASSWORD"    => gettext("bind Password"),
		       "WELCOME"     => gettext("Welcome to LDAPted"),
		       "LANGUAGE"    => gettext("Language"),
		       "SERVER"      => gettext("LDAP host"),
		       "LOGINHELP"   => gettext("Please enter Username and Password."),
		       "LOGINBUTTON" => gettext("Login"),
		       'Skin'        => gettext('Skin'),
		       'options'     => $options,
               'config'      => $config,
               'skin_folder' => $skin_folder
		       ));

  $tmpls->display("login.tpl");
}
else {

  // gets the ldap_base
  $hosts = $config->get_hosts();
  $host = '';
  for ( $i=0; $i < count($hosts); $i++) {
    if ($hosts[$i] == $_REQUEST['host'] ) {
      $host         = $hosts[$i];
      $host_options = $config->get_host_options($hosts[$i]);
      break;
    }
  }

  if( $i != count( $hosts ) )
  {
		session_start();
		$HTTP_SESSION_VARS['user']      = get_user_dn($_REQUEST["user"], $_REQUEST["pass"], $host, $host_options);
		$HTTP_SESSION_VARS['ldap_base'] = $host_options['ldapbase'];
		$HTTP_SESSION_VARS['pass']      = $_REQUEST['pass'];
		$HTTP_SESSION_VARS['lang']      = $_REQUEST['lang'];
		$HTTP_SESSION_VARS['host']      = $_REQUEST['host'];
		$HTTP_SESSION_VARS['skin']      = $_REQUEST['skin'] ? $_REQUEST['skin'] : $options['defskin'];

		header("Location: browser.php");
	}
}

function get_user_dn($user, $pass, $host, $host_options)
{
  if( $pass )
  {
    if( $host_options['alias_login'] )
    {
      	// We need to find DN first
		include "includes/LDAPinterface.php";

		$ldap = new LDAPinterface($host, $host_options["search_username"], $host_options["search_password"] );
		$result_set = $ldap->search( $host_options['search_base_dn'],
		                             array($host_options['alias_attribute']),
		                             $host_options['alias_attribute'].'='.$user,
		                             1
		                           );

		if ($result_set["count"] != 0)
		{
			return $result_set[0]["dn"];
		}
    }
    else
    {
		return $user;
    }
  }

	return gettext('anonymous');
}
?>
Return current item: LDAPted