uid();
$isadmin = ISADMIN();
#
# Verify page arguments.
#
$optargs = OptionalPageArguments("target_user", PAGEARG_USER,
"showtype", PAGEARG_STRING,
"bypid", PAGEARG_STRING);
if (isset($target_user)) {
if (! $target_user->AccessCheck($this_user, $TB_USERINFO_READINFO)) {
USERERROR("You do not have permission to do this!", 1);
}
$target_uid = $target_user->uid();
$target_idx = $target_user->uid_idx();
}
else {
$target_uid = $uid;
$target_idx = $this_user->uid_idx();
$target_user = $this_user;
}
#
# Standard Testbed Header
#
PAGEHEADER("Node Control Center");
echo "Show: summary,
pcs,
wireless maps,
wireless list,";
if ($TBMAINSITE) {
echo "
GNU USRP (software defined radio) maps,
robot maps, ";
}
echo " widearea";
if ($isadmin) {
echo ", utilization,
virtual,
physical,
all";
}
echo ".
\n";
if (!isset($showtype)) {
$showtype='summary';
}
$additionalVariables = "";
$additionalLeftJoin = "";
if (! strcmp($showtype, "summary")) {
# Separate query below.
$role = "";
$clause = "";
$view = "Free Node Summary";
}
elseif (! strcmp($showtype, "all")) {
$role = "(role='testnode' or role='virtnode')";
$clause = "";
$view = "All";
}
elseif (! strcmp($showtype, "pcs")) {
$role = "(role='testnode')";
$clause = "and (nt.class='pc')";
$view = "PCs";
}
elseif (! strcmp($showtype, "sharks")) {
$role = "(role='testnode')";
$clause = "and (nt.class='shark')";
$view = "Sharks";
}
elseif (! strcmp($showtype, "virtnodes")) {
$role = "(role='virtnode')";
$clause = "";
$view = "Virtual Nodes";
}
elseif (! strcmp($showtype, "physical")) {
$role = "";
$clause = "(nt.isvirtnode=0)";
$view = "Physical Nodes";
}
elseif (! strcmp($showtype, "widearea")) {
$role = "(role='testnode')";
$clause = "and (nt.isremotenode=1)";
$additionalVariables = ",".
"wani.machine_type,".
"REPLACE(CONCAT_WS(', ',".
"wani.city,wani.state,wani.country,wani.zip), ".
"'USA, ','')".
"AS location, ".
"wani.connect_type, ".
"wani.hostname, " .
"wani.site";
$additionalLeftJoin = "LEFT JOIN widearea_nodeinfo AS wani ".
"ON n.node_id=wani.node_id";
$view = "Widearea";
}
elseif (! strcmp($showtype, "wireless")) {
$role = "(role='testnode')";
$clause = "and (loc.node_id is not null)";
$additionalLeftJoin = "LEFT JOIN location_info AS loc ".
"ON n.node_id=loc.node_id";
$view = "Wireless";
}
elseif (preg_match("/^[-\w]+$/", $showtype)) {
$role = "(role='testnode')";
$clause = "and (nt.type='$showtype')";
$view = "only $showtype";
}
else {
$role = "(role='testnode')";
$clause = "and (nt.class='pc')";
$view = "PCs";
}
# If admin or widearea, show the vname too.
$showvnames = 0;
if ($isadmin || !strcmp($showtype, "widearea")) {
$showvnames = 1;
}
#
# Summary info very different.
#
if (! strcmp($showtype, "summary")) {
# Get permissions table so as not to show nodes the user is not allowed
# to see.
$perms = array();
if (!$isadmin || isset($bypid)) {
$query_result =
DBQueryFatal("select type from nodetypeXpid_permissions");
while ($row = mysql_fetch_array($query_result)) {
$perms{$row[0]} = 0;
}
$pidclause = "";
if (isset($bypid)) {
if ($bypid == "" || !TBvalid_pid($bypid)) {
PAGEARGERROR("Invalid characters in 'bypid' argument!");
}
if (! ($target_project = Project::Lookup($bypid))) {
PAGEARGERROR("No such project '$bypid'!");
}
if (!$target_project->AccessCheck($this_user,
$TB_PROJECT_READINFO)){
USERERROR("You are not a member of project '$bypid!", 1);
}
$pidclause = "and g.pid='$bypid'";
}
if ($isadmin) {
$query_result =
DBQueryFatal("select distinct type ".
" from nodetypeXpid_permissions ".
"where pid='$bypid'");
}
else {
$query_result =
DBQueryFatal("select distinct type from group_membership as g ".
"left join nodetypeXpid_permissions as p ".
" on g.pid=p.pid ".
"where uid_idx='$target_idx' $pidclause");
}
while ($row = mysql_fetch_array($query_result)) {
$perms{$row[0]} = 1;
}
}
# Get totals by type.
$query_result =
DBQueryFatal("select n.type,count(*) from nodes as n ".
"left join node_types as nt on n.type=nt.type ".
"where (role='testnode') and ".
" (nt.class!='shark' and nt.class!='pcRemote' ".
" and nt.class!='pcplabphys') ".
"group BY n.type");
$alltotal = 0;
$allfree = 0;
$allunknown = 0;
$totals = array();
$freecounts = array();
$unknowncounts = array();
while ($row = mysql_fetch_array($query_result)) {
$type = $row[0];
$count = $row[1];
$totals[$type] = $count;
$freecounts[$type] = 0;
$unknowncounts[$type] = 0;
}
# Get free totals by type.
$query_result =
DBQueryFatal("select n.eventstate,n.type,count(*) from nodes as n ".
"left join node_types as nt on n.type=nt.type ".
"left join reserved as r on r.node_id=n.node_id ".
"where (role='testnode') and ".
" (nt.class!='shark' and nt.class!='pcRemote' ".
" and nt.class!='pcplabphys') ".
" and r.pid is null and n.reserved_pid is null ".
"group BY n.eventstate,n.type");
while ($row = mysql_fetch_array($query_result)) {
$type = $row[1];
$count = $row[2];
# XXX Yeah, I'm a doofus and can't figure out how to do this in SQL.
if (($row[0] == TBDB_NODESTATE_ISUP) ||
($row[0] == TBDB_NODESTATE_PXEWAIT) ||
($row[0] == TBDB_NODESTATE_ALWAYSUP) ||
($row[0] == TBDB_NODESTATE_POWEROFF)) {
$freecounts[$type] += $count;
}
else {
$unknowncounts[$type] += $count;
}
}
$projlist = $target_user->ProjectAccessList($TB_PROJECT_CREATEEXPT);
if (count($projlist) > 1) {
echo "By Project Permission: ";
while (list($project) = each($projlist)) {
echo "$project,\n";
}
echo "".
"combined membership.\n";
echo "
\n";
}
echo "
Type | Free Nodes |
Total Nodes |
|
---|---|---|---|
\n"; else echo " | \n"; echo " $key | ${freecount}${ast} | $value |
Totals | $allfree | $alltotal | |
Create a new type | \n"; } echo "
![]() |
$num_up |
![]() |
$num_pd |
![]() |
$num_unk |
![]() |
$num_down |
![]() |
$num_free |
Total | $num_total |
Free Subtotals | |
$key | $value |
ID | \n"; if ($showvnames) { echo "Name | \n"; } echo "Type (Class) | Up? | \n"; if ($isadmin) { echo "PID | EID | Default OSID | \n";
}
elseif (strcmp($showtype, "widearea")) {
# Widearea nodes are always "free"
echo "Free? | \n"; } if (!strcmp($showtype, "widearea")) { echo "Site | Processor | Connection | Location | "; } echo "||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
$node_id " . (!strcmp($node_id, $phys_nodeid) ? "" : "($phys_nodeid)") . " | \n"; } else { echo "$node_id " . (!strcmp($node_id, $phys_nodeid) ? "" : "($phys_nodeid)") . " | \n"; } if ($showvnames) { if ($vname) echo "$vname | \n"; else echo "-- | \n"; } echo "$type ($class) | \n"; if (!$pid) echo "
![]() | \n";
elseif (!$status)
echo "
![]() | \n";
elseif ($status == "up")
echo "
![]() | \n";
elseif ($status == "down")
echo "
![]() | \n";
else
echo "
![]() | \n";
# Admins get pid/eid/vname, but mere users yes/no.
if ($isadmin) {
if ($pid) {
echo "$pid | $eid | \n"; } else { echo "-- | -- | \n"; } if ($def_boot_osid && ($osinfo = OSinfo::Lookup($def_boot_osid))) { $osname = $osinfo->osname(); echo "$osname | \n"; } else echo "  | \n"; } elseif (strcmp($showtype, "widearea")) { if ($pid) echo "-- | \n"; else echo "Yes | \n"; } if (!strcmp($showtype, "widearea")) { echo "$site | $machine_type | $connect_type | $location | \n"; } echo "