ServDoc_0105unixbasics

Code Index:



NAME

ServDoc_0105unixbasics - describe some unix basic configurations


VERSION

$Id: ServDoc_0105unixbasics,v 1.19 2004/02/22 21:27:48 uherbst Exp $


SYNOPSIS

ServDoc_0105unixbasics [-h|help] [-v|version] [--debug UXBAS,intensity]


DESCRIPTION

ServDoc_0105unixbasics describes:


OPTIONS

-h|help
This help.

-v|version
Version

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

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


AUTHORS

Ulrich Herbst <Ulrich.Herbst@gmx.de> James Whitwell


#!/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 File::Basename;
use vars qw($options);

# our own perl modules
use ServDoc;

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

$options->{Version} = '$Id: ServDoc_0105unixbasics,v 1.19 2004/02/22 21:27:48 uherbst Exp $';

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

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

$options = &process_cmdline($options);

my $h='Unix%%+Basics%%+';
%{$options->{lang}->{en}}=
  (
   running         => i18n_std('running',$0),

   inittab         => $h . 'inittab',
   inittab_short   => i18n_std('filecontent','/etc/inittab'),
   inittab_long    => 'This is the first config file for your booting system.',

   users           => $h . 'Users',
   users_short     => i18n_std('filecontent','/etc/passwd'),
   users_long      => '',

   group           => $h . 'Groups',
   group_short     => i18n_std('filecontent','/etc/group'),
   group_long      => '',

   shell           => $h . 'Login Shells',
   shell_short     => i18n_std('filecontent','/etc/shells'),
   shell_long      => 'Which shells are allowed as login shells and '.
   'for ftp ?',

   unsupp_cron     => "ServDoc doesn't currently support OS with crontabs",

   cronallow        => $h . 'Crontab%%+cron.alllow',
   # no cronallow_short
   cronallow_long   => '',
   cronallow_no     => "You haven't got %s",

   crondeny        => $h . 'Crontab%%+cron.deny',
   # no crondeny_short
   crondeny_long   => '',

   cronuser        => $h . 'Crontab%%+User: %s',
   cronuser_short  => i18n_std('cmdout','crontab -l'),
   cronuser_long   => '',

   cronglob        => $h . 'Crontab%%+global%%+crontab file',
   cronglob_short  => i18n_std('filecontent','/etc/crontab'),
   cronglob_long   => '',

   cron_h          => $h . 'Crontab%%+global%%+hourly jobs',
   cron_h_short    => i18n_std('filecontent','/etc/cron.hourly'),
   cron_h_long     => '',
   cron_d          => $h . 'Crontab%%+global%%+daily jobs',
   cron_d_short    => i18n_std('filecontent','/etc/cron.daily'),
   cron_d_long     => '',
   cron_w          => $h . 'Crontab%%+global%%+weekly jobs',
   cron_w_short    => i18n_std('filecontent','/etc/cron.weekly'),
   cron_w_long     => '',
   cron_m          => $h . 'Crontab%%+global%%+monthly jobs',
   cron_m_short    => i18n_std('filecontent','/etc/cron.monthly'),
   cron_m_long     => '',
   cron_d2         => $h . 'Crontab%%+global%%+daily jobs',
   cron_d2_short   => i18n_std('filecontent','/etc/periodic/cron.daily'),
   cron_d2_long    => '',
   cron_w2         => $h . 'Crontab%%+global%%+weekly jobs',
   cron_w2_short   => i18n_std('filecontent','/etc/periodic/cron.weekly'),
   cron_w2_long    => '',
   cron_m2         => $h . 'Crontab%%+global%%+monthly jobs',
   cron_m2_short   => i18n_std('filecontent','/etc/periodic/cron.monthly'),
   cron_m2_long    => '',

   atallow         => $h . 'at%%+at.allow',
   # no atallow_short
   atallow_long    => '',
   noatallow       => "You haven't got an at.allow-file.",

   atdeny         => $h . 'at%%+at.deny',
   # no atdeny_short
   atdeny_long    => '',
   noatdeny       => "You haven't got an at.deny-file.",

   atq            => $h . 'at%%+jobs',
   atq_short      => i18n_std('cmdout','atq'),
   atq_long       => '',

   atl            => $h . 'at%%+jobs',
   atl_short      => i18n_std('cmdout','at -l'),
   atl_long       => '',

   shm            => $h . 'Shared Memory',
   shm_short      => i18n_std('cmdout','ipcs'),
   shm_long       => '',

   shl            => $h . 'Shared Libraries%%+Directories',
   shl_short      => i18n_std('filecontent','/etc/ld.so.conf'),
   shl_long       => "Where are your shared libraries ?",
   shl2            => $h . 'Shared Libraries%%+Known Libs',
   shl2_short      => i18n_std('cmdout','ldconfig -vN'),
   shl2_long       => "Which shared libraries are known to your system ?",

   unknown_shl     => "ServDoc doesn't support this OS with shared ".
   "library documentation.",

   kernel         => $h . 'Kernel configuration',
   kernel_short   => i18n_std('filecontent','/usr/src/linux/.config'),
   kernel_long    => '',

   unknown_kernel => "ServDoc doesn't support this OS whis kernel config.",
   unsup_lp       => "ServDoc doesn't support this OS with printer status.",

   lp             => $h . 'Printer status',
   # no lp_short
   lp_long        => '',

   printcap       => $h . 'Printer configuration',
   printcap_short => i18n_std('filecontent','/etc/printcap'),
   printcap_long  => '',

   lssrc          => $h . 'Subsystems',
   lssrc_short    => i18n_std('cmdout','lssrc -a'),
   lssrc_long     => '',

   procs          => $h . 'Running Processes',
   procs_short    => i18n_std('cmdout','ps -ef'),
   procs_long     => '',

   );

