return to first page linux journal archive
keywordscontents

Listing 2. Script for Remote Access to Sendmail Queue

#!/usr/bin/perl -T
#
# A simple script to provide remote access to the
# sendmail queue.
# (c) John Blair, jun.97
#   The University Computer Center
#   The University of Alabama at Birmingham
#
# NOTE: The -T flag is used to turn on "Taint"
# checking. This helps to ensure that this script
# is secure.
use CGI;
use CGI::Base;
#
# blank $PATH environmental var
$ENV\{`PATH'\} = "";
#
# command strings (change this if your setup is
# different)
$sendmail_showqueue = "/usr/sbin/sendmail -bp";
$sendmail_flush = "/usr/sbin/sendmail -q";
$diskspace = "/bin/df /dev/hda1";
#
# title string (edit this to match the name of
# your host)
$title_string = "Bartleby Sendmail Queue";
#
# create CGI object
$query = new CGI;
#
# start outputing response
print $query->header;
print $query->start_html($title_string);
print "<h1>$title_string</h1>";
print "<hr>";
#
# should I first attempt to flush the queue?
if ($query->param('action') eq 'flush') {
	system($sendmail_flush);
}
#
# show sendmail queue
print "<b>Current sendmail queue contents:</b><p>";
if (! &show_cmd_output($sendmail_showqueue)) {
print "<b><a href=\"?action=flush\">
[Flush queue]</a></b><p>";
}
print "<hr>";
#
# show disk space
print "<b>Current disk space:</b><p>";
&show_cmd_output($diskspace);
print "<hr>";
#
# subroutine to run a command and print the output
# to stdout
sub show_cmd_output \{
  my $cmd = shift;
  open CMD, "$cmd |";
  my @output = <CMD>;
  print "<pre>";
  print join('<br>', html_escape(@output));
  print "</pre>";
  close CMD;
  if ($output[0] =~ /empty/) {
	return 1;
  } else {
	return 0;
  }
}
}