showstuff.php3 12.8 KB
Newer Older
1
2
<?php
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
3
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
7
# All rights reserved.
#
#
8
9
10
11
# This is an included file. No headers or footers.
#
# Functions to dump out various things.  
#
12
13
include_once("osinfo_defs.php");
include_once("node_defs.php");
14

Mike Hibler's avatar
Mike Hibler committed
15
function SHOWNODES($pid, $eid, $sortby, $showclass) {
16
    global $SCRIPT_NAME;
17
    global $TBOPSPID;
18
    
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    #
    # 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";
43
    }
44

45
46
47
    # XXX
    if ($pid == "emulab-ops" && $eid == "hwdown") {
	$showlastlog = 1;
Mike Hibler's avatar
Mike Hibler committed
48
49
50
	if (empty($showclass)) {
	    $showclass = "no-pcplabphys";
	}
51
52
53
54
55
    }
    else {
	$showlastlog = 0;
    }	

56
57
58
    $classclause = "";
    $noclassclause = "";
    
Mike Hibler's avatar
Mike Hibler committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    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 . ")";
	}
    }

Kirk Webb's avatar
   
Kirk Webb committed
85
86
87
88
89
90
91
92
93
94
95
96
    #
    # Discover whether to show or hide certain columns
    #
    $colcheck_query_result = 
      DBQueryFatal("SELECT sum(oi.OS = 'Windows') as winoscount, ".
                   "       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 ".
                   "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);
97
98
    $anywindows = $colcheckrow["winoscount"];
    $anyplab    = $colcheckrow["plabcount"];
Kirk Webb's avatar
   
Kirk Webb committed
99

100
101
102
103
104
105
106
107
108
109
110
111
    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.
	#
	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 ".
112
		     "WHERE r.eid='$eid' and r.pid='$pid' ".
113
114
115
116
117
118
119
120
		     "GROUP BY r.node_id");
	#
	# 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 =
Kirk Webb's avatar
   
Kirk Webb committed
121
122
	    DBQueryFatal("SELECT r.*,n.*,nt.isvirtnode,nt.isplabdslice, ".
                         " oi.OS,tip.tipname,wa.site,wa.hostname, ".
123
124
125
126
127
		         " ns.status as nodestatus, ".
		         " date_format(rsrv_time,\"%Y-%m-%d&nbsp;%T\") as rsrvtime, ".
		         "nl.reported,nl.entry ".
		         "from reserved as r ".
		         "left join nodes as n on n.node_id=r.node_id ".
Kirk Webb's avatar
   
Kirk Webb committed
128
                         "left join widearea_nodeinfo as wa on wa.node_id=n.phys_nodeid ".
129
130
		         "left join node_types as nt on nt.type=n.type ".
		         "left join node_status as ns on ns.node_id=r.node_id ".
131
		         "left join os_info as oi on n.def_boot_osid=oi.osid ".
132
			 "left join tiplines as tip on tip.node_id=r.node_id ".
133
134
135
136
		         "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
137
			 "$classclause $noclassclause".
138
139
140
141
142
		         "ORDER BY $sortclause");
	DBQueryFatal("DROP table nodelogtemp");
    }
    else {
	$query_result =
Kirk Webb's avatar
   
Kirk Webb committed
143
144
	    DBQueryFatal("SELECT r.*,n.*,nt.isvirtnode,nt.isplabdslice, ".
                         " oi.OS,tip.tipname,wa.site,wa.hostname, ".
145
146
147
148
		         " ns.status as nodestatus, ".
		         " date_format(rsrv_time,\"%Y-%m-%d&nbsp;%T\") as rsrvtime ".
		         "from reserved as r ".
		         "left join nodes as n on n.node_id=r.node_id ".
Kirk Webb's avatar
   
Kirk Webb committed
149
                         "left join widearea_nodeinfo as wa on wa.node_id=n.phys_nodeid ".
150
151
		         "left join node_types as nt on nt.type=n.type ".
		         "left join node_status as ns on ns.node_id=r.node_id ".
152
		         "left join os_info as oi on n.def_boot_osid=oi.osid ".
153
			 "left join tiplines as tip on tip.node_id=r.node_id ".
154
		         "WHERE r.eid='$eid' and r.pid='$pid' ".
Mike Hibler's avatar
Mike Hibler committed
155
			 "$classclause $noclassclause".
156
157
		         "ORDER BY $sortclause");
    }
