summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2002-05-24 06:39:38 +0000
committerfukachan <fukachan>2002-05-24 06:39:38 +0000
commit2e541e14ea45586d311832005e8ba68a542a5d94 (patch)
treef213afb2be232f7afd03ab30ca078f31a81824d3
parent26d6b2b8ae436a1ed6d5197120b203cb3068d179 (diff)
downloadfml8-2e541e14ea45586d311832005e8ba68a542a5d94.tar.gz
fml8-2e541e14ea45586d311832005e8ba68a542a5d94.tar.bz2
fml8-2e541e14ea45586d311832005e8ba68a542a5d94.zip
use FML::MTAControl ACAP
-rw-r--r--fml/lib/FML/Command/Admin/newml.pm45
-rw-r--r--fml/lib/FML/MTAControl.pm174
2 files changed, 80 insertions, 139 deletions
diff --git a/fml/lib/FML/Command/Admin/newml.pm b/fml/lib/FML/Command/Admin/newml.pm
index b7ff6b51..6864fe7e 100644
--- a/fml/lib/FML/Command/Admin/newml.pm
+++ b/fml/lib/FML/Command/Admin/newml.pm
@@ -4,7 +4,7 @@
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
-# $FML: newml.pm,v 1.30 2002/04/27 05:25:02 fukachan Exp $
+# $FML: newml.pm,v 1.31 2002/05/21 09:21:08 fukachan Exp $
#
package FML::Command::Admin::newml;
@@ -150,16 +150,25 @@ sub _install_template_files
my $config = $curproc->{ config };
my $template_dir = $curproc->template_files_dir_for_newml();
my $ml_home_dir = $params->{ ml_home_dir };
+ my $templ_files = $config->{ newml_command_template_files };
- my $newml_template_files =
- $config->get_as_array_ref('newml_command_postfix_template_files');
- for my $file (@$newml_template_files) {
+ for my $file (@$templ_files) {
my $src = File::Spec->catfile($template_dir, $file);
my $dst = File::Spec->catfile($ml_home_dir, $file);
print STDERR "creating $dst\n";
_install($src, $dst, $params);
}
+
+ use FML::MTAControl;
+
+ # setup include include-ctl ...
+ my $postfix = new FML::MTAControl { mta_type => 'postfix' };
+ $postfix->setup($curproc, $params);
+
+ # setup ~fml/.qmail-*
+ my $qmail = new FML::MTAControl { mta_type => 'qmail' };
+ $qmail->setup($curproc, $params);
}
@@ -209,7 +218,6 @@ sub _update_aliases
}
-
# Descriptions: $alias file has an $ml_name entry or not
# Arguments: OBJ($self) OBJ($curproc) STR($ml_name)
# Side Effects: none
@@ -412,28 +420,11 @@ sub _install
{
my ($src, $dst, $config) = @_;
- use FileHandle;
- my $in = new FileHandle $src;
- my $out = new FileHandle "> $dst.$$";
-
- if (defined $in && defined $out) {
- chmod 0644, "$dst.$$";
-
- eval q{
- use FML::Config::Convert;
- &FML::Config::Convert::convert($in, $out, $config);
- };
- croak($@) if $@;
-
- $out->close();
- $in->close();
-
- rename("$dst.$$", $dst) || croak("fail to rename $dst");
- }
- else {
- croak("fail to open $src") unless defined $in;
- croak("fail to open $dst") unless defined $out;
- }
+ eval q{
+ use FML::Config::Convert;
+ &FML::Config::Convert::convert_file($src, $dst, $config);
+ };
+ croak($@) if $@;
}
diff --git a/fml/lib/FML/MTAControl.pm b/fml/lib/FML/MTAControl.pm
index 03862b83..e05e1a55 100644
--- a/fml/lib/FML/MTAControl.pm
+++ b/fml/lib/FML/MTAControl.pm
@@ -4,7 +4,7 @@
# All rights reserved. This program is free software; you can
# redistribute it and/or modify it under the same terms as Perl itself.
#
-# $FML: MTAControl.pm,v 1.3 2002/04/25 04:40:03 fukachan Exp $
+# $FML: MTAControl.pm,v 1.4 2002/04/27 05:25:01 fukachan Exp $
#
package FML::MTAControl;
@@ -52,23 +52,51 @@ sub new
$me->{ mta_type } =
defined $args->{ mta_type } ? $args->{ mta_type } : 'postfix';
+ _update_isa($me);
+
return bless $me, $type;
}
-# Descriptions: update alias
-# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
+sub _update_isa
+{
+ my ($self, $optargs) = @_;
+ my $mta_type =
+ defined $optargs->{ mta_type } ? $optargs->{ mta_type } :
+ $self->{ mta_type };
+
+ if ($mta_type eq 'postfix') {
+ eval q{
+ use FML::MTAControl::Postfix;
+ push(@ISA, qw(FML::MTAControl::Postfix));
+ };
+ croak($@) if $@;
+ }
+ elsif ($mta_type eq 'qmail') {
+ eval q{
+ use FML::MTAControl::Qmail;
+ push(@ISA, qw(FML::MTAControl::Qmail));
+ };
+ croak($@) if $@;
+ }
+}
+
+
+# Descriptions: install configuration temaplate alias
+# Arguments: OBJ($self)
+# HASH_REF($curproc) HASH_REF($params) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
-sub update_alias
+sub setup
{
- my ($self, $curproc, $optargs) = @_;
+ my ($self, $curproc, $params, $optargs) = @_;
my $mta_type =
defined $optargs->{ mta_type } ? $optargs->{ mta_type } :
$self->{ mta_type };
- if ($mta_type eq 'postfix') {
- $self->postfix_update_alias($curproc, $optargs);
+ if ($mta_type eq 'postfix' || $mta_type eq 'qmail') {
+ my $method = "${mta_type}_setup";
+ $self->$method($curproc, $params, $optargs);
}
else {
croak("unknown MTA");
@@ -80,15 +108,19 @@ sub update_alias
# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
# Side Effects: update aliases
# Return Value: none
-sub postfix_update_alias
+sub update_alias
{
my ($self, $curproc, $optargs) = @_;
- my $config = $curproc->{ config };
- my $prog = $config->{ path_postalias };
- my $maps = $optargs->{ alias_maps };
+ my $mta_type =
+ defined $optargs->{ mta_type } ? $optargs->{ mta_type } :
+ $self->{ mta_type };
- for my $alias (@$maps) {
- system "$prog $alias";
+ if ($mta_type eq 'postfix' || $mta_type eq 'qmail') {
+ my $method = "${mta_type}_update_alias";
+ $self->$method($curproc, $optargs);
+ }
+ else {
+ croak("unknown MTA");
}
}
@@ -105,8 +137,9 @@ sub find_key_in_alias
$self->{ mta_type };
my $key = $optargs->{ key };
- if ($mta_type eq 'postfix') {
- $self->postfix_find_key_in_alias($curproc, $optargs);
+ if ($mta_type eq 'postfix' || $mta_type eq 'qmail') {
+ my $method = "${mta_type}_find_key_in_alias";
+ $self->$method($curproc, $optargs);
}
else {
croak("unknown MTA");
@@ -125,8 +158,9 @@ sub get_aliases_as_hash_ref
defined $optargs->{ mta_type } ? $optargs->{ mta_type } :
$self->{ mta_type };
- if ($mta_type eq 'postfix') {
- $self->postfix_get_aliases_as_hash_ref($curproc, $optargs);
+ if ($mta_type eq 'postfix' || $mta_type eq 'qmail') {
+ my $method = "${mta_type}_get_aliases_as_hash_ref";
+ $self->$method($curproc, $optargs);
}
else {
croak("unknown MTA");
@@ -134,103 +168,19 @@ sub get_aliases_as_hash_ref
}
-# Descriptions: find key in aliases
-# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
-# Side Effects: none
-# Return Value: NUM(1 or 0)
-sub postfix_find_key_in_alias
-{
- my ($self, $curproc, $optargs) = @_;
- my $key = $optargs->{ key };
- my $maps = $self->postfix_alias_maps($curproc, $optargs);
-
- for my $map (@$maps) {
- print STDERR "scan key = $key, map = $map\n" if $debug;
-
- use FileHandle;
- my $fh = new FileHandle $map;
- if (defined $fh) {
- while (<$fh>) {
- return 1 if /^$key:/;
- }
- }
- else {
- warn("cannot open $map");
- }
- $fh->close;
- }
-
- return 0;
-}
-
-
-# Descriptions: get { key => value } in aliases
-# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
-# Side Effects: none
-# Return Value: HASH_REF
-sub postfix_get_aliases_as_hash_ref
-{
- my ($self, $curproc, $optargs) = @_;
- my $config = $curproc->{ config };
- my $alias_file = $config->{ mail_aliases_file };
- my $key = $optargs->{ key };
- my $mode = $optargs->{ mode };
- my $maps = $self->postfix_alias_maps($curproc, $optargs);
- my $aliases = {};
-
- # $0 -n shows fml only aliases
- if ($mode eq 'fmlonly') {
- $maps = [ $alias_file ];
- }
-
- for my $map (@$maps) {
- print STDERR "scan key = $key, map = $map\n" if $debug;
-
- use FileHandle;
- my $fh = new FileHandle $map;
- if (defined $fh) {
- my ($key, $value);
-
- LINE:
- while (<$fh>) {
- next LINE if /^#/;
- next LINE if /^\s*$/;
-
- chomp;
- ($key, $value) = split(/:/, $_, 2);
- $value =~ s/^\s*//;
- $value =~ s/s*$//;
- $aliases->{ $key } = $value;
- }
- }
- else {
- warn("cannot open $map");
- }
- $fh->close;
- }
-
- return $aliases;
-}
-
-
-# Descriptions: return alias_maps as ARRAY_REF
-# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs)
-# Side Effects: none
-# Return Value: ARRAY_REF
-sub postfix_alias_maps
+# Descriptions: install file $dst with variable expansion of $src
+# Arguments: OBJ($self) STR($src) STR($dst) HASH_REF($config)
+# Side Effects: create $dst
+# Return Value: none
+sub _install
{
- my ($self, $curproc, $optargs) = @_;
- my $config = $curproc->{ config };
- my $prog = $config->{ path_postconf };
+ my ($self, $src, $dst, $config) = @_;
-
- my $maps = `$prog alias_maps`;
- $maps =~ s/\s+\w+:/ /g;
- $maps =~ s/^.*=\s*//;
- chomp $maps;
-
- my (@maps) = split(/\s+/, $maps);
- return \@maps;
+ eval q{
+ use FML::Config::Convert;
+ &FML::Config::Convert::convert_file($src, $dst, $config);
+ };
+ croak($@) if $@;
}