## OpenCA - RA Server Command
## (c) 2000-2001 by Michael Bell and OpenCA Group
##
##   File Name: addCertsLDAP
##       Brief: Add all certificates to LDAP server
## Description: Add all issued certificates to LDAP server
##  Parameters:

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

## ca-certificates
print startLogPage (gettext ("Exporting ca-certificates to LDAP ..."));
my @items = $db->searchItems ( DATATYPE => "VALID_CA_CERTIFICATE" );
for my $h (@items) {
  my $result = eximObjectToLDAP ( AUTHORITY_CERTIFICATE => $h );
  if ($result and $result->{STATUS}) {
    print addPreLogLine (i18nGettext ("Certificate __CERT_SERIAL__ OK", "__CERT__SERIAL__", $h->getSerial()));
  } else {
    print addPreLogLine ("<FONT COLOR=#ff0000>".
                         i18nGettext ("Certificate __CERT_SERIAL__ FAILED", "__CERT_SERIAL__", $h->getSerial()).
                         "</FONT>");
  }
}
closeLogSection ();

## certificates
print startLogPage (gettext ("Exporting certificates to LDAP ..."));
my @items = $db->searchItems ( DATATYPE => "VALID_CERTIFICATE" );
for my $h (@items) {
  my $result = eximObjectToLDAP ( CERTIFICATE => $h );
  if ($result and $result->{STATUS}) {
    print addPreLogLine (i18nGettext ("Certificate __CERT_SERIAL__ OK", "__CERT_SERIAL__", $h->getSerial()));
  } else {
    print addPreLogLine ("<FONT COLOR=#ff0000>".
                         i18nGettext ("Certificate __CERT_SERIAL__ FAILED", "__CERT_SERIAL__", $h->getSerial()).
                         "</FONT>");
  }
}
closeLogSection ();

closePage ();

}

1;
