#!/usr/bin/perl -w
use strict;

# Version: 1.2
# Date:    2001.01.07
# Revised: 2005.03.22
# Author:  V. Alex Brennen <vab@cryptnet.net>
#          http://www.cryptnet.net/people/vab/
# Author:  Gerfried Fuchs <alfie@ist.org>
#          http://alfie.ist.org/alfie/
# Author:  Damien Raude-Morvan <drazib@drazzib.com>
#          http://www.drazzib.com
# License: Public Domain
# 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

# Damien Raude-Morvan : Ported to XHTML and UTF-8.

my $keyring = "linuxnantes";

my @fps = `gpg --display-charset utf-8 --fingerprint --no-default-keyring --no-options --with-colons --keyring ./$keyring.keyring | egrep '^(pub|fpr):'`;

open(FILEWRITE, "> $keyring.html");

print FILEWRITE "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n";
print FILEWRITE "<html><head><title>PGP Keysigning Party Keys</title>\n";
print FILEWRITE "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>";
print FILEWRITE "</head>\n";
print FILEWRITE "<body><h1>Keyring : $keyring</h1>";
print FILEWRITE "<h3>Global graph : <a href=\"keygraphs/global.png\">$keyring</a><h3>";
print FILEWRITE "<table style=\"border: thin #A9A9A9 solid\" border=\"1\">\n";
print FILEWRITE "<tr><th>Key ID</th><th>Owner</th><th>Fingerprint</th>";
print FILEWRITE "<th>Size</th><th>Type</th><th>Key Info Matches?</th><th>Owner ID Matches?</th></tr>\n";

while(my $line = shift(@fps))
{
        if($line =~ /^pub/)
	{
                my ($pub,$comptrust,$size,$type,$longid,$date,undef,
                    undef,$settrust,$owner,undef,undef,$flags,undef)
                      = split /:/, $line;
                my $id = substr($longid, 8);
                my ($fpr,undef,undef,undef,undef,undef,undef,undef,undef,$fingerprint)
                      = split /:/, shift(@fps);

		my $fingerp = $fingerprint;

                if($type eq '17')
		{
                        $type = 'DSA';
                }
		elsif($type eq '20')
		{
                        $type = 'El Gamal';
                }
		elsif($type eq '1')
		{
                        $type = 'RSA';
                }
                if(length($fingerprint) == 40)
		{
			for my $i (36,32,28,24,20,16,12,8,4)
			{
                                if($i != 20)
				{
					substr($fingerprint,$i,0,' ');
				}
				if($i == 20)
				{
					substr($fingerprint,$i,0,"\n");
				}
			}
                }
		elsif (length($fingerprint) == 32)
		{
                        for my $i (30,28,26,24,22,20,18,16,14,12,10,8,6,4,2)
			{
                                if($i != 16)
				{
					substr($fingerprint,$i,0,' ');
				}
				if($i == 16)
				{
					substr($fingerprint,$i,0,"\n");
				}
                        }
                }
		$owner =~ s/&/&amp;/;
		$owner =~ s/</&lt\;/;
                $owner =~ s/>/&gt\;/;

                print FILEWRITE "<tr><td><a title=\"See graph for this key !\" href=\"keygraphs/$fingerp.png\"><pre>$id</pre></a></td><td>$owner</td>\n";
		print FILEWRITE "<td><pre>$fingerprint</pre></td><td>$size</td>\n";
                print FILEWRITE "<td>$type</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
        }
}

print FILEWRITE "</table>\n";
print FILEWRITE "</body></html>";

close FILEWRITE;

