#!/usr/local/bin/perl
# postfinger.cgi
# check postfix configuration
require './postfix-lib.pl';
&ReadParse();
$System=1;
$Package=1;
$Locking=1;
$Tables=1;
$Main=1;
$Master=1;
$Permissions=1;
$Libraries=1;
$Warn=1;
$Defaultsinmain=1;
$access{'postfinger'} || &error($text{'postfinger_ecannot'});
&header($text{'postfinger_title'}, "");
&head;
if (! -x $config{'postfix_config_command'} && ! -r $config{'postfix_config_file'} ) {
print "Can not find postconf";
exit;
}
# Verify that current configuration is valid
if ($config{'index_check'} && ($err = &check_postfix())) {
print "
",&text('check_error'),"
\n";
print "
$err
\n";
&ui_print_footer("/", $text{'index'});
exit;
}
if ($System eq 1 ) {
# print '--System Parameters--';
if (&has_command($config{'postfix_config_command'})) {
print "Postfix Version: $postfix_version
";
print "";
print "
";
print "";
open(MAILQ, "/bin/hostname 2>/dev/null |");
while (my $hostname = ) { print "| Hostname | $hostname |
"; }
close(MAILQ);
open(MAILQ, "/bin/uname -a 2>/dev/null |");
while (my $uname = ) { print "| System | $uname |
"; }
close(MAILQ);
}
print "
";
}
if ($Locking eq 1 ) {
print 'Mailbox locking methods
';
print '';
open(MAILQ, "$config{'postfix_config_command'} -l 2>/dev/null |");
while (my $locking_methods = ) {
print "| $locking_methods |
"; }
close(MAILQ);
print "
";
}
if ($Tables eq 1 ) {
print 'Supported Lookup Tables
';
print '';
# print '--Supported Lookup tables--
';
open(MAILQ, "$config{'postfix_config_command'} -m 2>/dev/null |");
while (my $lookup_tables = ) {
print "| $lookup_tables |
"; }
close(MAILQ);
print "
";
}
if (($Main eq 1 || $Defaultsinmain eq 1 ) && ("x`find . -prune \( -perm 020 -o -perm 002 \) -print`" != "x")){
print "Do not run this in a public- or group-writable directory
";
exit;
} else {
system ("rm postfinger.*.d postfinger.*.n");
# unlink "postfinger.*.d, postfinger.*.n";
`$config{'postfix_config_command'} -d | tr -s [:blank:] | sort > postfinger.$$.d`;
`$config{'postfix_config_command'} -n | tr -s [:blank:] | sort > postfinger.$$.n`;
if ($Main eq 1 ) {
print 'main.cf
non-default parameters
';
print '';
# print '--main.cf non-default parameters--
';
open(MAILQ, "/usr/bin/comm -13 postfinger.$$.d postfinger.$$.n 2>/dev/null |");
while (my $postfinger = ) {
($postf1,$postf2)=split(/=/,$postfinger,2);
print "| $postf1 | ";
print "$postf2 |
"; }
close(MAILQ);
print "
";
}
if ($Defaultsinmain eq 1 ) {
print 'main.cf
parameters defined as per defaults
';
print '';
# print '--main.cf parameters defined as per defaults--
';
open(MAILQ, "/usr/bin/comm -12 postfinger.$$.d postfinger.$$.n 2>/dev/null |");
while (my $postfinger = ) {
($postf1,$postf2)=split(/=/,$postfinger,2);
print "| $postf1 | ";
print "$postf2 |
"; }
close(MAILQ);
print "
";
}
unlink "postfinger.*.d, postfinger.*.n";
}
if ($Master eq 1 ) {
print 'master.cf
';
print '';
print "| service | type | ",
"private | unpriv | ",
"chroot | wakeup | ",
"maxproc | command + args |
";
open(MAILQ, "/bin/cat `$config{'postfix_config_command'} -h config_directory`/master.cf 2>/dev/null |");
while (my $postfinger = ) {
($postf1,$postf2,$postf3,$postf4,$postf5,$postf6,$postf7,$postf8)=split(/\s+/,$postfinger,8);
if ($postfinger =~ /\-o/) {
print " | | ",
" | | ",
" | | ",
" | $postf2 |
"
if ( !grep(/^#|^\[ \]*$/,$postfinger));
} elsif ($postfinger =~ /user=/) {
print " | | ",
" | | ",
" | | ",
" | $postf1 |
"
if ( !grep(/^#|^\[ \]*$/,$postfinger));
} else {
print "| $postf1 | $postf2 | ",
"$postf3 | $postf4 | ",
"$postf5 | $postf6 | ",
"$postf7 | $postf8 |
"
if ( !grep(/^#|^\[ \]*$/,$postfinger));
}
}
close(MAILQ);
print "
";
}
if ($Permissions eq 1 ) {
print 'Specific file and directory permissions
';
print '';
print "| Permission Deep Owner Group Size Date Directory/File |
";
open(MAILQ, "/bin/ls -ld `$config{'postfix_config_command'} -h queue_directory`/maildrop 2>/dev/null |");
while (my $postfinger = ) {
print "| $postfinger |
"
if ( !grep(/total|^#|^\[ \]*$/,$postfinger));
}
close(MAILQ);
print " |
";
open(MAILQ, "/bin/ls -ld `$config{'postfix_config_command'} -h queue_directory`/public 2>/dev/null |");
while (my $postfinger = ) {
print "| $postfinger |
"
if ( !grep(/total|^#|^\[ \]*$/,$postfinger));
}
close(MAILQ);
print " |
";
if (! open(MAILQ, "/bin/ls -l `$config{'postfix_config_command'} -h queue_directory`/public 2>/dev/null |")) {
print 'WARNING: No access to $queue_directory/public
Try running postfinger as user root or postfix
';
} else {
while (my $postfinger = ) {
print "| $postfinger |
"
if ( !grep(/total|^#|^\[ \]*$/,$postfinger));
}
close(MAILQ);
print " |
";
}
open(MAILQ, "/bin/ls -ld `$config{'postfix_config_command'} -h queue_directory`/private 2>/dev/null |");
while (my $postfinger = ) {
print "| $postfinger |
"
if ( !grep(/total|^#|^\[ \]*$/,$postfinger));
}
close(MAILQ);
print " |
";
if (! open(MAILQ, "/bin/ls -l `$config{'postfix_config_command'} -h queue_directory`/private 2>/dev/null |")) {
print 'WARNING: No access to $queue_directory/private
Try running postfinger as user root or postfix
';
} else {
while (my $postfinger = ) {
print "| $postfinger |
"
if ( !grep(/total|^#|^\[ \]*$/,$postfinger));
}
close(MAILQ);
print " |
";
}
open(MAILQ, "/bin/ls -l `$config{'postfix_config_command'} -h command_directory`/postdrop 2>/dev/null |");
while (my $postfinger = ) {
print "| $postfinger |
"
if ( !grep(/total|^#|^\[ \]*$/,$postfinger));
}
close(MAILQ);
print " |
";
open(MAILQ, "/bin/ls -l `$config{'postfix_config_command'} -h command_directory`/postqueue 2>/dev/null |");
while (my $postfinger = ) {
print "| $postfinger |
"
if ( !grep(/total|^#|^\[ \]*$/,$postfinger));
}
close(MAILQ);
print "
";
}
if ($Libraries eq 1 ) {
print 'Library dependencies
';
print '';
if (! open(MAILQ, "/usr/bin/ldd `$config{'postfix_config_command'} -h daemon_directory`/smtpd 2>/dev/null |")) {
print 'WARNING: Can not find ldd. Check you have it installed and in your path
';
} else {
while (my $postfinger = ) {
($postf1,$postf2)=split(/=/,$postfinger,2);
print "| $postf1 | ";
print "=$postf2 |
";
}
close(MAILQ);
print "
";
}
}
print "";
&ui_print_footer("index.cgi", $text{'index_title'});
sub head {
print "";
#print "Postfinger";
#print "