158
159
    
    if (mysql_num_rows($query_result)) {
160
161
162
	echo "
              <script type='text/javascript' language='javascript' src='sorttable.js'></script>
              <center>
163
              <br>
164
              <a href=" . $_SERVER["REQUEST_URI"] . "#reserved_nodes>
165
                <font size=+1><b>Reserved Nodes</b></font></a>
166
              </center>
167
              <a NAME=reserved_nodes>
168
              <table class='sortable' id='nodetable' align=center border=1>
169
              <tr>
170
171
                <th>Node ID</th>
                <th>Name</th>\n";
Kirk Webb's avatar
   
Kirk Webb committed
172
173
174
175
176
177
178

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

179
180
181
	if ($pid == $TBOPSPID) {
	    echo "<th>Reserved<br>
                      <a href=\"$SCRIPT_NAME?pid=$pid&eid=$eid".
Mike Hibler's avatar
Mike Hibler committed
182
		         "&sortby=rsrvtime-up&showclass=$showclass\">Up</a> or 
183
                      <a href=\"$SCRIPT_NAME?pid=$pid&eid=$eid".
Mike Hibler's avatar
Mike Hibler committed
184
		         "&sortby=rsrvtime-down&showclass=$showclass\">Down</a>
185
186
187
                  </th>\n";
	}
	echo "  <th>Type</th>
188
189
                <th>Default OSID</th>
                <th>Node<br>Status</th>
190
                <th>Hours<br>Idle[<b>1</b>]</th>
191
192
193
194
195
                <th>Startup<br>Status[<b>2</b>]</th>\n";
	if ($showlastlog) {
	    echo "  <th>Last Log<br>Time</th>
		    <th>Last Log Message</th>\n";
	}
Kirk Webb's avatar
   
Kirk Webb committed
196

197
        echo "  <th><a href=\"docwrapper.php3?docname=ssh-mime.html\">SSH</a></th>
198
199
                <th><a href=\"faq.php3#tiptunnel\">Console</a></th> .
                <th>Log</th>";
200
201
202
203
204
205
206
207

	# Only put out a RDP column header if there are any Windows nodes.
	if ($anywindows) {
            echo "  <th>
                        <a href=\"docwrapper.php3?docname=rdp-mime.html\">RDP</a>
                    </th>\n";
	}
	echo "  </tr>\n";
208

209
	$stalemark = "<b>?</b>";
210
	$count = 0;
211

212
	while ($row = mysql_fetch_array($query_result)) {
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
	    $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"];
	    $startstatus   = $row["startstatus"];
	    $status        = $row["nodestatus"];
	    $bootstate     = $row["eventstate"];
	    $isvirtnode    = $row["isvirtnode"];
            $isplabdslice  = $row["isplabdslice"];
	    $tipname       = $row["tipname"];
	    $iswindowsnode = $row["OS"]=='Windows';

	    if (! ($node = Node::Lookup($node_id))) {
		TBERROR("SHOWNODES: Could not map $node_id to its object", 1);
	    }
Leigh B. Stoller's avatar
Leigh B. Stoller committed
231
232
	    $idlehours = $node->IdleTime();
	    $stale     = $node->IdleStale();
233
234
235

	    $idlestr = $idlehours;
	    if ($idlehours > 0) {
236
237
238
239
240
241
242
		if ($stale) {
		    $idlestr .= $stalemark;
		}
	    }
	    elseif ($idlehours == -1) {
		$idlestr = "&nbsp;";
	    }
243

244
245
246
	    if (!$vname)
		$vname = "--";

247
248
249
250
251
	    if ($count & 1) {
		echo "<tr></tr>\n";
	    }
	    $count++;

252
	    echo "<tr>
253
                    <td><a href='shownode.php3?node_id=$node_id'>$node_id</a></td>
254
                    <td>$vname</td>\n";
Kirk Webb's avatar
   
Kirk Webb committed
255
256
257
258
259
260

            if ($isplabdslice) {
              echo "  <td>$wasite</td>
                      <td>$wahost</td>\n";
            }
            elseif ($anyplab) {
261
262
              echo "  <td>&nbsp;</td>
                      <td>&nbsp;</td>\n";
Kirk Webb's avatar
   
Kirk Webb committed
263
264
            }

265
266
267
	    if ($pid == $TBOPSPID)
		echo "<td>$rsrvtime</td>\n";
            echo "  <td>$type</td>\n";
268
269
270
	    if ($def_boot_osid) {
		echo "<td>";
		SPITOSINFOLINK($def_boot_osid);
271
		echo "</td>\n";
272
	    }
273
	    else
274
		echo "<td>&nbsp;</td>\n";
275
276
277
278
279
280

	    if ($bootstate != "ISUP") {
		echo "  <td>$status ($bootstate)</td>\n";
	    } else {
		echo "  <td>$status</td>\n";
	    }
281
	    
282
	    echo "  <td>$idlestr</td>
283
284
                    <td align=center>$startstatus</td>\n";

285
286
	    if ($showlastlog) {
		echo "  <td>$row[reported]</td>\n";
287
288
289
		echo "  <td>$row[entry] 
                            (<a href='shownodelog.php3?node_id=$node_id'>LOG</a>)
                        </td>\n";
290
291
	    }

292
	    echo "  <td align=center>
293
294
                        <a href='nodessh.php3?node_id=$node_id'>
                        <img src=\"ssh.gif\" alt=s></a>
295
296
                    </td>\n";

297
	    if ($isvirtnode || !isset($tipname) || $tipname = '') {
298
		echo "<td>&nbsp;</td>\n";
299
300
301
	    }
	    else {
		echo "  <td align=center>
302
303
                            <a href='nodetipacl.php3?node_id=$node_id'>
                            <img src=\"console.gif\" alt=c></a>
304
                        </td>\n";
305
306

		echo "  <td align=center>
307
                            <a href='showconlog.php3?node_id=$node_id".
308
		                  "&linecount=200'>
309
                            <img src=\"/icons/f.gif\" alt='console log'></a>
310
                        </td>\n";
311
	    }
312
313
314

	    if ($iswindowsnode) {
		echo "  <td align=center>
315
316
                            <a href='noderdp.php3?node_id=$node_id'>
                            <img src=\"rdp.gif\" alt=r></a>
317
318
319
                        </td>\n";
	    }
	    elseif ($anywindows) {
320
		echo "  <td>&nbsp;</td>\n";
321
322
	    }

323
	    echo "</tr>\n";
324
325
	}
	echo "</table>\n";
326
327
	echo "<h4><blockquote><blockquote><blockquote>
              <ol>
328
	        <li>A $stalemark indicates that the data is stale, and
329
	            the node has not reported on its proper schedule.</li>
330
                <li>Exit value of the node startup command. A value of
331
                        666 indicates a testbed internal error.</li>
332
333
              </ol>
              </blockquote></blockquote></blockquote></h4>\n";
334
335
336
    }
}

