genihistory.php 6.38 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2015 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
#
# 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";

if (1) {
87
    $myindex = $index;
88
    $dblink  = GetDBLink(($ch ? "ch" : "cm"));
89
    $clause  = "";
90

91
    if (isset($slice_uuid)) {
92 93 94
	if (!preg_match("/^\w+\-\w+\-\w+\-\w+\-\w+$/", $slice_uuid)) {
	    USERERROR("Invalid slice uuid", 1);
	}
95
	$clause = "and a.slice_uuid='$slice_uuid' ";
96
    }
97 98
    else {
	if ($myindex) {
99
	    $clause = "and a.idx<$myindex ";
100 101 102 103 104
	}
	if (isset($search) && isset($searchfor)) {
	    $safe_searchfor = addslashes($searchfor);

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

    $table = array('#id'	   => 'aggregate',
		   '#title'        => "Aggregate History",
		   '#headings'     => array("idx"          => "ID",
141 142
					    "slice_hrn"    => "Slice",
					    "creator_hrn"  => "Creator",
143 144 145 146 147 148 149 150
					    "created"      => "Created",
					    "Destroyed"    => "Destroyed",
					    "Manifest"     => "Manifest"));
    $rows = array();

    if (mysql_num_rows($query_result)) {
	while ($row = mysql_fetch_array($query_result)) {
	    $idx         = $row["idx"];
151
	    $slice_idx   = $row["slice_idx"];
152 153
	    $uuid        = $row["uuid"];
	    $slice_hrn   = $row["slice_hrn"];
154
	    $slice_uuid  = $row["slice_uuid"];
155
	    $creator_hrn = $row["creator_hrn"];
156 157
	    $slice_urn   = $row["slice_urn"];
	    $creator_urn = $row["creator_urn"];
158 159
	    $created     = $row["created"];
	    $destroyed   = $row["destroyed"];
160
	    $DN          = $row["DN"];
161

162 163 164 165 166 167 168 169 170
	    # 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";
	    }
171 172 173 174 175 176 177 178 179 180 181
	    if (isset($DN) &&
		#
		# See if we can find the email.
		#
		(preg_match("/emailAddress=([A-Z0-9._%-]+@".
			    "[A-Z0-9.-]+\.[A-Z]{2,4})/i", $DN, $matches) ||
		 preg_match("/\/emailAddress=(.*)/", $DN, $matches) ||
		 preg_match("/^emailAddress=(.*),/", $DN, $matches))) {

		$creator_info .= "<br>" . $matches[1];
	    }
182 183 184 185 186 187 188 189
	    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>";
190

191 192
	    $manifest_url = "<a href='manifesthistory.php?uuid=$uuid'>manifest</a>";

193
	    $tablerow = array("idx"       => $idx,
194
			      "hrn"       => $url,
195
			      "creator"   => $creator_info,
196
			      "created"   => $created,
197 198
			      "destroyed" => $destroyed,
			      "manifest"  => $manifest_url );
199

200 201 202 203 204 205 206
	    $rows[]  = $tablerow;
	    $myindex = $idx;
	}
	list ($html, $button) = TableRender($table, $rows);
	echo $html;

	$query_result =
Leigh B Stoller's avatar
Leigh B Stoller committed
207 208
	    DBQueryFatal("select count(*) from aggregate_history as a ".
			 "where `type`='Aggregate' and a.idx<$myindex $clause ",
209 210 211 212 213 214
			 $dblink);

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

	if ($remaining) {
215 216 217 218 219 220 221 222
	    $opts = "";
	    if ($ch) {
		$opts .= "&ch=$ch";
	    }
	    if (isset($search)) {
		$opts .= "&search=yes&searchfor=" .
		    rawurlencode($searchfor);
	    }
223
	    echo "<center>".
224
	      "<a href='genihistory.php?index=${myindex}${opts}'>".
225 226 227 228 229 230 231 232 233 234 235
	      "More Entries</a></center><br>\n";
	}
    }
}

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