#!/usr/bin/perl
 
# Version: 1.0
# Date:    2001.01.07
# Author:  V. Alex Brennen <vab@cryptnet.net>
#          http://www.cryptnet.net/people/vab/
# License: GPL
# Description:
#          This script was written as part of the gpg keysigning
#          party howto.  It generates a checklist for individuals
#          participating in a keysigning party. The keysigning
#          howto lives at:
#               http://www.cryptnet.net/fdp/crypto/gpg-party.html

###
# CHANGES:
# 2001-12-19 - John Abreau <jabr@blu.org>
# - added table of names (lastname, firstname) to sort table by,
# and "byname" sort proc
# - added "uid" section to include all defined uids, not just the first one

if($ARGV[0] eq "")
{
        print "\nUsage: party-table.pl <keyring> > out_file.html\n";
        print "\nThe keyring should be the keyring where the public keys for the\n";
        print "party participants are stored.\n\n";
        exit;
}

@fps = `gpg --fingerprint --keyring $ARGV[0]`;

$name = {
	'000B8797' => 'Horne, E. William',
	'2CFE18A3' => 'Brodeur, Matthew J.',
	'34B14BCB' => 'Brodeur, Heather',
	'657A4BBC' => 'Horne, E. William',
	'B1D7BB90' => 'Horne, E. William',
	'7024BE2C' => 'Hillman, Suzanne',
	'73A537E4' => 'Brown, Robert',
	'81CFE75D' => 'Martin, Derek',
	'86C77C44' => 'Kramer, David',
	'8D27E5B5' => 'Arvizo, Teodoro',
	'A32F166D' => 'Rao, Anand',
	'B6D365A1' => '**SKIP** Peterson, Ron',
	'BE809418' => 'Brodeur, Matthew J.',
	'C5061EA9' => 'Feldman, Jerry',
	'D5C7B5D9' => 'Abreau, John',
	'E26A6F28' => '**SKIP** Pennace, Alexander',
	'57C3430B' => 'Ledoux, Mike',
	'BE5E3517' => '**SKIP** Ledoux, Mike',
	'6A62B072' => 'Ledoux, Mike',
	'7024BE2C' => 'Hillman, Suzanne',
	'1F1671F8' => 'Caron, Mark',
};

print "<HTML>\n";
print "<TABLE BORDER=1>\n";
print "<TR><TH>Key ID</TH><TH>Key Owner</TH><TH>Key Fingerprint</TH><TH>Key Size</TH><TH>Key Type</TH><TH>Key Info Matches?</TH><TH>Owner ID Matches?</TH></TR>\n";
 
my $curr_id = undef;
my $keyring;
while($line = shift(@fps))
{
        if($line =~ /^pub/) {
                $key_info = substr($line,5,14);
                ($size_type,$id) = split(/\//,$key_info);
                $size = substr($size_type,0,4);
                $type = substr($size_type,-1,1);
                $owner = substr($line,31,-1);
                $fp_line = shift(@fps);
                ($trash,$fp) = split(/ = /,$fp_line);
                if($type eq "D"){$type = "DSA";}
                elsif($type eq "R"){$type = "RSA";}
                $owner =~ s/</&lt\;/;
                $owner =~ s/>/&gt\;/;
		$owner .= ' **NEW**' unless $name->{$id};
		$curr_id = $id;
		$keyring->{$id}->{id} = $id;
		$keyring->{$id}->{owner} = $owner;
		$keyring->{$id}->{fp} = $fp;
		$keyring->{$id}->{size} = $size;
		$keyring->{$id}->{type} = $type;
        } elsif($line =~ /^uid/) {
		$line =~ s/^uid\s+//;
                $line =~ s/</&lt\;/;
                $line =~ s/>/&gt\;/;
		$keyring->{$curr_id}->{owner} .= ",<br>" . $line;
        }
}

for (sort byname keys %$keyring) {
	next if $name->{$_} =~ /SKIP/;
	my $h = $keyring->{$_};

	print <<EOF;
<TR>
<TD><FONT SIZE='-2'>$h->{id}</FONT></TD>
<TD><FONT SIZE='-2'>$h->{owner}</FONT></TD>
<TD><FONT SIZE='-2'>$h->{fp}</FONT></TD>
<TD><FONT SIZE='-2'>$h->{size}</FONT></TD>
<TD><FONT SIZE='-2'>$h->{type}</FONT></TD>
<TD><FONT SIZE='-2'>&nbsp;</FONT></TD>
<TD><FONT SIZE='-2'>&nbsp;</FONT></TD>
</TR>
EOF
}

print "</TABLE>\n";
print "</HTML>";

sub byname {
	my $x = $name->{$a} || "zzzzzzzz";
	my $y = $name->{$b} || "zzzzzzzz";

	$x =~ tr/A-Z/a-z/;
	$y =~ tr/A-Z/a-z/;
	$x cmp $y;
}
