genihistory.php 7.26 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2015, 2018 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 Stoller's avatar
Leigh 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 Stoller's avatar
Leigh 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.portal_url,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
		     $dblink);

138 139 140 141 142 143 144 145 146 147 148 149 150 151
    echo "<center>\n";
    echo "<br>";
    echo "<font size=+1><b>Aggregate History</b></font>";
    echo "<br>\n";
    echo "<table>\n";
    echo " <thead>\n";
    echo "  <tr>\n";
    echo "   <th>ID</th>\n";
    echo "   <th>Slice/Creator</th>\n";
    echo "   <th>Created/Destroyed</th>\n";
    echo "   <th>Manifest/Portal</th>\n";
    echo "  </tr>\n";
    echo " </thead>\n";
    echo " <tbody>\n";
152 153 154 155

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

168 169 170 171 172 173 174 175 176
	    # 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";
	    }
177 178 179 180 181 182 183 184 185 186 187
	    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];
	    }
188 189 190 191 192 193 194 195
	    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>";
196

197
	    $manifest_url = "<a href='manifesthistory.php?uuid=$uuid'>manifest</a>";
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
            #
            # Try to form a URL back to the (Utah) Portal. 
            #
            if ($row["portal_url"]) {
                $tmp = $row["portal_url"];
                $portal_url = "<a href='$tmp'>portal</a>";
            }
            elseif ($row["speaksfor_urn"] && $row["speaksfor_urn"] != "") {
                $active = ($destroyed ? 0 : 1);
                $tmp = GenPortalURL($active,
                                    $row["speaksfor_urn"], $slice_uuid);
                if ($tmp) {
                    $portal_url = "<a href='$tmp'>portal</a>";
                }
            }
            echo "<tr>";
            echo " <td rowspan=2>$idx</td>";
            echo " <td>$url</td>";
            echo " <td>$created</td>";
            echo " <td>$manifest_url</td>";
            echo "</tr>";
            echo "<tr>";
            echo " <td>$creator_info</td>";
            echo " <td>$destroyed</td>";
            echo " <td>$portal_url</td>";
            echo "</tr>";
Leigh Stoller's avatar
Leigh Stoller committed
224
	    echo "<tr></tr>\n";
225

226 227
	    $myindex = $idx;
	}
228 229 230
        echo "</tbody>\n";
        echo "</table>\n";
        echo "</center>\n";
231 232

	$query_result =
233 234
	    DBQueryFatal("select count(*) from aggregate_history as a ".
			 "where `type`='Aggregate' and a.idx<$myindex $clause ",
235 236 237 238 239 240
			 $dblink);

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

	if ($remaining) {
241 242 243 244 245 246 247 248
	    $opts = "";
	    if ($ch) {
		$opts .= "&ch=$ch";
	    }
	    if (isset($search)) {
		$opts .= "&search=yes&searchfor=" .
		    rawurlencode($searchfor);
	    }
249
	    echo "<center>".
250
	      "<a href='genihistory.php?index=${myindex}${opts}'>".
251 252 253 254 255 256 257 258 259 260 261
	      "More Entries</a></center><br>\n";
	}
    }
}

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