## OpenCA - RA Server Command
## (c) 2000-2001 by Michael Bell and OpenCA Group
##
##   File Name: deleteCertFromLDAPbyName
##       Brief: Add certificate to LDAP server
## Description: Add a single certificate to LDAP server
##  Parameters:

require "$common_libs/export-import.lib";
 
sub cmdDeleteCertFromLDAPbyName {

## certificates
print startLogPage (gettext ("Removing certificate from LDAP ..."));

my $key = $query->param ('key');
if (not $key and ($key != 0)) {
	print addPreLogLine ("<FONT COLOR=#ff0000>".
			gettext ("No certificate was specified! FAILED").
            "</FONT>");
	closeLogSection ();
	closePage ();
	return undef;
}

my $dn = $query->param ('new_dn');
if (not $dn) {
	print addPreLogLine ("<FONT COLOR=#ff0000>".
			gettext ("No distinguished name was specified! FAILED").
            "</FONT>");
	closeLogSection ();
	closePage ();
	return undef;
}

my $dataType = $query->param ('dataType');
$dataType = "CERTIFICATE" if (not $dataType);

my $item = $db->getItem ( DATATYPE => $dataType, KEY => $key );

## modify the DN
$item->{parsedItem}->{DN} = $dn;

my $result;
if ($dataType =~ /CA_CERTIFICATE/i) {
        $result = deleteLDAPattribute ( AUTHORITY_CERTIFICATE => $item, NOPRINT => 1 );
} else {
        $result = deleteLDAPattribute ( CERTIFICATE => $item, NOPRINT => 1 );
}

if ($result and $result->{STATUS}) {
	print addLogSection (i18nGettext ("Certificate __CERT_SERIAL__ OK", "__CERT_SERIAL__", $item->getSerial()));
} else {
	print addLogSection ("<FONT COLOR=#ff0000>".
	        i18nGettext ("Certificate __CERT_SERIAL__ FAILED", "__CERT_SERIAL__", $item->getSerial()).
	        "</FONT>");
}
closeLogSection ();

closePage ();

}

1;
