Name

add-gpg-key — add a GPG/PGP key to keyring

ATTRIBUTES

Attribute Pos. Req. Default Description
name Yes Name of the CGI variable where the key text can be found.
text GPG/PGP key text, specified in-place. If defined, takes precedence over the CGI variable pointed to by the name= attribute.
return_id 0 Return key ID upon import?
success 1 Value to return if key import action succeeds.
failure undef Value to return if key import action fails.
interpolate     0 interpolate output?
hide     0 Hide the tag return value?

DESCRIPTION

This tag imports a GPG/PGP key into the keyring.

Key text can either be specified in-place, or a name of the CGI variable containing the key text can be provided.

BEHAVIOR

This tag appears to be affected by, or affects, the following:
Global Variables: GPG_PATH

EXAMPLES

Example: Importing a key by specifying CGI variable containing key text

[add-gpg-key name=pgpkeytext return_id=1 failure=FAILED]


Example: Importing a key by specifying key text in-place

[add-gpg-key text="[value pgpkeytext]" return_id=1 failure=FAILED]


NOTES

AVAILABILITY

add-gpg-key is available in Interchange versions:

4.6.0-5.9.0 (git-head)

SOURCE

Interchange 5.9.0:

Source: code/UI_Tag/add_gpg_key.coretag
Lines: 67


# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# 
# $Id: add_gpg_key.coretag,v 1.6 2007-03-30 23:40:54 pajamian Exp $

UserTag add-gpg-key Order   name
UserTag add-gpg-key addAttr
UserTag add-gpg-key Version $Revision: 1.6 $
UserTag add-gpg-key Routine <<EOR
sub {
my ($name, $opt) = @_;
my $gpgexe = $Global::Variable->{GPG_PATH} || 'gpg';

my $outfile = "$Vend::Cfg->{ScratchDir}/$Vend::Session->{id}.gpg_results";

my $flags = "--import --batch 2> $outfile";
#::logDebug("gpg_add flags=$flags");

my $keytext = $opt->{text} || $CGI::values{$name};
$keytext =~ s/^\s+//;
$keytext =~ s/\s+$//;
open(GPGIMP, "| $gpgexe $flags") 
  or die "Can't fork: $!";
print GPGIMP $keytext;
close GPGIMP;

if($?) {
  $::Scratch->{ui_failure} = ::errmsg("Failed GPG key import.");
  return defined $opt->{failure} ? $opt->{failure} : undef;
}
else {
  my $keylist = `$gpgexe --list-keys`;
  $::Scratch->{ui_message} =
            ::errmsg(
              "GPG key imported successfully.<PRE>\n%s\n</PRE>",
              $keylist,
              );
}

if($opt->{return_id}) {
  open(GETGPGID, "< $outfile")
    or do {
      ::logGlobal("GPG key ID read -- can't read %s: %s", $outfile, $!);
      return undef;
    };
  my $id;
  while(<GETGPGID>) {
    next unless /\bkey\s+(\w+)\s*:\s+(public\s+key|)(.*)(imported|not\s+changed)/i;
    $id = $1;
    last;
  }
  close GETGPGID;
  return $id || 'Failed ID get?';
  
}
elsif (defined $opt->{success}) {
  return $opt->{success};
}
else {
  return 1;
}
}
EOR

AUTHORS

Interchange Development Group

SEE ALSO

DocBook! Interchange!