showvlantaghistory.php 7.26 KB
Newer Older
1 2
<?php
#
Leigh Stoller's avatar
Leigh Stoller committed
3
# Copyright (c) 2000-2013 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#
include("defs.php3");

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

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

#
# Verify page arguments.
#
$optargs = OptionalPageArguments("datetime",  PAGEARG_STRING,
				 "record",    PAGEARG_INTEGER,
				 "count",     PAGEARG_INTEGER,
43 44 45
				 "current",   PAGEARG_BOOLEAN,
				 "tag",       PAGEARG_INTEGER,
				 "lanid",     PAGEARG_INTEGER);
46 47 48 49 50 51 52 53 54

#
# Standard Testbed Header
#
PAGEHEADER("Vlan Tag History");

if (!isset($count)) {
    $count = 200;
}
55 56 57
if (!isset($current)) {
    $current = false;
}
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
if (!isset($record) || $record == "") {
    $record = null;
}
if (isset($record)) {
    # Record overrides date/when.
    $dateopt  = "";
    $datetime = null;
    $when     = null;
}
elseif (isset($datetime) && $datetime != "") {
    if (! strtotime($datetime)) {
	USERERROR("Invalid date specified", 1);
    }
    $dateopt = "&datetime=" . urlencode($datetime);
    $record  = null;
73
    $lanid   = null;
74 75 76 77
}
if (isset($tag)) {
    $tag_opt  = "tag=$tag";
    $form_opt = "<input type=hidden name=tag value=$tag>";
78
    $lanid    = null;
79
}
80 81
elseif (isset($lanid)) {
    $dateopt  = "";
82 83 84 85 86
    $tag_opt  = "";
    $form_opt = "";
    $tag      = null;
}
else {
87 88 89
    $tag_opt  = "";
    $tag      = null;
    $form_opt = "";
90 91 92 93 94 95 96
}

#
# Spit out the various search forms.
#
echo "<br>";
echo "<table class=stealth>\n";
97 98 99 100 101 102
echo "<tr><td class=stealth>
              <a href='showvlantaghistory.php?current=1'>Show Current</a>,
              <a href='showvlantaghistory.php'>All</a>
          </td>
          <td class=stealth></td>
      </tr>";
103 104 105 106 107 108
echo "<tr><form action=showvlantaghistory.php method=get>
      <td class=stealth><b>Show Datetime:</b></td>
      <td class=stealth><input type=text style=\"float:right\"
             name=datetime
             size=20 
             value=\"" . ($datetime ? $datetime : "mm/dd/yy HH:MM") . "\"></td>
109
      $form_opt
110 111 112 113 114 115 116 117 118 119 120 121
      </td><td class=stealth>
        <b><input type=submit name=search1 value=Search></b></td>\n";
echo "</form></tr>\n";
echo "<tr><form action=showvlantaghistory.php method=get>
      <td class=stealth><b>Search for tag:</b></td>
      <td class=stealth><input type=text style=\"float:right\"
             name=tag
             size=6
             value=\"$tag\"></td>
      <td class=stealth>
         <b><input type=submit name=search3 value=Search></b></td>\n";
    echo "</form></tr>\n";
122 123 124 125 126 127 128 129 130
echo "<tr><form action=showvlantaghistory.php method=get>
      <td class=stealth><b>Search for lanid:</b></td>
      <td class=stealth><input type=text style=\"float:right\"
             name=lanid
             size=10
             value=\"$lanid\"></td>
      <td class=stealth>
         <b><input type=submit name=search4 value=Search></b></td>\n";
    echo "</form></tr>\n";
131 132 133 134 135
echo "</table><br>\n";

