debug und log options
authorheiko
Fri, 05 Aug 2005 08:47:57 +0000
changeset 7 67d354931c6d
parent 6 ebc6c26ef723
child 8 06152fae4247
debug und log options
exiacl
--- a/exiacl	Fri Aug 05 08:35:26 2005 +0000
+++ b/exiacl	Fri Aug 05 08:47:57 2005 +0000
@@ -2,6 +2,28 @@
 # © Heiko Schlittermann
 # $Id$
 # $URL$
+use constant USAGE => << '#'; 
+!ME! [options] [-- exim native options]
+
+    --[no]log	show the log output	[!$Cf->log!]
+    --[no]debug	show debug debug output	[!$Cf->debug!]
+
+    --src=s	src ip/name		[!$Cf->src!]
+    --dst=s	dst ip/name		[!$Cf->dst!]
+
+
+    --helo=s	helo name		[!$Cf->helo!]
+    --From=s	envelope from		[!$Cf->From!]
+
+    --from=s	mail from:		[!$Cf->from!]
+    --to=s	rcpt to:		[!$Cf->to!]
+
+    --exim=s	exim binary		[!$Cf->exim!]
+    --config=s	exim config file	[!$Cf->config!]
+
+    $Id$
+    $URL$
+#
 
 
 use strict;
@@ -19,8 +41,9 @@
 
 use constant CONFIG => (
     { CASE => 1 },
-    config  => { ARGS => "=s", DEFAULT => $ENV{EXIM_CONF} || "/etc/exim/exim.conf.t" , 
-		 ALIAS => "C" },
+
+    log	    => { ARGS => "!",  DEFAULT => 1 },
+    debug   => { ARGS => "!",  DEFAULT => 0 },
 
     src	    => { ARGS => "=s", DEFAULT => "131.111.8.41" },
     dst	    => { ARGS => "=s"  },
@@ -33,7 +56,10 @@
     to	    => { ARGS => "=s", DEFAULT => "hans\@nowhere.example" },
 
     exim    => { ARGS => "=s", DEFAULT => $ENV{EXIM} || "exim" },
-    verbose => { ARGS => "!" },
+    config  => { ARGS => "=s", DEFAULT => $ENV{EXIM_CONF} || "/etc/exim/exim.conf.t" , 
+		 ALIAS => "C" },
+
+    help    => { ARGS => "!" },
 
 );
 
@@ -44,57 +70,66 @@
 sub write_exim($@);
 sub addr(@);
 
-
 my $Cf;
 $Cf = new AppConfig CONFIG or die;
     $Cf->dst(addr(exim_option("primary_hostname")));
-    $Cf->getopt(\@ARGV);
+    $Cf->getopt(\@ARGV) or die $@;
     $Cf->From($Cf->From || $Cf->from);
 
-die "Config file for exim not readable ".$Cf->config.": $!\n" if not -r $Cf->config;
+
+MAIN: {
+    die "Config file for exim not readable ".$Cf->config.": $!\n" if not -r $Cf->config;
+
+    my ($w, $r);
+    my @cmd = ($Cf->exim, 
+	    -C => $Cf->config, 
+	    $Cf->dst ? (-oMi => addr($Cf->dst)) : (),
+	    -bhc => addr($Cf->src),
+	    @ARGV);		    # remaining args are exim native
 
-my ($w, $r);
-my @cmd = ($Cf->exim, 
-	-C => $Cf->config, 
-	$Cf->dst ? (-oMi => addr($Cf->dst)) : (),
-	-bhc => addr($Cf->src),
-	@ARGV);		    # remaining args are exim native
+    if ($Cf->help) {
+	($_ = USAGE) =~ s/!(.*?)!/eval $1||""/egs;
+	print; exit;
+    }
 
-my $s = new IO::Select;
+    my $s = new IO::Select;
 
-warn "@cmd\n";
-open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
+    print "**> @cmd\n";
+
+    open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
 
- read_exim $r;
-write_exim $w, "EHLO ".$Cf->helo."\n";
- read_exim $r;
-write_exim $w, "MAIL FROM: ".$Cf->From."\n";
- read_exim $r;
-write_exim $w, "RCPT TO: ".$Cf->to."\n";
- read_exim $r;
-write_exim $w, "DATA\n";
- read_exim $r;
-write_exim $w, "From: ".$Cf->from."\n";
-write_exim $w, "To: ".$Cf->to."\n";
+     read_exim $r;
+    write_exim $w, "EHLO ".$Cf->helo."\n";
+     read_exim $r;
+    write_exim $w, "MAIL FROM: ".$Cf->From."\n";
+     read_exim $r;
+    write_exim $w, "RCPT TO: ".$Cf->to."\n";
+     read_exim $r;
+    write_exim $w, "DATA\n";
+     read_exim $r;
+    write_exim $w, "From: ".$Cf->from."\n";
+    write_exim $w, "To: ".$Cf->to."\n";
 
-if (not -t STDIN) {
-    write_exim $w, "\n";
-    while (<>) {
-	write_exim $w, $_;
+    if (not -t STDIN) {
+	write_exim $w, "\n";
+	while (<>) {
+	    write_exim $w, $_;
+	}
     }
+
+    write_exim $w, "\n.\n";
+     read_exim $r;
+    write_exim $w, "QUIT\n";
+
+
 }
 
-write_exim $w, "\n.\n";
- read_exim $r;
-write_exim $w, "QUIT\n";
-
-
 sub read_exim($) {
     my $fh = shift;
     while (<$fh>) {
 	/^\d\d\d/ and print("< $_") and next;
-	/^LOG/ and print STDERR and next;
-	print STDERR if $Cf->verbose;
+	/^LOG/ and print and next if $Cf->log;
+	print and next if $Cf->debug;
     } continue {
 	last if /^\d\d\d\s/;
     }
@@ -119,6 +154,7 @@
     $opts{$opt}
 } }
 
+
 sub addr(@) {
     map { inet_ntoa scalar gethostbyname $_ } @_;
 }