Mail-Milter-Authentication
view release on metacpan or search on metacpan
lib/Mail/Milter/Authentication/Config.pm view on Meta::CPAN
package Mail::Milter::Authentication::Config;
use strict;
use warnings;
use version; our $VERSION = version->declare('v1.1.7');
use Mail::Milter::Authentication;
use Module::Load;
use Exporter qw{ import };
our @EXPORT_OK = qw{
get_config
default_config
};
use JSON;
our $PREFIX = '/etc';
our $IDENT = 'authentication_milter';
my $CONFIG;
sub default_config {
my $config = {
'debug' => 0,
'dryrun' => 0,
'logtoerr' => 0,
'error_log' => '/var/log/authentication_milter.err',
'connection' => 'inet:12345@localhost',
'umask' => '0000',
'runas' => 'nobody',
'rungroup' => 'nogroup',
'listen_backlog' => 20,
'min_children' => 20,
'max_children' => 200,
'min_spare_children' => 10,
'max_spare_children' => 20,
'max_requests_per_child' => 200,
'protocol' => 'milter',
'connect_timeout' => 30,
'command_timeout' => 30,
'content_timeout' => 300,
'addheader_timeout' => 30,
'dns_timeout' => 10,
'dns_retry' => 2,
'tempfail_on_error' => '1',
'tempfail_on_error_authenticated' => '0',
'tempfail_on_error_local' => '0',
'tempfail_on_error_trusted' => '0',
'handlers' => {}
};
my $installed_handlers = Mail::Milter::Authentication::get_installed_handlers();
foreach my $handler ( @$installed_handlers ) {
my $handler_module = 'Mail::Milter::Authentication::Handler::' . $handler;
load $handler_module;
if ( $handler_module->can( 'default_config' ) ) {
$config->{'handlers'}->{ $handler } = $handler_module->default_config();
}
else {
$config->{'handlers'}->{ $handler } = {};
}
}
return $config;
}
sub load_file {
my ( $file ) = @_;
if ( !-e $file ) {
die "Could not find configuration file $file";
}
my $text;
{
open my $cf, '<',
$file || die "Could not open configuration file $file";
my @t = <$cf>;
close $cf;
$text = join( q{}, @t );
}
my $json = JSON->new();
$json->relaxed(1);
my $data = $json->decode($text)
|| die "Error parsing config file $file";
return $data;
}
sub get_config {
return $CONFIG if $CONFIG;
my $file = $PREFIX . '/authentication_milter.json';
my $config = load_file( $file );
my $folder = $PREFIX . '/authentication_milter.d';
( run in 1.757 second using v1.01-cache-2.11-cpan-39bf76dae61 )