status.php 11.8 KB
Newer Older
Leigh B Stoller's avatar
Leigh B Stoller committed
1
2
<?php
#
3
# Copyright (c) 2000-2017 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
elseif (!$ISAPT && GETUID()) {
    # User with an account, redirect to login. APT allows guest users.
    RedirectLoginPage();
}
47
48
49
50
51
52
#
# 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;
53

Leigh B Stoller's avatar
Leigh B Stoller committed
54
55
56
#
# Verify page arguments.
#
57
58
59
$reqargs = OptionalPageArguments("uuid",      PAGEARG_STRING,
                                 "maxextend", PAGEARG_INTEGER,
				 "oneonly",   PAGEARG_BOOLEAN);
60

Leigh B Stoller's avatar
Leigh B Stoller committed
61
62
if (!isset($uuid)) {
    SPITHEADER(1);
63
64
65
66
67
    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
68
69
70
71
72
    SPITFOOTER();
    return;
}

#
Leigh B Stoller's avatar
Leigh B Stoller committed
73
# See if the instance exists. If not, redirect back to the create page
Leigh B Stoller's avatar
Leigh B Stoller committed
74
#
Leigh B Stoller's avatar
Leigh B Stoller committed
75
76
$instance = Instance::Lookup($uuid);
if (!$instance) {
Leigh B Stoller's avatar
Leigh B Stoller committed
77
    SPITHEADER(1);
78
79
80
81
82
    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
83
84
85
    SPITFOOTER();
    flush();
    sleep(3);
86
    PAGEREPLACE("landing.php");
Leigh B Stoller's avatar
Leigh B Stoller committed
87
88
    return;
}
Leigh B Stoller's avatar
Leigh B Stoller committed
89
90
91
$creator = GeniUser::Lookup("sa", $instance->creator_uuid());
if (! $creator) {
    $creator = User::LookupByUUID($instance->creator_uuid());
92
}
Leigh B Stoller's avatar
Leigh B Stoller committed
93
94
if (!$creator) {
    SPITHEADER(1);
95
96
    echo "<div class='align-center'>
            <p class='lead text-center'>
Leigh B Stoller's avatar
Leigh B Stoller committed
97
               Hmm, there seems to be a problem.
98
99
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
100
    SPITFOOTER();
Leigh B Stoller's avatar
Leigh B Stoller committed
101
    TBERROR("No creator for instance: $uuid", 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
102
103
    return;
}
Leigh B Stoller's avatar
Leigh B Stoller committed
104
#
105
# Only logged in admins can access an experiment created by someone else.
Leigh B Stoller's avatar
Leigh B Stoller committed
106
#
107
108
109
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
110
111
    if (! ((get_class($creator) == "User" && isset($this_user) &&
            $instance->CanView($this_user)) ||
112
113
114
	   (get_class($creator) == "GeniUser" &&
	    isset($_COOKIE['quickvm_user']) &&
	    $_COOKIE['quickvm_user'] == $creator->uuid()))) {
115
116
117
118
119
120
121
        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
122
123
124
    }
}
$slice = GeniSlice::Lookup("sa", $instance->slice_uuid());
Leigh B Stoller's avatar
Leigh B Stoller committed
125

Leigh B Stoller's avatar
Leigh B Stoller committed
126
$instance_status = $instance->status();
Leigh B Stoller's avatar
Leigh B Stoller committed
127
128
$creator_uid     = $creator->uid();
$creator_email   = $creator->email();
Leigh B Stoller's avatar
Leigh B Stoller committed
129
if ($profile = Profile::Lookup($instance->profile_id(),
130
			       $instance->profile_version())) {
131
132
133
134
135
136
137
    $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
138
139
    $canclone       = ((isset($this_user) &&
                        $profile->CanClone($this_user)) ||
140
141
142
		       ISADMIN() ? 1 : 0);
    $public_url     = ($instance->public_url() ?
		       "'" . $instance->public_url() . "'" : "null");
Leigh B Stoller's avatar
Leigh B Stoller committed
143
    $ispprofile     = $profile->isParameterized() ? 1 : 0;
144
145
146
147
148
149
150
151
}
else {
    $profile_name   = "";
    $profile_uuid   = "";
    $profile_public = "false";
    $cansnap        = 0;
    $canclone       = 0;
    $public_url     = "null";
152
    $ispprofile     = 0;
153
154

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

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

#
# 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") {
212
    $webtask = $instance->WebTask();
213
214
215
216
    if ($webtask && ! $webtask->exited()) {
	$snapping = 1;
    }
}
Leigh B Stoller's avatar
Leigh B Stoller committed
217

218
SPITHEADER(1);
219

220
221
222
echo "<link rel='stylesheet'
            href='css/nv.d3.css'>\n";

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

