| 1 |
#!perl -w |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
http_config |
| 6 |
|
| 7 |
=head1 DESCRIPTION |
| 8 |
|
| 9 |
Example config plugin. Gets configuration data via http requests. |
| 10 |
|
| 11 |
=head1 CONFIG |
| 12 |
|
| 13 |
http_config is configured at plugin loading time via the plugins |
| 14 |
config. Load the plugin with a list of urls like the following (on one line) |
| 15 |
|
| 16 |
http_config http://localhost/~smtpd/config/ http://www.example.com/cgi-bin/qp?config= |
| 17 |
|
| 18 |
Looking to config "me", qpsmtpd will try loading |
| 19 |
http://localhost/~smtpd/config/me and if failing that try |
| 20 |
http://www.example.com/cgi-bin/qp?config=me |
| 21 |
|
| 22 |
=head1 BUGS |
| 23 |
|
| 24 |
http_config doesn't do any caching. It should do some simple caching |
| 25 |
to be used in production. |
| 26 |
|
| 27 |
=cut |
| 28 |
|
| 29 |
use LWP::Simple qw(get); |
| 30 |
|
| 31 |
my @urls; |
| 32 |
|
| 33 |
sub register { |
| 34 |
my ($self, $qp, @args) = @_; |
| 35 |
@urls = @args; |
| 36 |
} |
| 37 |
|
| 38 |
sub hook_config { |
| 39 |
my ($self, $transaction, $config) = @_; |
| 40 |
$self->log(LOGNOTICE, "http_config called with $config"); |
| 41 |
for my $url (@urls) { |
| 42 |
$self->log(LOGDEBUG, "http_config loading from $url"); |
| 43 |
my @config = split /[\r\n]+/, (get "$url$config" || ""); |
| 44 |
chomp @config; |
| 45 |
@config = grep { $_ and $_ !~ m/^\s*#/ and $_ =~ m/\S/ } @config; |
| 46 |
close CF; |
| 47 |
|
| 48 |
# $self->log(LOGNOTICE, "returning http_config for $config ",Data::Dumper->Dump([\@config], [qw(config)])); |
| 49 |
return (OK, @config) if @config; |
| 50 |
} |
| 51 |
return DECLINED; |
| 52 |
} |