#!/usr/bin/perl5
#
##############################################################################
#
# The contents of this file are subject to the Netscape Public License Version
# 1.0 (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at http://www.mozilla.org/NPL/ 
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
# the specific language governing rights and limitations under the License. 
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
# Communications Corporation. All Rights Reserved.
#
##############################################################################
#
# This CGI script is used for showing LDAP information to the end-user.
#   It is meant to be a tool for the Help Desk to look at expiration
#   dates since the phonebook commander could not do that at the
#   time of this writing.
#
# Author:  Luke Sheneman
# Written: 01/1998
# 

use Ldapp;			# LDAP module for Perl5, very cool!
use LdapConf;                   # LDAP config tools
use LdapUtils;			# Some defaults and utilities we use.

require 'cgi-lib.pl';
&ReadParse(*input);

$user="uid=$input{user}";

print "Content-type: text/html","\n\n";
print "<HTML> <BODY TEXT=\"#000000\" BGCOLOR=\"#ffffff\" LINK=\"#FFD700\" VLINK=\"#FFFF00\" ALINK=\"#FF0000\">";
print "<CENTER> <H1> $user According to LDAP </H1> </CENTER>\n";
print "<p> <p> <br> <hr> \n";

$ld{root} = $LdapConf::ROOT;
$ld{host} = $LdapConf::HOST;
$ld{port} = $LdapConf::PORT;
$ld{bind} = "uid=sheneman,$LdapConf::PEOPLE_ROOT";
$ld{pswd} = "nimos.";


#################################################################################
# Instantiate an LDAP object, which also binds to the LDAP server.
#
$ld{conn} = new Ldapp($ld{host}, $ld{port}, $ld{bind}, $ld{pswd}, $ld{cert});
die "Couldn't connect to LDAP server $ld{host}" unless $ld{conn};


#################################################################################
# Now do all the searches, one by one.
#
$entry = $ld{conn}->search($LdapConf::PEOPLE_ROOT, "subtree", $user);

if($entry)
{
    # get the necessary fields here
    $uid           = @{$entry->{'uid'}}[0];
    $cn            = @{$entry->{'cn'}}[0];
    $manager       = @{$entry->{'manager'}}[0];
    $employeetype  = @{$entry->{'employeetype'}}[0];
    $exp           = @{$entry->{'nscppersonexpdate'}}[0];
    $mailhost      = @{$entry->{'mailhost'}}[0];
    $nscpharold    = @{$entry->{'nscpharold'}}[0];
    $userpassword  = @{$entry->{'userpassword'}}[0];
    $uidnumber     = @{$entry->{'uidnumber'}}[0];
    $gidnumber     = @{$entry->{'gidnumber'}}[0];
    $admin         = @{$entry->{'secretary'}}[0];
    $number        = @{$entry->{'telephonenumber'}}[0];
    $bc            = @{$entry->{'businesscategory'}}[0];
    $group         = @{$entry->{'ou'}}[0];


    print("uid = &nbsp&nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp $uid <br>\n");
    print("cn =  &nbsp&nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp $cn  <br>\n");
    if($exp) {
	print("expiration = $exp <br>\n");
    } else {
	print("expiration = {EMPTY} <br>\n");
    }
    print("<hr>\n");
    print("manager = &nbsp&nbsp&nbsp $manager <br>\n");
    print("emp type = &nbsp&nbsp&nbsp $employeetype <br>\n");
    print("legal name = &nbsp&nbsp $nscpharold <br>\n");
    print("<hr>\n");
    print("mailhost = &nbsp&nbsp&nbsp&nbsp&nbsp $mailhost <br> \n");
    print("passwd = &nbsp&nbsp&nbsp&nbsp&nbsp $userpassword <br> \n");
    print("UNIX uid =  &nbsp&nbsp&nbsp $uidnumber <br> \n");
    print("UNIX gid = &nbsp&nbsp&nbsp $gidnumber <br> \n");
    print("Admin = &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp  $admin <br>\n");
    print("Number = &nbsp&nbsp&nbsp&nbsp&nbsp $number <br> \n");
    print("Dept = &nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp&nbsp&nbsp $bc <br> \n");
    print("Organization = &nbsp $group <br> \n");

    
} else {
    print("Could not find entry $user\n  <br> ");
}


#################################################################################
# Close the connection.
#
$ld{conn}->close if $ld{conn};









