#!/usr/bin/perl
#
#
#

use XML::Simple;

$IPFC_DRSERVER_ROOT="/opt/ipfc/htdocs/ipfc";
$IPFC_URL_ROOT="http://195.207.52.190:44000/ipfc";

require "common.pl";

&dr_monitor_head;
&dr_monitor_title("IPFC::DR-SERVER::REAL-TIME MONITOR","global-overview");
&dr_monitor_list_smod;
&dr_monitor_end;

sub dr_monitor_list_smod
{
	print "<br> <br>";
	opendir( DRDIR, $IPFC_DRSERVER_ROOT);
	while( defined($smod_file = readdir(DRDIR)) ) 
	{
		if (-d $IPFC_DRSERVER_ROOT."/".$smod_file) 
		{
			if (!($smod_file =~ m/\./))
			{
			print "<li><a href=\"$IPFC_URL_ROOT/$smod_file/\"> $smod_file</a>";
			opendir (SMODDIR, "$IPFC_DRSERVER_ROOT"."/".$smod_file."/"."status");
			undef $cpt;
			for my $file (sort { -C "$dir/$a" <=> -C "$dir/$b"} readdir SMODDIR) {$filearr[$cpt]=$file;$cpt++;};
			if ($filearr[0] =~ m/\.ok$/)
			{$filearr[0] =~ s/.ok//;}
			$dirfull = $IPFC_DRSERVER_ROOT."/".$smod_file."/"."status/".$filearr[0];
			}
			if ($dirfull =~ m/\.status$/)
			{
				$ipfc_xmlevents = XMLin($dirfull);
				print " <b> Retry time </b> :";
				print $ipfc_xmlevents->{'data'}->{'entry'}->{'retrytime'};
				print " <b> Last seen </b> :";
				print $ipfc_xmlevents->{'agent'}->{'date'};
			}

			print "</li>";

		}
	}
	closedir(DRDIR);
print "<br><br>";
}

sub dr_monitor_head
{
	print "Content-type: text/html", "\n\n";
	print <<HEADDR;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>IPFC::DR-SERVER::REAL-TIME MONITOR</TITLE>


HEADDR

}

sub dr_monitor_title
{

($title,$status) = @_;

	print <<HEADTITLE;

<BODY BGCOLOR="#ffffff">
<TABLE BORDER=0 WIDTH=100% CELLSPACING=0 BGCOLOR="#993333">
<TR VALIGN=TOP>
<TD><font size=+2 color=#ffffff> IPFC</TD>
<TD VALIGN=CENTER ALIGN=LEFT>
<font size=+1 color=#ffffff>
<B>
$title
</B>
</font>
</TD>
<TD ALIGN=RIGHT>
<font color="#ffffff">
$status
</font>
</TD>
</TR>
</TABLE>

HEADTITLE


}
sub dr_monitor_end
{
	print "DR-Monitor";

}

