nodeinfo.php3 3.36 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27
#
chdir("..");
include("defs.php3");

#
28
# Only known and logged in users.
29
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
33 34

#
35
# Verify page args
36
#
37 38 39
$optargs = OptionalPageArguments("building",      PAGEARG_STRING,
				 "floor",         PAGEARG_STRING);

40 41 42 43 44 45 46 47 48 49 50 51 52 53
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.");
    }
}
else {
    $building = "MEB-ROBOTS";
    $floor    = 4;
}
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

# Initial goo.
header("Content-Type: text/plain");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();

#
# Clean up when the remote user disconnects
#
function SPEWCLEANUP()
{
    exit(0);
}
register_shutdown_function("SPEWCLEANUP");

# Get the robot information. Actually, this includes motes.
$query_result =
73 74
    DBQueryFatal("select loc.node_id,r.pid,r.eid,r.vname,n.type,nt.class, ".
		 "       loc.loc_x,loc.loc_y,loc.loc_z,loc.orientation ".
75 76 77 78 79
		 "  from location_info as loc ".
		 "left join reserved as r on r.node_id=loc.node_id ".
		 "left join nodes as n on n.node_id=loc.node_id ".
		 "left join node_types as nt on nt.type=n.type ".
		 "where loc.building='$building' and ".
Leigh Stoller's avatar
Leigh Stoller committed
80
		 "      loc.floor='$floor' ".
81 82 83 84 85 86 87 88 89
		 "order by n.type,n.node_id");

while ($row = mysql_fetch_array($query_result)) {
    $pname  = $row["node_id"];
    $vname  = $row["vname"];
    $pid    = $row["pid"];
    $eid    = $row["eid"];
    $type   = $row["type"];
    $class  = $row["class"];
90 91 92 93
    $loc_x  = $row["loc_x"];
    $loc_y  = $row["loc_y"];
    $loc_z  = $row["loc_z"];
    $or     = $row["orientation"];
94 95
    $mobile = ($class == "robot" ? 1 : 0);
    # In meters.
96 97 98 99 100 101 102 103 104 105 106 107
    if ($class == "robot") {
	$size   = 0.27;
	$radius = 0.18;
    }
    elseif ($class == "pc" || $class == "pcwireless") {
	$size   = 1.0;
	$radius = 0.5;
    }
    else {
	$size   = 0.07;
	$radius = 0.04;
    }
108 109 110 111 112 113 114 115
    $alloc  = 0;
    $dead   = 0;
    if (isset($pid)) {
	$alloc = 1;
	if ($pid == $NODEDEAD_PID && $eid == $NODEDEAD_EID) {
	    $dead = 1;
	}
    }
116 117
    if (!isset($vname))
	$vname = $pname;
118 119 120 121
    if (!isset($loc_z))
	$loc_z = "";
    if (!isset($or))
	$or = "";
122
							      
123 124 125 126
    echo "$pname, ";
    if (!isset($selector)) {
	echo "$vname, ";
    }
127
    echo "$type, $alloc, $dead, $mobile, $size, $radius, ";
128
    echo "$loc_x, $loc_y, $loc_z, $or";
129
    echo "\n";
130 131 132
}

?>