sub ReadCurrentFile {
    &DEBUG("Starting");
    my $ip = shift || return;
    my(@p);

    my $cmd = "grep '$ip ' $Currentfile";
    my $cf = `$cmd`; chomp $cf;
    return unless $cf;

    $cf =~ s/ \(([^\)]*)\)\t/\tname: $1\t/;
    $cf =~ s/: / => '/g;
    $cf =~ s/\t/', /g;
    $cf .= "'";
    $cf =~ s/ //g;

    my %site = ( eval($cf) );
    my $ports = $site{'Ports'};
    $ports =~ s/^Ports: //;
    foreach (split(/,\s*/, $ports)) {
      @p = split /\//;
      $site{'ports'} .= $p[0].',';
    }
    chop $site{'ports'};

# $Configfile: (ipmask portmask)
    my $done = 0;
    foreach (&ReadConfigfile()) {
      ($ipmask, $portmask) = split / /;
      foreach (&GenerateSiteList($ipmask)) {
        next unless $_ eq $ip;
        $site{'portlist'} = join(',',&GeneratePortList($portmask));
        $done = 1;
        last;
      }
      last if $done;
    }

    my %info = &GetStoredInfo($ip);
    foreach (keys %info) { $site{$_} = $info{$_}; }

    $site{'status'} = ($site{'Status'} eq "Down") ? $Stat_fail : ($site{'ports'} eq $site{'portlist'}) ? $Stat_ok : $Stat_warn;
    $site{'ip'}     = $ip;
    $site{'sip'}    = &sip($ip);
    $site{'alias'}  = $site{'Alias_8'};

    return %site;
}

sub ReadHistoryFile_old {
    &DEBUG("Starting");
    my($ip) = shift;
    my($f) = &ip2file($ip);
    my $starttime = shift;

    my(%history) = ();
    my($time, $host, $status, @p);
    local(*F);

    my %info = &GetStoredInfo($ip);

# $Configfile: (ipmask portmask)
    my $done = 0;
    foreach (&ReadConfigfile()) {
      ($ipmask, $portmask) = split / /;
      foreach (&GenerateSiteList($ipmask)) {
        next unless $_ eq $ip;
        $info{'portlist'} = join(',',&GeneratePortList($portmask));
        $done = 1;
        last;
      }
      last if $done;
    }
    $history{'portlist'} = $info{'portlist'};

	open(F, "<$f.hist") || &Error("Unable to open $f.hist for reading.");
	while (<F>) {
      chomp;
      ($time, $host, $status) = split /\t/;
      next unless $time > $starttime;
      next if $history{$time}{'ip'};
      ($history{$time}{'ip'}, $history{$time}{'name'}) = $host =~ m/^Host: ([^ ]+) \(([^\)]+)\).*$/;
      $history{$time}{'sip'}    = &sip($history{$time}{'ip'});
      $history{$time}{'line'}   = $_;
      if ($status =~ /^Status/) {
        $history{$time}{'status'} = ($status =~ /Down/) ? $Stat_fail : $Stat_ok;
        $history{$time}{'ports'}  = "";
      } else {
        $status =~ s/^Ports: //;
        foreach (split(/,\s*/, $status)) {
          @p = split /\//;
          $history{$time}{'ports'} .= $p[0].',';
        }
        chop $history{$time}{'ports'};
        $history{$time}{'status'} = ($history{$time}{'ports'} eq $info{'portlist'}) ? $Stat_ok : $Stat_warn;
      }
      $history{$time}{'status'} = ($status =~ /Down/) ? $Stat_fail : ($history{$time}{'ports'} ne $info{'portlist'}) ? $Stat_warn : $Stat_ok;
    }
    close(F);
    return %history;
}

sub ReadHistoryFile {
    &DEBUG("Starting");
    my($ip,$start_year,$startmon,$startday,$endyear,$endmon,$endday) = @_;
    my($f) = &ip2file($ip);
    use Time::Local;
    my $starttime = timelocal(1,0,0,$startday,$startmon,$startyear);
    my $endtime = timelocal(59,59,23,$endday,$endmon,$endyear);

    my(%history) = ();
    my($time, $host, $status, $s, @p);
    local(*F);

    my %info = &GetStoredInfo($ip);

# $Configfile: (ipmask portmask)
    my $done = 0;
    foreach (&ReadConfigfile()) {
      ($ipmask, $portmask) = split / /;
      foreach (&GenerateSiteList($ipmask)) {
        next unless $_ eq $ip;
        $info{'portlist'} = join(',',&GeneratePortList($portmask));
        $done = 1;
        last;
      }
      last if $done;
    }
    $history{'portlist'} = $info{'portlist'};

	open(F, "<$f.hist") || &Error("Unable to open $f.hist for reading.");
	while (<F>) {
      chomp;
      ($time, $host, $status) = split /\t/;
      last if $time > $endtime;
      next unless $time >= $starttime;
      @ntimes = localtime($time);
      $ntime = $Months[$ntimes[4]].' '.$ntimes[3];
      push(@hkeys,$ntime) unless grep(/^$ntime$/,@hkeys);

      if ($status =~ /^Status/) {
        if ($status =~ /Down/) {
          $history{'system'}{$ntime}{$Stat_fail}++;
        } else {
          $history{'system'}{$ntime}{$Stat_ok}++;
        }
        foreach $port (split(/,/,$history{'portlist'})) {
          $history{'portstatus'}{$ntime}{$port}{$Stat_fail}++;
        }
      } else {
        undef @portok;
        $allok = $noneok = 1;
        ($s = $status) =~ s/^\s*Ports:\s*//;
        foreach (split(/,\s*/, $s)) {
          @p = split /\//;
          push(@portok,$p[0]);
        }
        foreach $port (split(/,/,$history{'portlist'})) {
          if (grep(/^$port$/,@portok)) {
            $history{'portstatus'}{$ntime}{$port}{$Stat_ok}++;
            $noneok = 0;
          } else {
            $history{'portstatus'}{$ntime}{$port}{$Stat_fail}++;
            $allok = 0;
          }
        }
        if ($allok) {
          $history{'system'}{$ntime}{$Stat_ok}++;
        } elsif ($noneok) {
          $history{'system'}{$ntime}{$Stat_fail}++;
        } else {
          $history{'system'}{$ntime}{$Stat_warn}++;
        }
      }
    }
    close(F);
    $history{'keys'} = join(",",@hkeys);
    return %history;
}

sub ReadConfigfile {
    &DEBUG("Starting");
    local(*F);
    my(@out) = ();
	open(F, "<$Configfile") || &Error("Unable to open Configfile: $Configfile for reading.<p>Click on the Setup Button to setup your network.");
	@out = <F>;
	close(F);
    chomp @out;
    return wantarray ? @out : join("\n",@out);
}

sub ip2file {
    return $Basedir . '/' . join('/', split(/\./, shift));
}

sub GenerateSiteList {
    my(@sites) = ();
    my($ip1, $ip2, $ip3, $ip4, @ips);

    my($ipmask) = shift || return;
    @ips = split(/\./, $ipmask);
    return unless $#ips == 3;
    foreach $i (0..3) {
      $ips[$i] =~ s/\-/\.\./g;
      $ips[$i] =~ s/\*/0\.\.255/g;
      $ips[$i] =~ s/^00?(\d)/$1/g;
      $ips[$i] =~ s/(\D)00?(\d)/$1$2/g;
    }
    foreach $ip1 (eval($ips[0])) {
      next unless $ip1 =~ /^\d+$/;
      foreach $ip2 (eval($ips[1])) {
        next unless $ip2 =~ /^\d+$/;
        foreach $ip3 (eval($ips[2])) {
          next unless $ip3 =~ /^\d+$/;
          foreach $ip4 (eval($ips[3])) {
            next unless $ip4 =~ /^\d+$/;
            push(@sites, $ip1.'.'.$ip2.'.'.$ip3.'.'.$ip4);
          }
        }
      }
    }
            
    return wantarray ? @sites : join("\n",@sites);
}

sub GeneratePortList {
    my($portmask) = shift;
    my(@ports);
    if ($portmask =~ /\*/) {
      $portmask = "1..65535";
    } else {
      $portmask =~ s/^[^0-9\., -]//g;
      $portmask =~ s/-/../g;
    }
    foreach (eval($portmask)) {
      push(@ports, $_);
    }
    return sort {$a <=> $b} @ports;
}

sub sint {
    my($val) = shift;
    my($w) = shift || 3;
    my($c) = sprintf("%${w}d",$val);
    $c =~ s/ /0/g;
    return $c;
}

sub sip {
    my(@ips) = split(/\./, shift);
    my($ip) = &sint($ips[0]).'.'.&sint($ips[1]).'.'.&sint($ips[2]).'.'.&sint($ips[3]);
    return $ip;
}

