Make pool.sks-keyservers.net the default keyserver (closes: #527941).
[pgp-tools.git] / keyanalyze / scripts / top50.pl
1 #!/usr/bin/perl -w
2 # this short script is for making the HTML for the top50 report monthly
3 # Copyright (c)2001 M. Drew Streib
4 # This code is released under the GPL version 2 or later.
5
6 # 2004-09-14: modifications by Christoph Berg <cb@df7cb.de>:
7 # * use perl to read top50comments.txt
8 # * use gpg --list-key instead of wget
9 # * use strict & warnings
10
11 # 2008-07-18: modifications by Christoph Berg <cb@df7cb.de>:
12 # * directly read msd.txt instead of a -sorted variant
13
14 use strict;
15 use Getopt::Std;
16
17 #my $keyserver = "http://pks.gpg.cz:11371/pks/lookup?op=vindex&fingerprint=on&search=0x";
18 #my $keyserver = "http://keyserver.noreply.org/pks/lookup?op=index&fingerprint=on&search=0x";
19 my $keyserver = "http://pool.sks-keyservers.net:11371/pks/lookup?op=index&fingerprint=on&search=0x";
20 my %options;
21 getopts('c:k:n:', \%options);
22 my $comments = $options{c} || "top50comments.txt";
23 my $keyring = $options{k} ? "--no-default-keyring --keyring=$options{k}" : "";
24 my $top = $options{n} || 50;
25
26 my %comment;
27 if (open F, $comments) {
28 while(<F>) {
29 die "$comments.$.: syntax error" unless /([\dA-F]+)\b ?(.*)/;
30 $comment{$1} = $2;
31 }
32 close F;
33 }
34
35 my %msd;
36 while (my $line = <>) {
37 $line =~ /^\w+\s+(\w+)\s+([\d\.]+)/ or die "cannot parse line $.: $line";
38 $msd{$1} = $2;
39 }
40
41 print "<table>\n";
42 print "<tr><th>#</th><th>Id</th><th></th><th>Name</th><th>MSD</th></tr>\n";
43
44 my $oldmsd = 0;
45 my $i = 1;
46 foreach my $key (sort { $msd{$a} <=> $msd{$b} } keys %msd) {
47 my $rank = "";
48 if($oldmsd != $msd{$key}) {
49 $rank = $i++;
50 }
51 last if $rank and $rank > $top;
52 $oldmsd = $msd{$key};
53 my $name = "";
54 open G, "gpg --list-key --fixed-list-mode --with-colon --trust-model always $keyring $key |" or die "gpg: $!";
55 while(<G>) {
56 #uid:u::::1082202576::1DC0BEA2AC64671CC902D50B8121F6E4E6336E15::Christoph Berg <cb@df7cb.de>:
57 next unless /^uid:[-qmfue]::::\d*::[\dA-F]*::(.+):$/;
58 $name = $1;
59 $name =~ s/</&lt;/g;
60 $name =~ s/>/&gt;/g;
61 $name =~ s/\@/&#64;/g;
62 last;
63 }
64 close G;
65 my $comment = $comment{$key} || "";
66 $key =~ /^([\dA-F]{2})/;
67 #my $prefix = $1;
68 #print "<TR><TD align=\"right\">$rank</TD><TD><a href=\"$prefix/$key.html\">$key</a> <small><A href=\"$keyserver$key\">keyserver</A></small></TD><TD>$name</TD><TD><I>$comment</I></TD><TD align=\"right\">$msd</TD></TR>\n";
69 print "<TR><TD align=\"right\">$rank</TD><TD><a href=\"$key.html\">$key</a></TD><TD><small><A href=\"$keyserver$key\">keyserver</A></small></TD><TD>$name <I>$comment</I></TD><TD align=\"right\">$msd{$key}</TD></TR>\n";
70 }
71
72 print "</table>\n";