Commit 30667bc5 authored by Leigh Stoller's avatar Leigh Stoller

Pass around pid,eid (through the applet) so that the backend knows

what locpiper to connect to. Locpiper now binds a dynamic port, and
stores that into the DB, and the php script expects to get that pid,eid
back.

Changed the showexp page so that pid,eid are passed to the robotrack
top level page.

Changed the robotrack page so that if it does not get a pid,eid, it looks
for an experiment running (a locpiper). If none is running, let the applet
start of course, but there will be an error dialog when it starts. You can
still play with the applet of course. If there is more then one experiment
running, then just pick first one. At some point I might add a page to ask
which experiment, but its low priority.
parent b79de1cf
......@@ -253,7 +253,6 @@ if (!event_subscribe($handle, \&callbackFunc, $tuple)) {
#
$sock = IO::Socket::INET->new(Listen => 10,
LocalAddr => 'localhost',
LocalPort => 9005,
Reuse => 1,
Proto => 'tcp');
fatal("Could not create socket!")
......
......@@ -7,11 +7,46 @@
chdir("..");
include("defs.php3");
function SPITERROR($code, $msg)
{
header("HTTP/1.0 $code $msg");
exit();
}
#
# Only known and logged in users can watch LEDs
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$status = CHECKLOGIN($uid);
if (($status & CHECKLOGIN_LOGGEDIN) != CHECKLOGIN_LOGGEDIN) {
SPITERROR(401, "Not logged in");
}
#
# Optional pid,eid. Without a building/floor, show all the nodes for the
# experiment in all buildings/floors. Without pid,eid show all wireless
# nodes in the specified building/floor.
#
if (isset($pid) && $pid != "" && isset($eid) && $eid != "") {
if (!TBvalid_pid($pid)) {
SPITERROR(400, "Invalid project ID.");
}
if (!TBvalid_eid($eid)) {
SPITERROR(400, "Invalid experiment ID.");
}
if (! TBValidExperiment($pid, $eid)) {
SPITERROR(400, "The experiment $pid/$eid is not a valid experiment!");
}
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_READINFO)) {
USERERROR(401,
"You do not have permission to view experiment $pid/$eid!");
}
}
else {
SPITERROR(400, "Must supply pid and eid arguments");
}
#
# Verify page arguments. Allow user to optionally specify building/floor.
......@@ -19,11 +54,11 @@ LOGGEDINORDIE($uid);
if (isset($building) && $building != "") {
# Sanitize for the shell.
if (!preg_match("/^[-\w]+$/", $building)) {
PAGEARGERROR("Invalid building argument.");
SPITERROR(400, "Invalid building argument.");
}
# Optional floor argument. Sanitize for the shell.
if (isset($floor) && !preg_match("/^[-\w]+$/", $floor)) {
PAGEARGERROR("Invalid floor argument.");
SPITERROR(400, "Invalid floor argument.");
}
}
else {
......@@ -31,6 +66,20 @@ else {
$floor = 4;
}
#
# Need the locpiper port for this experiment.
#
$query_result =
DBQueryFatal("select locpiper_port from experiments ".
"where pid='$pid' and eid='$eid'");
if (!mysql_num_rows($query_result)) {
SPITERROR(400, "No such experiment!");
}
else {
$row = mysql_fetch_array($query_result);
$locpiper_port = $row["locpiper_port"];
}
# Initial goo.
header("Content-Type: text/plain");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
......@@ -86,10 +135,9 @@ register_shutdown_function("SPEWCLEANUP");
# Avoid PHP error reporting in sockopen that confuse the headers.
error_reporting(0);
$socket = fsockopen("localhost", 9005);
$socket = fsockopen("localhost", $locpiper_port);
if (!$socket) {
header("HTTP/1.0 404 Error opening locpiper socket - $errstr");
exit();
SPITERROR(404, "Error opening locpiper socket - $errstr");
}
while (! feof($socket)) {
......
......@@ -12,6 +12,46 @@ LOGGEDINORDIE($uid);
PAGEHEADER("Real Time Robot Tracking Applet");
#
# Optional pid,eid. Without a building/floor, show all the nodes for the
# experiment in all buildings/floors. Without pid,eid show all wireless
# nodes in the specified building/floor.
#
if (isset($pid) && $pid != "" && isset($eid) && $eid != "") {
if (!TBvalid_pid($pid)) {
PAGEARGERROR("Invalid project ID.");
}
if (!TBvalid_eid($eid)) {
PAGEARGERROR("Invalid experiment ID.");
}
if (! TBValidExperiment($pid, $eid)) {
USERERROR("The experiment $pid/$eid is not a valid experiment!", 1);
}
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_READINFO)) {
USERERROR("You do not have permission to view experiment $pid/$eid!",
1);
}
}
else {
#
# Else, we need to find whatever experiment is running. What if there
# is more then one? Good question; I do not have a plan for that yet!
#
$query_result =
DBQueryFatal("select pid,eid from experiments ".
"where locpiper_pid!=0 and locpiper_port!=0");
if (mysql_num_rows($query_result)) {
$row = mysql_fetch_array($query_result);
$pid = $row["pid"];
$eid = $row["eid"];
}
else {
unset($pid);
unset($eid);
}
}
#
# Verify page arguments. Allow user to optionally specify building/floor.
#
......@@ -127,7 +167,10 @@ $baseurl = "../floormap_aux.php3?prefix=$uniqueid";
# Temp for debugging.
if (isset($fake))
$pipeurl .= "&fake=yes";
$pipeurl .= "&fake=yes";
if (isset($pid) && isset($eid)) {
$pipeurl .= "&pid=$pid&eid=$eid";
}
echo "<applet name='tracker' code='RoboTrack.class'
archive='tracker.jar'
......
......@@ -247,7 +247,8 @@ if ($types['garcia'] || $types['static-mica2']) {
elseif ($expstate == $TB_EXPTSTATE_ACTIVE ||
$expstate == $TB_EXPTSTATE_ACTIVATING) {
WRITESUBMENUBUTTON("Tracker Applet",
"robotrack/robotrack.php3?");
"robotrack/robotrack.php3?".
"pid=$exp_pid&eid=$exp_eid");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment