genihistory.php 6.64 KB
Newer Older
1 2
<?php
#
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
#
include("defs.php3");
include_once("geni_defs.php");
include("table_defs.php");

#
#
# Only known and logged in users allowed.
#
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
35
$searchbox = "user/slice urn or slice uuid or date";
36 37 38 39

#
# Verify Page Arguments.
#
40 41
$optargs = OptionalPageArguments("searchfor",  PAGEARG_STRING,
				 "search",     PAGEARG_STRING,
42
				 "slice_uuid", PAGEARG_STRING,
43
				 "ch",         PAGEARG_BOOLEAN,
44
				 "index",      PAGEARG_INTEGER);
45
if (!isset($index)) {
46 47
    $index = 0;
}
48 49
if (!isset($searchfor)) {
    $searchfor = $searchbox;
50
}
51 52
if (!isset($ch)) {
    $ch = 0;
53 54 55 56 57 58 59
}

#
# Standard Testbed Header
#
PAGEHEADER("Geni History");

60
if (! ($isadmin || STUDLY())) {
61 62 63
    USERERROR("You do not have permission to view Geni slice list!", 1);
}

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#
# Spit out a search form
#
echo "<br>";
echo "<form action=genihistory.php method=post>
      <b>Search:</b> 
      <input type=text
             name=searchfor
             size=50
             value=\"$searchfor\"";
if ($searchfor == $searchbox) {
    echo "   onfocus='focus_text(this, \"$searchfor\")'
             onblur='blur_text(this, \"$searchfor\")'";
}
echo " />
      <b><input type=submit name=search value=Go></b> ";
if ($ISCLRHOUSE) {
    echo "<input type=checkbox name=ch value=1 ".
	($ch ? "checked" : "") . "> Search CH";
}
echo "</form>\n";

function GeneratePopupDiv($id, $text) {
    return "<div id=\"$id\" ".
	"style='display:none;width:700;height:400;overflow:auto;'>\n" .
	"$text\n".
	"</div>\n";
}

if (1) {
94
    $myindex = $index;
95
    $dblink  = GetDBLink(($ch ? "ch" : "cm"));
96
    $clause  = "";
97

98
    if (isset($slice_uuid)) {
99 100 101
	if (!preg_match("/^\w+\-\w+\-\w+\-\w+\-\w+$/", $slice_uuid)) {
	    USERERROR("Invalid slice uuid", 1);
	}
102
	$clause = "and a.slice_uuid='$slice_uuid' ";
103
    }
104 105
    else {
	if ($myindex) {
106
	    $clause = "and a.idx<$myindex ";
107 108 109 110 111
	}
	if (isset($search) && isset($searchfor)) {
	    $safe_searchfor = addslashes($searchfor);

	    if (preg_match("/^\w+\-\w+\-\w+\-\w+\-\w+$/", $searchfor)) {
112
		$clause = "$clause and a.slice_uuid='$safe_searchfor' ";
113 114 115
	    }
	    elseif (preg_match("/^urn:publicid:IDN\+[-\w\.]+\+slice\+[-\w]*$/",
			       $searchfor)) {
116
		$clause = "$clause and a.slice_urn='$safe_searchfor' ";
117 118 119
	    }
	    elseif (preg_match("/^urn:publicid:IDN\+[-\w\.]+\+user\+[-\w]*$/",
			       $searchfor)) {
120
		$clause = "$clause and a.creator_urn='$safe_searchfor' ";
121 122 123
	    }
	    elseif (strtotime($searchfor)) {
		$ts = strtotime($searchfor);
124 125
		$clause = "$clause and ($ts >= UNIX_TIMESTAMP(a.created) && ".
		 "(a.destroyed is null or $ts <= UNIX_TIMESTAMP(a.destroyed)))";
126
	    }
127 128 129
	    elseif ($searchfor == $searchbox) {
		# Just a press of the ch box, so dump out the CH records.
	    }
130 131 132 133 134
	    else {
		USERERROR("Invalid search specification", 1);
	    }
	}
    }
135
    $query_result =
136 137 138 139 140
	DBQueryFatal("select a.*,s.idx as slice_idx ".
		     "  from aggregate_history as a ".
		     "left join geni_slices as s on s.uuid=a.slice_uuid ".
		     "where a.type='Aggregate' $clause ".
		     "order by a.idx desc limit 20",
141 142 143 144 145
		     $dblink);

    $table = array('#id'	   => 'aggregate',
		   '#title'        => "Aggregate History",
		   '#headings'     => array("idx"          => "ID",
146 147
					    "slice_hrn"    => "Slice HRN/URN",
					    "creator_hrn"  => "Creator HRN/URN",
148 149 150 151
					    "created"      => "Created",
					    "Destroyed"    => "Destroyed",
					    "Manifest"     => "Manifest"));
    $rows = array();
152
    $popups = array();
153 154 155 156

    if (mysql_num_rows($query_result)) {
	while ($row = mysql_fetch_array($query_result)) {
	    $idx         = $row["idx"];
157
	    $slice_idx   = $row["slice_idx"];
158 159
	    $uuid        = $row["uuid"];
	    $slice_hrn   = $row["slice_hrn"];
160
	    $slice_uuid  = $row["slice_uuid"];
161
	    $creator_hrn = $row["creator_hrn"];
162 163
	    $slice_urn   = $row["slice_urn"];
	    $creator_urn = $row["creator_urn"];
164 165 166
	    $created     = $row["created"];
	    $destroyed   = $row["destroyed"];

167 168 169 170 171 172 173 174 175
	    # If we have urns, show those instead.
	    $slice_info = $slice_hrn;
	    if (isset($slice_urn)) {
		$slice_info = "$slice_urn";
	    }
	    $creator_info = $creator_hrn;
	    if (isset($creator_urn)) {
		$creator_info = "$creator_urn";
	    }
176 177 178 179 180 181 182 183
	    if ($destroyed) {
		$url = "<a href='showslicelogs.php?slice_uuid=$slice_uuid'>";
	    }
	    else {
		$url =
		    "<a href='showslice.php?slice_idx=$slice_idx&showtype=cm'>";
	    }
	    $url .= "$slice_info</a>";
184

185
	    $tablerow = array("idx"       => $idx,
186
			      "hrn"       => $url,
187
			      "creator"   => $creator_info,
188 189 190 191 192 193 194 195 196 197 198
			      "created"   => $created,
			      "destroyed" => $destroyed);

	    $manifest_result =
		DBQueryFatal("select * from manifest_history ".
			     "where aggregate_uuid='$uuid' ".
			     "order by idx desc limit 1", $dblink);

	    if (mysql_num_rows($manifest_result)) {
		$mrow = mysql_fetch_array($manifest_result);
		$manifest = $mrow["manifest"];
199 200 201

		$stuff = GeneratePopupDiv("manifest$idx", $manifest);
		$popups[] = $stuff;
202 203
		$tablerow["manifest"] =
		    "<a href='#' title='' ".
204 205
		    "onclick='PopUpWindowFromDiv(\"manifest$idx\");'".
		    ">manifest</a>\n";
206 207 208 209 210 211 212 213 214 215
	    }
	    else {
		$tablerow["Manifest"] = "Unknown";
	    }
	    $rows[]  = $tablerow;
	    $myindex = $idx;
	}
	list ($html, $button) = TableRender($table, $rows);
	echo $html;

216 217 218 219
	foreach ($popups as $i => $popup) {
	    echo "$popup\n";
	}

220
	$query_result =
221 222
	    DBQueryFatal("select count(*) from aggregate_history as a ".
			 "where `type`='Aggregate' and a.idx<$myindex $clause ",
223 224 225 226 227 228
			 $dblink);

	$row = mysql_fetch_array($query_result);
	$remaining = $row[0];

	if ($remaining) {
229 230 231 232 233 234 235 236
	    $opts = "";
	    if ($ch) {
		$opts .= "&ch=$ch";
	    }
	    if (isset($search)) {
		$opts .= "&search=yes&searchfor=" .
		    rawurlencode($searchfor);
	    }
237
	    echo "<center>".
238
	      "<a href='genihistory.php?index=${myindex}${opts}'>".
239 240 241 242 243 244 245 246 247 248 249
	      "More Entries</a></center><br>\n";
	}
    }
}

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