status.php 8.48 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-2015 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

Leigh B Stoller's avatar
Leigh B Stoller committed
44
45
46
#
# Verify page arguments.
#
47
48
$reqargs = OptionalPageArguments("uuid",    PAGEARG_STRING,
				 "extend",  PAGEARG_INTEGER,
49
				 "oneonly", PAGEARG_BOOLEAN);
50

Leigh B Stoller's avatar
Leigh B Stoller committed
51
52
if (!isset($uuid)) {
    SPITHEADER(1);
53
54
55
56
57
    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
58
59
60
61
62
    SPITFOOTER();
    return;
}

#
Leigh B Stoller's avatar
Leigh B Stoller committed
63
# See if the instance exists. If not, redirect back to the create page
Leigh B Stoller's avatar
Leigh B Stoller committed
64
#
Leigh B Stoller's avatar
Leigh B Stoller committed
65
66
$instance = Instance::Lookup($uuid);
if (!$instance) {
Leigh B Stoller's avatar
Leigh B Stoller committed
67
    SPITHEADER(1);
68
69
70
71
72
    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
73
74
75
    SPITFOOTER();
    flush();
    sleep(3);
76
    PAGEREPLACE("instantiate.php");
Leigh B Stoller's avatar
Leigh B Stoller committed
77
78
    return;
}
Leigh B Stoller's avatar
Leigh B Stoller committed
79
80
81
$creator = GeniUser::Lookup("sa", $instance->creator_uuid());
if (! $creator) {
    $creator = User::LookupByUUID($instance->creator_uuid());
82
}
Leigh B Stoller's avatar
Leigh B Stoller committed
83
84
if (!$creator) {
    SPITHEADER(1);
85
86
    echo "<div class='align-center'>
            <p class='lead text-center'>
Leigh B Stoller's avatar
Leigh B Stoller committed
87
               Hmm, there seems to be a problem.
88
89
            </p>
          </div>\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
90
    SPITFOOTER();
Leigh B Stoller's avatar
Leigh B Stoller committed
91
    TBERROR("No creator for instance: $uuid", 0);
Leigh B Stoller's avatar
Leigh B Stoller committed
92
93
    return;
}
Leigh B Stoller's avatar
Leigh B Stoller committed
94
#
95
# Only logged in admins can access an experiment created by someone else.
Leigh B Stoller's avatar
Leigh B Stoller committed
96
#
97
98
99
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
100
101
    if (! ((get_class($creator) == "User" && isset($this_user) &&
            $instance->CanView($this_user)) ||
102
103
104
	   (get_class($creator) == "GeniUser" &&
	    isset($_COOKIE['quickvm_user']) &&
	    $_COOKIE['quickvm_user'] == $creator->uuid()))) {
105
	PAGEERROR("You do not have permission to look at this experiment!");
Leigh B Stoller's avatar
Leigh B Stoller committed
106
107
108
    }
}
$slice = GeniSlice::Lookup("sa", $instance->slice_uuid());
Leigh B Stoller's avatar
Leigh B Stoller committed
109

Leigh B Stoller's avatar
Leigh B Stoller committed
110
$instance_status = $instance->status();
Leigh B Stoller's avatar
Leigh B Stoller committed
111
112
$creator_uid     = $creator->uid();
$creator_email   = $creator->email();
113
if ($instance->profile_id() &&
114
    $profile = Profile::Lookup($instance->profile_id(),
115
			       $instance->profile_version())) {
116
117
118
119
120
121
122
    $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
123
124
    $canclone       = ((isset($this_user) &&
                        $profile->CanClone($this_user)) ||
125
126
127
128
129
130
131
132
133
134
135
136
137
		       ISADMIN() ? 1 : 0);
    $public_url     = ($instance->public_url() ?
		       "'" . $instance->public_url() . "'" : "null");
}
else {
    $profile_name   = "";
    $profile_uuid   = "";
    $profile_public = "false";
    $cansnap        = 0;
    $canclone       = 0;
    $public_url     = "null";

}
138
139
if ($slice) {
    $slice_urn       = $slice->urn();
140
141
142
143
144
    $instance_name   = $instance->name();
    # Until old instances are gone.
    if (!$instance_name) {
        $instance_name = $slice_urn;
    }
145
    $slice_expires   = DateStringGMT($slice->expires());
146
    $slice_expires_text = gmdate("m-d\TH:i\Z", strtotime($slice->expires()));
Leigh B Stoller's avatar
Leigh B Stoller committed
147
    $slice_created   = DateStringGMT($instance->created());
148
149
150
151
152
}
else {
    $slice_urn = "";
    $slice_expires = "";
    $slice_expires_text = ""; 
Leigh B Stoller's avatar
Leigh B Stoller committed
153
    $slice_created  = "";
154
    $instance_name  = "";
155
}
156
$registered      = (isset($this_user) ? "true" : "false");
157
$snapping        = 0;
158
$oneonly         = (isset($oneonly) && $oneonly ? 1 : 0);
159
$isadmin         = (ISADMIN() ? 1 : 0);
160
161
162
163
$lockdown        = ($instance->admin_lockdown() ||
                    $instance->user_lockdown() ? 1 : 0);
