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.

status.php 11 KB
Newer Older
Leigh B Stoller's avatar
Leigh B Stoller committed
1 2
<?php
#
Leigh B Stoller's avatar
Leigh B Stoller committed
3
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
Leigh B Stoller's avatar
Leigh B Stoller committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# 
# {{{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/>.
# 
# }}}
#
chdir("..");
include("defs.php3");
include_once("osinfo_defs.php");
include_once("geni_defs.php");
28
include_once("webtask.php");
29
chdir("apt");
Leigh B Stoller's avatar
Leigh B Stoller committed
30
include("quickvm_sup.php");
31 32
include_once("profile_defs.php");
include_once("instance_defs.php");
Leigh B Stoller's avatar
Leigh B Stoller committed
33
$page_title = "Experiment Status";
Leigh B Stoller's avatar
Leigh B Stoller committed
34 35
$ajax_request = 0;

36 37 38 39
#
# Get current user.
#
$this_user = CheckLogin($check_status);
40
if (isset($this_user)) {
41
    CheckLoginOrDie(CHECKLOGIN_NONLOCAL);
42
}
43 44 45 46 47 48
#
# We do not set the isfadmin flag if the user has normal permission
# to see this experiment, since that would change what the user sees.
# Okay for real admins, but not for foreign admins.
#
$isfadmin = 0;
49

Leigh B Stoller's avatar
Leigh B Stoller committed
50 51 52
#
# Verify page arguments.
#
53 54 55
$reqargs = OptionalPageArguments("uuid",      PAGEARG_STRING,
                                 "maxextend", PAGEARG_INTEGER,
				 "oneonly",   PAGEARG_BOOLEAN);
56

Leigh B Stoller's avatar
Leigh B Stoller committed
57 58
if (!isset($uuid)) {
    SPITHEADER(1);
59 60 61 62 63
    echo "<div class='align-center'>
            <p class='lead text-center'>
              What experiment would you like to look at?
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
64 65 66 67 68
    SPITFOOTER();
    return;
}

