Remove link to GitHub sponsors
[openssl-web.git] / bin / mk-omc
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Getopt::Long;
7 use Pod::Usage;
8 use OpenSSL::Query::REST;
9 use HTML::Entities;
10
11 my %options = ();
12 GetOptions(
13     \%options,
14     'name|n',                   # Show name
15     'email|e',                  # Show email
16     'locale|l',                 # Show locale
17     'pgp|p',                    # Show PGP key ID
18     'activity|a',               # Show whether person is active
19     'title|t=s',                # Title of the resulting table
20     'help|?',                   # Help
21     'man',                      # Full manual
22    ) or pod2usage(2);
23
24 pod2usage(1) unless $options{title};
25 pod2usage(1)
26     unless ($options{name} || $options{email} || $options{locale}
27                 || $options{activity} || $options{pgp});
28 pod2usage(1) if $options{help};
29 pod2usage(-exitval => 0, -verbose => 2) if $options{man};
30
31 my $query = OpenSSL::Query->new();
32
33 my %data = ();                  # Indexed by name, value is a hash table of vals
34 foreach my $groupname (@ARGV) {
35     my @members = $query->members_of($groupname);
36     foreach my $ids (@members) {
37         my $name = (grep m|\s|, @$ids)[0];
38         my $email = (grep m|\@openssl\.org$|, @$ids)[0];
39         my $locale = $query->find_person_tag($email, 'country');
40         my $pgpid = $query->find_person_tag($email, 'pgp');
41         $data{$name} = { email => $email, locale => $locale, pgpid => $pgpid,
42                          active => !!($groupname !~ m|-inactive$|),
43                          emeritus => !!($groupname =~ m|-emeritus$|) };
44     }
45 }
46
47 my @columns = ();
48 push @columns, 'Name' if $options{name};
49 push @columns, 'Email' if $options{email};
50 push @columns, 'Locale' if $options{locale};
51 push @columns, 'PGP Key ID' if $options{pgp};
52
53 print "<table summary=\"$options{title}\">\n";
54 print "  <tr>\n";
55 print join("    <th>&nbsp;&nbsp;</th>\n",
56            map { "    <th>$_</th>\n" } @columns);
57 print "  </tr>\n";
58
59 foreach my $key (sort { mk_sortable($a) cmp mk_sortable($b) } keys %data) {
60     my $pgpurl = $data{$key}->{pgpid} if $options{pgp};
61     $pgpurl =~ s|\s+||g if $pgpurl;
62     $pgpurl =
63         "http://pool.sks-keyservers.net:11371/pks/lookup?op=get&search=0x$pgpurl"
64         if $pgpurl;
65
66     my @columndata = ();
67     push @columndata,
68         join('',
69              $data{$key}->{active} ? "" : "<i>",
70              encode_entities($key),
71              $data{$key}->{active} ? "" : "</i> (I)",
72              $data{$key}->{emeritus} ? " (OMC Emeritus)" : "")
73         if $options{name};
74     push @columndata,
75         "<a href='mailto:$data{$key}->{email}'>$data{$key}->{email}</a>"
76         if $options{email};
77     push @columndata, $data{$key}->{locale} if $options{locale};
78     push @columndata,
79         $data{$key}->{pgpid}
80         ? "<a href='$pgpurl'>$data{$key}->{pgpid}</a>" : '&nbsp;'
81         if $options{pgp};
82
83     print "  <tr>\n";
84     print join("    <td>&nbsp;&nbsp;</td>\n",
85                map { "    <td>$_</td>\n" } @columndata);
86     print "  </tr>\n";
87 }
88
89 print "</table>\n";
90
91 sub mk_sortable {
92     my $name = shift;
93
94     # Peel off any title
95     $name =~ s/(Dr|Mr|Mrs|Miss)\.?\s+//;
96
97     # Split into first+middle name and last names and flip them over with
98     # a comma between.
99     # We work with the assumption that the middle name, if included, is
100     # given as a single letter followed by a possible period.
101     $name = ($name =~ m|^(\S+(?:\s\S\.?)?)\s+(.*)$|, "$2, $1");
102
103     return $name;
104 }