1 # Copyright 2002-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: add_gpg_key.coretag,v 1.6 2007-03-30 23:40:54 pajamian Exp $
10 UserTag add-gpg-key Order name
11 UserTag add-gpg-key addAttr
12 UserTag add-gpg-key Version $Revision: 1.6 $
13 UserTag add-gpg-key Routine <<EOR
15 my ($name, $opt) = @_;
16 my $gpgexe = $Global::Variable->{GPG_PATH} || 'gpg';
18 my $outfile = "$Vend::Cfg->{ScratchDir}/$Vend::Session->{id}.gpg_results";
20 my $flags = "--import --batch 2> $outfile";
21 #::logDebug("gpg_add flags=$flags");
23 my $keytext = $opt->{text} || $CGI::values{$name};
26 open(GPGIMP, "| $gpgexe $flags")
27 or die "Can't fork: $!";
28 print GPGIMP $keytext;
32 $::Scratch->{ui_failure} = ::errmsg("Failed GPG key import.");
33 return defined $opt->{failure} ? $opt->{failure} : undef;
36 my $keylist = `$gpgexe --list-keys`;
37 $::Scratch->{ui_message} =
39 "GPG key imported successfully.<PRE>\n%s\n</PRE>",
44 if($opt->{return_id}) {
45 open(GETGPGID, "< $outfile")
47 ::logGlobal("GPG key ID read -- can't read %s: %s", $outfile, $!);
52 next unless /\bkey\s+(\w+)\s*:\s+(public\s+key|)(.*)(imported|not\s+changed)/i;
57 return $id || 'Failed ID get?';
60 elsif (defined $opt->{success}) {
61 return $opt->{success};