#!/usr/bin/perl -wT # (c) 2002 Peter Palfrader # $Id: pingd,v 1.10 2002/07/02 17:12:45 weasel Exp $ # =pod =head1 NAME pingd - echolot ping daemon =head1 SYNOPSIS =over =item B B =item B B =item B B I
[I
...] =item B B option=value [option=value..] I
[I
...] =item B B =back =head1 DESCRIPTION pingd is a the heart of echolot. Echolot is a pinger for anonymous remailers. A Pinger in the context of anonymous remailers is a program that regularily sends messages through remailers to check their reliability. It then calculates reliability statistics which are used by remailer clients to choose the chain of remailers to use. Additionally it collects configuration parameters and keys of all remailers and offers them in a format readable by remailer clients. When called without parameters pingd schedules tasks like sending pings, processing incoming mail and requesting remailer-xxx data and runs them in configurable intervalls. =head1 COMMANDS =over =item B Start the ping daemon. =item B Send the running pingd process a SIGTERM. =item B I
[I
...] Add I
to the list of remailers to query for keys and confs. =item B option=value [option=value..] I
[I
...] Possible options and values: =over =item B{B,B} Set B (show remailer in mlist, rlist etc.) for remailer I
to either B or B. =item B{B,B} Set B (send out pings to that remailer) for remailer I
to either B or B. =item B{B,B} Set B (fetch remailer-key and remailer-conf) for remailer I
to either B or B. =back =item B Dumps the current configuration to standard output. =head1 OPTIONS =over =item --verbose Verbose mode. Causes B to print debugging messages about its progress. =item --help Print a short help and exit sucessfully. =back =head1 FILES F =head1 AUTHOR Peter Palfrader Epeter@palfrader.org =head1 SEE ALSO echolot Documentation =head1 BUGS Please report them at URL:http://savannah.gnu.org/bugs/?group=echolot =cut use strict; use XML::Parser; use XML::Dumper; use Getopt::Long; use English; use lib qw{ . lib }; use Echolot::Config; use Echolot::Globals; use Echolot::Storage::File; use Echolot::Scheduler; use Echolot::Conf; use Echolot::Mailin; use Echolot::Pinger; use Echolot::Stats; use Echolot::Commands; $ENV{'PATH'} = '/bin:/usr/bin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; my $scheduler; sub setSigHandlers() { $SIG{'HUP'} = sub { print "Got SIGINT. scheduling readcommands\n"; $scheduler->schedule('readcommands', time() ); }; $SIG{'INT'} = sub { print "Got SIGINT. scheduling exit\n"; $scheduler->schedule('exit', time() ); }; $SIG{'QUIT'} = sub { print "Got SIGQUIT. scheduling exit\n"; $scheduler->schedule('exit', time() ); }; $SIG{'TERM'} = sub { print "Got SIGTERM. scheduling exit\n"; $scheduler->schedule('exit', time() ); }; }; sub commit_prospective_address() { Echolot::Globals::get()->{'storage'}->commit_prospective_address(); }; sub expire() { Echolot::Globals::get()->{'storage'}->expire(); }; #Echolot::Mailin::process(); #Echolot::Pinger::send_pings(); #Echolot::Mailin::process(); #Echolot::Conf::send_requests(); #Echolot::Stats::build(); my $params; Getopt::Long::config('bundling'); if (!GetOptions ( 'help' => \$params->{'help'}, 'verbose' => \$params->{'verbose'} )) { die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [-fwhv]\n"); }; if ($params->{'help'}) { print ("Usage: $PROGRAM_NAME [options]\n"); #FIXME exit 0; }; my $COMMAND = shift @ARGV; die ("command required\n") unless defined $COMMAND; Echolot::Config::init( $params ); chdir( Echolot::Config::get()->{'homedir'} ); Echolot::Globals::init(); if ($COMMAND eq 'add') { die ("add requires argument
\n") unless scalar @ARGV; my @addresses; for my $address (@ARGV) { die ("argument
is not a valid email address\n") unless ($address =~ /^[a-zA-Z0-9+._-]+\@[a-zA-Z0-9+.-]+$/ ); push @addresses, $address; }; for my $address (@addresses) { Echolot::Commands::addCommand("add $address"); }; # FIXME send hup } elsif ($COMMAND eq 'set') { my @settings; while (scalar @ARGV && $ARGV[0] =~ /^(showit|pingit|fetch)=(on|off)$/) { push @settings, $ARGV[0]; shift @ARGV; }; my @addresses; for my $address (@ARGV) { die ("argument $address is not a valid email address\n") unless ($address =~ /^[a-zA-Z0-9+._-]+\@[a-zA-Z0-9+.-]+$/ ); push @addresses, $address; }; for my $address (@ARGV) { for my $setting (@settings) { Echolot::Commands::addCommand("set $address $setting"); }; }; # FIXME send hup } elsif ($COMMAND eq 'stop') { die ("stop not implemented yet"); } elsif ($COMMAND eq 'start') { Echolot::Globals::initStorage(); setSigHandlers(); $scheduler = new Echolot::Scheduler; $scheduler->add('exit' , -1 , 0, 'exit' ); $scheduler->add('readcommands' , -1 , 0, \&Echolot::Commands::processCommands ); $scheduler->add('processmail' , 60 , 0, \&Echolot::Mailin::process ); $scheduler->add('ping' , Echolot::Config::get()->{'pinger_interval'} , 0, \&Echolot::Pinger::send_pings ); $scheduler->add('buildstats' , 60 , 0, \&Echolot::Stats::build ); $scheduler->add('commitprospectives' , 30*60 , 0, \&commit_prospective_address ); $scheduler->add('expire' , 15*60 , 0, \&expire ); $scheduler->add('getkeyconf' , 24*60*60 , 0, \&Echolot::Conf::send_requests ); $scheduler->run(); Echolot::Globals::get()->{'storage'}->commit(); Echolot::Globals::get()->{'storage'}->finish(); } elsif ($COMMAND eq 'dumpconf') { Echolot::Config::dump(); } elsif ($COMMAND eq 'convert') { Echolot::Globals::initStorage(); setSigHandlers(); Echolot::Globals::get()->{'storage'}->convert(); Echolot::Globals::get()->{'storage'}->commit(); Echolot::Globals::get()->{'storage'}->finish(); } else { die ("Command $COMMAND unknown"); }; exit 0; # vim: set ts=4 shiftwidth=4: