#! /usr/local/bin/perl
# 
# /*   $Id: bcnuagent.cgi,v 1.7 2000/05/05 13:05:50 jap Exp $
#
# *    Copyright (c) 1998 John Phillips
# *
# *    You may distribute under the terms of the Artistic License
# *
# */
#
require "bcnu.inc";
require "bcnulib.pl";

&methodparse;


$navigate=&navigate();
$showkey=&showkey();

$host=$in{"host"};
$inagent=$in{"agent"};
$reason=$in{"reason"};
$ignotice=$in{"ignotice"};
#
# main
#

&cklogin();

$errlevel=0;
if ($ignotice) {
	if ($ignotice =~ /Ignore/) {
		open(IGNORE,">$BCNUHOME/flags/$host.ignore")  || &bcnuerror("$host", "can't create $BCNUHOME/flags/$host.ignore");
		print IGNORE "$now:$loginid:$reason\n";
		&weback("Ignore: $host  :Reason: $reason");
		close (IGNORE);
	}
	elsif ($ignotice =~ /Notice/) {
		if ( -r "$BCNUHOME/flags/$host.ignore") {
			&weback("Notice: $host :Reason: $reason");
			unlink("$BCNUHOME/flags/$host.ignore") || &bcnuerror("$host", "can't remove $BCNUHOME/flags/$host.ignore");
			unlink("$BCNUHOME/flags/sentalert.$host");
			undef $reason;
			}
   }
}


if ($inagent) {

	$agent="$inagent";	
	&agentdetail ($host,$agent);
	&agent_info;
	print &printhdr;
	print &header("$host - Agent ($inagent)",$errlevel,$REFRESH);
	print $agdisp;
	print &ignoreform if $loginid;
	print &footer();
}
else	{

	&getagents($host);
	&agenthost ($host);
	&agent_info;
	print &printhdr;
	print &header("$host - Agent Summary",$errlevel,$REFRESH);
	print $agdisp;
	print $agalertinfo;
	print &ignoreform if $loginid;
	print &footer();
}


sub ignoreform {

if (open(IGNORE,"$BCNUHOME/flags/$host.ignore")) {
	$flagignore=<IGNORE>;
	chop $flagignore;
	($done,$loginid,$reason) = split(":",$flagignore);
	close(IGNORE);
	$ignore="Notice errors for $host";
	}

else
	{
	$ignore = "Ignore errors for $host" ;
	}

$form = <<"Endofform";
</TABLE>
<HR WIDTH=75%>
<TABLE BORDER=0>
<FORM METHOD="POST"> 
<INPUT TYPE=HIDDEN NAME="host" VALUE="$host">
<INPUT TYPE=HIDDEN NAME="agent" VALUE="$agent">
<TR>	<TH $DEFCELL>Comment $done<BR>($loginid)</TH>
	<TD><TEXTAREA COLS=30 ROWS=2 NAME="reason">$reason</TEXTAREA>
</TR>
<TR>	<TD Align=CENTER COLSPAN=2><INPUT TYPE="submit" NAME="ignotice" VALUE="$ignore">
</TR>
</FORM>
</TABLE>
<P>

Endofform

return ($form);
}

sub agent_info {

eval { require "$BCNUHOME/data/hostinfo"};

if ( ! $hostinfo{$host} ) { 
	$hostinfo{$host} = "No details";
	}
if ( ! $hostemail{$host} ) { 
	$hostemail{$host} = $defemail;
	}
if ( ! $hostpager{$host} ) {
        $hostpager{$host} = $defpager;
        }
if ( ! $hostwin32{$host} ) {
        $hostwin32{$host} = $defwin32;
        }

opendir(DIR,"$DATA/win32alert");
@win32on=grep (/\w$/,readdir(DIR));

$agalertinfo = <<"Endofaginfo";
</TABLE><HR WIDTH=75%>
Information about this system ($host)
<TABLE BORDER=1>
<TR><TD $ECELL>Description<TD BGCOLOR=#ffff80>$hostinfo{$host}</TR>
<TR><TD $ECELL>System Type<TD BGCOLOR=#ffff80>$bcnu_host_type{$platform{$host}}</TR>
<TR><TD $ECELL>Email alerts<TD BGCOLOR=#ffff80>$hostemail{$host}</TR>
<TR><TD $ECELL>Pager alerts<TD BGCOLOR=#ffff80>$hostpager{$host}</TR>
<TR><TD $ECELL>Win32 alerts<TD BGCOLOR=#ffff80>$hostwin32{$host}</TR>
<TR><TD $ECELL>Win32 online<TD BGCOLOR=#ffff80>@win32on</TR>
</TABLE><TABLE BORDER=1>
Endofaginfo
}