sub rsip {
    my(@ips) = split(/\./, shift);
    my($ip) = int($ips[0]).'.'.int($ips[1]).'.'.int($ips[2]).'.'.int($ips[3]);
    return $ip;
}


sub CreateDir {
    &DEBUG("Starting");
	my $filename = shift || &Error("Unable to create a null directory.");
    my @dirs = split(/\//, $filename);
    pop @dirs;     #Filename part
    unshift @dirs; #Root part
    my $dir = "";
    foreach (@dirs) {
      $dir .= "/" . $_;
      mkdir($dir,0775) unless -d $dir;
      &Error("Unable to create directory: $dir") unless -d $dir;
    }
    return 1;
}

sub colorStatus {
    my($stat) = shift;
	  if ($stat == $Stat_ok) {
	    return $Color_ok, $Text_ok, "OK";
      } elsif ( $stat == $Stat_warn) {
        return $Color_warn, $Text_warn, "WARN";
      } else {
	    return $Color_fail, $Text_fail, "FAIL";
	  }
}

sub GetStoredInfo {
    &DEBUG("Starting");
    my($ip) = shift || return 0;
    my %site = ();
    my($cmd);

    if ($Infofile && open(I, "<$Infofile")) {
      my @info = grep(/ip => "$ip"/,<I>);
      close(I);
      if ($#info >= 0) {
        chomp $info[0];
        %site = ( eval($info[0]) );
      }
    }

    my %tmpl = ( eval($Templatetext) );
    foreach (keys %tmpl) {
      $site{$_} = $tmpl{$_} unless exists $site{$_};
    }

    foreach (keys %site) { $site{$_} = &Decode($site{$_}); }
    return %site;
}

sub SaveStoredInfo {
    &DEBUG("Starting");
    my($ip) = shift || return;
    local(*F);
    my($cmd, $out, @result);

    %site = &GetStoredInfo($ip);

    delete $site{''};
    delete $site{'ip'};
    my $output = "ip => \"".$ip."\", ";

    foreach (keys %site) {
      $site{$_} = $in{$_} if exists $in{$_};
      $output .= $_ . " => \"" . &Encode($site{$_}) . "\", ";
    }
    chop $output; chop $output;

    open(F, "<$Infofile");
    open(G, ">$Infofile.new");
    my $changed = 0;
    while (<F>) {
      chomp;
      $line = $_;
      if ($line =~ /ip => "$ip"/) {
        print G $output,"\n";
        $changed = 1;
      } else {
        print G $line,"\n";
      }
    }
    close(F);
    print G $output,"\n" unless $changed;
    close(G);
    rename("$Infofile.new", $Infofile);
}

sub ReadServices {
    &DEBUG("Starting");
    open(F, "<$Servicesfile") || &Error("Unable to open the services file: $Servicesfile");
    while (<F>) {
      $Services{$2} = $1 if m/\s*([^:\s]+)\s*:\s*(.*)$/;
    }
    $Services{'0'} = "alive";
    close(F);
}

sub GetAllOS {
    my(@iplist) = @_;
    &DEBUG("Starting\n",join("\n",@iplist));
    return unless $#iplist >= 0;

    my(%OS,@result,$h,$ngo);
    foreach (@iplist) { $OS{$_} = "Unknown"; }
    
    my $tmpfile = $Cgidir.'/ostmp'.$$;
    open(IL, ">$tmpfile") or return;
    print IL join("\n",@iplist);
    close(IL);

    $ngo = $nmap_general_options." ".$nmap_extra_options;
    $ngo =~ s/\-P[IBS0]//;
    $ngo =~ s/\-PT[0-9]*//;
    $ngo =~ s/\-s.//;
    my $cmd = $Nmapcmd." ".$ngo." -v -oM - -O ".$NmapScan." -iL $tmpfile 2>/dev/null | grep '^Host'";
    &DEBUG($cmd);
    @result = `$cmd`;

    foreach $h (@result) {
      if ($h =~ /^Host: ([0-9\.]+).*OS: ([^\t]+).*$/) {
        $ip = $1;
        $os = $2;
        chomp $os;
        $OS{$ip} = $os;
        &DEBUG("Setting $ip to $os");
      }
    }
    unlink "$tmpfile";
    return %OS;
}

sub GetICON {
    &DEBUG("Starting");
    my($os) = shift || return "unk";
    my($icon) = "unk";

    if ($os =~ /Mac/) { $icon = "mac";
    } elsif ($os =~ /print|phaser|laser|inkjet/i) { $icon = "printr01";
    } elsif ($os =~ /Solaris|Sun/i) { $icon = "sun";
    } elsif ($os =~ /3com/i) {        $icon = "3com";
    } elsif ($os =~ /novell/i) {      $icon = "novell";
    } elsif ($os =~ /suse/i) {        $icon = "suse";
    } elsif ($os =~ /beos/i) {        $icon = "beos";
    } elsif ($os =~ /nortel/i) {      $icon = "nortel";
    } elsif ($os =~ /juniper/i) {     $icon = "juniper";
    } elsif ($os =~ /lucent/i) {      $icon = "lucent";
    } elsif ($os =~ /amiga/i) {       $icon = "amiga";
    } elsif ($os =~ /cabletron/i) {   $icon = "cabletron";
    } elsif ($os =~ /citrix/i) {      $icon = "citrix";
    } elsif ($os =~ /Cisco/i) {       $icon = "cisco";
    } elsif ($os =~ /Tru64/i) {       $icon = "tru64";
    } elsif ($os =~ /SCO/i) {         $icon = "sco";
    } elsif ($os =~ /Linux/i) {       $icon = "linux";
    } elsif ($os =~ /IRIX/i) {        $icon = "irix";
    } elsif ($os =~ /BSD/) {          $icon = "bsd";
    } elsif ($os =~ /AIX/) {          $icon = "aix";
    } elsif ($os =~ /Windows/) {      $icon = "windows";
    } elsif ($os =~ /Unix|Open|Net|MVS|UX|UNIX|OSF|BSD/) { $icon = "server01";
    } elsif ($os =~ /SNMP|SMTP|Router|router|RAS|switch|Gate|Bridge/) { $icon = "router01";
    } else {
      $icon = "unk";
    }
    return $icon;
}

sub Error {
	my($msg) = shift;
    my($pages) = shift || 1;
    &DEBUG($msg);
    print &Header($Myname,"ERROR",0) unless $DoneHeader;
	print <<EOE;
  $msg
  <p><a href="javascript:top.history.go(-$pages)">Continue</a></p>
EOE
	print &Footer();
	exit;
}

sub DEBUG {
  return unless $ADEBUG;
  my $caller = (caller(1))[3];
  open(BUG, ">>$Vardir/debug.log") or return;
  print BUG $caller,': ',join("",@_),"\n";
  close(BUG);
}

sub WaitForLockFile {
  &DEBUG("Starting");
  my $lockfile = $Vardir.'/autorecheck.lock';
  return 1 unless -f $lockfile;
  my $t = time;
  while (-f $lockfile) {
    &DEBUG("Waiting for lock to clear");
    sleep(3);
    return 0 if int(time - $t) > $RecheckTimeout;
  }
  return 1;
}

sub StartAutoCheck {
 &DEBUG("Starting");
  my $cmd = shift;
  if ($cmd) {
    if (&WaitForLockFile()) {
      &DEBUG("Issuing cmd: $cmd");
      system($cmd);
      return 1;
    } else {
      return 0;
    }
  } else {
    &StopAutoCheck();
    my $pidfile = $Vardir."/autorecheck.pid";
    $Autointerval ||= 20;
    $Autointerval = abs($Autointerval);
    $cmd = $Autorecheck." ".$pidfile." ".$Autointerval;
    &DEBUG("Issuing cmd: $cmd");
    system($cmd);
    return (-f $pidfile)?1:0;
  }
}

sub StopAutoCheck {
 &DEBUG("Starting");
  my $pidfile = $Vardir."/autorecheck.pid";
  if (open(F, "<$pidfile")) {
    my $autopid = <F>;
    chomp $autopid;
    close(F);
    &DEBUG("Sending TERM to $autopid");
    kill 'TERM', $autopid;
    unlink $pidfile;
    $Autointerval = -abs($Autointerval);
  }
}

sub RestartAutoCheck {
  &DEBUG("Starting");
  return if &HUPAutoCheck();
  &DEBUG("Calling StartAutoCheck");
  &StartAutoCheck();
}

sub HUPAutoCheck {
  &DEBUG("Starting");
  return 0 if $Autointerval <= 0;
  my $pidfile = $Vardir."/autorecheck.pid";
  if (open(F, "<$pidfile")) {
    my $autopid = <F>;
    chomp $autopid;
    close(F);
    &DEBUG("Sending HUP to $autopid");
    return kill('HUP', $autopid);
  }
  return 0;
}

sub AutoCheckStatus {
  &DEBUG("Starting");
  my $pidfile = $Vardir."/autorecheck.pid";
  return 0 unless -f $pidfile;
  open(F, "<$pidfile") || return 0;
  my $autopid = <F>;
  chomp $autopid;
  close(F);
  return kill(0, $autopid);
}

sub ServerCheckStatus {
  &DEBUG("Starting");
  my $pidfile = $Vardir."/miniserv.pid";
  return 0 unless -f $pidfile;
  open(F, "<$pidfile") || return 0;
  my $pid = <F>;
  chomp $pid;
  close(F);
  return kill(0, $pid);
}

sub Encode {
  my $text = shift || return;
  $text =~ s/([^a-zA-Z0-9_\. -])/uc sprintf("%%%02x",ord($1))/eg;
  return $text;
}

sub Decode {
  my $text = shift || return;
  $text =~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge;
  return $text;
}

sub FilterSite {
    &DEBUG("Starting");
    return unless $in{'f'};
    my($fname,$style);
    ($fname,$style) = $in{'f'} =~ /^(.*)_(.*)$/;
    return unless $Filters{$fname}{$style};
    
    my @iplist;
    foreach (split(/\s*\t\s*/,$Filters{$fname}{$style})) {
      push(@iplist,&GenerateSiteList($_));
    }
    
    my($o,$sip);
    foreach $o ($Stat_ok,$Stat_warn,$Stat_fail) {
      foreach $sip (keys %{$Site{$o}}) {
        delete $Site{$o}{$sip} unless grep(/^$Site{$o}{$sip}{'ip'}$/,@iplist);
      }
    }
    &DEBUG("Returning ips: ".join(",",@iplist));
    return @iplist;
}

sub Header {
    my($title, $extra, $increfresh) = @_;
    &DEBUG("Starting");

    if (&AutoCheckStatus()) { $auto = "on";  $nauto = "off"; }
    else                    { $auto = "off"; $nauto = "on"; }
    my $autocheck = '<a href="'.$nPulseurl.'?a=auto&s='.$nauto.'" title="Automatic Monitoring On/Off">'.
                    '<img src="/images/serv_'.$auto.'.gif" width=26 height=43 border=0 alt="AutoCheck On/Off"></a>';

    $extra = $extra?'<table border=0 cellspacing=0 cellpadding=0 width="100%"><tr><td align="right"><big>'.$extra.'</big>&nbsp;</td></tr></table>':'';

    my $select = '<select name=f style="font-size:7pt;color:black">';
    my($fname,$style);
    foreach $fname (sort keys %Filters) {
      foreach $style (sort keys %{$Filters{$fname}}) {
        $selected = ($in{'f'} eq $fname.'_'.$style) ? " selected" : "";
        $select .= '<option'.$selected.' value="'.$fname.'_'.$style.'">'.ucfirst(lc($fname)).':'.ucfirst(lc($style)).'</option>';
      }
    }
    $select .= '<option value="filter_new_filter">Edit Filters</option></select>';
    my $demomode = $DEMO?"&nbsp;<em><small>DEMO</small></em>":"$Version";
    $DoneHeader = 1;
    
    my $refresh = "";
    if ($increfresh) {
      if ($increfresh == 2) {
        $refresh = '<meta http-equiv="refresh" content="'.int($HtmlRefresh).';URL='.$HTTP.
                   $nPulseurl.'?a=status">' if int($HtmlRefresh) > 0;
      } else {
        $refresh = '<meta http-equiv="refresh" content="'.int($HtmlRefresh).';URL='.$HTTP.
                   $nPulseurl.'?a=display&f='.$in{'f'}.'">' if int($HtmlRefresh) > 0;
      }
    }

    my $buttons;
    if ($AdminUser) {
      $buttons = <<EOB;
         <td bgcolor="#bdbdbd"><a href="$nPulseurl?a=recheck" onMouseOver="recheck.src='images/recheck_on.gif'" onMouseOut="recheck.src='images/recheck.gif'"><img name=recheck src="images/recheck.gif" width=63 height=43 border=0 alt="Manual Recheck" title="Manual Network Rescan"></a></td>
         <td bgcolor="#bdbdbd"><a href="$nPulseurl?a=setup"   onMouseOver="setup.src='images/setup_on.gif'"     onMouseOut="setup.src='images/setup.gif'"><img     name=setup   src="images/setup.gif"   width=63 height=43 border=0 alt="Network Setup" title="Network Configuration Setup"></a></td>
         <td bgcolor="#bdbdbd"><a href="$nPulseurl?a=pref"    onMouseOver="prefs.src='images/prefs_on.gif'"     onMouseOut="prefs.src='images/prefs.gif'"><img     name=prefs   src="images/prefs.gif"   width=63 height=43 border=0 alt="Preferences" title="Preferences"></a></td>
         <td bgcolor="#bdbdbd"><a href="$nPulseurl?a=status"  onMouseOver="status.src='images/status_on.gif'"   onMouseOut="status.src='images/status.gif'"><img   name=status  src="images/status.gif"  width=63 height=43 border=0 alt="Status" title="nPulse Status Monitor"></a></td>
EOB
      $autocheck = <<EOA;
      <td>$autocheck</td>
EOA
    } else {
      $buttons   = "";
      $autocheck = "";
    }

    my $div = ($IsIE or $IsNS)?'<div style="height:50;overflow:none">':'<div>';
  
    return <<EOH;
<html>
 <head>
  <title>$title</title>
  <meta name="Keywords" content="Linux,Unix,npulse,nPulse,NPULSE,network,monitor,statistics">
  <meta name="Description" content="nPulse Network Monitoring Program for Linux and Unix.">
  <meta http-equiv="Expires" content="-1">
  $refresh
  <style language="text/css">
   BODY    {$Fsn;font-weight:normal}
   A       {font-weight:normal;text-decoration:none}
   A:hover {text-decoration:underline}
  </style>
 </head>
 <body bgcolor="#000000" text="#ffffff" link="#9999ff" vlink="#9999ff" alink="#ff0000" style="margin:0;" MARGINWIDTH=0 MARGINHEIGHT=0>
  $div
    <table cellspacing=0 cellpadding=0 width="100%">
    <form method=get action="$nPulseurl" style="padding:0;margin:0;border:0">
    <input type="hidden" name=a value="display">
     <tr>
      <td width=104><img src="images/alogo.gif" width=80 height=49 border=0 alt="nPulse"></td>
      <td width="100%" valign="bottom"><font size=1 color="#999999">$demomode &nbsp;</font></td>
      <td align="right">
       <table border=1 cellspacing=0 cellpadding=0>
        <tr valign="bottom">
         <td bgcolor="#bdbdbd"><a href="$Home_url" onMouseOver="home.src='images/home_on.gif'" onMouseOut="home.src='images/home.gif'"><img name=home src="images/home.gif" width=63 height=43 border=0 alt="Home" title="Home Page"></a></td>
$buttons
         <td bgcolor="#bdbdbd"><a href="$Help_url" onMouseOver="help.src='images/help_on.gif'" onMouseOut="help.src='images/help.gif'"><img name=help src="images/help.gif" width=63 height=43 border=0 alt="Help" title="Help Page"></a></td>
         <td bgcolor="#bdbdbd" nowrap align=center style="font-size:7pt;color:black;text-align:center">$select<input type=submit value="Go" style="font-size:6pt;color:black;border:0"></td>
        </tr>
       </table>
      </td>$autocheck
     </tr>
     <tr><td height=1 colspan=5 bgcolor="#a0a0a0"><img src="images/dot.gif" height=1 width=100></td></tr>
    </form></table>
   </div>$extra
EOH
}

sub Footer {
	return <<EOF;
  <hr>
  <table border=0 cellspacing=0 cellpadding=0 width="100%">
  <tr><td align="left"><span style="$Fxs"><a href="$Copyright_url">Copyright</a> &copy;2001, <a href="http://www.horsburgh.com/">Horsburgh.com</a>. All Rights Reserved.</span></td>
  <td align="right"><span style="$Fxs">User: $User [<a href="$Logout_url">Logout</a>]</span></td></tr></table>
 </body>
</html>
EOF
}

sub DisplayHTMLfile {
    &DEBUG("Starting");
    my $f = shift || return;
    my $extra = shift;
    local(*F); local($/) = undef;
    open(F, "<$f") || return;
    my $output = <F>;
    close(F);
    print &Header($Myname,"",$extra,0).$output.&Footer();
    exit;
}

sub GetUserCmds {
    my %Cmds;
    if (open(F, "<$Ucmdfile")) {
      my($name,$admin,$cmd);
      while (<F>) {
        chomp;
        ($name,$admin,$cmd) = split /\t/;
        if ($cmd eq "") {
          $cmd = $admin;
          $admin = 0;
        }
        $Cmds{$name}{cmd}   = $cmd;
        $Cmds{$name}{admin} = $admin?1:0;
        $name = $admin = $cmd = "";
      }
      close(F);
    }
    return %Cmds;
}

1;
