<?php

/*
** CBLM
** $Id: index.php,v 1.11 2006/06/20 22:49:13 sella Exp $
** Copyright (c) 2005-2006 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

	require('config/config.php');
	require('menu.php');

	/* Connect to database */
	$server = $config['databaseServer'];
	if (isset($config['databasePort']) && strlen($config['databasePort']) > 1) {
		$server .= ':' . $config['databasePort'];
	}
	$dbase = $config['databaseName'];
	$username = $config['databaseUsername'];
	$password = $config['databasePassword'];
	$persistent = $config['databasePersistent'];

	if ($persistent) {
		$con = mysql_pconnect($server, $username, $password);
	} else {
		$con = mysql_connect($server, $username, $password);
	}
	mysql_select_db($dbase);

	printf("<HTML>\n<HEAD>\n<TITLE>%s %s</TITLE>\n</HEAD>\n<BODY>\n", $config['program'], $config['version']);
	menu();

?>
	<TABLE ALIGN="center">
		<TR>
			<TD COLSPAN="3" BGCOLOR="#aeaeae" ALIGN="center"><B><? printf("%s %s", $config['program'], $config['version']); ?></B></TD>
		</TR>
		<TR BGCOLOR="#aeaeae">
			<TD><B>Probe</B></TD>
			<TD ALIGN="center"><B>Avg RTT</B></TD>
			<TD ALIGN="center"><B>Loss</B></TD>
		</TR>
<?
	$sql = "SELECT INET_NTOA(ip) ip, name, AVG(rtt_avg)/1000 rtt_avg, 100-SUM(rx)/SUM(tx)*100 loss FROM probes LEFT JOIN data ON (probes.ip = data.src) WHERE secs = 60 AND UNIX_TIMESTAMP() - UNIX_TIMESTAMP(data.timestamp) < 10800 GROUP BY ip ORDER BY name";
	$result = mysql_query($sql);
	while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
		printf("<TR BGCOLOR=\"#c9c9c9\"><TD>%s (%s)</TD><TD ALIGN=\"center\">%.2f ms</TD><TD ALIGN=\"center\">%.2f%%</TD></TR>\n", $line['name'], $line['ip'], $line['rtt_avg'], $line['loss']);
	}
	printf("</TABLE>\n");
	printf("<DIV ALIGN=\"right\">%s %s</DIV>\n", $config['program'], $config['version']);
	printf("</BODY>\n</HTML>\n");

	// Free resultset
	mysql_free_result($result);

	// Closing connection
	mysql_close($con);

/*
 * Local Variables:
 * c-basic-offset: 3
 * tab-width: 3
 * End:
 * vim: noet ts=3 sw=3 sts=3
 */

?>
