showslice.php 7.31 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-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 35 36 37 38
#
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();

#
# Verify Page Arguments.
#
39
$reqargs = RequiredPageArguments("slice_idx",  PAGEARG_INTEGER);
40 41 42 43 44 45 46 47 48 49 50
$optargs = OptionalPageArguments("showtype",   PAGEARG_STRING);

if (!isset($showtype)) {
    $showtype='sa';
}

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

51
if (! ($isadmin || STUDLY())) {
52 53 54 55 56 57 58 59 60 61 62 63
    USERERROR("You do not have permission to view Geni slices!", 1);
}

if (! ($showtype == "sa"|| $showtype == "cm" || $showtype == "ch")) {
    USERERROR("Improper argument: showtype=$showtype", 1);
}

$slice = GeniSlice::Lookup($showtype, $slice_idx);
if (!$slice) {
    USERERROR("No such slice $slice_idx", 1);
}

64 65 66 67 68 69 70 71
function GeneratePopupDiv($id, $text) {
    return "<div id=\"$id\" ".
	"style='display:none;width:700;height:400;overflow:auto;'>\n" .
	"$text\n".
	"</div>\n";
}
$manifestidx = 0;

72 73 74 75
# The table attributes:
$table = array('#id'	   => 'form1',
	       '#title'    => "Slice $slice_idx ($showtype)");
$rows = array();
76
$popups = array();
77 78 79

$rows[] = array("idx"      => $slice->idx());
$rows[] = array("hrn"      => $slice->hrn());
80 81 82 83
$urn = $slice->urn();
if ($urn) {
    $rows[] = array("urn"      => $slice->urn());
}
84 85 86
$rows[] = array("uuid"     => $slice->uuid());
$rows[] = array("created"  => $slice->created());
$rows[] = array("expires"  => $slice->expires());
87 88 89
if ($slice->locked()) {
    $rows[] = array("locked"  => $slice->locked());
}
90 91 92 93 94 95
if ($slice->expiration_max()) {
    $rows[] = array("expires limit"  => $slice->expiration_max());
}
if ($slice->renew_limit()) {
    $rows[] = array("renew limit"  => $slice->renew_limit());
}
96 97 98 99
if ($slice->monitor_pid()) {
    $rows[] = array("Monitor PID"  => $slice->monitor_pid());
}
if ($slice->publicid()) {
100
    $url = "$TBBASE/showslicepub.php?publicid=" . $slice->publicid();
101
    
102
    $rows[] = array("Public URL" => "<a href='$url'>https:// ...</a>");
103
}
104 105 106 107 108 109 110 111 112 113 114 115 116 117
if ($slice->portal_tag()) {
    $rows[] = array("Portal" => $slice->portal_tag());
    if ($slice->portal_url()) {
        $url = $slice->portal_url();
        $rows[] = array("Portal URL" => "<a href='$url'>https:// ...</a>");
    }
}
elseif ($slice->speaksfor_urn()) {
    $portal_url = GenPortalURL(1, $slice->speaksfor_urn(), $slice->uuid());
    if ($portal_url) {
        $rows[] = array("Portal URL" =>
                        "<a href='$portal_url'>https:// ...</a>");
    }
}
118
if (($manifest = $slice->GetManifest())) {
119
    $popups[] = GeneratePopupDiv("manifest$manifestidx", $manifest);
120 121
    $rows[] = array("manifest" =>
		    "<a href='#' title='' ".
122 123 124
		    "onclick='PopUpWindowFromDiv(\"manifest$manifestidx\");'".
		    ">manifest</a>\n");
    $manifestidx++;
125 126 127 128 129 130 131 132 133 134 135 136
}

$experiment = Experiment::LookupByUUID($slice->uuid());
if ($experiment) {
    $eid = $experiment->eid();
    $exptidx = $experiment->idx();
    $url = CreateURL("showexp", $experiment);
    $rows[] = array("Experiment"  => "<a href='$url'>$eid ($exptidx)</a>");
}

