2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2013-04-21 06:50:39 +02:00
|
|
|
|
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 {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $qp, @args) = @_;
|
|
|
|
@urls = @args;
|
2002-11-06 07:42:55 +01:00
|
|
|
}
|
|
|
|
|
2005-07-07 06:17:39 +02:00
|
|
|
sub hook_config {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $transaction, $config) = @_;
|
|
|
|
$self->log(LOGNOTICE, "http_config called with $config");
|
|
|
|
for my $url (@urls) {
|
|
|
|
$self->log(LOGDEBUG, "http_config loading from $url");
|
|
|
|
my @config = split /[\r\n]+/, (get "$url$config" || "");
|
|
|
|
chomp @config;
|
|
|
|
@config = grep { $_ and $_ !~ m/^\s*#/ and $_ =~ m/\S/ } @config;
|
|
|
|
close CF;
|
|
|
|
|
|
|
|
# $self->log(LOGNOTICE, "returning http_config for $config ",Data::Dumper->Dump([\@config], [qw(config)]));
|
|
|
|
return (OK, @config) if @config;
|
|
|
|
}
|
|
|
|
return DECLINED;
|
2002-11-06 07:42:55 +01:00
|
|
|
}
|