floormap.php3 3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Wireless Node Map");

#
# Only admin people for now.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);

# Careful with this local variable
unset($prefix);

24
#
25 26
# Verify page arguments. For now, just default to MEB since thats the only
# place we have wireless nodes!
27 28 29
# 
if (!isset($building) ||
    strcmp($building, "") == 0) {
30
    $building = "MEB";
31 32 33 34 35 36 37 38 39 40 41
}
# 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.");
}

42 43 44 45 46 47 48 49 50
#
# Run the script. It will produce two output files; an image and an areamap.
# We want to embed both of these images into the page we send back. This
# is painful!
#
# Need cleanup "handler" to make sure temp files get deleted! 
#
function CLEANUP()
{
51 52 53
    global $prefix;
    
    if (isset($prefix) && (connection_aborted())) {
54 55 56 57 58 59 60 61 62 63 64 65
	unlink("${prefix}.png");
	unlink("${prefix}.map");
	unlink($prefix);
    }
    exit();
}
register_shutdown_function("CLEANUP");

#
# Create a tempfile to use as a unique prefix; it is not actually used but
# serves the same purpose (the script uses ${prefix}.png and ${prefix}.map)
# 
66
$prefix = tempnam("/tmp", "floormap");
67

68 69 70 71 72 73 74 75 76 77
#
# Get the unique part to send back.
#
if (!preg_match("/^\/tmp\/([-\w]+)$/", $prefix, $matches)) {
    TBERROR("Bad tempnam: $prefix", 1);
}
$uniqueid = $matches[1];

$retval = SUEXEC("nobody", "nobody", "webfloormap -o $prefix " .
		 (isset($floor) ? "-f $floor " : "") . "$building",
78 79 80
		 SUEXEC_ACTION_IGNORE);

if ($retval) {
81
    SUEXECERROR(SUEXEC_ACTION_USERERROR);
82 83 84 85 86 87 88 89 90 91 92 93
    # Never returns.
    die("");
}

#
# Spit the areamap contained in the file out; it is fully formatted and
# called "floormap".
#
if (! readfile("${prefix}.map")) {
    TBERROR("Could not read ${prefix}.map", 1);
}

94 95 96 97
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";

98 99
# And the img ...
echo "<center>
100 101
      <table class=nogrid align=center border=0 vpsace=5
             cellpadding=6 cellspacing=0>
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
      <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>
118
      Click on the dots below to see information about the node
119
      <img src=\"floormap_aux.php3?prefix=$uniqueid\" usemap=\"#floormap\">
120 121
      </center>\n";

122

123 124 125 126 127
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>