<?
require_once("../classes/user.php");
require_once("../classes/network.php");
session_start();
//User have entered a name that already exists in the database.
$exists = false;
$err_code = "unknown";
$new_node = "";
$sel_node = "";
$sel_network = "";
$sel_parentnode = "";
$sel_node_type = "";
$ip_address = "";
$location = "";
$sel_monitor = "";
$sel_log = "";
$sel_signal = "";
$sel_alarm = "";
$password = "";
$process_id = "";
//Look if the page have been posted
if ($HTTP_POST_VARS)
{
$new_node = $HTTP_POST_VARS["newNode"];
$sel_node = $HTTP_POST_VARS["selNode"];
$sel_network = $HTTP_POST_VARS["selNetwork"];
$sel_parentnode = $HTTP_POST_VARS["selParentNode"];
$sel_node_type = $HTTP_POST_VARS["selNodeTypes"];
$ip_address = $HTTP_POST_VARS["ip_address"];
$location = $HTTP_POST_VARS["location"];
$sel_monitor = $HTTP_POST_VARS["selMonitor"];
$sel_log = $HTTP_POST_VARS["selLog"];
$sel_signal = $HTTP_POST_VARS["selSignal"];
$sel_alarm = $HTTP_POST_VARS["selAlarm"];
$password = $HTTP_POST_VARS["password"];
$type_submit = $HTTP_POST_VARS["type_submit"];
$sel_process_id = $HTTP_POST_VARS["selProcess_idTypes"];
if($sel_node == "N/A")
{
$new_node = "N/A";
$ip_address = "N/A";
$location = "N/A";
$password = "";
$sel_monitor = "Y";
$sel_log = "Y";
$sel_network = "";
$sel_node_type = "";
$process_id = "";
}
if( !empty($sel_node) && $sel_node != "N/A" && $type_submit == -1)
{
$user = new User();
$network = new Network();
$dbcn = new DBConnection();
$node_details = $network->GetNodeDetails($sel_node);
List($node_type_id, $network_id, $parent_node_id, $node_name, $node_pass, $node_ip, $location, $monitor, $log, $signal, $alarm, $node_type_name, $network_name, $process_id) = $dbcn->FetchRow($node_details);
$new_node = $node_name;
$ip_address = $node_ip;
$location = $location;
$password = $node_pass;
$sel_monitor = $monitor;
$sel_log = $log;
$sel_signal = $signal;
$sel_alarm = $alarm;
$sel_network = $network_id;
$sel_parentnode = $parent_node_id;
if($sel_parentnode ==0){
$sel_parentnode = -1;
}
$sel_node_type = $node_type_id;
$sel_process_id = $process_id;
}
//Try to edit a new network
if( !empty($new_node) && $type_submit == 1 && $sel_node != "N/A")
{
$exists = false;
$user = new User();
$network = new Network();
$dbcn = new DBConnection();
$node_result = $network->GetNodeNamesAndIDs();
while( List($node_id, $node_name) = $dbcn->FetchRow($node_result) )
{
if($node_name == $new_node && $node_id != $sel_node )
{
$exists = true;
}
}
if(!$exists)
{
if(!FindSqlSyntax($new_node) && $new_node != "")
{
if(!FindSqlSyntax($ip_address) && $ip_address != "")
{
if(!FindSqlSyntax($location) && $location != "")
{
if(!FindSqlSyntax($password) && $password != "")
{
$network->DelNode($sel_node);
}
else
{
$exists = true;
$err_code = "password is incorrect";
}
}
else
{
$exists = true;
$err_code = "location is incorrect";
}
}
else
{
$exists = true;
$err_code = "IP-address is incorrect";
}
}
else
{
$exists = true;
$err_code = "node name is incorrect";
}
}
else
{
$err_code = "node name exists";
$exists = true;
}
}
else
{
//$exists = true;
//$err_code = "node name is incorrect";
}
}
//Creates a user object
$user = new User();
//If we haven't logged in as a admin we should redirect to another page.
if (!$user->IsLoggedIn() || !$user->IsAdmin())
{
header("Location: index.php");
}
// check so that no unwanted SQL querys are inside the strings
function FindSqlSyntax($str)
{
$str = strtoupper($str);
if (strpos($str,"SELECT") === FALSE && strpos($str,"UPDATE") === FALSE && strpos($str,"INSERT") === FALSE && strpos($str,"DELETE") === FALSE)
return FALSE;
else
return TRUE;
}
function createOptionNodes()
{
$user = new User();
$networks = new Network();
$dbcn = new DBConnection();
//
// THIS CODE GENERATES NODES DROPDOWN LIST.
//
$node_result = $networks->GetNodeNamesAndIDs();
while( List($node_id, $node_name) = $dbcn->FetchRow($node_result) )
{
if(!empty($GLOBALS[sel_node]) && $GLOBALS[sel_node] == $node_id)
{
print "<option selected value=\"$node_id\">$node_name</option>\n";
}
else
{
print "<option value=\"$node_id\">$node_name</option>\n";
}
}
//
// END OF NODES DROPDOWN
//
}
function createOptionNetworks()
{
$user = new User();
$networks = new Network();
$dbcn = new DBConnection();
//
// THIS CODE GENERATES THE EXISTING NETWORK DROPDOWN LIST.
//
if($GLOBALS[sel_network]==""){
print "<input textarea readonly style=\"WIDTH: 100%\">\n";
}
$network_result = $networks->GetNetworks(0, "yes");
while( List($network_id, $network_name) = $dbcn->FetchRow($network_result) )
{
if(!empty($GLOBALS[sel_network]) && $GLOBALS[sel_network] == $network_id)
{
print "<input textarea readonly value=\"$network_name\" style=\"WIDTH: 100%\">\n";
}
}
//
// END OF EXISTING NETWORK
//
}
function createOptionParentNode()
{
$user = new User();
$networks = new Network();
$dbcn = new DBConnection();
//
// THIS CODE GENERATES THE EXISTING NODES DROPDOWN LIST.
//
if($GLOBALS[sel_parentnode]=="")
{
print "<input textarea readonly style=\"WIDTH: 100%\">\n";
}
if($GLOBALS[sel_parentnode] == -1)
{
print "<input textarea readonly value=\"No parent node\" style=\"WIDTH: 100%\">\n";
}
$node_result = $networks->GetNodeNamesAndIDs();
while( List($node_id, $node_name) = $dbcn->FetchRow($node_result) )
{
#if(!empty($GLOBALS[sel_parentnode]) && $GLOBALS[sel_parentnode] == $node_id)
if($GLOBALS[sel_parentnode] == $node_id)
{
print "<input textarea readonly value=\"$node_name\" style=\"WIDTH: 100%\">\n";
}
}
//
// END OF EXISTING NODE
//
}
function createOptionTypes()
{
$user = new User();
$networks = new Network();
$dbcn = new DBConnection();
//
// THIS CODE GENERATES THE EXISTING NODE TYPES DROPDOWN LIST.
//
if($GLOBALS[sel_node_type]=="")
{
print "<input textarea readonly style=\"WIDTH: 100%\">\n";
}
$node_types_result = $networks->GetNodeTypes();
while( List($node_type_id, $node_type_name, $interface) = $dbcn->FetchRow($node_types_result) )
{
if(!empty($GLOBALS[sel_node_type]) && $GLOBALS[sel_node_type] == $node_type_id)
{
print "<input textarea readonly value=\"$node_type_name\" style=\"WIDTH: 100%\">\n";
}
}
//
// END OF EXISTING NODE TYPES
//
}
function createProcess_idTypes()
{
$user = new User();
$networks = new Network();
$dbcn = new DBConnection();
//
// THIS CODE GENERATES THE EXISTING PROCESS ID TYPES DROPDOWN LIST.
//
if($GLOBALS[sel_process_id]=="")
{
print "<input textarea readonly style=\"WIDTH: 100%\">\n";
}
$process_id_types_result = $networks->GetProcess_idTypes();
while( List($locprocess_id) = $dbcn->FetchRow($process_id_types_result) )
{
if(!empty($GLOBALS[sel_process_id]) && $GLOBALS[sel_process_id] == $locprocess_id)
{
print "<input type=\"text\" readonly value=\"$locprocess_id\" style=\"WIDTH: 100%\">\n";
}
}
//
// END OF EXISTING process id
//
}
function setIP()
{
if(!empty($GLOBALS[ip_address]))
{
return $GLOBALS[ip_address];
}
else
{
return "";
}
}
function setLocation()
{
if(!empty($GLOBALS[location]))
{
return $GLOBALS[location];
}
else
{
return "";
}
}
function setNodeName()
{
if(!empty($GLOBALS[new_node]))
{
return $GLOBALS[new_node];
}
else
{
return "";
}
}
function setPassword()
{
if(!empty($GLOBALS[password]))
{
return $GLOBALS[password];
}
else
{
return "";
}
}
function setMonitor($yes_no)
{
if(!empty($GLOBALS[sel_monitor]) && $yes_no == 'Y' && $GLOBALS[sel_monitor] == 'Y')
{
return "selected";
}
else if(!empty($GLOBALS[sel_monitor]) && $yes_no == 'N' && $GLOBALS[sel_monitor] == 'N')
{
return "selected";
}
else
{
return "";
}
}
function setLog($yes_no)
{
if(!empty($GLOBALS[sel_log]) && $yes_no == 'Y' && $GLOBALS[sel_log] == 'Y')
{
return "selected";
}
else if(!empty($GLOBALS[sel_log]) && $yes_no == 'N' && $GLOBALS[sel_log] == 'N')
{
return "selected";
}
else
{
return "";
}
}
function setSignal($yes_no)
{
if(!empty($GLOBALS[sel_signal]) && $yes_no == 'Y' && $GLOBALS[sel_signal] == 'Y')
{
return "selected";
}
else if(!empty($GLOBALS[sel_signal]) && $yes_no == 'N' && $GLOBALS[sel_signal] == 'N')
{
return "selected";
}
else
{
return "";
}
}
function setAlarm($yes_no)
{
if(!empty($GLOBALS[sel_alarm]) && $yes_no == 'Y' && $GLOBALS[sel_alarm] == 'Y')
{
return "selected";
}
else if(!empty($GLOBALS[sel_alarm]) && $yes_no == 'N' && $GLOBALS[sel_alarm] == 'N')
{
return "selected";
}
else
{
return "";
}
}
function showErr()
{
return $GLOBALS[err_code];
}
?>
<html>
<head>
<title>Wavewatcher Edit Node</title>
<link href="css/style1.css" rel="styleSheet" type="text/css">
<script language="Javascript">
function CheckSelect()
{
//document.forms("edit_node").item("type_submit").value = -1;
document.edit_node.type_submit.value = -1;
document.edit_node.submit();
}
function AskConfirm()
{
var bQuestion = confirm("Are you sure you want to delete this node?");
if(bQuestion)
{
//document.forms("edit_node").item("type_submit").value = 1;
document.edit_node.type_submit.value = 1;
document.edit_node.submit();
}
}
</script>
</head>
<body bgcolor="#ffffff">
<table width = "100%" height=20 align="center" border=0 cellpadding="0" cellspacing="0">
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size=1 color="#000000"><b>Wavewatcher</b></font></td>
<td align=right>
<a href="home.php">home</a> |
<a href="monitor.php">monitor network</a> |
<a href="profile.php">profile</a> |
<? if ($user->IsAdmin())
print "<a href=\"procsetup.php\">process setup</a> | ";
?>
<? if ($user->IsAdmin())
print "<a href=\"sconfig.php\">configure server</a> | ";
?>
<a href="help.html" target="_blank">help</a> |
<a href="logout.php">logout</a>
</td>
</tr>
</table>
<form name="edit_node" method="post">
<table width = "50%" height="80%" align="center" border="0">
<tr>
<td>
<!-- background table -->
<table width="350" align="center" border="0" cellspacing="1" cellpadding="0" bgcolor="#000000">
<tr>
<td>
<!-- gui table -->
<table width="350" border="0" cellspacing="1" cellpadding="2">
<!-- title row -->
<tr>
<td bgcolor="#515173">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">
<b>Delete Node</b>
</font>
</td>
</tr>
<!-- message row -->
<?
if (!$exists)
{
?>
<!-- message row -->
<tr>
<td bgcolor="#c0c0c0">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
Select a node you want to delete.
</font>
</td>
</tr>
<?
}
else
{
?>
<tr>
<td bgcolor="#FC4848">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
There is an error.<br>
Error code: <? echo showErr() ?>
</font>
</td>
</tr>
<?
}
?>
<!-- edit node -->
<tr bgcolor="#fcfcfc">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td align="left">
<select name="selNode" style="WIDTH: 100%" onchange="javascript:CheckSelect()">
<option value="N/A">- - - - SELECT NODE - - - -</option>
<? createOptionNodes() ?>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#fcfcfc">
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
Node Name:
</font>
</td>
<td align="left">
<input type="text" readonly size="40" name="newNode" value="<? echo setNodeName() ?>">
</td>
</tr>
<tr>
<td align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
Network:
</font>
</td>
<td align="left">
<? createOptionNetworks() ?>
</select>
</td>
</tr>
<tr>
<td align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
Parent Node:
</font>
</td>
<td align="left">
<? createOptionParentNode() ?>
</select>
</td>
</tr>
<tr>
<td align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
Node Type:
</font>
</td>
<td>
<? createOptionTypes() ?>
</select>
</td>
</tr>
<tr>
<td align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
Process id:
</font>
</td>
<td>
<? createProcess_idTypes()?>
</select>
</td>
</tr>
<tr>
<td align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
IP Address:
</font>
</td>
<td>
<input type="text" readonly name="ip_address" size="40" value="<? echo setIP() ?>">
</td>
</tr>
<tr>
<td align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
Location:
</font>
</td>
<td >
<input type="text" readonly name="location" size="40" value="<? echo setLocation() ?>">
</td>
</tr>
<tr>
<td align="right">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">
Password:
</font>
</td>
<td>
<input type="password" readonly name="password" size="40" value="<? echo setPassword() ?>">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input onClick="javascript:AskConfirm()" name="createBtn" type="button" value="Remove this node from the database">
<input type="hidden" name="type_submit" value="-1">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
</td>
</tr>
</table>
</form>
</body>
<html>