floormap.php3 2.8 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 24 25 26
<?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);
if (! $isadmin) {
    USERERROR("You do not have permission to view this page!", 1);
}

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

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#
# Verify page arguments.
# 
if (!isset($building) ||
    strcmp($building, "") == 0) {
    PAGEARGERROR("Must provide a building and an optional floor!");
}
# 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.");
}

44 45 46 47 48 49 50 51 52
#
# 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()
{
53 54 55
    global $prefix;
    
    if (isset($prefix) && (connection_aborted())) {
56 57 58 59 60 61 62 63 64 65 66 67
	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)
# 
68
$prefix = tempnam("/tmp", "floormap");
69

70 71 72 73 74 75 76 77 78 79
#
# 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",
80 81 82
		 SUEXEC_ACTION_IGNORE);

if ($retval) {
83
    SUEXECERROR(SUEXEC_ACTION_USERERROR);
84 85 86 87 88 89 90 91 92 93 94 95 96 97
    # 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);
}

# And the img ...
echo "<center>
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
      <table class=nogrid align=center border=0 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>
      <br><br>
      <img src=\"floormap_aux.php3?prefix=$uniqueid\" usemap=\"#floormap\">
117 118 119 120 121 122 123
      </center>\n";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>