$h='Unix%%+Grundlagen%%+';
%{$options->{lang}->{de}}=
  (
   running         => i18n_std('running',$0),

   inittab         => $h . 'inittab',
   inittab_short   => i18n_std('filecontent','/etc/inittab'),
   inittab_long    => 'Das ist die Konfigurationsdatei, die beim '.
   'Booten zuerst benutzt wird.',

   users           => $h . 'Benutzer',
   users_short     => i18n_std('filecontent','/etc/passwd'),
   users_long      => '',

   group           => $h . 'Gruppen',
   group_short     => i18n_std('filecontent','/etc/group'),
   group_long      => '',

   shell           => $h . 'Anmelde-Shells',
   shell_short     => i18n_std('filecontent','/etc/shells'),
   shell_long      => 'Welche Shells sind als Anmelde-Shells und '.
   'f&uuml;r FTP erlaubt ?',

   unsupp_cron     => "ServDoc unterst&uuml;tzt (noch) nicht dieses OS".
   "mit Crontabs.",

   cronallow        => $h . 'Crontab%%+cron.alllow',
   # no cronallow_short
   cronallow_long   => '',
   cronallow_no     => "Dieses System hat kein %s",

   crondeny        => $h . 'Crontab%%+cron.deny',
   # no crondeny_short
   crondeny_long   => '',

   cronuser        => $h . 'Crontab%%+Benutzer: %s',
   cronuser_short  => i18n_std('cmdout','crontab -l'),
   cronuser_long   => '',

   cronglob        => $h . 'Crontab%%+Global%%+Crontab-Datei',
   cronglob_short  => i18n_std('filecontent','/etc/crontab'),
   cronglob_long   => '',

   cron_h          => $h . 'Crontab%%+Global%%+St&uuml;ndliche Aufgaben',
   cron_h_short    => i18n_std('filecontent','/etc/cron.hourly'),
   cron_h_long     => '',
   cron_d          => $h . 'Crontab%%+Global%%+T&auml;gliche Aufgaben',
   cron_d_short    => i18n_std('filecontent','/etc/cron.daily'),
   cron_d_long     => '',
   cron_w          => $h . 'Crontab%%+Global%%+W&ouml;chentliche Aufgaben',
   cron_w_short    => i18n_std('filecontent','/etc/cron.weekly'),
   cron_w_long     => '',
   cron_m          => $h . 'Crontab%%+Global%%+Monatliche Aufgaben',
   cron_m_short    => i18n_std('filecontent','/etc/cron.monthly'),
   cron_m_long     => '',
   cron_d2         => $h . 'Crontab%%+Global%%+T&auml;gliche Aufgaben',
   cron_d2_short   => i18n_std('filecontent','/etc/periodic/cron.daily'),
   cron_d2_long    => '',
   cron_w2         => $h . 'Crontab%%+Global%%+W&ouml;chentliche Aufgaben',
   cron_w2_short   => i18n_std('filecontent','/etc/periodic/cron.weekly'),
   cron_w2_long    => '',
   cron_m2         => $h . 'Crontab%%+Global%%+Monatliche Aufgaben',
   cron_m2_short   => i18n_std('filecontent','/etc/periodic/cron.monthly'),
   cron_m2_long    => '',

   atallow         => $h . 'at%%+at.allow',
   # no atallow_short
   atallow_long    => '',
   noatallow       => "Dieses System hat keine at.allow-Datei.",

   atdeny         => $h . 'at%%+at.deny',
   # no atdeny_short
   atdeny_long    => '',
   noatdeny       => "Dieses System hat keine at.deny-Datei.",

   atq            => $h . 'at%%+Jobs',
   atq_short      => i18n_std('cmdout','atq'),
   atq_long       => '',

   atl            => $h . 'at%%+Jobs',
   atl_short      => i18n_std('cmdout','at -l'),
   atl_long       => '',

   shm            => $h . 'Shared Memory',
   shm_short      => i18n_std('cmdout','ipcs'),
   shm_long       => '',

   shl            => $h . 'Shared Libraries%%+Verzeichnisse',
   shl_short      => i18n_std('filecontent','/etc/ld.so.conf'),
   shl_long       => "Wo liegen die Shared Libraries ?",
   shl2            => $h . 'Shared Libraries%%+Bekannte Libs',
   shl2_short      => i18n_std('cmdout','ldconfig -vN'),
   shl2_long       => "Welche Shared Libraries sind dem System bekannt ?",

   unknown_shl     => "ServDoc unterst&uuml;tzt (noch) nicht dieses OS ".
   "bei Shared Library-Dokumentation",

   kernel         => $h . 'Kernel Konfiguration',
   kernel_short   => i18n_std('filecontent','/usr/src/linux/.config'),
   kernel_long    => '',

   unknown_kernel => "ServDoc unterst&uuml;tzt (noch) nicht dieses OS ".
   "bei der Kernel-Konfiguration",
   unsup_lp       => "ServDoc unterst&uuml;tzt (noch) nicht dieses OS ".
   "bei der Drucker-Dokumentation",

   lp             => $h . 'Drucker-Zustand',
   # no lp_short
   lp_long        => '',

   printcap       => $h . 'Drucker-Konfiguration',
   printcap_short => i18n_std('filecontent','/etc/printcap'),
   printcap_long  => '',

   lssrc          => $h . 'Subsysteme',
   lssrc_short    => i18n_std('cmdout','lssrc -a'),
   lssrc_long     => '',

   procs          => $h . 'Laufende Prozesse',
   procs_short    => i18n_std('cmdout','ps -ef'),
   procs_long     => '',
   );
