shownodehistory.php3 7.38 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/>.
# 
# }}}
23 24
#
include("defs.php3");
25
include_once("node_defs.php");
26 27 28 29

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

34
if (! ($isadmin || OPSGUY() || STUDLY())) {
35 36 37 38
    USERERROR("Cannot view node history.", 1);
}

#
39 40 41
# Verify page arguments.
#
$optargs = OptionalPageArguments("showall",   PAGEARG_BOOLEAN,
42
				 "reverse",   PAGEARG_BOOLEAN,
43
				 "datetime",  PAGEARG_STRING,
44 45 46
				 "record",    PAGEARG_INTEGER,
				 "count",     PAGEARG_INTEGER,
				 "when",      PAGEARG_STRING,
47
				 "IP",        PAGEARG_STRING,
48
				 "mac",       PAGEARG_STRING,
49 50 51
				 # To allow for pcvm search, since they are
                                 # transient and will not map to a node.
				 "node_id",   PAGEARG_STRING);
52

53 54 55 56 57
#
# Standard Testbed Header
#
PAGEHEADER("Node History");

58 59 60
if (!isset($showall)) {
    $showall = 0;
}
61
if (!isset($reverse)) {
62
    $reverse = 1;
63
}
64
if (!isset($count)) {
65
    $count = 200;
66
}
67 68 69 70 71 72 73 74
if (!isset($record) || $record == "") {
    $record = null;
}
if (isset($record)) {
    # Record overrides date/when.
    $dateopt  = "";
    $datetime = null;
    $when     = null;
75
}
76
elseif (isset($datetime) && $datetime != "") {
77 78 79 80
    if (! strtotime($datetime)) {
	USERERROR("Invalid date specified", 1);
    }
    $dateopt = "&datetime=" . urlencode($datetime);
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    $record  = null;
}
elseif (isset($when) && $when == "yesterday") {
    $datetime = date("Y-m-d H:i:s", time() - (24 * 3600));
    $dateopt = "&datetime=" . urlencode($datetime);
    $record  = null;
}
elseif (isset($when) && $when == "lastweek") {
    $datetime = date("Y-m-d H:i:s", time() - (7 * 24 * 3600));
    $dateopt = "&datetime=" . urlencode($datetime);
    $record  = null;
}
elseif (isset($when) && $when == "lastmonth") {
    $datetime = date("Y-m-d H:i:s", time() - (30 * 24 * 3600));
    $dateopt = "&datetime=" . urlencode($datetime);
    $record  = null;
97 98
}
else {
Leigh Stoller's avatar
Leigh Stoller committed
99 100
    $dateopt  = "";
    $datetime = null;
101
    $when     = "epoch";
102
}
103
if (isset($IP)) {
104 105 106
    if (! preg_match('/^[0-9\.]+$/', $IP)) {    
	USERERROR("Does not look like a valid IP address.", 1);
    }
107
}
Leigh Stoller's avatar
Leigh Stoller committed
108 109 110
else {
    $IP = null;
}
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
if (isset($mac)) {
    if (! preg_match('/^[\w\:]+$/', $mac)) {    
	USERERROR("Does not look like a valid mac address.", 1);
    }
    $node = Node::LookupByMac($mac);

    #
    # Switch to a node_id if its a physical node. Otherwise, 
    # continue with the mac.
    #
    if ($node && !$node->IsVirtNode()) {
	$node_id = $node->node_id();
	$mac = null;
    }
}
else {
    $mac = null;
}
129
if (isset($node_id)) {
130
    $node_opt = "node_id=$node_id";
131
    $form_opt = "<input type=hidden name=node_id value=$node_id>";
Leigh Stoller's avatar
Leigh Stoller committed
132
    $IP      = null;
133
    $mac     = null;
134 135
}
else if (isset($IP)) {
136
    $node_opt = "IP=$IP";
137
    $form_opt = "<input type=hidden name=IP value=$IP>";
Leigh Stoller's avatar
Leigh Stoller committed
138
    $node_id = null;
139 140 141 142 143 144 145
    $mac     = null;
}
else if (isset($mac)) {
    $node_opt = "mac=$mac";
    $form_opt = "<input type=hidden name=mac value=$mac>";
    $node_id = null;
    $IP      = null;
146 147 148 149
}
else {
    $node_opt = "";
    $form_opt = "";
Leigh Stoller's avatar
Leigh Stoller committed
150 151
    $IP      = null;
    $node_id = null;
152
    $mac     = null;
153
}
154

