My overall goal with this is to save new or update existing xml files on our web server. This is in a relatively locked down environment in that unless you are working in our lab, there is no network access to this web servers...because of this I am not worried about the security side of how I am implementing the php portion (I'm aware that I can pass any argument and it will hypothetically change files on the server...I am OKAY with this).
This is stictly a proof of concept for this project I am working on...
The quick explanation of what we are doing is creating a web frontend visualizer and management tool for TinyOS/TOSSIM simulations. Because I can't integrate TinyOS with the webserver directly, I'm having to use XML files to transfer information between the two frameworks. Pulling the XML information into the web server is, using javascript, easy and already implemented/working.
Saving files though is not so trivial. We have up to 16 wireless nodes that may get updated at the same time using the same command and value so I wouldn't quite be having a problem if I could update a single node at a time....so instead of expecting:
Managepane.php?node=node5&command=setRFPower&value=18
I may need to consider and expect:
Managepane.php?node=node5&node=node6&node=node7&command=setRFPower&value=18";
Now, I am unsure if this is possible to list multiples of 'node' all in one swoop - so I'm wondering if I can pass a single String of EVERYTHING.
Unless there is an easier way to just 'get this working' I am wanting to send a string of the full XML file as arguments to the php file. I am having major issues getting even portions of this. I've tried using the func_get_args() function to get an array of commands - this doesnt seem to be working. I've also tried to use individual arguments like argv[0],1,2 etc...
Any help would be greatly appreciated. I've commented out stuff within the php but glancing through that it should be pretty obvious what I am trying to accomplish. I have everything EXCEPT getting the correct argument(s) working...
Filename: Managepane.php
Code: Select all
<?php
//if (count($argv) > 0) for ($i = 0; i < count($argv); i++)
$argList = func_get_args();
print count($argList); // count always shows 1
/*
$xmlstr = $xml;
if ($xmlstr != "") {
$dom = new domDocument;
$dom->loadXML($xmlstr);
$test = $dom->save("C:/Panorama/Modified.xml");
echo "Written String : ".$xmlstr;
print $xmlstr;
}
*/
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<!--<title>Untitled Page</title>-->
<link href="panoramaStyles.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
function init()
{
populateMoteInformation();
}
function populateMoteInformation()
{
//load xml file
var xmlDoc=null;
if (window.ActiveXObject) xmlDoc=new ActiveXObject("Microsoft.XMLDOM");//IE
else if (document.implementation.createDocument) xmlDoc=document.implementation.createDocument("","",null); //Mozilla
else alert('Your browser cannot handle this script');
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("menu.xml");
var x= xmlDoc.getElementsByTagName("Node");
if(x.length > 0 )
{
var nodeList = '<label style="vertical-align: top">Select node(s) : </label><select id="nodes" multiple="multiple" size="4" style="font-family: Tahoma; font-size: 12px; width: 120px">'
for (i=0;i<x.length;i++)
{
nodeList = nodeList + '<option value="Node' + x[i].getElementsByTagName("moteID")[0].childNodes[0].nodeValue + '">'
+ 'Node ' + x[i].getElementsByTagName("moteID")[0].childNodes[0].nodeValue + '</option>';
}
document.getElementById('divNodes').innerHTML = nodeList + '</select>';
}
xmlDoc.load("rpcCommands.xml");
var x= xmlDoc.getElementsByTagName("RpcCommand");
if(x.length > 0 )
{
var rpcCommandList = '<label style="vertical-align: top">Rpc Commands : </label><select id="commands" style="font-family: Tahoma; font-size: 12px; width: 120px">'
for (i=0;i<x.length;i++)
{
rpcCommandList = rpcCommandList + '<option value="' + x[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue + '">'
+ x[i].getElementsByTagName("Name")[0].childNodes[0].nodeValue + '</option>';
}
document.getElementById('divCommands').innerHTML = rpcCommandList + '</select>';
}
}
}
function ReturnXMLString() {
var xml = "";
for (var i = 0; i < document.getElementById("nodes").options.length; i++) {
var comm = document.getElementById("commands").value;
var val = document.getElementById("value").value;
if (document.getElementById("nodes").options[i].selected) {
var node = document.getElementById("nodes").options[i].value;
xml += " <" + node + ">\n";
xml += " <" + comm + ">" + val + "</" + comm + ">\n";
xml += " </" + node + ">\n";
}
}
var runPath = "Managepane.php?" + xml; // actual data to be passed as arguments
document.getElementById("Output").value = runPath;
//parent.location.href = runPath;
// lets hardcode some data and see if we can get it working with this...
parent.location.href = "Managepane.php?node=node5&command=setRFPower&value=18";
}
</script>
</head>
<body class="FullSize" onload="init()">
<table cellpadding="2" cellspacing="2" style="font-family: Tahoma; font-size: 12px">
<tr>
<td valign='top' style="height: 100%; width: 100%">
<div id="divNodes">
</div>
</td>
</tr>
<tr>
<td valign='top' style="height: 100%; width: 100%">
<div id="divCommands">
</div>
</td>
</tr>
<tr>
<td valign='top' style="height: 100%; width: 100%">
New Value : <input type="text" id="value" name="value" /></td>
</tr>
<tr>
<td valign='top' style="height: 100%; width: 100%">
<input type="submit" value="Modify" onclick='ReturnXMLString();' />
</td>
</tr>
</table>
<form><textarea id="Output" style="width:100%" rows="10"></textarea></form>
</body>
</html>