showstuff.php3 15.5 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2014 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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23 24
#
#
25 26 27 28
# This is an included file. No headers or footers.
#
# Functions to dump out various things.  
#
29 30
include_once("osinfo_defs.php");
include_once("node_defs.php");
31

Mike Hibler's avatar
Mike Hibler committed
32
function SHOWNODES($pid, $eid, $sortby, $showclass) {
33
    global $TBOPSPID;
34
    global $WIKIDOCURL;
Leigh Stoller's avatar
Leigh Stoller committed
35
    global $login_user;
36
    
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    #
    # If this is an expt in emulab-ops, we also want to see the reserved
    # time. Note that vname might not be useful, but show it anyway.
    #
    # XXX The above is not always true. There are also real experiments in
    # emulab-ops.
    #
    if (!isset($sortby)) {
	$sortclause = "n.type,n.priority";
    }
    elseif ($sortby == "vname") {
	$sortclause = "r.vname";
    }
    elseif ($sortby == "rsrvtime-up") {
	$sortclause = "rsrvtime asc";
    }
    elseif ($sortby == "rsrvtime-down") {
	$sortclause = "rsrvtime desc";
    }
    elseif ($sortby == "nodeid") {
	$sortclause = "n.node_id";
    }
    else {
	$sortclause = "n.type,n.priority";
61
    }
62

63
    # XXX
64 65
    if ($pid == "emulab-ops" &&
	($eid == "hwdown" || $eid == "hwbroken")) {
66
	$showlastlog = 1;
Mike Hibler's avatar
Mike Hibler committed
67 68 69
	if (empty($showclass)) {
	    $showclass = "no-pcplabphys";
	}
70 71 72 73 74
    }
    else {
	$showlastlog = 0;
    }	

75 76 77
    $classclause = "";
    $noclassclause = "";
    
Mike Hibler's avatar
Mike Hibler committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
    if (!empty($showclass)) {
	$opts = explode(",", $showclass);
	foreach ($opts as $opt) {
	    if (preg_match("/^no-([-\w]+)$/", $opt, $matches)) {
		if (!empty($noclassclause)) {
		    $noclassclause .= ",";
		}
		$noclassclause .= "'$matches[1]'";
	    } elseif ($opt == "all") {
		$classclause = "";
		$noclassclause = "";
	    } else {
		if (!empty($classclause)) {
		    $classclause .= ",";
		}
		$classclause .= "'$opt'";
	    }
	}
	if (!empty($classclause)) {
	    $classclause = "and nt.class in (" . $classclause . ")";
	}
	if (!empty($noclassclause)) {
	    $noclassclause = "and nt.class not in (" . $noclassclause . ")";
	}
    }

104 105 106 107
    #
    # Discover whether to show or hide certain columns
    #
    $colcheck_query_result = 
108
      DBQueryFatal("SELECT sum(ov.OS = 'Windows') as winoscount, ".
109 110 111 112
                   "       sum(nt.isplabdslice) as plabcount ".
                   "from reserved as r ".
                   "left join nodes as n on n.node_id=r.node_id ".
                   "left join os_info as oi on n.def_boot_osid=oi.osid ".
113 114
		   "left join os_info_versions as ov on ".
		   "     ov.osid=oi.osid and ov.vers=oi.version ".
115 116 117
                   "left join node_types as nt on n.type = nt.type ".
                   "WHERE r.eid='$eid' and r.pid='$pid'");
    $colcheckrow = mysql_fetch_array($colcheck_query_result);
118 119
    $anywindows = $colcheckrow["winoscount"];
    $anyplab    = $colcheckrow["plabcount"];
120

121 122 123 124 125 126 127 128
    if ($showlastlog) {
	#
	# We need to extract, for each node, just the latest nodelog message.
	# I could not figure out how to do this in a single select so instead
	# create a temporary table of node_id and latest log message date
	# for all reserved nodes to re-join with nodelog to extract the latest
	# log message.
	#
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
	if (!empty($classclause) || !empty($noclassclause)) {
	    DBQueryFatal("CREATE TEMPORARY TABLE nodelogtemp ".
			 "SELECT r.node_id, MAX(reported) AS reported ".
			 "FROM reserved AS r ".
			 "LEFT JOIN nodelog AS l ON r.node_id=l.node_id ".
			 "LEFT JOIN nodes AS n ON r.node_id=n.node_id ".
			 "LEFT JOIN node_types AS nt ON n.type=nt.type ".
			 "WHERE r.eid='$eid' and r.pid='$pid' ".
			 "$classclause $noclassclause ".
			 "GROUP BY r.node_id");
	} else {
	    DBQueryFatal("CREATE TEMPORARY TABLE nodelogtemp ".
			 "SELECT r.node_id, MAX(reported) AS reported ".
			 "FROM reserved AS r ".
			 "LEFT JOIN nodelog AS l ON r.node_id=l.node_id ".
			 "WHERE r.eid='$eid' and r.pid='$pid' ".
			 "GROUP BY r.node_id");
	}
147 148 149 150 151 152 153
	#
	# Now join this table and nodelog with the standard set of tables
	# to get all the info we need.  Note the inner join with the temp
	# table, this is faster and still safe since it has an entry for
	# every reserved node.
	#
	$query_result =
154
	    DBQueryFatal("SELECT r.*,n.*,nt.isvirtnode,nt.isplabdslice, ".
155
                         " ov.OS,tip.tipname,wa.site,wa.hostname, ".
156 157
		         " ns.status as nodestatus, ".
		         " date_format(rsrv_time,\"%Y-%m-%d&nbsp;%T\") as rsrvtime, ".
158
		         "nl.reported,nl.entry,nt.isjailed,nt.isremotenode ".
159 160
		         "from reserved as r ".
		         "left join nodes as n on n.node_id=r.node_id ".
161
                         "left join widearea_nodeinfo as wa on wa.node_id=n.phys_nodeid ".
162 163
		         "left join node_types as nt on nt.type=n.type ".
		         "left join node_status as ns on ns.node_id=r.node_id ".
164
		         "left join os_info as oi on n.def_boot_osid=oi.osid ".
165 166
			 "left join os_info_versions as ov on ".
			 "     ov.osid=oi.osid and ov.vers=oi.version ".
167 168
			 "left join tiplines as tip on tip.node_id=r.node_id and ".
			 "     tip.disabled=0 ".
169 170 171 172
		         "inner join nodelogtemp as t on t.node_id=r.node_id ".
		         "left join nodelog as nl on nl.node_id=r.node_id and nl.reported=t.reported ".

		         "WHERE r.eid='$eid' and r.pid='$pid' ".
Mike Hibler's avatar
Mike Hibler committed
173
			 "$classclause $noclassclause".
174 175 176 177 178
		         "ORDER BY $sortclause");
	DBQueryFatal("DROP table nodelogtemp");
    }
    else {
	$query_result =
179
	    DBQueryFatal("SELECT r.*,n.*,nt.isvirtnode,nt.isplabdslice, ".
180
                         " ov.OS,tip.tipname,wa.site,wa.hostname, ".
181
		         " ns.status as nodestatus, ".
182 183
		         " date_format(rsrv_time,\"%Y-%m-%d&nbsp;%T\") ".
			 "   as rsrvtime,nt.isjailed,nt.isremotenode ".
184 185
		         "from reserved as r ".
		         "left join nodes as n on n.node_id=r.node_id ".
186
                         "left join widearea_nodeinfo as wa on wa.node_id=n.phys_nodeid ".
187 188
		         "left join node_types as nt on nt.type=n.type ".
		         "left join node_status as ns on ns.node_id=r.node_id ".
189
		         "left join os_info as oi on n.def_boot_osid=oi.osid ".
190 191
			 "left join os_info_versions as ov on ".
			 "     ov.osid=oi.osid and ov.vers=oi.version ".
192 193
			 "left join tiplines as tip on tip.node_id=r.node_id and ".
			 "     tip.disabled=0 ".
194
		         "WHERE r.eid='$eid' and r.pid='$pid' ".
Mike Hibler's avatar
Mike Hibler committed
195
			 "$classclause $noclassclause".
196 197
		         "ORDER BY $sortclause");
    }
198 199
    
    if (mysql_num_rows($query_result)) {
200
	echo "<div align=center>
201
              <br>
202
              <a href=" . $_SERVER["REQUEST_URI"] . "#reserved_nodes>
203
                <font size=+1><b>Reserved Nodes</b></font></a>
204
              <a NAME=reserved_nodes></a>
205 206
              <table id='nodetable' align=center border=1>
              <thead class='sort'>
207
              <tr>
208 209
                <th>Node ID</th>
                <th>Name</th>\n";
210 211 212 213 214 215 216

        # Only show 'Site' column if there are plab nodes.
        if ($anyplab) {
            echo "  <th>Site</th>
                    <th>Widearea<br>Hostname</th>\n";
        }

217
	if ($pid == $TBOPSPID) {
218
	    $SCRIPT_NAME = $_SERVER["SCRIPT_NAME"];
219
	    echo "<th class='sorttable_nosort'>Reserved<br>
220
                      <a href=\"$SCRIPT_NAME?pid=$pid&eid=$eid".
Mike Hibler's avatar
Mike Hibler committed
221
		         "&sortby=rsrvtime-up&showclass=$showclass\">Up</a> or 
222
                      <a href=\"$SCRIPT_NAME?pid=$pid&eid=$eid".
Mike Hibler's avatar
Mike Hibler committed
223
		         "&sortby=rsrvtime-down&showclass=$showclass\">Down</a>
224 225 226
                  </th>\n";
	}
	echo "  <th>Type</th>
227 228
                <th>Default OSID</th>
                <th>Node<br>Status</th>
229
                <th>Hours<br>Idle[<b>1</b>]</th>
230 231 232
                <th>Startup<br>Status[<b>2</b>]</th>\n";
	if ($showlastlog) {
	    echo "  <th>Last Log<br>Time</th>
233
		    <th class='sorttable_nosort'>Last Log Message</th>\n";
234
	}
235

Leigh Stoller's avatar
Leigh Stoller committed
236 237
        echo "  <th class='sorttable_nosort'>SSH<br>URL</th>
                <th class='sorttable_nosort'>SSH<br>mime</th>
238
                <th class='sorttable_nosort'><a href=\"$WIKIDOCURL/kb25\">Console</a></th>
239
                <th class='sorttable_nosort'>Log</th>";
240 241 242

	# Only put out a RDP column header if there are any Windows nodes.
	if ($anywindows) {
243
            echo "  <th class='sorttable_nosort'>
244
                        <a href=\"$WIKIDOCURL/rdp_mine\">RDP</a>
245 246
                    </th>\n";
	}
247
	echo "  </tr></thead>\n";
248

249
	$stalemark = "<b>?</b>";
250
	$sharednodes = 0;
251

252
	while ($row = mysql_fetch_array($query_result)) {
253 254 255 256 257 258 259
	    $node_id = $row["node_id"];
	    $vname   = $row["vname"];
	    $rsrvtime= $row["rsrvtime"];
	    $type    = $row["type"];
            $wasite  = $row["site"];
            $wahost  = $row["hostname"];
	    $def_boot_osid = $row["def_boot_osid"];
260
	    $def_boot_osid_vers = $row["def_boot_osid_vers"];
261 262 263 264 265
	    $startstatus   = $row["startstatus"];
	    $status        = $row["nodestatus"];
	    $bootstate     = $row["eventstate"];
	    $isvirtnode    = $row["isvirtnode"];
            $isplabdslice  = $row["isplabdslice"];
266 267
	    $isjailed      = $row["isjailed"];
	    $isremote      = $row["isremotenode"];
268 269
	    $tipname       = $row["tipname"];
	    $iswindowsnode = $row["OS"]=='Windows';
270
	    $sharemode     = $row["sharing_mode"];
271 272 273 274

	    if (! ($node = Node::Lookup($node_id))) {
		TBERROR("SHOWNODES: Could not map $node_id to its object", 1);
	    }
275 276
	    $idlehours = $node->IdleTime();
	    $stale     = $node->IdleStale();
277 278 279

	    $idlestr = $idlehours;
	    if ($idlehours > 0) {
280 281 282 283 284 285 286
		if ($stale) {
		    $idlestr .= $stalemark;
		}
	    }
	    elseif ($idlehours == -1) {
		$idlestr = "&nbsp;";
	    }
287

288 289 290 291
	    if (!$vname)
		$vname = "--";

	    echo "<tr>
292 293 294 295 296 297 298
                    <td><a href='shownode.php3?node_id=$node_id'>$node_id</a>";
	    if (isset($sharemode) && $sharemode == "using_shared_local") {
		echo " *";
		$sharednodes++;
	    }
	    echo "</td>\n";
	    echo "<td>$vname</td>\n";
299 300 301 302 303 304

            if ($isplabdslice) {
              echo "  <td>$wasite</td>
                      <td>$wahost</td>\n";
            }
            elseif ($anyplab) {
305 306
              echo "  <td>&nbsp;</td>
                      <td>&nbsp;</td>\n";
307 308
            }

309 310 311
	    if ($pid == $TBOPSPID)
		echo "<td>$rsrvtime</td>\n";
            echo "  <td>$type</td>\n";
312 313
	    if ($def_boot_osid) {
		echo "<td>";
314
		SPITOSINFOLINK($def_boot_osid, $def_boot_osid_vers);
315
		echo "</td>\n";
316
	    }
317
	    else
318
		echo "<td>&nbsp;</td>\n";
319

320 321 322 323
	    if ($isvirtnode && !($isjailed || $isplabdslice)) {
		echo "  <td>$bootstate</td>\n";
	    }
	    elseif ($bootstate != "ISUP") {
324
		echo "  <td>$status ($bootstate)</td>\n";
325 326
	    }
	    else {
327 328
		echo "  <td>$status</td>\n";
	    }
329
	    
330
	    echo "  <td>$idlestr</td>
331 332
                    <td align=center>$startstatus</td>\n";

333 334
	    if ($showlastlog) {
		echo "  <td>$row[reported]</td>\n";
335 336 337
		echo "  <td>$row[entry] 
                            (<a href='shownodelog.php3?node_id=$node_id'>LOG</a>)
                        </td>\n";
338
	    }
Leigh Stoller's avatar
Leigh Stoller committed
339 340 341 342 343
	    $sshurl = $node->sshurl($login_user->uid());
	    echo "  <td align=center>
                          <a href='$sshurl'>
                            <img src=\"ssh.gif\" alt=s></a>
                    </td>\n";
344

345
	    echo "  <td align=center>
346 347
                        <a href='nodessh.php3?node_id=$node_id'>
                        <img src=\"ssh.gif\" alt=s></a>
348 349
                    </td>\n";

350
	    if (!isset($tipname) || $tipname == '') {
351
		echo "  <td>&nbsp;</td>\n";
352 353 354
	    }
	    else {
		echo "  <td align=center>
355 356
                            <a href='nodetipacl.php3?node_id=$node_id'>
                            <img src=\"console.gif\" alt=c></a>
357
                        </td>\n";
358 359 360 361 362 363 364 365
	    }
	    if ($isvirtnode) {
		echo "  <td align=center>
                            <a href='bootlog.php3?node_id=$node_id'>
                            <img src=\"/icons/f.gif\" alt='boot log'></a>
                         </td>\n";
	    }
	    else {
366
		echo "  <td align=center>
367
                            <a href='showconlog.php3?node_id=$node_id".
368
		                  "&linecount=200'>
369
                            <img src=\"/icons/f.gif\" alt='console log'></a>
370
                        </td>\n";
371
	    }
372 373 374

	    if ($iswindowsnode) {
		echo "  <td align=center>
375 376
                            <a href='noderdp.php3?node_id=$node_id'>
                            <img src=\"rdp.gif\" alt=r></a>
377 378 379
                        </td>\n";
	    }
	    elseif ($anywindows) {
380
		echo "  <td>&nbsp;</td>\n";
381 382
	    }

383
	    echo "</tr>\n";
384 385
	}
	echo "</table>\n";
386 387 388 389 390
	if ($sharednodes) {
	    echo "<center>* This experiment is using <a href='showpool.php'>";
	    echo "<b>shared nodes</b></a></center>\n";
	}

391 392 393
	echo "<div style=\"width:70%; margin:auto;\">\n";
	echo "<font size=-1>\n";
	echo "<ol style=\"text-align: left;\">
394
	        <li>A $stalemark indicates that the data is stale, and
395
	            the node has not reported on its proper schedule.</li>
396
                <li>Exit value of the node startup command. A value of
397 398
                        666 indicates a testbed internal error.</li>\n";
        echo "</ol>
399 400
              </font></div>\n";
	echo "</div>\n";
401
	
402 403
	# Sort initialized later when page fully loaded.
	AddSortedTable('nodetable');
404 405 406
    }
}

