Commit 31d48a9d authored by Leigh Stoller's avatar Leigh Stoller

Add map display of a particular experiment's wireless nodes via a

-e pid,eid option. When using -e, floor and building become optional, which
will restrict the display to just that building (and floor). Note that we
do not really have multiple building support yet, but we can pretend.
parent a36687a5
......@@ -7,15 +7,22 @@
use English;
use Getopt::Std;
#
# TODO: Deal with multiple buildings? Currently defaults to MEB!
#
sub usage {
print STDERR "Usage: plaything [-o <prefix>] [-f <floor>] <building>\n";
print STDERR "Usage: floormap [-o <prefix>] [-f <floor>] <building> or \n";
print STDERR "Usage: floormap [-o <prefix>] [-f <floor>] ";
print STDERR "[-e <pid,eid>] [<building>]\n";
exit(-1);
}
my $optlist = "df:o:";
my $building;
my $optlist = "df:o:e:";
my $building = "MEB";
my $floor;
my $debug;
my $image;
my $pid;
my $eid;
my @areamaps = ();
my $prefix = "/tmp/floormap";
......@@ -31,6 +38,15 @@ use lib '@prefix@/lib';
use libdb;
use GD;
#
# Hardwire the imagemaps for now.
#
my %baseimages = ();
$baseimages{"MEB"}{"4"} = "$TB/www/meb4fl.png";
$baseimages{"MEB"}{"3"} = "$TB/www/meb3fl.png";
#$baseimages{"MEB"}{"2"} = "$TB/www/meb2fl.png";
#$baseimages{"MEB"}{"1"} = "$TB/www/meb1fl.png";
#
# Turn off line buffering on output
#
......@@ -55,9 +71,6 @@ sub adjustmap($$$);
if (! getopts($optlist, \%options)) {
usage();
}
if (@ARGV != 1) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
......@@ -67,19 +80,46 @@ if (defined($options{"f"})) {
if (defined($options{"o"})) {
$prefix = $options{"o"};
}
$building = $ARGV[0];
#
# Hardwire the imagemaps for now.
#
my %baseimages = ();
$baseimages{"MEB"}{"4"} = "$TB/www/meb4fl.png";
$baseimages{"MEB"}{"3"} = "$TB/www/meb3fl.png";
#$baseimages{"MEB"}{"2"} = "$TB/www/meb2fl.png";
#$baseimages{"MEB"}{"1"} = "$TB/www/meb1fl.png";
if (defined($options{"e"})) {
if ($options{"e"} =~ /([-\w]*),([-\w]*)/) {
$pid = $1;
$eid = $2;
}
else {
die("*** $0:\n".
" Invalid argument to -e option!\n");
}
#
# Verify permission to view this experiment.
#
if ($UID && !TBAdmin($UID) &&
! TBExptAccessCheck($UID, $pid, $eid, TB_EXPT_READINFO)) {
die("*** $0:\n".
" You do not have permission to view $pid/$eid!\n");
}
#
# Optional building and floor (see above) for a specific experiment.
#
usage()
if (@ARGV > 1);
if (@ARGV) {
$building = $ARGV[0];
}
}
elsif (@ARGV != 1) {
usage();
}
else {
$building = $ARGV[0];
}
# Building must exist. Someday deal with multiple buildings.
if (!exists($baseimages{$building})) {
die("No such building: $building\n");
die("*** $0:\n".
" No such building: $building\n");
}
#
......@@ -217,11 +257,14 @@ sub dofloor($$)
my $nodeid = $rowref->{"node_id"};
my $x = $rowref->{"loc_x"};
my $y = $rowref->{"loc_y"};
my $pid = $rowref->{"pid"};
my $eid = $rowref->{"eid"};
my $rpid = $rowref->{"pid"};
my $reid = $rowref->{"eid"};
my ($x1,$y1,$x2,$y2);
if (!defined($pid)) {
# Without -e option, green means node is free.
# With -e option, green means node belongs to experiment.
if ((!defined($pid) && !(defined($rpid))) ||
(defined($pid) && defined($rpid) && $pid eq $rpid)) {
$x1 = $x - int($greendot_width / 2.0);
$y1 = $y - int($greendot_height / 2.0);
$x2 = $x1 + $greendot_width;
......@@ -230,7 +273,7 @@ sub dofloor($$)
$baseimage->copy($greendot, $x1, $y1, 0, 0,
$greendot_width, $greendot_height);
}
elsif ($pid eq NODEDEAD_PID() and $eid eq NODEDEAD_EID()) {
elsif ($rpid eq NODEDEAD_PID() and $reid eq NODEDEAD_EID()) {
$x1 = $x - int($reddot_width / 2.0);
$y1 = $y - int($reddot_height / 2.0);
$x2 = $x1 + $reddot_width;
......
......@@ -12,7 +12,7 @@ include("defs.php3");
PAGEHEADER("Wireless Node Map");
#
# Only admin people for now.
# Only logged in people at the moment; might open up at some point.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
......@@ -22,21 +22,50 @@ $isadmin = ISADMIN($uid);
unset($prefix);
#
# Verify page arguments. For now, just default to MEB since thats the only
# place we have wireless nodes!
#
if (!isset($building) ||
strcmp($building, "") == 0) {
$building = "MEB";
# Verify page arguments. First allow user to optionally specify building/floor.
#
if (isset($building) && $building != "") {
# Sanitize for the shell.
if (!preg_match("/^[-\w]+$/", $building)) {
PAGEARGERROR("Invalid building argument.");
}
# Optional floor argument. Sanitize for the shell.
if (isset($floor) && !preg_match("/^[-\w]+$/", $floor)) {
PAGEARGERROR("Invalid floor argument.");
}
}
# Sanitize for the shell.
if (!preg_match("/^[-\w]+$/", $building)) {
PAGEARGERROR("Invalid building argument.");
else {
unset($building);
unset($floor);
}
# Optional floor argument. Sanitize for the shell.
if (isset($floor) && !preg_match("/^[-\w]+$/", $floor)) {
PAGEARGERROR("Invalid floor argument.");
#
# 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 {
unset($pid);
unset($eid);
}
if (!isset($building) && !isset($pid)) {
PAGEARGERROR();
}
#
......@@ -73,8 +102,10 @@ if (!preg_match("/^\/tmp\/([-\w]+)$/", $prefix, $matches)) {
}
$uniqueid = $matches[1];
$retval = SUEXEC("nobody", "nobody", "webfloormap -o $prefix " .
(isset($floor) ? "-f $floor " : "") . "$building",
$retval = SUEXEC($uid, "nobody", "webfloormap -o $prefix " .
(isset($pid) ? "-e $pid,$eid " : "") .
(isset($floor) ? "-f $floor " : "") .
(isset($building) ? "$building" : ""),
SUEXEC_ACTION_IGNORE);
if ($retval) {
......@@ -95,30 +126,62 @@ echo "<font size=+1>For more info on using wireless nodes, see the
<a href='tutorial/docwrapper.php3?docname=wireless.html'>
wireless tutorial.</a></font><br><br>\n";
# And the img ...
echo "<center>
<table class=nogrid align=center border=0 vpsace=5
cellpadding=6 cellspacing=0>
<tr>
<td align=right>Free</td>
<td align=left><img src='/autostatus-icons/greenball.gif' alt=Free>
</td>
</tr>
<tr>
<td align=right>Reserved</td>
<td align=left><img src='/autostatus-icons/blueball.gif' alt=reserved>
</td>
</tr>
<tr>
<td align=right>Dead</td>
<td align=left><img src='/autostatus-icons/redball.gif' alt=Free>
</td>
</tr>
</table>
Click on the dots below to see information about the node
<img src=\"floormap_aux.php3?prefix=$uniqueid\" usemap=\"#floormap\">
</center>\n";
echo "<center>\n";
# Legend
if (isset($pid)) {
echo "Wireless nodes in experiment <b>".
"<a href='showproject.php3?pid=$pid'>$pid</a>/".
"<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b>\n";
echo "<table class=nogrid align=center border=0 vpsace=8
cellpadding=6 cellspacing=0>
<tr>
<td align=right>Experiment Nodes</td>
<td align=left>
<img src='/autostatus-icons/greenball.gif' alt=Experiment>
</td>
</tr>
<tr>
<td align=right>Other Nodes</td>
<td align=left>
<img src='/autostatus-icons/blueball.gif' alt=Other>
</td>
</tr>
<tr>
<td align=right>Dead</td>
<td align=left><img src='/autostatus-icons/redball.gif' alt=Dead>
</td>
</tr>
</table>
Click on the dots below to see information about the node\n";
}
else {
echo "<table class=nogrid align=center border=0 vpsace=5
cellpadding=6 cellspacing=0>
<tr>
<td align=right>Free</td>
<td align=left>
<img src='/autostatus-icons/greenball.gif' alt=Free>
</td>
</tr>
<tr>
<td align=right>Reserved</td>
<td align=left>
<img src='/autostatus-icons/blueball.gif' alt=reserved>
</td>
</tr>
<tr>
<td align=right>Dead</td>
<td align=left><img src='/autostatus-icons/redball.gif' alt=Dead>
</td>
</tr>
</table>
Click on the dots below to see information about the node\n";
}
# Image
echo "<img src=\"floormap_aux.php3?prefix=$uniqueid\" usemap=\"#floormap\">
</center>\n";
#
# Standard Testbed Footer
......
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