ServDoc_0231apache

Code Index:



NAME

ServDoc_apache - describe the apache daemon


VERSION

$Id: ServDoc_0231apache,v 1.4 2003/11/05 15:28:27 uherbst Exp $


SYNOPSIS

ServDoc_apache [-h|help] [-v|version] [--debug APACH,intensity]


DESCRIPTION

ServDoc_apache describe the apache daemon (if installed).

We describe only if apache is running.


OPTIONS

-h|help
This help.

-v|version
Version

--debug APACH,intensity
Turn on Debugging for that module.

The debug feature for that module is named ``APACH''.


AUTHORS

Ulrich Herbst <Ulrich.Herbst@gmx.de>


#!/usr/bin/perl -w

#----------------------------------------------------------------------

# standard perl modules
use strict;                       # print error about unknown variables ...
use English;                      # long internal variable names;
use FindBin;                      # In which directory is ServDoc itself ?
                                  # There has to be the module and the lib dir!
use lib $FindBin::Bin. "/lib";    # Here are the ServDoc-perl-modules
use vars qw($options);

# our own perl modules
use ServDoc;

#----------------------------------------------------------------------

$options->{Version} = '$Id: ServDoc_0231apache,v 1.4 2003/11/05 15:28:27 uherbst Exp $';

# We need the cmdline to call the modules with the same debug options.
$options->{cmdline} = join " ", @ARGV;

sub debug { ServDoc_debug( "APACH", $options, shift, shift ); }

$options = &process_cmdline($options);

debug( 9, i18n_std('running',$0));

my $h='Net%%+Services%%+Apache%%+';
%{$options->{lang}->{en}}=
  (
   version         => $h . "Version, Compile Parameters",
   #version_short   => i18n_std('cmd','httpd -V'),
   version_long    => '',

   config          => $h . "Config File%%+httpd.conf",
#   config_short
   config_long     => "",

   include         => $h . 'Config File%%+Include: %s',
   # include_short
   include_long    => '',
);

$h='Netzwerk%%+Dienste%%+Apache%%+';
%{$options->{lang}->{de}}=
  (
   version         => $h . "Version, mit&uuml;bersetzte Parameter",
   #version_short   => i18n_std('cmd','httpd -V'),
   version_long    => '',

   config          => $h . "Konfigurationsdatei%%+httpd.conf",
#   config_short
   config_long     => "",

   include         => $h . 'Konfigurationsdatei%%+Include: %s',
   # include_short
   include_long    => '',
);

#----------------------------------------------------------------------

# Main

# Here is your useful code.

my $file;

# check if we have really apache running (and not ... Netscape
# FTrack,... )
my @httpd = ps_grep ("httpd|apache");
exit 0 if ($#httpd < 0);

my @extradirs = ("/usr/local/apache/*bin","/usr/sbin","/usr/local/sbin");
my $fullcmd = find_path("httpd",@extradirs) || 
  find_path("apache",@extradirs);

if (!defined($fullcmd)) {
  debug(8,"We can't find the apache executable");
  exit
}

# standalone or from inetd ?
# FIXME

# Which version, where are the config files ?
my $versionstring = do_cmd("$fullcmd -V");

report_string(i18n_mesg('version'),
              i18n_std('cmd',"$fullcmd -V"),
              i18n_mesg('version_long'),
              $versionstring);

# httpd.conf
# Problem: Where is httpd.conf ?
# We could look at ps
# or try some standard dirs
# or look at the output from $fullcmd -V

my $httpdroot = $versionstring;
$httpdroot    =~ s/.*HTTPD_ROOT="(.*?)".*/$1/s;
my $httpdconf = $versionstring;
$httpdconf    =~ s/.*SERVER_CONFIG_FILE="(.*?)".*/$1/s;
if ($httpdconf !~ /^\//) {$httpdconf =$httpdroot . "/" . $httpdconf;}

my $conffile = readfile($httpdconf);
report_string(i18n_mesg('config'),
              i18n_std('file',$httpdconf),
              i18n_mesg('config_long'),
              $conffile);

# Files included from httpd.conf with Include
# For relative pathes we need ServerRoot
$conffile =~ m{^ServerRoot (")*([\w/]*)(")*.*?$}m;
my $ServerRoot=$2;

my $ifile;
for $ifile (
  map { m/.*Include (.*)/i; $1 }
  grep /Include /i,
  grep !/#/,
  split /\n/,$conffile) {
  next if (! $ifile);

  chomp ($ifile);
  
  # ifile can be a absolute path name or a relative pathname
  if ($ifile !~ m{^/}) { 
    # ok, ifile is a relative pathname (relative to 
    # ServerRoot)
    $ifile = "$ServerRoot/$ifile";
  }
  report_file(i18n_mesg('include',$ifile),
              i18n_std('file',$ifile),
              i18n_mesg('include_long'),
              $ifile);
}

# FIXME: Maybe we should write a summary at first ?