| 1 |
#!/usr/bin/perl -w
|
| 2 |
|
| 3 |
# mixmaster-update: (c) 2002 Peter Palfrader <peter@palfrader.org>
|
| 4 |
# $Id: mixmaster-update 459 2007-11-21 10:12:30Z weasel $
|
| 5 |
#
|
| 6 |
# This program is free software. you can redistribute it and/or modify
|
| 7 |
# it under the terms of the GNU General Public License as published by
|
| 8 |
# the Free Software Foundation; either version 2 of the License, or
|
| 9 |
# (at your option) any later version.
|
| 10 |
#
|
| 11 |
# This program is distributed in the hope that it will be useful,
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
# GNU General Public License for more details.
|
| 15 |
#
|
| 16 |
# You should have received a copy of the GNU General Public License
|
| 17 |
# along with this program; if not, write to the Free Software
|
| 18 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 19 |
|
| 20 |
=pod
|
| 21 |
|
| 22 |
=head1 NAME
|
| 23 |
|
| 24 |
mixmaster-update - Fetch new reliability stats and keyrings for mixmaster
|
| 25 |
|
| 26 |
=head1 SYNOPSIS
|
| 27 |
|
| 28 |
=over
|
| 29 |
|
| 30 |
=item B<mixmaster-update> [B<--verbose>] [B<--source>=I<SOURCE>] [B<--configfile>=I<FILE>] [B<--destination>=I<DIRECTORY>]
|
| 31 |
|
| 32 |
=item B<mixmaster-update> B<--list-sources>
|
| 33 |
|
| 34 |
=item B<mixmaster-update> B<--help>
|
| 35 |
|
| 36 |
=item B<mixmaster-update> B<--version>
|
| 37 |
|
| 38 |
=back
|
| 39 |
|
| 40 |
=head1 DESCRIPTION
|
| 41 |
|
| 42 |
B<mixmaster-update> is a simple yet configurable script that downloads latest
|
| 43 |
remailer reliability statistics and keyrings for your mixmaster.
|
| 44 |
|
| 45 |
As having uptodate reliability statistics is imperative if you want to make use
|
| 46 |
of remailers it is recommended that you always update this data should it be
|
| 47 |
older that twelve or twentyfour hours and you intent to use mixmaster.
|
| 48 |
|
| 49 |
B<mixmaster-update> has several built in stats sources. You can view the list
|
| 50 |
of stats sources with the B<--list-sources> parameter.
|
| 51 |
|
| 52 |
If you want to make use of another stats source which is not listed in the output
|
| 53 |
of B<--list-sources> you can do so by setting the location of B<mlist> and others
|
| 54 |
in your configuration file.
|
| 55 |
|
| 56 |
=head1 OPTIONS
|
| 57 |
|
| 58 |
=over
|
| 59 |
|
| 60 |
=item B<--verbose>
|
| 61 |
|
| 62 |
Print verbose output to standard output. May be given more than once to increase verbosity.
|
| 63 |
|
| 64 |
=item B<--source>=I<SOURCE>
|
| 65 |
|
| 66 |
Use this built in stats source.
|
| 67 |
|
| 68 |
=item B<--configfile>=I<FILE>
|
| 69 |
|
| 70 |
Also parse the configuration file I<FILE>.
|
| 71 |
|
| 72 |
=item B<--destination>=I<DIRECTORY>
|
| 73 |
|
| 74 |
Write output to I<DIRECTORY> rather than the directory given in the config file
|
| 75 |
or ~/.Mix/.
|
| 76 |
|
| 77 |
=item B<--list-sources>
|
| 78 |
|
| 79 |
List available stats sources.
|
| 80 |
|
| 81 |
=item B<--help>
|
| 82 |
|
| 83 |
Print a brief help message and exit successfully.
|
| 84 |
|
| 85 |
=item B<--version>
|
| 86 |
|
| 87 |
Print a version information and exit successfully.
|
| 88 |
|
| 89 |
=back
|
| 90 |
|
| 91 |
|
| 92 |
=head1 FILES
|
| 93 |
|
| 94 |
=over
|
| 95 |
|
| 96 |
=item B</etc/mixmaster/update.conf>
|
| 97 |
|
| 98 |
=item B<~/.Mix/update.conf>
|
| 99 |
|
| 100 |
=item MIXMASTER_UPDATE_CONF environment
|
| 101 |
|
| 102 |
=item B<--configfile> parameter
|
| 103 |
|
| 104 |
=back
|
| 105 |
|
| 106 |
These files are parsed in this order. Later definitions overwrite older ones.
|
| 107 |
This config file defines proxy settings, where to write the results to and
|
| 108 |
which stats source to use
|
| 109 |
|
| 110 |
=over
|
| 111 |
|
| 112 |
=item B</etc/mixmaster/allpingers.txt>
|
| 113 |
|
| 114 |
=item B<~/.Mix/allpingers.txt>
|
| 115 |
|
| 116 |
=item MIXMASTER_ALLPINGERS environment
|
| 117 |
|
| 118 |
=item B<--allpingers> parameter
|
| 119 |
|
| 120 |
=back
|
| 121 |
|
| 122 |
These files are parsed in this order. Later definitions overwrite older ones.
|
| 123 |
The B<allpingers.txt> is a list of all pingers.
|
| 124 |
|
| 125 |
=head1 FILEFORMAT
|
| 126 |
|
| 127 |
The B<update.conf> configuration file for B<mixmaster-update> is simple. Lines
|
| 128 |
with whitespace only are ignored as are lines that have the hash our pound
|
| 129 |
(C<#>) sign as their first non whitespace character.
|
| 130 |
|
| 131 |
Lines are always truncated at the first hash our pound (C<#>) sign.
|
| 132 |
|
| 133 |
Lines are pairs of keys and values seperated by a convenient amount of
|
| 134 |
whitespace. The key is case insensitive.
|
| 135 |
|
| 136 |
Allowed keys:
|
| 137 |
|
| 138 |
=over
|
| 139 |
|
| 140 |
=item B<source>
|
| 141 |
|
| 142 |
Use the builtin stats source with this name
|
| 143 |
|
| 144 |
=item B<destination>
|
| 145 |
|
| 146 |
Write the downloaded data to this directory rather than ~/.Mix
|
| 147 |
|
| 148 |
=item B<proxy>
|
| 149 |
|
| 150 |
Set proxies for different protocols. The value is split into two parts:
|
| 151 |
protocol and proxy URL. They are seperated by whitespace.
|
| 152 |
|
| 153 |
Example:
|
| 154 |
PROXY http http://proxy.example.com:8080/
|
| 155 |
PROXY ftp http://proxy.example.com:8080/
|
| 156 |
|
| 157 |
=back
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
The format for B<allpingers.txt> is simple too:
|
| 162 |
|
| 163 |
[example]
|
| 164 |
base = http://stats.example.net/
|
| 165 |
rlist = http://stats.example.net/rlist.txt
|
| 166 |
mlist = http://stats.example.net/mlist.txt
|
| 167 |
rlist2 = http://stats.example.net/rlist2.txt
|
| 168 |
mlist2 = http://stats.example.net/mlist2.txt
|
| 169 |
rlist_html = http://stats.example.net/rlist.html
|
| 170 |
mlist_html = http://stats.example.net/mlist.html
|
| 171 |
rlist2_html = http://stats.example.net/rlist2.html
|
| 172 |
mlist2_html = http://stats.example.net/mlist2.html
|
| 173 |
rchain_html = http://stats.example.net/mlist2.html
|
| 174 |
pgpring = http://stats.example.net/pgp-all.asc
|
| 175 |
pgpring_rsa = http://stats.example.net/pgp-rsa.asc
|
| 176 |
mixring = http://stats.example.net/pubring.mix
|
| 177 |
type2list = http://stats.example.net/type2.list
|
| 178 |
|
| 179 |
The file may contain several such definitions.
|
| 180 |
|
| 181 |
=head1 ENVIRONMENT
|
| 182 |
|
| 183 |
=over
|
| 184 |
|
| 185 |
=item MIXMASTER_UPDATE_CONF
|
| 186 |
|
| 187 |
=item MIXMASTER_ALLPINGERS
|
| 188 |
|
| 189 |
See the FILES section abobe.
|
| 190 |
|
| 191 |
=item HOME
|
| 192 |
|
| 193 |
Your homedirectory. Used for finding your user configuration file. Also the
|
| 194 |
default destination directory is $HOME/.Mix/
|
| 195 |
|
| 196 |
=back
|
| 197 |
|
| 198 |
|
| 199 |
=head1 SEE ALSO
|
| 200 |
|
| 201 |
B<mixmaster>(1)
|
| 202 |
|
| 203 |
=head1 BUGS
|
| 204 |
|
| 205 |
Please report them to the Debian Bug Tracking System as described at
|
| 206 |
C<http://bugs.debian.org/> or use a tool like reportbug(1).
|
| 207 |
|
| 208 |
=head1 AUTHOR
|
| 209 |
|
| 210 |
Peter Palfrader E<lt>peter@palfrader.orgE<gt>
|
| 211 |
|
| 212 |
=cut
|
| 213 |
|
| 214 |
use strict;
|
| 215 |
use Getopt::Long;
|
| 216 |
use English;
|
| 217 |
use POSIX qw(:errno_h);
|
| 218 |
|
| 219 |
my $VERSION = '$Revision: 459 $';
|
| 220 |
my %SOURCES;
|
| 221 |
my %DESTINATION_FILES = (
|
| 222 |
rlist => 'rlist.txt',
|
| 223 |
mlist => 'mlist.txt',
|
| 224 |
rlist2 => 'rlist2.txt',
|
| 225 |
mlist2 => 'mlist2.txt',
|
| 226 |
mixring => 'pubring.mix',
|
| 227 |
pgpring => 'pubring.asc' );
|
| 228 |
my @configfiles = ( '/etc/mixmaster/update.conf',
|
| 229 |
$ENV{'HOME'}.'/.Mix/update.conf');
|
| 230 |
my @sourcesfiles = ( '/etc/mixmaster/allpingers.txt',
|
| 231 |
$ENV{'HOME'}.'/.Mix/allpingers.txt');
|
| 232 |
my $destination = $ENV{'HOME'}.'/.Mix/';
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
my $params;
|
| 238 |
Getopt::Long::config('bundling');
|
| 239 |
if (!GetOptions (
|
| 240 |
'help' => \$params->{'help'},
|
| 241 |
'version' => \$params->{'version'},
|
| 242 |
'verbose+' => \$params->{'verbose'},
|
| 243 |
'configfile=s' => \$params->{'conffile'},
|
| 244 |
'allpingers=s' => \$params->{'allpingers'},
|
| 245 |
'source=s' => \$params->{'source'},
|
| 246 |
'list-sources' => \$params->{'list-sources'},
|
| 247 |
'destination=s'=> \$params->{'destination'},
|
| 248 |
)) {
|
| 249 |
die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [-fwhv]\n");
|
| 250 |
};
|
| 251 |
if ($params->{'help'}) {
|
| 252 |
print "Usage: $PROGRAM_NAME [options]\n";
|
| 253 |
print "mixmaster-update $VERSION - (c) 2002 Peter Palfrader <peter\@palfrader.org>\n";
|
| 254 |
print " --configfile FILE Also source this config file.\n";
|
| 255 |
print " --source NAME Use this built in source.\n";
|
| 256 |
print " --destination Write files to this directory.\n";
|
| 257 |
print " --verbose Be verbose.\n";
|
| 258 |
print "\n";
|
| 259 |
print " --list-sources List available sources.\n";
|
| 260 |
print " --help Print this message.\n";
|
| 261 |
print " --version Print version information.\n";
|
| 262 |
print "\n";
|
| 263 |
print "ENVIRONMENT VARIABLES:\n";
|
| 264 |
print " MIXMASTER_UPDATE_CONF Also source this config file.\n";
|
| 265 |
print " HOME Home directory (base for user config\n";
|
| 266 |
print " file and destination).\n";
|
| 267 |
exit 0;
|
| 268 |
};
|
| 269 |
if ($params->{'version'}) {
|
| 270 |
print ("mixmaster-update $VERSION\n");
|
| 271 |
print ("(c) 2002 Peter Palfrader <peter\@palfrader.org>\n");
|
| 272 |
exit 0;
|
| 273 |
};
|
| 274 |
|
| 275 |
|
| 276 |
push (@configfiles, $ENV{'MIXMASTER_UPDATE_CONF'}) if defined $ENV{'MIXMASTER_UPDATE_CONF'};
|
| 277 |
push (@configfiles, $params->{'configfile'}) if defined $params->{'configfile'};
|
| 278 |
|
| 279 |
push (@sourcesfiles, $ENV{'MIXMASTER_ALLPINGERS'}) if defined $ENV{'MIXMASTER_ALLPINGERS'};
|
| 280 |
push (@sourcesfiles, $params->{'allpingers'}) if defined $params->{'allpingers'};
|
| 281 |
|
| 282 |
for my $file (@sourcesfiles) {
|
| 283 |
next unless (-e $file);
|
| 284 |
my $source;
|
| 285 |
open(F,$file) or die("Could not open $file: $!");
|
| 286 |
while(<F>) {
|
| 287 |
s/\s*(.*)\s*/$1/;
|
| 288 |
$source = $1, next if (/^\[(.*)\]$/);
|
| 289 |
if (/(.+?)\s*=\s*(.+)/) {
|
| 290 |
$SOURCES{$source}->{$1} = $2 if defined $source;
|
| 291 |
};
|
| 292 |
};
|
| 293 |
close(F);
|
| 294 |
};
|
| 295 |
die("No stats sources available\n") unless scalar keys %SOURCES;
|
| 296 |
|
| 297 |
if ($params->{'list-sources'}) {
|
| 298 |
print (join(', ', sort {$a cmp $b} keys %SOURCES), "\n");
|
| 299 |
exit 0;
|
| 300 |
};
|
| 301 |
|
| 302 |
my %proxy;
|
| 303 |
|
| 304 |
my $source;
|
| 305 |
for my $file (@configfiles) {
|
| 306 |
next unless (-e $file);
|
| 307 |
open (FILE, $file) or
|
| 308 |
warn ("Cannot open '$file': $!\n"), next;
|
| 309 |
my $line=0;
|
| 310 |
while (<FILE>) {
|
| 311 |
$line++;
|
| 312 |
chomp;
|
| 313 |
s/#.*//;
|
| 314 |
s/^\s*//;
|
| 315 |
s/\s*$//;
|
| 316 |
next unless $_;
|
| 317 |
|
| 318 |
my ($key, $value) = split(/\s+/, $_, 2);
|
| 319 |
$key = lc($key);
|
| 320 |
warn ("$PROGRAM_NAME: Value is not defined (line $line of $file)\n"), next
|
| 321 |
unless defined $value;
|
| 322 |
|
| 323 |
if ($key eq 'source') {
|
| 324 |
warn ("$PROGRAM_NAME: Source '$value' is not defined (line $line of $file)\n"), next
|
| 325 |
unless defined $SOURCES{$value};
|
| 326 |
$source = $SOURCES{$value};
|
| 327 |
} elsif ($key eq 'destination' ) {
|
| 328 |
$destination = $value;
|
| 329 |
} elsif ($key eq 'proxy' ) {
|
| 330 |
my ($proto, $proxy) = split(/\s+/, $value, 2);
|
| 331 |
$proxy{$proto} = $proxy;
|
| 332 |
} else {
|
| 333 |
warn "$PROGRAM_NAME: key '$key' not known (line $line of $file)\n";
|
| 334 |
};
|
| 335 |
};
|
| 336 |
close (FILE);
|
| 337 |
};
|
| 338 |
|
| 339 |
$destination = $params->{'destination'} if defined $params->{'destination'};
|
| 340 |
|
| 341 |
if (defined $params->{'source'}) {
|
| 342 |
die ("$PROGRAM_NAME: Source '$params->{'source'}' is not defined\n")
|
| 343 |
unless (defined $SOURCES{$params->{'source'}});
|
| 344 |
$source = $SOURCES{$params->{'source'}};
|
| 345 |
};
|
| 346 |
|
| 347 |
die ("$PROGRAM_NAME: destination directory '$destination' does not exist or is not a directory.\n")
|
| 348 |
unless ( -d $destination );
|
| 349 |
|
| 350 |
|
| 351 |
require LWP::UserAgent;
|
| 352 |
my $user_agent =
|
| 353 |
LWP::UserAgent->new(env_proxy => 1,
|
| 354 |
keep_alive => 1,
|
| 355 |
timeout => 30 );
|
| 356 |
|
| 357 |
for my $proto (keys %proxy) {
|
| 358 |
if ($proxy{$proto}) {
|
| 359 |
print "Setting proxy for protocol $proto to $proxy{$proto}\n"
|
| 360 |
if $params->{'verbose'};
|
| 361 |
$user_agent->proxy($proto, $proxy{$proto});
|
| 362 |
};
|
| 363 |
};
|
| 364 |
|
| 365 |
my %result;
|
| 366 |
for my $key (keys %$source) {
|
| 367 |
warn ("$PROGRAM_NAME: $key is not defined, Skipping download\n"), next
|
| 368 |
unless defined $source->{$key};
|
| 369 |
next unless defined ($DESTINATION_FILES{$key});
|
| 370 |
|
| 371 |
my $value = $source->{$key};
|
| 372 |
print "Getting $value\n"
|
| 373 |
if $params->{'verbose'};
|
| 374 |
|
| 375 |
my $uri = URI->new($value);
|
| 376 |
if ($user_agent->is_protocol_supported( $uri )) {
|
| 377 |
eval {
|
| 378 |
local $SIG{ALRM} = sub { die "alarm\n" };
|
| 379 |
alarm 35;
|
| 380 |
my $response = $user_agent->get($value);
|
| 381 |
unless ($response->is_success) {
|
| 382 |
warn ("$PROGRAM_NAME: Get failed for $value (".$response->code()." ".$response->message().")\n");
|
| 383 |
alarm 0;
|
| 384 |
next;
|
| 385 |
};
|
| 386 |
my $content = $response->content;
|
| 387 |
$content =~ s/\r\n/\n/g;
|
| 388 |
$result{$key} = $content;
|
| 389 |
alarm 0;
|
| 390 |
};
|
| 391 |
if ($EVAL_ERROR) {
|
| 392 |
die unless ($EVAL_ERROR eq "alarm\n");
|
| 393 |
warn ("PROGRAM_NAME: Get timed out for $value\n");
|
| 394 |
next;
|
| 395 |
};
|
| 396 |
} else {
|
| 397 |
warn ("$PROGRAM_NAME: Protocoll for '$value' not supported\n");
|
| 398 |
};
|
| 399 |
};
|
| 400 |
|
| 401 |
if (defined $params->{'verbose'} && $params->{'verbose'} >= 2) {
|
| 402 |
print "Got results for:\n";
|
| 403 |
for my $key (keys %result) {
|
| 404 |
print "$key\n";
|
| 405 |
print "-------------------\n";
|
| 406 |
print $result{$key},"\n";
|
| 407 |
print "-------------------\n";
|
| 408 |
};
|
| 409 |
};
|
| 410 |
|
| 411 |
die ("Downloading of mlist and/or mixring failed (do you need a proxy?). Aborting.\n")
|
| 412 |
unless (defined $result{'mlist'} && defined $result{'mixring'});
|
| 413 |
die ("mlist seems to not have the correct format (do you need a proxy?). Aborting.\n")
|
| 414 |
unless ($result{'mlist'} =~ /^Last update: /m && (
|
| 415 |
$result{'mlist'} =~ /^mixmaster\s/m ||
|
| 416 |
$result{'mlist'} =~ /^remailer\s/m));
|
| 417 |
die ("pubring.mix seems to not have the correct format (do you need a proxy?). Aborting.\n")
|
| 418 |
unless ($result{'mixring'} =~ /^-----Begin Mix Key-----$/m);
|
| 419 |
|
| 420 |
for my $key (keys %result) {
|
| 421 |
unless (open (F, '>'.$destination.'/'.$DESTINATION_FILES{$key})) {
|
| 422 |
my $hint = ($! == EACCES) ? ' (do you want --destination or run as a different user?)' : '';
|
| 423 |
warn ("$PROGRAM_NAME: Cannot write to $destination/$DESTINATION_FILES{$key}: $!$hint\n");
|
| 424 |
next;
|
| 425 |
};
|
| 426 |
print F $result{$key};
|
| 427 |
close F;
|
| 428 |
}
|
| 429 |
|
| 430 |
# vim:set ts=4:
|
| 431 |
# vim:set shiftwidth=4:
|