All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

genislices.php 4.39 KB
Newer Older
1 2
<?php
#
Leigh B Stoller's avatar
Leigh B Stoller committed
3
# Copyright (c) 2000-2014 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();
Leigh B Stoller's avatar
Leigh B Stoller committed
35
$defaultsearchstring = 'Search CM for URN or IP or MAC or VLAN';
36 37 38 39

#
# Verify Page Arguments.
#
40 41
$optargs = OptionalPageArguments("showtype",   PAGEARG_STRING,
				 "query",      PAGEARG_STRING);
42 43
$showtypes = array();

44 45 46 47
if (isset($query) && $query != $defaultsearchstring) {
    $showtypes[] = "cm";
}
elseif (!isset($showtype)) {
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    $showtypes[] = "cm";
    $showtypes[] = "sa";
    $showtypes[] = "ch";
}
else {
    if (! ($showtype == "sa"|| $showtype == "cm" || $showtype == "ch")) {
	USERERROR("Improper argument: showtype=$showtype", 1);
    }
    $showtypes[] = $showtype;
}

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

64
if (! ($isadmin || STUDLY())) {
65 66 67
    USERERROR("You do not have permission to view Geni slice list!", 1);
}

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#
# Search box for CM only. 
#
if (isset($query) && $query != $defaultsearchstring) {
    $searchstring = $query;
}
else {
    $searchstring = $defaultsearchstring;
}
echo "<center>";
echo "<table class=stealth>\n";
echo "<tr>";
echo "<td class=stealth>";
echo "<form method='get' action='genislices.php'>";
echo "<input name='query' class='textInputEmpty'
        size=64 id='searchbox'
	value='$searchstring' 
        onfocus='focus_text(this, \"$defaultsearchstring\")'
        onblur='blur_text(this, \"$defaultsearchstring\")' />";
echo "</td><td><input type='submit' id='searchsub' value=Go />";
echo "</form>";
echo "</td></tr></table>";
echo "</center>\n";

92
foreach ($showtypes as $type) {
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    if ($type == "cm" && isset($query) && $query != $defaultsearchstring) {
	$slicelist  = array();
	$uuidlist   = array();
	$safe_query = escapeshellarg($query);
	
	$fp = popen("$TBSUEXEC_PATH $uid nobody ".
		    "webmaptoslice -w $safe_query", "r");
	if (!$fp) {
	    TBERROR("Could not start maptoslice: $safe_query", 1);
	}
	while ($line = fgets($fp)) {
	    $uuidlist[] = rtrim($line);
	}
	$status = pclose($fp);
	if ($status > 0 || !count($uuidlist)) {
	    USERERROR("No slices matching your search term", 1);
	}
	elseif ($status < 0) {
	    TBERROR("Could not run maptoslice: $safe_query", 1);
	}
	foreach ($uuidlist as $uuid) {
	    $slicelist[] = GeniSlice::Lookup($type, $uuid);
	}
    }
    else {
	$slicelist = GeniSlice::AllSlices($type);
    }
120 121 122 123 124 125 126 127
    $which = ($type == "cm" ? "Component Manager" :
	      ($type == "sa" ? "Slice Authority" : "Clearing House"));

    if (!$slicelist || !count($slicelist))
	continue;

    # The form attributes:
    $table = array('#id'       => $type,
128 129 130 131 132 133 134
		   '#title'    => $which,
		   '#sortable' => 1,
		   '#headings' => array("idx"          => "ID",
					"hrn"          => "HRN",
					"created"      => "Created",
					"expires"      => "Expires"));

135 136 137 138 139
    $rows = array();

    foreach ($slicelist as $slice) {
	$slice_idx  = $slice->idx();
	$slice_hrn  = $slice->hrn();
140 141
	$created    = $slice->created();
	$expires    = $slice->expires();
142

143 144 145 146 147 148 149 150 151 152
	$url = CreateURL("showslice", "showtype", $type,
			 "slice_idx", $slice_idx);
	$href = "<a href='$url'>$slice_hrn</a>";

	$experiment = Experiment::LookupByUUID($slice->uuid());
	if ($experiment) {
	    $eid     = $experiment->eid();
	    $expurl  = CreateURL("showexp", $experiment);
	    $href    = "$href (<a href='$expurl'>$eid</a>)";
	}
153 154 155 156
	$rows[$slice_idx] = array("idx"       => $slice_idx,
				  "hrn"       => $href,
				  "created"   => $created,
				  "expires"   => $expires);
157 158 159 160 161 162 163 164 165 166 167
    }
    list ($html, $button) = TableRender($table, $rows);
    echo $html;
}

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