#!/usr/bin/perl
# Author: Brad Marshall (bmarshal@pisoftware.com)
# Date: 20010803

# This script is released under the GNU GPL.  See http://www.gnu.org/copyleft/gpl.html
# for full licensing details.

# TODO:

use CGI;
use CGI::Carp qw(fatalsToBrowser carpout);
use Net::LDAP; 

my($debug) = 0;
my($basedn) = "dc=gumby";
my($ldaphost) = "eta";

my($adminuser) = "cn=admin,ou=People," . $basedn;
my($adminpasswd) = "admin";

my($query) = new CGI();

if ($query->param('group')) {
    $group = $query->param('group');

    print $query->header(-type=>"text/html"),
        $query->start_html(-title=>'LDAP Deleting Group', -BGCOLOR=>"white"), "\n",
        $query->h1("Deleting LDAP Group");

    $groupdn = "cn=$user,ou=Group,$basedn";

    print "Group is $groupdn" if $debug;
    print $query->br if $debug;

    my($ldap) = Net::LDAP->new("$ldaphost") or die "Can't bind to $ldaphost: $!\n";

    $mesg = $ldap->bind(
                dn       => $adminuser,
                password => $adminpasswd,
    );

	if ($mesg->code) {
		print "Problem binding to ldapserver: " . $mesg->error;
	} else {
		$ldap->delete( $groupdn );
		print "Deleted group $group.\n";
	}
} else {
    print $query->header(-type=>"text/html"),
        $query->start_html(-title=>'LDAP Delete Group', -BGCOLOR=>"white"), 
		$query->h1('LDAP Delete Group'), "\n";

    print $query->hr, "\n",
        "<FORM METHOD='post' ACTION='/cgi-bin/ldap/delgroup.pl' ENCTYPE='application/x-www-form-urlencoded'>", "\n";

    print "User: ", $query->textfield(-name=>'group', -default=>'group', -size=>'10');

    print $query->br,
        $query->submit,
        $query->end_form,
        $query->hr,
        $query->end_html;

}