407
#
408
# Spit out an OSID link in user format.
409
#
410
function SPITOSINFOLINK($osid, $version)
411
{
412
    if (! ($osinfo = OSinfo::Lookup($osid, $version)))
413
	return;
414

415 416
    $osname = $osinfo->osname();
    
417
    echo "<a href='showosinfo.php3?osid=$osid&version=$version'>$osname</a>\n";
418
}
419

420 421 422 423 424
#
# A list of widearea accounts.
#
function SHOWWIDEAREAACCOUNTS($webid) {
    $none = TBDB_TRUSTSTRING_NONE;
425

426
    if (! ($user = User::Lookup($webid))) {
427
	return;
428 429 430 431 432 433 434 435 436 437
    }
    $uid = $user->uid();
    
    $query_result =
	DBQueryFatal("SELECT * FROM widearea_accounts ".
		     "WHERE uid='$uid' and trust!='$none' ".
		     "order by node_id");
    
    if (! mysql_num_rows($query_result)) {
	return;
438
    }
439

440 441 442 443
    echo "<center>
          <h3>Widearea Accounts</h3>
          </center>
          <table align=center border=1 cellpadding=1 cellspacing=2>\n";
444 445

    echo "<tr>
446 447 448
              <th>Node ID</th>
              <th>Approved</th>
              <th>Privs</th>
449 450
          </tr>\n";

451 452 453 454
    while ($row = mysql_fetch_array($query_result)) {
	$node_id   = $row[node_id];
	$approved  = $row[date_approved];
	$trust     = $row[trust];
455

456 457 458 459 460 461 462 463 464 465
	if (TBTrustConvert($trust) != $TBDB_TRUST_NONE) {
	    echo "<tr>
                      <td>$node_id</td>
                      <td>$approved</td>
                      <td>$trust</td>\n";
	    echo "</tr>\n";
	}
    }
    echo "</table>\n";
}
466

467 468 469 470 471 472 473 474 475 476
#
# Add a LED like applet that turns on/off based on the output of a URL.
#
# @param uid The logged-in user ID.
# @param auth The value of the user's authentication cookie.
# @param pipeurl The url the applet should connect to to get LED status.  This
# string must include any parameters, or if there are none, end with a '?'.
#
# Example:
#   SHOWBLINKENLICHTEN($uid,
477
#                      $_COOKIE[$TBAUTHCOOKIE],
478 479
#                      "ledpipe.php3?node=em1");
#
480
function SHOWBLINKENLICHTEN($uid, $auth, $pipeurl, $width = 40, $height = 10) {
481 482 483 484 485 486 487 488
	echo "
          <applet code='BlinkenLichten.class' width='$width' height='$height'>
            <param name='pipeurl' value='$pipeurl'>
            <param name='uid' value='$uid'>
            <param name='auth' value='$auth'>
          </applet>\n";
}

489 490 491
#
# This is an included file.
# 
492
?>