$geniuser = GeniUser::Lookup($showtype, $slice->creator_uuid());
if ($geniuser) {
137
    $rows[] = array("Creator" => $geniuser->urn());
138 139 140
    if ($geniuser->email()) {
	$rows[] = array("Email" => $geniuser->email());
    }
141 142 143 144
}
else {
    $user = User::LookupByUUID($slice->creator_uuid());
    if ($user) {
145 146
	$url = CreateURL("showuser", $user);
	$rows[] = array("Creator" => "<a href='$url'>". $user->uid() ."</a>");
147 148 149
    }
}

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
if ($showtype != "sa") {
    $saslice = GeniSlice::Lookup("sa", $slice->uuid());
    if ($saslice) {
	$saidx = $saslice->idx();
	$url   = CreateURL("showslice", "slice_idx", $saidx, "showtype", "sa");

	$rows[] = array("SA Slice" => "<a href='$url'>$saidx</a>");
    }
}
if ($showtype != "cm") {
    $cmslice = GeniSlice::Lookup("cm", $slice->uuid());
    if ($cmslice) {
	$cmidx = $cmslice->idx();
	$url   = CreateURL("showslice", "slice_idx", $cmidx, "showtype", "cm");

	$rows[] = array("CM Slice" => "<a href='$url'>$cmidx</a>");
    }
}
168 169 170 171 172 173 174

list ($html, $button) = TableRender($table, $rows);
echo $html;

$clientslivers = ClientSliver::SliverList($slice);
if ($clientslivers && count($clientslivers)) {
    $table = array('#id'	   => 'clientslivers',
175 176 177 178 179 180
		   '#title'        => "Client Slivers",
		   '#headings'     => array("idx"      => "ID",
					    "urn"      => "URN",
					    "manager"  => "Manager URN",
					    "created"  => "Created",
					    "manifest" => "Manifest"));
181 182 183 184 185 186 187 188 189
    $rows = array();

    foreach ($clientslivers as $clientsliver) {
	$row = array("idx"      => $clientsliver->idx(),
		     "urn"      => $clientsliver->urn(),
		     "manager"  => $clientsliver->manager_urn(),
		     "created"  => $clientsliver->created());

	if ($clientsliver->manifest()) {
190 191
	    $popups[] = GeneratePopupDiv("manifest$manifestidx",
					 $clientsliver->manifest());
192 193
	    $row["manifest"] =
		"<a href='#' title='' ".
194
		"onclick='PopUpWindowFromDiv(\"manifest$manifestidx\");'>".
195
		"Manifest</a>";
196
	    $manifestidx++;
197
	}
198 199 200
	else {
	    $row["manifest"] = "Unknown";
	}
201 202 203 204 205 206
	$rows[] = $row;
    }

    list ($html, $button) = TableRender($table, $rows);
    echo $html;
}
207 208 209
foreach ($popups as $i => $popup) {
    echo "$popup\n";
}
210

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
#
# Find all logs associated with this slice.
#
$query_result =
    DBQueryFatal("select m.logidx,l.logid,l.date_created,m2.metaval ".
		 "  from logfile_metadata as m ".
		 "left join logfiles as l on l.logidx=m.logidx ".
		 "left join logfile_metadata as m2 on ".
		 "      m2.logidx=m.logidx and m2.metakey='Method' ".
		 "where m.metakey='slice_idx' and m.metaval='$slice_idx' ".
		 "order by l.date_created asc");

if ($query_result && mysql_num_rows($query_result)) {
    $table = array('#id'	   => 'logfiles',
		   '#title'        => "Log Files",
		   '#headings'     => array("idx"      => "ID",
					    "method"   => "Op",
					    "created"  => "Created",
					    "log"      => "Link"));
    $rows = array();
    $img  = "<img border='0' src='greenball.gif' />";
    
    while ($row = mysql_fetch_array($query_result)) {
	$logidx = $row["logidx"];
	$logid  = $row["logid"];
	$op     = $row["metaval"];
	$date   = $row["date_created"];
	$url    = CreateURL("spewlogfile", "logfile", $logid);

	$row = array("idx"      => $logidx,
		     "method"   => $op,
		     "created"  => $date,
		     "log"      => "<a href='$url'>$img</a>",
	    );
	
	$rows[] = $row;
    }
    list ($html, $button) = TableRender($table, $rows);
    echo $html;
    echo "<center>
            <a href='showslicelogs.php?slice_idx=$slice_idx&download=1'>
            Download All Logs</a></center>";
}

255 256 257 258 259 260
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>