337
#
338
# Spit out an OSID link in user format.
339
#
340
341
342
343
function SPITOSINFOLINK($osid)
{
    if (! ($osinfo = OSinfo::Lookup($osid)))
	return;
344

345
346
347
348
    $osname = $osinfo->osname();
    
    echo "<a href='showosinfo.php3?osid=$osid'>$osname</a>\n";
}
349

350
351
352
353
354
#
# A list of widearea accounts.
#
function SHOWWIDEAREAACCOUNTS($webid) {
    $none = TBDB_TRUSTSTRING_NONE;
355

356
    if (! ($user = User::Lookup($webid))) {
Russ Fish's avatar
Russ Fish committed
357
	return;
358
359
360
361
362
363
364
365
366
367
    }
    $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;
368
    }
369

370
371
372
373
    echo "<center>
          <h3>Widearea Accounts</h3>
          </center>
          <table align=center border=1 cellpadding=1 cellspacing=2>\n";
374
375

    echo "<tr>
376
377
378
              <th>Node ID</th>
              <th>Approved</th>
              <th>Privs</th>
379
380
          </tr>\n";

381
382
383
384
    while ($row = mysql_fetch_array($query_result)) {
	$node_id   = $row[node_id];
	$approved  = $row[date_approved];
	$trust     = $row[trust];
385

386
387
388
389
390
391
392
393
394
395
	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";
}
396

397
398
399
400
401
402
403
404
405
406
407
408
409
#
# 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,
#                      $HTTP_COOKIE_VARS[$TBAUTHCOOKIE],
#                      "ledpipe.php3?node=em1");
#
410
function SHOWBLINKENLICHTEN($uid, $auth, $pipeurl, $width = 40, $height = 10) {
411
412
413
414
415
416
417
418
	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";
}

419
420
421
#
# This is an included file.
# 
422
?>