$extension_reason= ($instance->extension_reason() ?
                    CleanString($instance->extension_reason()) : "");
164
165
166
$extension_history= ($instance->extension_history() ?
                    CleanString($instance->extension_history()) : "");
$freenodes_url   = $freenodes_mapping[$instance->aggregate_urn()];
Leigh B Stoller's avatar
Leigh B Stoller committed
167
$lockout         = $instance->extension_lockout();
Leigh B Stoller's avatar
Leigh B Stoller committed
168
169
170
171
172
173
174
175

#
# We give ssh to the creator (real user or guest user).
#
$dossh =
    (((isset($this_user) && $this_user->SameUser($creator)) ||
      (isset($_COOKIE['quickvm_user']) &&
       $_COOKIE['quickvm_user'] == $creator->uuid())) ? 1 : 0);
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

#
# 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
193

194
SPITHEADER(1);
195

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

199
echo "<script type='text/javascript'>\n";
200
echo "  window.APT_OPTIONS.uuid = '" . $uuid . "';\n";
201
echo "  window.APT_OPTIONS.name = '" . $instance_name . "';\n";
202
203
echo "  window.APT_OPTIONS.instanceStatus = '" . $instance_status . "';\n";
echo "  window.APT_OPTIONS.profileName = '" . $profile_name . "';\n";
204
echo "  window.APT_OPTIONS.profileUUID = '" . $profile_uuid . "';\n";
205
echo "  window.APT_OPTIONS.profilePublic = " . $profile_public . ";\n";
206
echo "  window.APT_OPTIONS.sliceURN = '" . $slice_urn . "';\n";
207
echo "  window.APT_OPTIONS.sliceExpires = '" . $slice_expires . "';\n";
208
echo "  window.APT_OPTIONS.sliceExpiresText = '" . $slice_expires_text . "';\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
209
echo "  window.APT_OPTIONS.sliceCreated = '" . $slice_created . "';\n";
210
211
echo "  window.APT_OPTIONS.creatorUid = '" . $creator_uid . "';\n";
echo "  window.APT_OPTIONS.creatorEmail = '" . $creator_email . "';\n";
212
echo "  window.APT_OPTIONS.registered = $registered;\n";
213
echo "  window.APT_OPTIONS.isadmin = $isadmin;\n";
214
echo "  window.APT_OPTIONS.cansnap = $cansnap;\n";
215
echo "  window.APT_OPTIONS.canclone = $canclone;\n";
216
echo "  window.APT_OPTIONS.snapping = $snapping;\n";
217
echo "  window.APT_OPTIONS.oneonly = $oneonly;\n";
218
echo "  window.APT_OPTIONS.dossh = $dossh;\n";
219
echo "  window.APT_OPTIONS.publicURL = $public_url;\n";
220
echo "  window.APT_OPTIONS.lockdown = $lockdown;\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
221
echo "  window.APT_OPTIONS.lockout = $lockout;\n";
222
echo "  window.APT_OPTIONS.AJAXURL = 'server-ajax.php';\n";
223
echo "  window.APT_OPTIONS.freenodesurl = '$freenodes_url';\n";
224
225
226
if (isset($extend) && $extend != "") {
    echo "  window.APT_OPTIONS.extend = $extend;\n";
}
227
echo "var FOO = null;\n";
228
echo "</script>\n";
229
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
230
echo "<script src='js/lib/jquery-ui.js'></script>\n";
231
echo "<script src='js/lib/codemirror-min.js'></script>\n";
232
echo "<script src='js/lib/bootstrap.js'></script>\n";
233
echo "<script src='js/lib/require.js' data-main='js/status'></script>";
234
235
echo "<link rel='stylesheet'
            href='css/jquery-ui-1.10.4.custom.min.css'>\n";
236
237
# For progress bubbles in the imaging modal.
echo "<link rel='stylesheet' href='css/progress.css'>\n";
238
echo "<link rel='stylesheet' href='css/codemirror.css'>\n";
239
echo "<div class='hidden'><textarea id='extension_reason'>$extension_reason</textarea></div>\n";
240
echo "<pre class='hidden' id='extension_history'>$extension_history</pre>\n";
241

Leigh B Stoller's avatar
Leigh B Stoller committed
242
243
SPITFOOTER();
?>