#!/usr/bin/perl

do "ldap_users.pl";
do "users.pl";
&connect ();
&ReadParse();

$sort_on = $in{sort_on};

if ($in{delete_user}) {
    &delete_user ($in{dn});
    &redirect ("index.cgi?sort_on=$sort_on");
    exit (0);
}
if ($in{delete_home}) {
    $entry = &get_user_attr ($in{dn});
    $home = $entry->{homedirectory}[0];
    $owner = ((stat($home))[4]);
    if ($owner == $entry->{uidnumber}[0]) {
        system "rm -rf $home";
    }
    else {
        &error ("The user "  . $entry->{uid}[0] .
            " is not the owner of his home dir ($home).");
    }
    &delete_user ($in{dn});
    &redirect ("index.cgi?sort_on=$sort_on");
    exit (0);
}

# display current user data

$dn = $in{dn};
$entry = &get_user_attr ($dn);
&user_from_entry ($entry);

&header ("Delete LDAP User", "");
print "<HR noshade size=2>\n";

print "<H3>Are you sure you want to delete user <B>'$cn'</B> ($uid)?</H3>\n";
print "<FORM method=\"post\" action=\"delete_user.cgi\">\n";
print "<INPUT type=\"hidden\" name=\"dn\" value=\"$dn\">\n";
print "<INPUT type=\"hidden\" name=\"sort_on\" value=\"$sort_on\">\n";
print "<INPUT type=\"submit\" name=\"delete_user\" value=\" Delete just the user \">\n";
print "<INPUT type=\"submit\" name=\"delete_home\" value=\" Delete user AND his home directory \">\n";

print "<P>\n";
&footer ("index.cgi?sort_on=$sort_on", "LDAP Users");
do "footer.pl";