debug( 9, i18n_mesg('running'));

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

# Main

# Here is your useful code.

if ($OSNAME !~ /darwin/ ) { # darwin hasn't /etc/inittab ?
  report_i18n('file','inittab','/etc/inittab')
}

#FIXME: Long desc could be description of GECOS-Fields....
report_i18n('file','users','/etc/passwd');
report_i18n('file','group','/etc/group');

# There are systems without /etc/shells....
if (-e "/etc/shells" ) {
  report_i18n('file','shell','/etc/shells');
}
# list crontab of all users
# FIXME: Maybe only uid < 100 or something like that....

# The path to crontabs is OS-dependent
my $crontabpath;
my $cronallowpath;
CRONTAB: {
 SETPATH: {
    if ($OSNAME =~ /linux/) {
      $crontabpath   = "/var/spool/cron";    # is this correct for ALL
                                             # linux distros ?
      $cronallowpath ="/etc";
      last SETPATH;
    }
    if ($OSNAME =~ /hpux|solaris|aix/) {
      $crontabpath   = "/var/spool/cron/crontabs";
      $cronallowpath = "/var/adm/cron";
      last SETPATH;
    }
    if ($OSNAME =~ /darwin/) {
	$crontabpath = '/var/cron/tabs';
	$cronallowpath = '/var/cron/allow';
	last SETPATH;
    }

    debug(1,i18n_mesg('unsupp_cron'));
    last CRONTAB;
  }

  # cron.allow, cron.deny
  if ( -e "$cronallowpath/cron.allow" ) {
    report_file(i18n_mesg('cronallow'),
                i18n_std('filecontent',"$cronallowpath/cron.allow"),
                i18n_mesg('cronallow_long'),
                "$cronallowpath/cron.allow");
  } else {
    report_string(i18n_mesg('cronallow'),
                  i18n_std('filecontent',"$cronallowpath/cron.allow"),
                  i18n_mesg('cronallow_long'),
                  i18n_mesg('cronallow_no',"$cronallowpath/cron.allow"),
		  );
  }
  if ( -e "$cronallowpath/cron.deny" ) {
    report_file(i18n_mesg('crondeny'),
                i18n_std('filecontent',"$cronallowpath/cron.deny"),
                i18n_mesg('crondeny_long'),
                "$cronallowpath/cron.deny");
  } else {
    report_string(i18n_mesg('crondeny'),
                  i18n_std('filecontent',"$cronallowpath/cron.deny"),
                  i18n_mesg('crondeny_long'),
                  i18n_mesg('cronallow_no',"$cronallowpath/cron.deny")
                 );
  }

  # Crontabs
  # Only root can see all crontabs
  if ( $UID > 0 ) {
    my $USER=getpwuid($UID);

    my $crontab =
      do_cmd("crontab -l",
	     "*",
	     20,
	     stderrfilter => 'no crontab for',
	    );
    report_string(i18n_mesg('cronuser',$USER),
                  i18n_mesg('cronuser_short'),
                  i18n_mesg('cronuser_long'),
                  $crontab);
  } else { # we are root
    foreach my $cronfile ( map {basename($_)} listdir($crontabpath)) {
      report_file(i18n_mesg('cronuser',$cronfile),
                  i18n_mesg('cronuser_short'),
                  i18n_mesg('cronuser_long'),
                  "$crontabpath/$cronfile");
    }
  }
}

