3 # onak-mail.pl - Mail processing interface for onak, an OpenPGP Keyserver.
5 # Written by Jonathan McDowell <noodles@earth.li>
6 # Copyright 2002 Project Purple
7 # Released under the GPL.
19 # Reads in our config file. Ignores any command it doesn't understand rather
20 # than having to list all the ones that are of no interest to us.
24 open(CONFIG, "@CONFIG@") or
25 die "Can't read config file: $!";
29 # Ignore; comment line.
30 } elsif (/^this_site (.*)/) {
31 $config{'thissite'} = $1;
32 } elsif (/^logfile (.*)/) {
33 $config{'logfile'} = $1;
34 } elsif (/^maintainer_email (.*)/) {
35 $config{'adminemail'} = $1;
36 } elsif (/^mail_delivery_client (.*)/) {
38 } elsif (/^pks_bin_dir (.*)/) {
39 $config{'pks_bin_dir'} = $1;
40 } elsif (/^db_dir (.*)/) {
41 $config{'db_dir'} = $1;
42 } elsif (/^syncsite (.*)/) {
43 push @{$config{'syncsites'}}, $1;
55 # Takes an armored OpenPGP stream and submits it to the keyserver. Returns the
56 # difference between what we just added and what we had before (ie the least
57 # data need to get from what we had to what we have).
61 my (@errors, @mergedata);
63 open(LOCKFILE, '>'.$config{'db_dir'}.'/onak-mail.lck');
64 flock(LOCKFILE, LOCK_EX);
67 open3(\*MERGEIN, \*MERGEOUT, \*MERGEERR,
68 $config{'pks_bin_dir'}."/onak", "-u", "add");
72 @mergedata = <MERGEOUT>;
77 flock(LOCKFILE, LOCK_UN);
83 my ($inheader, %seenby, $subject, $from, $replyto, @body, @syncmail);
91 if (/^Subject:\s*(.*)\s*$/i) {
93 } elsif (/^X-KeyServer-Sent:\s*(.*)\s*$/i) {
95 } elsif (/^From:\s*(.*)\s*$/i) {
97 } elsif (/^Reply-To:\s*(.*)\s*$/i) {
107 if (! defined($replyto)) {
111 # HELP, ADD, INCREMENTAL, VERBOSE INDEX <keyid>, INDEX <keyid>, GET <keyid>,
114 if ($subject =~ /^INCREMENTAL$/i) {
118 my @newupdate = submitupdate(@body);
122 foreach $i (@{$config{'syncsites'}}) {
123 if (! defined($seenby{$i})) {
128 open (LOG, ">>$config{'logfile'}");
129 @time = localtime(time);
131 print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d",
132 $time[3], $time[4] + 1, $time[5] + 1900,
133 $time[2], $time[1], $time[0];
134 print LOG "] onak-mail[$$]: Syncing with $count sites.\n";
137 if ((! defined($newupdate[0])) || $newupdate[0] eq '') {
138 open (LOG, ">>$config{'logfile'}");
140 print LOG sprintf "%02d/%02d/%04d %02d:%02d:%02d",
141 $time[3], $time[4] + 1, $time[5] + 1900,
142 $time[2], $time[1], $time[0];
143 print LOG "] onak-mail[$$]: Nothing to sync.\n";
149 open(MAIL, "|$config{mta}");
150 print MAIL "From: $config{adminemail}\n";
152 foreach $i (@{$config{'syncsites'}}) {
153 if (! defined($seenby{$i})) {
162 print MAIL "Subject: incremental\n";
163 foreach $site (keys %seenby) {
164 print MAIL "X-KeyServer-Sent: $site\n";
166 print MAIL "X-KeyServer-Sent: $config{thissite}\n";
167 print MAIL "Precedence: list\n";
168 print MAIL "MIME-Version: 1.0\n";
169 print MAIL "Content-Type: application/pgp-keys\n";
171 print MAIL @newupdate;
174 } elsif ($subject =~ /^(VERBOSE )?INDEX (.*)$/i) {
175 my (@indexdata, $command);
182 open3(\*INDEXIN, \*INDEXOUT, \*INDEXERR,
183 $config{'pks_bin_dir'}."/onak", $command, "$2");
185 @indexdata = <INDEXOUT>;
189 open(MAIL, "|$config{mta}");
190 print MAIL "From: $config{adminemail}\n";
191 print MAIL "To: $replyto\n";
192 print MAIL "Subject: Reply to INDEX $2\n";
193 print MAIL "Precedence: list\n";
194 print MAIL "MIME-Version: 1.0\n";
195 print MAIL "Content-Type: text/plain\n";
197 print MAIL "Below follows the reply to your recent keyserver query:\n";
199 print MAIL @indexdata;