]> Frank Brehm's Git Trees - my-stuff/postfix-maps.git/commitdiff
Überprüfungen aktuelles Postfix
authorFrank Brehm <frank@brehm-online.com>
Fri, 6 Aug 2010 11:32:03 +0000 (11:32 +0000)
committerFrank Brehm <frank@brehm-online.com>
Fri, 6 Aug 2010 11:32:03 +0000 (11:32 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/postfix-maps/trunk@113 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

etc/config.yml
lib/FrBr/Postfix/App.pm

index 36a3c2af572938ac7cc3a1439162a30fe06e98d8..20d183d230b4823b7424d6e66e688f75e0ea67b9 100644 (file)
 # Das Arbeitsverzeichnis zum zeitweiligen Auschecken, absolut oder relativ zu postfixdir
 #workdir: 'work'
 #
+# Die Lage der Postfix-Binaries
+#binary:
+#   postalias: /usr/sbin/postalias
+#   postconf: /usr/sbin/postconf
+#   postfix: /usr/sbin/postfix
+#   postmap: /usr/sbin/postmap
 # Datenbank-Konfiguration
 #schema_class: 'FrBr::Postffix::Db'
 'Model::Schema':
index 7c19d69d8d3c5ec81696acc184ca380a1690110c..ab8ebf4627acc8b3ea754eb00e7fa0cff246006f 100644 (file)
@@ -186,7 +186,7 @@ HashRef mit allen gültigen Map-Typen
 =cut
 
 has 'valid_maptypes' => (
-    is              => 'ro',
+    is              => 'rw',
     isa             => 'HashRef',
     traits          => [ 'NoGetopt' ],
     lazy            => 1,
@@ -214,6 +214,7 @@ sub _build_valid_maptypes {
         'static'    => { restart => 0, do_map => 0, exec_map => 0, },
         'tcp'       => { restart => 0, do_map => 0, exec_map => 0, },
         'unix'      => { restart => 0, do_map => 0, exec_map => 0, },
+        'nis'       => { restart => 0, do_map => 0, exec_map => 0, },
     };
 }
 
@@ -226,7 +227,7 @@ HashRef mit den Postfix-Binaries
 =cut
 
 has 'postfix_binary' => (
-    is              => 'ro',
+    is              => 'rw',
     isa             => 'HashRef',
     traits          => [ 'NoGetopt' ],
     lazy            => 1,
@@ -344,31 +345,34 @@ after 'evaluate_config' => sub {
     my $self = shift;
 
     #return if $self->configuration_evaluated;
-    $self->debug( "Werte Backup-Konfigurationsdinge aus ..." );
-    return unless $self->config and keys %{ $self->config };
 
-    my @ConfigKeys = qw( postfix_dir work_dir );
+    if ( $self->config and keys %{ $self->config } ) {
 
-    for my $key ( keys %{ $self->config } ) {
+        $self->debug( "Werte Konfigurationsdinge aus ..." );
+        my @ConfigKeys = qw( postfix_dir work_dir );
+
+        for my $key ( keys %{ $self->config } ) {
+
+            my $val = $self->config->{$key};
 
-        my $val = $self->config->{$key};
-
-        for my $p ( @ConfigKeys ) {
-            my $f = $p;
-            my $r = $p;
-            $r =~ s/_/\[_-\]\?/g;
-            $r = "^$r\$";
-            $self->debug( sprintf( "Regex 1: '%s'", $r ) ) if $self->verbose >= 4;
-            unless ( $self->used_cmd_params->{$f} ) {
-                if ( $key =~ /$r/i ) {
-                    $self->debug( sprintf( "Gefunden: \$self->config->{%s} -> '%s'", $key, ( defined $val ? $val : '<undef>' ) ) ) if $self->verbose >= 2;
-                    $self->$f($val);
+            for my $p ( @ConfigKeys ) {
+                my $f = $p;
+                my $r = $p;
+                $r =~ s/_/\[_-\]\?/g;
+                $r = "^$r\$";
+                $self->debug( sprintf( "Regex 1: '%s'", $r ) ) if $self->verbose >= 4;
+                unless ( $self->used_cmd_params->{$f} ) {
+                    if ( $key =~ /$r/i ) {
+                        $self->debug( sprintf( "Gefunden: \$self->config->{%s} -> '%s'", $key, ( defined $val ? $val : '<undef>' ) ) ) if $self->verbose >= 2;
+                        $self->$f($val);
+                    }
                 }
             }
-        }
 
-        if ( $key =~ /^schema[-_]?class$/i and not $self->config->{'schema_class'} ) {
-            $self->config->{'schema_class'} = $val;
+            if ( $key =~ /^schema[-_]?class$/i and not $self->config->{'schema_class'} ) {
+                $self->config->{'schema_class'} = $val;
+            }
+
         }
 
     }
@@ -393,12 +397,130 @@ after 'evaluate_config' => sub {
         $self->debug( sprintf( "Setze Arbeitsverzeichnis auf '%s' ...", $d ) ) if $self->verbose >= 2;
     }
 
+    $self->_initialise_binaries();
+    $self->_initialise_maptypes();
     $self->_initialise_maps();
 
 };
 
 #---------------------------------------------------------------------------
 
+=head2 _initialise_maptypes( )
+
+Überprüft, welche Maptypen Postfix auf der aktuellen Maschine überhaupt unterstützt
+
+=cut
+
+sub _initialise_maptypes {
+
+    my $self = shift;
+
+    my $valid_maptypes = $self->valid_maptypes;
+    my $postconf = $self->postfix_binary->{'postconf'};
+    my $cmd = $postconf . " -m";
+
+    $self->debug( "Überprüfe Lookup-Tabellenarten von Postfix ..." );
+    $self->debug( sprintf( "Mit dem Kommando: '%s'", $cmd ) );
+
+    my $out = `$cmd`;
+    if ( $? ) {
+        $self->error( sprintf( "Fehler beim Aufruf von '%s'.", $cmd ) );
+        exit 13;
+    }
+
+    my @Types = split /\s*\n+\s*/, $out;
+    $self->debug( "Gefundene Tabellenarten: ", \@Types ) if $self->verbose >= 3;
+
+    for my $type ( keys %$valid_maptypes ) {
+        $valid_maptypes->{$type}{'ok'} = undef;
+    }
+
+    for my $type ( @Types ) {
+        my $t = lc($type);
+        if ( $valid_maptypes->{$t} ) {
+            $valid_maptypes->{$t}{'ok'} = 1;
+        }
+        else {
+            $self->warn( sprintf( "Unbekannte Lookup-Tabellenart '%s' gefunden.", $t ) );
+        }
+    }
+
+    for my $type ( keys %$valid_maptypes ) {
+        if ( $valid_maptypes->{$type}{'ok'}  ) {
+            $self->debug( sprintf( "Tabellenart '%s' gefunden.", $type ) ) if $self->verbose >= 3;
+            delete $valid_maptypes->{$type}{'ok'};
+        }
+        else {
+            $self->debug( sprintf( "Tabellenart '%s' NICHT gefunden.", $type ) );
+            delete $valid_maptypes->{$type};
+        }
+    }
+
+    return 1;
+
+}
+
+#---------------------------------------------------------------------------
+
+=head2 _initialise_binaries( )
+
+Holt eventuelle Angaben zu den Postfix-Binaries aus der Konfiguration
+und überprüft deren Vorhandensein.
+
+=cut
+
+sub _initialise_binaries {
+
+    my $self = shift;
+
+    my $binary = $self->postfix_binary;
+
+    if ( $self->config and keys %{ $self->config } ) {
+
+        $self->debug( "Werte Konfigurationsdinge aus ..." );
+        
+        for my $key ( keys %{ $self->config } ) {
+
+            if ( $key =~ /^binary$/i ) {
+
+                my $hash = $self->config->{$key};
+                if ( $hash and ref($hash) and ref($hash) eq 'HASH' ) {
+                    for my $bin ( keys %$hash ) {
+                        my $name = lc($bin);
+                        my $executable = $hash->{$name};
+                        if ( $executable and $binary->{$name} ) {
+                            $self->debug( sprintf( "Weise '%s' die Datei '%s' zu.", $name, $executable ) ) if $self->verbose >= 2;
+                            $binary->{$name} = $executable;
+                        }
+                    }
+                }
+
+            }
+
+        }
+
+    }
+
+    my $bins_valid = 1;
+
+    for my $bin ( keys %$binary ) {
+
+        my $executable = $binary->{$bin};
+        $self->debug( sprintf( "Checke Vorhandensein von '%s' ...", $executable ) ) if $self->verbose >= 2;
+
+        unless ( -x $executable ) {
+            $self->error( sprintf( "Datei '%s' ist entweder nicht da oder nicht ausführbar.", $executable ) );
+            $bins_valid = undef;
+        }
+
+    }
+
+    exit 12 unless $bins_valid;
+
+}
+
+#---------------------------------------------------------------------------
+
 sub _initialise_maps {
 
     my $self = shift;