# Some Linuxes have some very (IMHO) strange global crontabs
if (-e "/etc/crontab") {
  report_i18n('file','cronglob','/etc/crontab');
}

report_i18n('dir','cron_h','/etc/cron.hourly');
report_i18n('dir','cron_d','/etc/cron.daily');
report_i18n('dir','cron_w','/etc/cron.weekly');
report_i18n('dir','cron_m','/etc/cron.monthly');
report_i18n('dir','cron_d2','/etc/periodic/cron.daily');

# AT-Jobs
# at.allow, at.deny
if ( -e "$cronallowpath/at.allow" ) {
  report_file(i18n_mesg('atallow'),
              i18n_std('filecontent',"$cronallowpath/at.allow"),
              i18n_mesg('atallow_long'),
              "$cronallowpath/at.allow");
} else {
  report_string(i18n_mesg('atallow'),
                i18n_std('filecontent',"$cronallowpath/at.allow"),
                i18n_mesg('atallow_long'),
                i18n_mesg('noatallow'));
}

if ( -e "$cronallowpath/at.deny" ) {
  report_file(i18n_mesg('atdeny'),
              i18n_std('filecontent',"$cronallowpath/at.deny"),
              i18n_mesg('atdeny_long'),
              "$cronallowpath/at.deny");
} else {
  report_string(i18n_mesg('atdeny'),
                i18n_std('filecontent',"$cronallowpath/at.deny"),
                i18n_mesg('atdeny_long'),
                i18n_mesg('noatdeny'));
}

