/********************************************************************
*
* CitySense Web Status Page
*
* December 11, 2006
* Kevin M. Bombino
* bombino@fas.harvard.edu
*
********************************************************************/
include_once('../../db/connection.php');
/*
// fetch list of plugins and determine active plugin
$q = sql_query("SELECT * FROM `config`");
$min_interval = 60;
while ($r = mysql_fetch_assoc($q)) {
if ($r['frequency'] < $min_interval && is_numeric($r['frequency'])) $min_interval = $r['frequency'];
$plugins[$r['name']] = $r;
if ($_REQUEST['display'] == $r['name'] || !strlen($display)) $display = $r['name'];
}
foreach ($plugins as $name => $plugin) {
$select_plugin .= '';
}
*/
// fetch list of nodes and determine node status
$TOTAL_DOWN = $TOTAL_OK = 0;
//$_REQUEST['historic'] = "2006-12-13 00:00:00";
if ($_REQUEST['historic']) $historic = date("Y-m-d H:i:s", strtotime($_REQUEST['historic']));
$q = sql_query("SELECT * FROM `nodes` "); //ORDER BY `id` ASC");
while ($r = mysql_fetch_assoc($q)) {
if ($r['online']) {
$r['status'] = 'OK';
$TOTAL_OK++;
} else {
$r['status'] = 'DOWN';
$TOTAL_DOWN++;
}
$NODES[$r['id']] = $r;
}
// execute plugin
/*
include_once("plugins/" . $display . ".inc.php");
foreach ($NODES as $id => $node) {
$q = sql_query("SELECT `id`,`data` FROM `log` WHERE `node_id`='" . $id . "' AND `command`='" . $display . "'" . ($historic ? " AND `timestamp`<'" . $historic . "' AND `timestamp` > DATE_ADD('" . $historic . "', INTERVAL -" . ($plugins[$display]['frequency'] * 2) . " MINUTE)" : " AND `timestamp` > DATE_ADD(NOW(), INTERVAL -" . ($plugins[$display]['frequency'] * 2) . " MINUTE)") . " ORDER BY `timestamp` DESC LIMIT 1");
if (mysql_num_rows($q)) {
$r = mysql_fetch_assoc($q);
if (function_exists($display . "_node")) {
$ret = call_user_func($display . "_node", $r['data']);
foreach ($ret as $k => $v) {
$NODES[$id][$k] = $v;
if ($k == 'pairs') {
foreach ($v as $pairnode => $pairinfo) {
if (!is_numeric($pairnode)) {
foreach ($NODES as $id2 => $node2) {
if ($pairnode == $node2['name'] || $pairnode == $node2['wireless_ip']) $pairnode = $id2;
}
}
$PAIRS[$id][$pairnode] = $pairinfo;
}
}
}
}
if (function_exists($display . "_pair")) {
call_user_func($display . "_pair", $r['data']);
}
}
}
*/
// render image
$img = imagecreatefromgif("../images/md-2.gif");
$box = imagecolorallocate($img, 255, 255, 180);
$blue = imagecolorallocate($img, 0, 0, 150);
$black = imagecolorallocate($img, 0, 0, 0);
$red = imagecolorallocate($img, 180, 0, 0);
if (count($PAIRS)) {
foreach ($PAIRS as $from_id => $pair) {
foreach ($pair as $to_id => $details) {
if ($from_id != $to_id) {
if (is_array($details['color'])) $color = imagecolorallocate($img, $details['color'][0], $details['color'][1], $details['color'][2]);
else $color = $blue;
if ($from_id < $to_id) $offset = 2;
else $offset = -2;
imageline($img, $NODES[$from_id]['long'] + $offset, $NODES[$from_id]['lat'], $NODES[$to_id]['long'] + $offset, $NODES[$to_id]['lat'], $color);
$pair_details .= "
| " . $NODES[$from_id]['name'] . " | " . $NODES[$to_id]['name'] . " | " . $details['output'] . " |
";
}
}
}
}
foreach ($NODES as $id => $node) {
imagefilledellipse($img, $node['long'], $node['lat'], 15, 15, $blue);
imagefilledrectangle($img, $node['long'] - 12, $node['lat'] + 10, $node['long'] + 200, $node['lat'] + 35, $box);
if (is_array($node['color'])) $color = imagecolorallocate($img, $node['color'][0], $node['color'][1], $node['color'][2]);
else $color = $red;
imagestring($img, 5, $node['long'] - 10, $node['lat'] + 10, $node['name'], $color);
imagestring($img, 1, $node['long'] - 10, $node['lat'] + 25, $node['output'], $color);
}
imagepng($img, "../images/md-2-live.png");
?>
CitySense - Live Status - Harvard/BBN Prototype Network

Prototype Status
if (count($NODES)) { ?>
Nodes:
There are =$TOTAL_OK?> active node=($TOTAL_UP != 1 ? "s" : "")?> (=$TOTAL_DOWN?> inaccessible node=($TOTAL_DOWN != 1 ? "s" : "")?>).
| Node ID | Network | Node Name | Software Version | Location | Status |
foreach ($NODES as $id => $node) { ?>
| =$node['id']?> |
=$node['subnetwork']?> |
=$node['name']?> |
=$node['version']?> |
=$node['location_desc']?> |
=$node['status']?> |
} ?>