#
Leigh B Stoller's avatar
Leigh B Stoller committed
69
# See if the instance exists. If not, redirect back to the create page
Leigh B Stoller's avatar
Leigh B Stoller committed
70
#
Leigh B Stoller's avatar
Leigh B Stoller committed
71 72
$instance = Instance::Lookup($uuid);
if (!$instance) {
Leigh B Stoller's avatar
Leigh B Stoller committed
73
    SPITHEADER(1);
74 75 76 77 78
    echo "<div class='align-center'>
            <p class='lead text-center'>
              Experiment does not exist. Redirecting to the front page.
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
79 80 81
    SPITFOOTER();
    flush();
    sleep(3);
82
    PAGEREPLACE("instantiate.php");
Leigh B Stoller's avatar
Leigh B Stoller committed
83 84
    return;
}
Leigh B Stoller's avatar
Leigh B Stoller committed
85 86 87
$creator = GeniUser::Lookup("sa", $instance->creator_uuid());
if (! $creator) {
    $creator = User::LookupByUUID($instance->creator_uuid());
88
}
Leigh B Stoller's avatar
Leigh B Stoller committed
89 90
if (!$creator) {
    SPITHEADER(1);
91 92
    echo "<div class='align-center'>
            <p class='lead text-center'>
Leigh B Stoller's avatar
Leigh B Stoller committed
93
               Hmm, there seems to be a problem.
94 95
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
96
    SPITFOOTER();
Leigh B Stoller's avatar
Leigh B Stoller committed
97
    TBERROR("No creator for instance: $uuid", 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
98 99
    return;
}
Leigh B Stoller's avatar
Leigh B Stoller committed
100
#
101
# Only logged in admins can access an experiment created by someone else.
Leigh B Stoller's avatar
Leigh B Stoller committed
102
#
103 104 105
if (! (isset($this_user) && ISADMIN())) {
    # An experiment created by a real user, can be accessed by that user only.
    # Ditto a guest user; must be the same guest.
Leigh B Stoller's avatar
Leigh B Stoller committed
106 107
    if (! ((get_class($creator) == "User" && isset($this_user) &&
            $instance->CanView($this_user)) ||
108 109 110
	   (get_class($creator) == "GeniUser" &&
	    isset($_COOKIE['quickvm_user']) &&
	    $_COOKIE['quickvm_user'] == $creator->uuid()))) {
111 112 113 114 115 116 117
        if (ISFOREIGN_ADMIN()) {
            # See comment above.
            $isfadmin = 1;
        }
        else {
            PAGEERROR("You do not have permission to look at this experiment!");
        }
Leigh B Stoller's avatar
Leigh B Stoller committed
118 119 120
    }
}
$slice = GeniSlice::Lookup("sa", $instance->slice_uuid());
Leigh B Stoller's avatar
Leigh B Stoller committed
121

Leigh B Stoller's avatar
Leigh B Stoller committed
122
$instance_status = $instance->status();
Leigh B Stoller's avatar
Leigh B Stoller committed
123 124
$creator_uid     = $creator->uid();
$creator_email   = $creator->email();
Leigh B Stoller's avatar
Leigh B Stoller committed
125
if ($profile = Profile::Lookup($instance->profile_id(),
126
			       $instance->profile_version())) {
127 128 129 130 131 132 133
    $profile_name   = $profile->name();
    $profile_uuid   = $profile->uuid();
    $profile_public = ($profile->ispublic() ? "true" : "false");
    $cansnap        = ((isset($this_user) &&
			$this_user->idx() == $creator->idx() &&
			$this_user->idx() == $profile->creator_idx()) ||
		       ISADMIN() ? 1 : 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
134 135
    $canclone       = ((isset($this_user) &&
                        $profile->CanClone($this_user)) ||
136 137 138
		       ISADMIN() ? 1 : 0);
    $public_url     = ($instance->public_url() ?
		       "'" . $instance->public_url() . "'" : "null");
139
    $ispprofile     = $profile->script() ? 1 : 0;
140 141 142 143 144 145 146 147
}
else {
    $profile_name   = "";
    $profile_uuid   = "";
    $profile_public = "false";
    $cansnap        = 0;
    $canclone       = 0;
    $public_url     = "null";
148
    $ispprofile     = 0;
149 150

}
151 152
if ($slice) {
    $slice_urn       = $slice->urn();
153 154 155
    $instance_name   = $instance->name();
    # Until old instances are gone.
    if (!$instance_name) {
Leigh B Stoller's avatar
Leigh B Stoller committed
156
        list ($a,$b,$instance_name) = Instance::ParseURN($slice_urn);
157
    }
158
    $slice_expires   = DateStringGMT($slice->expires());
159
    $slice_expires_text = gmdate("m-d\TH:i\Z", strtotime($slice->expires()));
Leigh B Stoller's avatar
Leigh B Stoller committed
160
    $slice_created   = DateStringGMT($instance->created());
161 162 163 164 165
}
else {
    $slice_urn = "";
    $slice_expires = "";
    $slice_expires_text = ""; 
Leigh B Stoller's avatar
Leigh B Stoller committed
166
    $slice_created  = "";
167
    $instance_name  = "";
168
}
169
$registered      = (isset($this_user) ? "true" : "false");
170
$snapping        = 0;
171
$oneonly         = (isset($oneonly) && $oneonly ? 1 : 0);
172
$isadmin         = (ISADMIN() ? 1 : 0);
173 174 175 176
$lockdown        = ($instance->admin_lockdown() ||
                    $instance->user_lockdown() ? 1 : 0);
$extension_reason= ($instance->extension_reason() ?
                    CleanString($instance->extension_reason()) : "");
177 178 179
$extension_denied_reason= ($instance->extension_denied_reason() ?
                    CleanString($instance->extension_denied_reason()) : "");
$extension_denied= $instance->extension_denied();
180
$freenodes_url   = Aggregate::Lookup($instance->aggregate_urn())->FreeNodesURL();
Leigh B Stoller's avatar
Leigh B Stoller committed
181
$lockout         = $instance->extension_lockout();
182
$isopenstack     = $instance->isopenstack();
183
$paniced         = $instance->paniced();
184
$project         = $instance->pid();
185
$group           = $instance->gid();
186
$extensions      = ExtensionInfo::LookupForInstance($instance);
Leigh B Stoller's avatar
Leigh B Stoller committed
187
$isstud          = (isset($this_user) && $this_user->stud() ? 1 : 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
188 189 190 191 192

#
# We give ssh to the creator (real user or guest user).
#
$dossh =
193
    (((isset($this_user) && $instance->CanDoSSH($this_user)) ||
Leigh B Stoller's avatar
Leigh B Stoller committed
194 195
      (isset($_COOKIE['quickvm_user']) &&
       $_COOKIE['quickvm_user'] == $creator->uuid())) ? 1 : 0);
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

#
# See if we have a task running in the background for this instance.
# At the moment it can only be a snapshot task. If there is one, we
# have to tell the js code to show the status of the snapshot.
#
# XXX we could be imaging for a new profile (Cloning) instead. In that
# case the webtask object will not be attached to the instance, but to
# whatever profile is cloning. We do not know that profile here, so we
# cannot show that progress. Needs more thought.
#
if ($instance_status == "imaging") {
    $webtask = WebTask::LookupByObject($instance->uuid());
    if ($webtask && ! $webtask->exited()) {
	$snapping = 1;
    }
}
Leigh B Stoller's avatar
Leigh B Stoller committed
213

214
SPITHEADER(1);
215

216 217 218
echo "<link rel='stylesheet'
            href='css/nv.d3.css'>\n";

219 220
# Place to hang the toplevel template.
echo "<div id='status-body'></div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
221

222
echo "<script type='text/javascript'>\n";
223
echo "  window.APT_OPTIONS.uuid = '" . $uuid . "';\n";
224
echo "  window.APT_OPTIONS.name = '" . $instance_name . "';\n";
225 226
echo "  window.APT_OPTIONS.instanceStatus = '" . $instance_status . "';\n";
echo "  window.APT_OPTIONS.profileName = '" . $profile_name . "';\n";
227
echo "  window.APT_OPTIONS.profileUUID = '" . $profile_uuid . "';\n";
228
echo "  window.APT_OPTIONS.profilePublic = " . $profile_public . ";\n";
229
echo "  window.APT_OPTIONS.sliceURN = '" . $slice_urn . "';\n";
230
echo "  window.APT_OPTIONS.sliceExpires = '" . $slice_expires . "';\n";
231
echo "  window.APT_OPTIONS.sliceExpiresText = '" . $slice_expires_text . "';\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
232
echo "  window.APT_OPTIONS.sliceCreated = '" . $slice_created . "';\n";
233 234
echo "  window.APT_OPTIONS.creatorUid = '" . $creator_uid . "';\n";
echo "  window.APT_OPTIONS.creatorEmail = '" . $creator_email . "';\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
235 236 237 238 239 240
if (isset($this_user)) {
    echo "  window.APT_OPTIONS.thisUid = '" . $this_user->uid() . "';\n";
}
else {
    echo "  window.APT_OPTIONS.thisUid = '" . $creator_uid . "';\n";
}
241
echo "  window.APT_OPTIONS.registered = $registered;\n";
242
echo "  window.APT_OPTIONS.isadmin = $isadmin;\n";
243
echo "  window.APT_OPTIONS.isfadmin = $isfadmin;\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
244
echo "  window.APT_OPTIONS.isstud = $isstud;\n";
245
echo "  window.APT_OPTIONS.cansnap = $cansnap;\n";
246
echo "  window.APT_OPTIONS.canclone = $canclone;\n";
247
echo "  window.APT_OPTIONS.snapping = $snapping;\n";
248
echo "  window.APT_OPTIONS.hidelinktest = false;\n";
249
echo "  window.APT_OPTIONS.oneonly = $oneonly;\n";
250
echo "  window.APT_OPTIONS.dossh = $dossh;\n";
251
echo "  window.APT_OPTIONS.ispprofile = $ispprofile;\n";
252
echo "  window.APT_OPTIONS.publicURL = $public_url;\n";
253
echo "  window.APT_OPTIONS.lockdown = $lockdown;\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
254
echo "  window.APT_OPTIONS.lockout = $lockout;\n";
255
echo "  window.APT_OPTIONS.isopenstack = $isopenstack;\n";
256
echo "  window.APT_OPTIONS.paniced = $paniced;\n";
257
echo "  window.APT_OPTIONS.project = '$project';\n";
258
echo "  window.APT_OPTIONS.group = '$group';\n";
259 260
echo "  window.APT_OPTIONS.extension_requested = " .
    $instance->extension_requested() . ";\n";
261
echo "  window.APT_OPTIONS.extension_denied = $extension_denied;\n";
262
echo "  window.APT_OPTIONS.AJAXURL = 'server-ajax.php';\n";
263 264 265 266 267 268
echo "  window.APT_OPTIONS.physnode_count = " .
    $instance->physnode_count() . ";\n";
echo "  window.APT_OPTIONS.virtnode_count = " .
    $instance->virtnode_count() . ";\n";
echo "  window.APT_OPTIONS.physnode_hours = " .
    sprintf("%.2f;\n", $instance->physnode_count() *
Leigh B Stoller's avatar
Leigh B Stoller committed
269
            ((time() - strtotime($instance->created())) / 3600));
270
echo "  window.APT_OPTIONS.freenodesurl = '$freenodes_url';\n";
271 272 273 274 275 276
if (isset($maxextend) && $maxextend != "") {
    # Assumed to be hours.
    echo "  window.APT_OPTIONS.MAXEXTEND = $maxextend;\n";
}
else {
    echo "  window.APT_OPTIONS.MAXEXTEND = null;\n";
277
}
278
echo "</script>\n";
279 280
echo "<script src='js/lib/d3.v3.js'></script>\n";
echo "<script src='js/lib/nv.d3.js'></script>\n";
281
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
282
echo "<script src='js/lib/jquery-ui.js'></script>\n";
283
echo "<script src='js/lib/codemirror-min.js'></script>\n";
284
echo "<script src='js/lib/bootstrap.js'></script>\n";
285
echo "<script src='js/lib/require.js' data-main='js/status'></script>";
286 287
echo "<link rel='stylesheet'
            href='css/jquery-ui-1.10.4.custom.min.css'>\n";
288 289
# For progress bubbles in the imaging modal.
echo "<link rel='stylesheet' href='css/progress.css'>\n";
290
echo "<link rel='stylesheet' href='css/codemirror.css'>\n";
291
echo "<div class='hidden'><textarea id='extension_reason'>$extension_reason</textarea></div>\n";
292 293 294 295 296 297
if (count($extensions)) {
    $foo = array();
    foreach ($extensions as $extension) {
        $foo[$extension->idx()] = $extension->info;
    }
    echo "<script type='text/plain' id='extensions-json'>\n";
298
    echo json_encode($foo, JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_TAG);
299 300
    echo "</script>\n";
}
301 302 303
if ($extension_denied_reason != "") {
   echo "<pre class='hidden' id='extension_denied_reason'>$extension_denied_reason</pre>\n";
}
304

Leigh B Stoller's avatar
Leigh B Stoller committed
305 306
SPITFOOTER();
?>