<?
/***************************************************************************
* Name: monitor.php
* Authors: Niklas Påhlsson, Pierre Svärd, Petter Miller, Mats Hörberg
/***************************************************************************/
require_once("../classes/network.php");
require_once("../classes/user.php");
session_start(); //Start session
$user = new User();
$network = new Network();
// Get user preferences ($prefs[0] is tooltip (Y or N), $prefs[1] is viewmode (All, Details or Overview)
$prefs = $user->GetUserPreferences();
//If the user hasn't logged in then we should send him to the loginpage.
if (!$user->IsLoggedIn())
header("Location: index.php");
//If the user hasn't selected any nodes then we should send him to the page where he can select nodes.
elseif (!List($network_id, $network_name) = $network->FetchRow($network->GetNetworks($user->GetUserID())))
header("Location: selnodes.php");
if($HTTP_GET_VARS && $user->IsAdmin() == TRUE)
{
$network_id = $HTTP_GET_VARS["network_id"];
$node_id = $HTTP_GET_VARS["node_id"];
$connection_id = $HTTP_GET_VARS["connection_id"];
if($network_id != 0)
$network->RemoveClientsOnNetwork($network_id);
elseif($node_id != 0)
$network->RemoveClientsOnNode($node_id);
elseif($connection_id != 0)
$network->RemoveClient($connection_id);
}
if($user->IsAdmin())
$clientpop_height = "370";
else
$clientpop_height = "280";
//Print client overview för $node_id
function UpdateUsageLog(){
$user = new User();
$luser_name = $user->GetUserName();
$user->usageLog($luser_name);
}
function PrintClientMatrix($node_id, $network, $user, $prefs)
{
$bgcolor = "bgcolor=\"#f6f6f6\"";
//New branch
print "['";
print "<table border=\"0\" width=\"462\" bgcolor=\"#ffffff\" cellpadding=\"0\" cellspacing=\"0\">";
print "<tr>";
print "<td>";
print "<table border=\"0\" width=\"462\" cellpadding=\"1\" cellspacing=\"1\">";
//Variables used to format the table.
$column_counter = 1;
$number_of_columns = 4;
$client_count = $network->GetClientCount($node_id);
$result = $network->GetClients($node_id);
while (List($connection_id, $mac, $if_name, $node_id, $alias, $sig_alarm_level, $noise_alarm_level, $sig_alarm_active, $noise_alarm_active, $locsig, $locnoi, $remsig, $remnoi, $status) = $network->FetchRow($result))
{
$tooltip = 'Alias: '."$alias".'\\\nName: '."$if_name".'\\\\nMAC-address: '."$mac".'\\\\nLocal signal level: '."$locsig".'\\\\nLocal noise level: '."$locnoi".'\\\nRemote signal level: '."$remsig".'\\\nRemote noise level: '."$remnoi".'\\\nSignal alarm level: '."$sig_alarm_level".'\\\nNoise alarm level: '."$noise_alarm_level".'\\\nStatus: '."$status";
$css_class = GetClientCssClass($status);
if ($prefs[0] == 'Y')
$tooltip_script = "onMouseover=\"showtip(this, event, \'$tooltip\')\" onMouseOut=\"hidetip()\"";
else
$tooltip_script = "";
$client_popup_script = "OnClick=\"Javascript: ClientPopup($connection_id)\"";
if($alias != "")
$connection_name = $alias;
else
$connection_name = $mac;
if($status == "Down")
{
$underline = "<u>";
$underline_end = "</u>";
}
else
{
$underline = "";
$underline_end = "";
}
//Check if we should start a new row
if ($column_counter == 1)
print "<tr>";
print "<td width=120 $bgcolor><a class=\"$css_class\" href=\"#\" $client_popup_script $tooltip_script>$underline"."$connection_name"."$underline_end</a></td>";
//Check if we should finish the row
if ($column_counter == $number_of_columns)
{
$column_counter = 1;
print "</tr>";
}
else
$column_counter++;
}
//Fill the gaps in the table with empty cells
while ($column_counter != 1)
{
print "<td width=\"120\" $bgcolor> </td>";
if ($column_counter == $number_of_columns)
{
$column_counter = 1;
print "</tr>";
}
else
$column_counter++;
}
//Finish the branch
print "</table>";
print "</td>";
print "</tr>";
print "</table>";
print "', '#', null";
print "],";
}
//Print clients för $node_id
function PrintClientTable($node_id, $network, $user, $prefs)
{
$bgcolor = "bgcolor=\"#f6f6f6\"";
//New branch
print "['";
print "<table border=\"0\" width=\"462\" bgcolor=\"#ffffff\" cellpadding=\"0\" cellspacing=\"0\">";
print "<tr>";
print "<td>";
print "<table border=\"0\" width=\"462\" cellpadding=\"1\" cellspacing=\"1\">";
//Header row
print "<tr>";
Print "<td width=\"150\" $bgcolor><u>Client</u></td>";
print "<td width=\"100\" $bgcolor><u>MAC</u></td>";
print "<td $bgcolor align=\"right\"><u>LS</u></td>";
print "<td $bgcolor align=\"right\"><u>RS</u></td>";
print "<td $bgcolor align=\"right\"><u>LN</u></td>";
print "<td $bgcolor align=\"right\"><u>RN</u></td>";
print "<td $bgcolor align=\"right\"><u>SAL</u></td>";
print "<td $bgcolor align=\"right\"><u>NAL</u></td>";
print "<td $bgcolor width=\"7\"><font color=\"red\"> </font></td>";
print "</tr>";
$result = $network->GetClients($node_id);
while (List($connection_id, $mac, $if_name, $node_id, $alias, $sig_alarm_level, $noise_alarm_level, $sig_alarm_active, $noise_alarm_active, $locsig, $locnoi, $remsig, $remnoi, $status) = $network->FetchRow($result))
{
$tooltip = 'Alias: '."$alias".'\\\nName: '."$if_name".'\\\\nMAC-address: '."$mac".'\\\\nLocal signal level: '."$locsig".'\\\\nLocal noise level: '."$locnoi".'\\\nRemote signal level: '."$remsig".'\\\nRemote noise level: '."$remnoi".'\\\nSignal alarm level: '."$sig_alarm_level".'\\\nNoise alarm level: '."$noise_alarm_level".'\\\nStatus: '."$status";
$button_tooltip_script = "onMouseover=\"showtip(this, event, \'Removes this client\')\"";
if ($prefs[0] == 'Y')
$tooltip_script = "onMouseover=\"showtip(this, event, \'$tooltip\')\" onMouseOut=\"hidetip()\"";
else
$tooltip_script = "";
$client_popup_script = "OnClick=\"Javascript: ClientPopup($connection_id)\"";
//Get the client css class
$css_class = GetClientCssClass($status);
if($status == "Down")
{
$underline = "<u>";
$underline_end = "</u>";
}
else
{
$underline = "";
$underline_end = "";
}
$local_signal_color = GetLocsigColor($sig_alarm_level, $locsig);
$local_noise_color = GetLocnoiColor($noise_alarm_level, $locnoi);
$remote_signal_color = GetRemsigColor($sig_alarm_level, $remsig);
$remote_noise_color = GetRemnoiColor($noise_alarm_level, $remnoi);
if($user->IsAdmin())
$button = "<a href=\"#\" onClick=\"javascript:ConfirmRemoveClient(0, 0, $connection_id)\" class=\"a_button\" $button_tooltip_script>clr</a>";
else
$button = " ";
if($alias != "")
$connection_name = $alias;
elseif($if_name != "")
$connection_name = $if_name;
else
$connection_name = "no name";
//Print client row
print "<tr>";
print "<td width=120 $bgcolor><a class=\"$css_class\" href=\"#\" $client_popup_script $tooltip_script>$underline"."$connection_name"."$underline_end</a></td>";
print "<td $bgcolor>$mac</td>";
if($locsig==0){
$locsig="---";
}
if($remsig==0){
$remsig="---";
}
if($locnoi==0){
$locnoi="---";
}
if($remnoi==0){
$remnoi="---";
}
print "<td $bgcolor align=\"right\"><font $local_signal_color>$locsig</font></td>";
print "<td $bgcolor align=\"right\"><font $remote_signal_color>$remsig</font></td>";
print "<td $bgcolor align=\"right\"><font $local_noise_color>$locnoi</font></td>";
print "<td $bgcolor align=\"right\"><font $remote_noise_color>$remnoi</font></td>";
print "<td $bgcolor align=\"right\">$sig_alarm_level</td>";
print "<td $bgcolor align=\"right\">$noise_alarm_level</td>";
print "<td $bgcolor align=\"right\" width=\"15\">$button</td>";
print "</tr>";
}
//Finish the branch
print "</table>";
print "</td>";
print "</tr>";
print "</table>";
print "', '#', null";
print "],";
}
function PrintClients($node_id, $network, $user, $prefs)
{
$bgcolor = "bgcolor=\"#f3f3f3\"";
if ($prefs[1] == "All")
{
//Matrix with a client in each cell.
print "['";
print "<table border=\"0\" width=\"463\" $bgcolor cellpadding=\"0\" cellspacing=\"0\">";
print "<tr>";
print "<td>Overview</td>";
print "</tr>";
print "</table>";
print "', null, null,";
PrintClientMatrix($node_id, $network, $user, $prefs);
print "],";
//Table with a client on each row.
print "['";
print "<table border=\"0\" width=\"463\" $bgcolor cellpadding=\"0\" cellspacing=\"0\">";
print "<tr>";
print "<td>Details</td>";
print "</tr>";
print "</table>";
print "', null, null,";
PrintClientTable($node_id, $network, $user, $prefs);
print "],";
}
elseif ($prefs[1] == "Details")
{
PrintClientTable($node_id, $network, $user, $prefs);
}
elseif ($prefs[1] == "Overview")
{
PrintClientMatrix($node_id, $network, $user, $prefs);
}
}
//Print nodes for each network.
function PrintNodes($network_id, $network, $user, $prefs)
{
$bgcolor = "bgcolor=\"#eaeaea\"";
$result = $network->GetNodes($user->GetUserID(), $network_id);
while (List($node_id, $parent_node_id, $node_name, $node_pass, $node_ip, $location, $monitor, $log, $signal, $alarm, $node_type_name, $network_name) = $network->FetchRow($result))
{
$status = $network->GetNodeStatus($node_id);
$css_class = GetNodeCssClass($status);
$status_text = GetNodeStatusText($status);
$clients_up = $network->GetClientsUpCount($node_id);
$clients_dn = $network->GetClientsDnCount($node_id);
$clients_wn = $network->GetClientsWnCount($node_id);
if($status == 0)
{
if($clients_up == 0)
$clients_up_text = " ";
else
$clients_up_text = $clients_up."up";
if($clients_dn == 0)
$clients_dn_text = " ";
else
$clients_dn_text = $clients_dn."dn";
if($clients_wn == 0)
$clients_wn_text = " ";
else
$clients_wn_text = $clients_wn."wn";
}
else
{
$clients_up_text = "";
$clients_dn_text = "";
$clients_wn_text = "";
if($clients_up == 0)
$clients_up_text = " ";
else
$clients_up_text = $clients_up."up";
if($clients_dn == 0)
$clients_dn_text = " ";
else
$clients_dn_text = $clients_dn."dn";
if($clients_wn == 0)
$clients_wn_text = " ";
else
$clients_wn_text = $clients_wn."wn";
}
$tooltip = 'Name: '."$node_name".'\\\nIP-address: '."$node_ip".'\\\nNode type: '."$node_type_name".'\\\nClients: '."$clients_up".'up, '."$clients_dn".'dn, '."$clients_wn".'wn\\\nStatus: '."$status_text".'\\\nLocation: '."$location";
if ($prefs[0] == 'Y')
$tooltip_script = "onMouseover=\"showtip(this, event, \'$tooltip\')\" onMouseOut=\"hidetip()\"";
else
$tooltip_script = "";
$button_tooltip_script = "onMouseover=\"showtip(this, event, \'Removes all clients for this node\')\" onMouseOut=\"hidetip()\"";
$node_popup_script = "OnClick=\"Javascript: NodePopup(\'$node_id\');\"";
$client_count = $network->GetClientCount($node_id);
if($user->IsAdmin() && $client_count > 0 && $status == 0)
$button = "<a href=\"#\" onClick=\"javascript:ConfirmRemoveClient(0, $node_id, 0)\" class=\"a_button\" $button_tooltip_script>clr</a>";
else
$button = " ";
print "['";
print "<table border=\"0\" width=\"479\" $bgcolor cellpadding=\"0\" cellspacing=\"0\">";
print "<tr>";
print "<td width=\"116px\"><a class=\"$css_class\" href=\"#\" $node_popup_script $tooltip_script>$node_name</a></td>";
print "<td width=\"100px\"><b>$node_ip</b></td>";
print "<td width=\"100px\">$node_type_name</td>";
print "<td width=\"40px\" class=\"td_client_up_count\">$clients_up_text</td>";
print "<td width=\"40px\" class=\"td_client_dn_count\">$clients_dn_text</td>";
print "<td width=\"40px\" class=\"td_client_wn_count\">$clients_wn_text</td>";
print "<td width=\"15\">$button</td>";
print "</tr>";
print "</table>";
print "', null, null,";
if($status == 0 && $client_count != 0)
PrintClients($node_id, $network, $user, $prefs);
if($status > 0 && $client_count != 0)
PrintClients($node_id, $network, $user, $prefs);
else
{
print "['";
print "<table border=\"0\" width=\"478\" $bgcolor cellpadding=\"0\" cellspacing=\"0\">";
print "<tr>";
print "<td>-</td>";
print "</tr>";
print "</table>";
print "', null, null,";
print "],";
}
print "],";
}
}
//Create newtwork branches.
function PrintNetworks($network, $user, $prefs)
{
$result = $network->GetNetworks($user->GetUserID());
while (List($network_id, $network_name) = $network->FetchRow($result))
{
$css_class = GetNetworkCssClass($network->GetNetworkStatus($network_id, $user->GetUserID()));
$nodes_up = $network->GetNodesUpCount($network_id, $user->GetUserID());
$nodes_dn = $network->GetNodesDnCount($network_id, $user->GetUserID());
if($nodes_up > 0)
$nodes_up_text = $nodes_up."up";
else
$nodes_up_text = " ";
if($nodes_dn > 0)
$nodes_dn_text = $nodes_dn."dn";
else
$nodes_dn_text = " ";
$button_tooltip_script = "onMouseover=\"showtip(this, event, \'Removes all clients for this network\')\" onMouseOut=\"hidetip()\"";
if($user->IsAdmin())
$button = "<a href=\"#\" onClick=\"javascript:ConfirmRemoveClient($network_id, 0, 0)\" class=\"a_button\" $button_tooltip_script>clr</a>";
else
$button = " ";
print "['";
print "<table border=\"0\" width=\"495\" bgcolor=\"#d7d7d7\" cellpadding=\"0\" cellspacing=\"0\">";
print "<tr>";
print "<td width=\"310px\" class=\"$css_class\">$network_name</td>";
print "<td width=\"40px\" class=\"td_node_up_count\">$nodes_up_text</td>";
print "<td width=\"40px\" class=\"td_node_dn_count\">$nodes_dn_text</td>";
print "<td width=\"40px\"> </td>";
print "<td width=\"15\">$button</td>";
print "</tr>";
print "</table>";
print "', null, null,";
PrintNodes($network_id, $network, $user, $prefs);
print "],";
}
}
//Create the treeview
function PrintTreeView($network, $user, $prefs)
{
//Start printing tree
print "var TREE_NODES = [";
PrintNetworks($network, $user, $prefs);
print "];";
}
function GetNetworkCssClass($status)
{
if($status == 0)
return "td_network";
return "td_network_alarm";
}
function GetNodeCssClass($status)
{
if($status == 0)
return "a_node_up";
else if($status == 1)
return "a_node_down";
else if($status == 2)
return "a_node_unknown";
}
function GetNodeStatusText($status)
{
if($status == 0)
return "Up";
else if($status == 1)
return "Down";
else if($status == 2)
return "Unknown";
}
function GetClientCssClass($status)
{
//Get the client css class
if($status == "OK")
return "a_client_up";
else if($status == "Critical")
return "a_client_warning";
else
return "a_client_down";
}
function GetLocsigColor($sig_alarm_level, $locsig)
{
if($sig_alarm_level != 0)
if($locsig <= $sig_alarm_level)
return "color=\"red\"";
return "color=\"black\"";
}
function GetLocnoiColor($noise_alarm_level, $locnoi)
{
if($noise_alarm_level != 0)
if(($locnoi >= $noise_alarm_level) &( $locnoi < 0))
return "color=\"red\"";
return "color=\"black\"";
}
function GetRemsigColor($sig_alarm_level, $remsig)
{
if($sig_alarm_level != 0)
if($remsig <= $sig_alarm_level)
return "color=\"red\"";
return "color=\"black\"";
}
function GetRemnoiColor($noise_alarm_level, $remnoi)
{
if($noise_alarm_level != 0)
if(($remnoi >= $noise_alarm_level)&($remnoi < 0))
return "color=\"red\"";
return "color=\"black\"";
}
// Returns the browser that the user uses.
function GetBrowser()
{
if((ereg("Nav", getenv("HTTP_USER_AGENT"))) ||
(ereg("Gold", getenv("HTTP_USER_AGENT"))) ||
(ereg("X11", getenv("HTTP_USER_AGENT"))) ||
(ereg("Mozilla", getenv("HTTP_USER_AGENT"))) ||
(ereg("Netscape", getenv("HTTP_USER_AGENT"))) AND
(!ereg("MSIE", getenv("HTTP_USER_AGENT"))))
return "Netscape";
elseif(ereg("MSIE", getenv("HTTP_USER_AGENT")))
return "MSIE";
return "Other";
}
?>
<html>
<head>
<title>WaveWatcher Network monitor</title>
<link href="css/tree.css" rel="styleSheet" type="text/css">
<link href="css/monitor.css" rel="styleSheet" type="text/css">
<script language="JavaScript" src="js/tooltip.js"></script>
<script language="JavaScript" src="js/tree_format.js"></script>
<script language="JavaScript" src="js/nostree.js"></script>
<script language="JavaScript">
function NodePopup(node_id)
{
window.open("nodepop.php?node_id=" + node_id, "_blank", "height=350,width=320, status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no");
}
function ClientPopup(connection_id)
{
window.open("clientpop.php?connection_id=" + connection_id, "_blank", "height=<?=$clientpop_height?>,width=340,status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no");
}
function RemoveClient(network_id, node_id, connection_id)
{
var str = "monitor.php?opennodes=";
var expandedNodes = NTrees['Tree'].getExpandedNodes();
for (var i=0; i<expandedNodes.length; i++)
str+='' + expandedNodes[i] + ',';
document.location.href = str + "&network_id=" + network_id + "&node_id=" + node_id + "&connection_id=" + connection_id;
}
function ConfirmRemoveClient(network_id, node_id, connection_id)
{
if(confirm("Are you sure you want to remove the client(s)?"))
{
RemoveClient(network_id, node_id, connection_id);
}
}
function HideLoadingText()
{
var hideItem = null;
if (document.getElementById)
hideItem = document.getElementById('waitDiv').style;
else if (document.all)
hideItem = document.all['waitDiv'].style;
else if (document.layers)
hideItem = document.layers['waitDiv'];
hideItem.visibility = 'hidden';
}
function Update()
{
var str = "monitor.php?opennodes=";
var expandedNodes = NTrees['Tree'].getExpandedNodes();
for (var i=0; i<expandedNodes.length; i++)
str+='' + expandedNodes[i] + ',';
document.location.href = str;
}
</script>
</head>
<!-- <body onload="setTimeout('Update()',300000)"> -->
<body>
<!-- Needed for Tooltip -->
<div id="tooltip" style="position:absolute;visibility:hidden;z-index:10000"></div>
<? include("menuinclude.php");?>
<div id="waitDiv" style="position:absolute;">Please wait, the page is loading...</div>
<!-- Generate Tree -->
<script language="JavaScript">
<? PrintTreeView($network, $user, $prefs);?>
// Create FolderView
var treeName = "Tree";
new NosTree (treeName, TREE_NODES, TREE_FORMAT);
//NTrees['Tree'].expandNode(12);
<?
// update the usage log table
UpdateUsageLog();
if (isset($opennodes))
{
$index = explode(",", $opennodes);
for ($i = 0; $i < count($index); $i++)
{
print "NTrees['Tree'].expandNode(".$index[$i].");";
}
}
// update the usage log table
?>
HideLoadingText();
</script>
<table width="514" border=0>
<tr>
<td align="right">
<?
if ($user->IsAdmin())
{
print "<a href=\"addnetwork.php\">add network</a> | ";
print "<a href=\"addnode.php\">add node</a> | ";
print "<a href=\"editnetwork.php\">edit network</a> | ";
print "<a href=\"editnode.php\">edit node</a> | ";
print "<a href=\"delnetwork.php\">delete network</a> | ";
print "<a href=\"delnode.php\">delete node</a> | ";
}
?>
<a href="javascript:Update()">reload page</a>
</td>
</tr>
</table>
</body>
</html>