if ($OSNAME =~ /darwin/) {
  report_i18n('cmd','atq','atq');
}
else {
  my $atjobs =
    do_cmd("at -l",
	   "*",
	   20,
	   stderrfilter => 'you are not authorized to use at.',
	  );
  report_i18n('string','atl',$atjobs);
}

# Shared memory
if ($OSNAME !~ /darwin/) {
  report_i18n('cmd','shm','ipcs');
}

# Known shared libraries
if ($OSNAME =~ /linux/) {
  report_i18n('file','shl','/etc/ld.so.conf');
  report_i18n('cmd','shl2','ldconfig -vN');
}
else {
  debug (1,i18n_mesg('unknown_shl'));
}

# Kernel konfig
if ($OSNAME =~ /linux/) {
  if (-e "/usr/src/linux/.config") {
    report_i18n('file','kernel','/usr/src/linux/.config');
  }
} else {
  debug (1,i18n_mesg('unknown_kernel'));
}

my $lpcmd;
($OSNAME =~ /solaris|hpux/)
  and $lpcmd="lpstat -t";
($OSNAME =~ /linux/) and $lpcmd="lpc status";
($OSNAME =~ /aix/)   and $lpcmd="qchk -A";
if ($lpcmd) {
  report_cmd(i18n_mesg('lp'),
             i18n_std('cmdout',$lpcmd),
             i18n_mesg('lp_long'),
             $lpcmd);
} else {
  debug(1,i18n_mesg('unsup_lp'));
}

if (-e "/etc/printcap") {
  report_i18n('file','printcap','/etc/printcap');
}

# Running Subsystems (only AIX ?)
if ($OSNAME =~ /aix/) {
  report_i18n('cmd','lssrc','lssrc -a');
}

if ($OSNAME !~ /darwin/) { 
  # Darwin hasn't a ps -eo etime command... (or I wasn't able to find
  # it).
  
  # Running Processes: Everything with etime > 10 minutes is a running daemon
  # (ok, maybe...)
  my $proclist = get_proc_info(".");
  my $pid;
  my $procref;
  my $output=
    "<table><tr><th>PID</th><th>UID</th>".
  "<th>GID</th><th>CMD</th></tr>";
  
  while (($pid,$procref) = each (%$proclist)) {
    
    # ETIME > 10 minutes ?
    my $etime=$procref->{ETIME};
    my $is_daemon=0;
    if ($etime =~ m/\d:\d\d:\d\d/) {
      # more than at least one hour
      $is_daemon=1;
    }
    if ($etime =~ m/(\d)\d:\d\d/ and
        $1 > 0) {
      # more than 10 minutes
      $is_daemon=1;
    }
    if ($is_daemon) {
      $output .= "<tr>" .
        "<td>${pid}</td>" .
          "<td>". scalar getpwuid($procref->{UID}) ."</td>" .
            "<td>". scalar getgrgid($procref->{GID}) ."</td>" .
              "<td>$procref->{CMD}</td></tr>";
    }
  }
  $output .= "</table>";
  report_i18n('string','procs',$output,tab=>'self');
}
exit 0;