## OpenCA - Command
## (c) Copyright 1998-2004 The OpenCA Project
##
##   File Name: revoke_req
##       Brief: begin to revoke a certificate
## Description: get the certificate which should be revoked and prompt
##              the user to a second ok
##  Parameters: none

use strict;

sub cmdRevoke_req {

	## try to determine a serial
	my $serial = $query->param ('key');
	if (not defined $serial or (not $serial and ($serial !~ /0/))) {
		$serial = $ENV{'SSL_CLIENT_M_SERIAL'};
	}

	my ($hidden_list, $info_list, $cmd_panel) = (undef, undef, undef);

        my @auth = grep /AUTH/, getRequiredList ("CmdRefs_revoke_req");
        if ($auth[0] =~ /NO_AUTH/i)
        {
            $hidden_list->{"cmd"} = "addCRR";
        } elsif ($auth[0] =~ /REQUIRE_AUTH/i) {
            $hidden_list->{"cmd"} = "confirm_revreq";
            $info_list->{BODY}->[2]->[0] = gettext ("CRIN code: [ revocation pin ]");
            $info_list->{BODY}->[2]->[1] = '<Input type="password" name="crin">';
            $info_list->{BODY}->[3]->[0] = gettext ("Retype CRIN code: [ retype revocation pin ]");
            $info_list->{BODY}->[3]->[1] = '<Input type="password" name="crin2">';
        } else {
            generalError (gettext ("Unknown authentication mode for revocation."));
        }

        $info_list->{BODY}->[0]->[0] = gettext ("Certificate Serial Number");
        $info_list->{BODY}->[0]->[1] = '<Input type="text" name="serial" value="'.$serial.'">';
        $info_list->{BODY}->[1]->[0] = gettext ("Reason: [ Reason for revocating the certificate ]");
        $info_list->{BODY}->[1]->[1] = '<textarea cols="35" rows="5" name="reason" wrap="virtual">'.
                                       gettext ("Private key compromised.").
                                       '</textarea>';

        $cmd_panel->[0] = '<input type="submit" name="Submit" value="'.gettext ("Continue").'">';

        return libSendReply (
                             "NAME"        => gettext ("Certificate Revocation Request"),
                             "EXPLANATION" => gettext ("If you don't know the certificate's serial number please use the lists."),
                             "INFO_LIST"   => $info_list,
                             "HIDDEN_LIST" => $hidden_list,
                             "CMD_PANEL"   => $cmd_panel
                            );
}

1;
