#!/usr/bin/perl

use strict;

my $cgi=0;

if ($#ARGV == 0) {
   if ($ARGV[0] eq "--cgi") {
      $cgi=1;
   } else {
      print STDERR "usage: $0 [--cgi]\n";
      exit(1);
   }
}
my $r=`/usr/bin/last -f /var/log/firstbootwtmp | /bin/grep reboot | /usr/bin/head -1`;
my $u=`/usr/bin/uptime`;
my $un=`uname -a`;
my $apm=`apm`;


if ($cgi) {
  my $proc=`cat /proc/cpuinfo`;
  my $disk=`df -k`;
  my $numproc=`echo /proc/[0-9]* | wc -w`;
  print "Content-Type: text/html\n\n";

  print "<html>
    <head>
      <title>Scuzzie Statistics</title>
    </head>

    <body>
      <h1>Scuzzie Statistics</h1>
       <b>Last rebooted:</b>
     <BR>
       $r
     <BR>
       <b>Uptime stats: (may be different to above, since it may have been suspended for a while)</b>
     <BR>
      $u
     <BR>See <A href=\"uptimes.cgi\">this script</A> for a graph of uptimes.
     <BR>
       <b>Number of current processes running</b>
     <BR>
      $numproc
     <BR>
       <b>Kernel stats:</b>
     <BR>
       $un
     <BR>
       <b>Power stats:</b>
     <BR>
       $apm
     <BR>
       <b>CPU stats:</b>
     <BR><pre>
       $proc
     </pre><BR>
      
     <BR>
       <b>Disk usage:</b>
     <BR><pre>
       $disk
     </pre><BR>
      
     <BR>
    </body>
  </html>
  ";
} else {
   print "$r";
   print "$u";
   print "$un";
   print "$apm";
}

