2012-04-29 05:41:31 +02:00
|
|
|
#!perl -Tw
|
2002-11-06 07:42:55 +01:00
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
http_config
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Example config plugin. Gets configuration data via http requests.
|
|
|
|
|
|
|
|
=head1 CONFIG
|
|
|
|
|
|
|
|
http_config is configured at plugin loading time via the plugins
|
2002-12-09 09:47:36 +01:00
|
|
|
config. Load the plugin with a list of urls like the following (on one line)
|
2002-11-06 07:42:55 +01:00
|
|
|
|
2002-12-09 09:47:36 +01:00
|
|
|
http_config http://localhost/~smtpd/config/ http://www.example.com/cgi-bin/qp?config=
|
2002-11-06 07:42:55 +01:00
|
|
|
|
|
|
|
Looking to config "me", qpsmtpd will try loading
|
2002-12-09 09:47:36 +01:00
|
|
|
http://localhost/~smtpd/config/me and if failing that try
|
2002-11-06 07:42:55 +01:00
|
|
|
http://www.example.com/cgi-bin/qp?config=me
|
|
|
|
|
|
|
|
=head1 BUGS
|
|
|
|
|
|
|
|
http_config doesn't do any caching. It should do some simple caching
|
|
|
|
to be used in production.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
use LWP::Simple qw(get);
|
|
|
|
|
|
|
|
my @urls;
|
|
|
|
|
|
|
|
sub register {
|
|
|
|
my ($self, $qp, @args) = @_;
|
|
|
|
@urls = @args;
|
|
|
|
}
|
|
|
|
|
2005-07-07 06:17:39 +02:00
|
|
|
sub hook_config {
|
2002-11-06 07:42:55 +01:00
|
|
|
my ($self, $transaction, $config) = @_;
|
2004-03-05 13:46:24 +01:00
|
|
|
$self->log(LOGNOTICE, "http_config called with $config");
|
2002-11-06 07:42:55 +01:00
|
|
|
for my $url (@urls) {
|
2004-03-05 13:46:24 +01:00
|
|
|
$self->log(LOGDEBUG, "http_config loading from $url");
|
2002-11-06 07:42:55 +01:00
|
|
|
my @config = split /[\r\n]+/, (get "$url$config" || "");
|
|
|
|
chomp @config;
|
|
|
|
@config = grep { $_ and $_ !~ m/^\s*#/ and $_ =~ m/\S/ } @config;
|
|
|
|
close CF;
|
2004-03-05 13:46:24 +01:00
|
|
|
# $self->log(LOGNOTICE, "returning http_config for $config ",Data::Dumper->Dump([\@config], [qw(config)]));
|
2002-11-06 07:42:55 +01:00
|
|
|
return (OK, @config) if @config;
|
|
|
|
}
|
|
|
|
return DECLINED;
|
|
|
|
}
|