155
$opts="$node_opt$dateopt";
156 157 158 159 160
$revopt="&reverse=" . ($reverse ? "1" : "0");
$showopt="&showall=" . ($showall ? "1" : "0");

echo "<b>Order records:</b> ";
if ($reverse) {
161
    echo "<a href='shownodehistory.php3?$opts$showopt&reverse=0'>oldest first</a>,
162 163 164 165 166 167 168
          newest first";
} else {
    echo "oldest first,
          <a href='shownodehistory.php3?$opts$showopt&reverse=1'>newest first</a>";
}

echo "<br><b>Show records:</b> ";
169
if ($showall) {
170
    echo "<a href='shownodehistory.php3?$opts$revopt'>allocated only</a>,
171 172 173
          all";
} else {
    echo "allocated only,
174
          <a href='shownodehistory.php3?$opts$revopt&showall=1'>all</a>";
175 176
}

177
$opts="$node_opt$revopt$showopt$dateopt";
178 179 180
echo "<br><b>Show:</b> ";
if ($when == "lastmonth") {
    echo "Last Month, ";
181
}
182 183
else {
    echo "<a href='shownodehistory.php3?$opts&when=lastmonth'>Last Month</a>, ";
184
}
185 186
if ($when == "lastweek") {
    echo "Last Week, ";
187
}
188 189 190 191 192 193 194 195 196 197 198 199 200 201
else {
    echo "<a href='shownodehistory.php3?$opts&when=lastweek'>Last Week</a>, ";
}
if ($when == "yesterday") {
    echo "Yesterday, ";
}
else {
    echo "<a href='shownodehistory.php3?$opts&when=yesterday'>Yesterday</a>, ";
}
if ($when == "Epoch") {
    echo "Epoch";
}
else {
    echo "<a href='shownodehistory.php3?$opts&when=epoch'>Epoch</a>";
202
}
203

204
#
205
# Spit out the various search forms.
206
#
207 208
echo "<br>";
echo "<table class=stealth>\n";
209
echo "<tr><form action=shownodehistory.php3 method=get>
210 211
      <td class=stealth><b>Show Datetime:</b> 
      <input type=text style=\"float:right\"
212
             name=datetime
213 214 215
             size=20 
             value=\"" . ($datetime ? $datetime : "mm/dd/yy HH:MM") . "\"></td>
      <input type=hidden name=showall value=$showall>
216
      <input type=hidden name=reverse value=$reverse>
217
      <input type=hidden name=when    value=$when>
218
      $form_opt
219 220
      <td class=stealth>
        <b><input type=submit name=search1 value=Search></b></td>\n";
221
echo "</form></tr>\n";
222 223 224 225 226 227
echo "<tr><form action=shownodehistory.php3 method=get>
      <td class=stealth><b>Search for Node:</b> 
      <input type=text align=right
             name=node_id
             size=20
             value=\"$node_id\"></td>
228
      <input type=hidden name=showall value=$showall>
229
      <input type=hidden name=reverse value=$reverse>
230
      <input type=hidden name=when    value=$when>
231 232 233 234 235 236 237 238 239
      <td class=stealth>
       <b><input type=submit name=search2 value=Search></b></td>\n";
    echo "</form></tr>\n";
echo "<tr><form action=shownodehistory.php3 method=get>
      <td class=stealth><b>Search for IP:</b> 
      <input type=text style=\"float:right\"
             name=IP
             size=20
             value=\"$IP\"></td>
240
      <input type=hidden name=showall value=$showall>
241
      <input type=hidden name=reverse value=$reverse>
242
      <input type=hidden name=when    value=$when>
243 244 245
      <td class=stealth>
         <b><input type=submit name=search3 value=Search></b></td>\n";
    echo "</form></tr>\n";
246 247 248 249 250 251 252
echo "<tr><form action=shownodehistory.php3 method=get>
      <td class=stealth><b>Search for mac:</b> 
      <input type=text style=\"float:right\"
             name=mac
             size=12
             value=\"$mac\"></td>
      <input type=hidden name=showall value=$showall>
253
      <input type=hidden name=reverse value=$reverse>
254 255 256 257
      <input type=hidden name=when    value=$when>
      <td class=stealth>
         <b><input type=submit name=search3 value=Search></b></td>\n";
    echo "</form></tr>\n";
258
echo "</table><br>\n";
259

260
ShowNodeHistory($node_id, $record, $count, $showall, $reverse, $datetime,
261
		$IP, $mac, $node_opt);
262 263 264 265 266 267

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