#
#
#
136
if ($current) {
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    $clauses = array();
    $clause  = "";

    if ($tag) {
	$clauses[] = "tag='$tag'";
    }
    if ($datetime) {
	$clauses[] = "reserve_time>" . strtotime($datetime);
    }
    if (count($clauses)) {
	$clause = "where " . join(" and ", $clauses);
    }
    
    $query_result =
	DBQueryFatal("select v.*, ".
		     "   reserve_time as allocated ".
		     " from reserved_vlantags as v ".
		     "left join experiment_stats as s on s.exptidx=v.exptidx ".
		     "$clause ".
		     "order by tag desc");
}
else {
    $clauses = array();
    $clause  = "";

    if ($tag) {
	$clauses[] = "tag='$tag'";
    }
165 166
    elseif ($lanid) {
	$clauses[] = "lanid='$lanid'";
167 168
    }
    if ($record) {
169 170 171 172
	$clauses[] = "history_id<$record";
    }
    elseif ($datetime) {
	$clauses[] = "allocated>" . strtotime($datetime);
173 174 175 176 177 178 179 180 181 182 183 184
    }
    if (count($clauses)) {
	$clause = "where " . join(" and ", $clauses);
    }

    $query_result =
	DBQueryFatal("select v.*,s.pid,s.eid, ".
		     "   from_unixtime(allocated) as allocated, ".
		     "   from_unixtime(released) as released ".
		     " from vlantag_history as v ".
		     "left join experiment_stats as s on s.exptidx=v.exptidx ".
		     "$clause ".
185
		     "order by history_id desc limit $count");
186 187 188 189 190 191
}

if (mysql_num_rows($query_result)) {
    $num_records = mysql_num_rows($query_result);
    
    # Keep track of history record bounds, for paging through.
192
    $min_history_id = -1;
193 194 195 196 197 198 199 200 201 202

    # Build up table contents.
    $html = "";

    while ($row = mysql_fetch_array($query_result)) {
	$thistag = $row{"tag"};
	$exptidx = $row{"exptidx"};
	$pid     = $row{"pid"};
	$eid     = $row{"eid"};
	$alloc   = $row{"allocated"};
Leigh Stoller's avatar
Leigh Stoller committed
203
	$lanid   = $row{"lanid"};
204
	$id      = 0;
205 206
	$slice   = "--";

207 208 209 210
	if (isset($row{"released"})) {
	    $free = $row{"released"};
	}
	else {
211
	    $free = "&nbsp";
212 213 214 215
	}
	if (isset($row{"history_id"})) {
	    $id = $row{"history_id"};
	}
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

	$experiment = Experiment::Lookup($exptidx);
	$experiment_stats = ExperimentStats::Lookup($exptidx);
	if ($experiment_stats &&
	    $experiment_stats->slice_uuid()) {
	    $url = CreateURL("genihistory",
			     "slice_uuid",
			     $experiment_stats->slice_uuid());
	    $slice = "<a href='$url'>" .
		"<img src=\"greenball.gif\" border=0></a>";
	}
	if ($experiment) {
	    $expurl = CreateURL("showexp",
				URLARG_EID, $experiment->idx());
	}
231 232 233 234 235
	elseif ($experiment_stats->slice_uuid()) {
	    $expurl = CreateURL("showslicelogs",
				"slice_uuid",
				$experiment_stats->slice_uuid());
	}
236 237 238 239 240
	else {
	    $expurl = CreateURL("showexpstats",
				"record",
				$experiment_stats->exptidx());
	}
241 242 243
	if ($min_history_id <= 0 || $id < $min_history_id) {
	    $min_history_id = $id;
	}
244 245 246 247 248

	$html .= "<tr>";
	if (!$tag) {
	    $html .= "<td>$thistag</td>";
	}
Leigh Stoller's avatar
Leigh Stoller committed
249
	$html .= "<td>$lanid</td>";
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
 	$html .= "<td>$pid</td>";
	if ($expurl) {
	    $html .= "<td><a href='$expurl'>$eid</a></td>";
	}
	else {
	    $html .= "<td>$eid</td>";
	}
	if ($PROTOGENI) {
	    $html .= "<td>$slice</td>";
	}
        $html .= "<td>$alloc</td>
                  <td>$free</td>
                </tr>\n";
    }

    if ($num_records >= $count && $when != "current") {
266
	echo "<center><a href='showvlantaghistory.php?record=$min_history_id".
267 268 269 270 271 272 273
	    "&count=$count&$tag_opt'>Next $count records</a></center>\n";
    }
    echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";
    echo "<tr>";
    if (! $tag) {
	echo "<th>Tag</th>";
    }
Leigh Stoller's avatar
Leigh Stoller committed
274 275
    echo "<th>Lanid</th>
	  <th>Pid</th>
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
          <th>Eid</th>";
    if ($PROTOGENI) {
	echo "<th>Slice</th>";
    }
    echo "<th>Allocated</th>
          <th>Released</th>
         </tr>\n";
    echo $html;
    echo "</table>\n";
}

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