226
echo "<script type='text/javascript'>\n";
227
echo "  window.APT_OPTIONS.uuid = '" . $uuid . "';\n";
228
echo "  window.APT_OPTIONS.name = '" . $instance_name . "';\n";
229
230
echo "  window.APT_OPTIONS.instanceStatus = '" . $instance_status . "';\n";
echo "  window.APT_OPTIONS.profileName = '" . $profile_name . "';\n";
231
echo "  window.APT_OPTIONS.profileUUID = '" . $profile_uuid . "';\n";
232
echo "  window.APT_OPTIONS.profilePublic = " . $profile_public . ";\n";
233
echo "  window.APT_OPTIONS.sliceURN = '" . $slice_urn . "';\n";
234
echo "  window.APT_OPTIONS.sliceExpires = '" . $slice_expires . "';\n";
235
echo "  window.APT_OPTIONS.sliceExpiresText = '" . $slice_expires_text . "';\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
236
echo "  window.APT_OPTIONS.sliceCreated = '" . $slice_created . "';\n";
237
238
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
239
240
241
242
243
244
if (isset($this_user)) {
    echo "  window.APT_OPTIONS.thisUid = '" . $this_user->uid() . "';\n";
}
else {
    echo "  window.APT_OPTIONS.thisUid = '" . $creator_uid . "';\n";
}
245
echo "  window.APT_OPTIONS.registered = $registered;\n";
246
echo "  window.APT_OPTIONS.isadmin = $isadmin;\n";
247
echo "  window.APT_OPTIONS.isfadmin = $isfadmin;\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
248
echo "  window.APT_OPTIONS.isstud = $isstud;\n";
249
echo "  window.APT_OPTIONS.cansnap = $cansnap;\n";
250
echo "  window.APT_OPTIONS.canclone = $canclone;\n";
251
echo "  window.APT_OPTIONS.snapping = $snapping;\n";
252
echo "  window.APT_OPTIONS.hidelinktest = false;\n";
253
echo "  window.APT_OPTIONS.oneonly = $oneonly;\n";
254
echo "  window.APT_OPTIONS.dossh = $dossh;\n";
255
echo "  window.APT_OPTIONS.ispprofile = $ispprofile;\n";
256
echo "  window.APT_OPTIONS.publicURL = $public_url;\n";
257
258
echo "  window.APT_OPTIONS.user_lockdown = $user_lockdown;\n";
echo "  window.APT_OPTIONS.admin_lockdown = $admin_lockdown;\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
259
echo "  window.APT_OPTIONS.lockout = $lockout;\n";
260
echo "  window.APT_OPTIONS.isopenstack = $isopenstack;\n";
261
echo "  window.APT_OPTIONS.paniced = $paniced;\n";
262
echo "  window.APT_OPTIONS.project = '$project';\n";
263
echo "  window.APT_OPTIONS.group = '$group';\n";
264
265
echo "  window.APT_OPTIONS.extension_requested = " .
    $instance->extension_requested() . ";\n";
266
echo "  window.APT_OPTIONS.extension_denied = $extension_denied;\n";
267
echo "  window.APT_OPTIONS.AJAXURL = 'server-ajax.php';\n";
268
269
270
271
272
273
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
274
            ((time() - strtotime($instance->created())) / 3600));
275
echo "  window.APT_OPTIONS.freenodesurl = '$freenodes_url';\n";
276
277
278
279
280
281
if (isset($maxextend) && $maxextend != "") {
    # Assumed to be hours.
    echo "  window.APT_OPTIONS.MAXEXTEND = $maxextend;\n";
}
else {
    echo "  window.APT_OPTIONS.MAXEXTEND = null;\n";
282
}
283
284
285
286
287
288
289
290
if ($instance->repourl()) {
    echo "  window.APT_OPTIONS.repourl = '" . $instance->repourl() . "';\n";
    if ($instance->reporef()) {
        echo "  window.APT_OPTIONS.reporef = '" . $instance->reporef() . "';\n";
        echo "  window.APT_OPTIONS.repohash = '" .
                substr($instance->repohash(),0,8) . "';\n";
    }
}
291
echo "</script>\n";
292
293
echo "<script src='js/lib/d3.v3.js'></script>\n";
echo "<script src='js/lib/nv.d3.js'></script>\n";
294
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
295
echo "<script src='js/lib/jquery-ui.js'></script>\n";
296
echo "<script src='js/lib/codemirror-min.js'></script>\n";
297
298
299
300
301
302
303
304
305
306
307
308
309

REQUIRE_UNDERSCORE();
REQUIRE_SUP();
REQUIRE_MOMENT();
REQUIRE_MARKED();
REQUIRE_URITEMPLATE();
REQUIRE_IMAGE();
REQUIRE_EXTEND();
REQUIRE_IDLEGRAPHS();
REQUIRE_OPENSTACKGRAPHS();
REQUIRE_CONTEXTMENU();
SPITREQUIRE("js/status.js");

310
311
echo "<link rel='stylesheet'
            href='css/jquery-ui-1.10.4.custom.min.css'>\n";
312
313
# For progress bubbles in the imaging modal.
echo "<link rel='stylesheet' href='css/progress.css'>\n";
314
echo "<link rel='stylesheet' href='css/codemirror.css'>\n";
315
echo "<div class='hidden'><textarea id='extension_reason'>$extension_reason</textarea></div>\n";
316
317
318
319
320
321
if (count($extensions)) {
    $foo = array();
    foreach ($extensions as $extension) {
        $foo[$extension->idx()] = $extension->info;
    }
    echo "<script type='text/plain' id='extensions-json'>\n";
322
    echo json_encode($foo, JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_TAG);
323
324
    echo "</script>\n";
}
325
326
327
if ($extension_denied_reason != "") {
   echo "<pre class='hidden' id='extension_denied_reason'>$extension_denied_reason</pre>\n";
}
328

329
AddTemplateList(array("status", "waitwait-modal", "oops-modal", "register-modal", "terminate-modal", "clone-help", "snapshot-help", "oneonly-modal", "approval-modal", "linktest-modal"));
330
AddTemplateKey("linktest-md", "template/linktest.md");
Leigh B Stoller's avatar
Leigh B Stoller committed
331
332
SPITFOOTER();
?>