show-dataset.php 5.9 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2016 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 23 24 25 26
# 
# {{{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("lease_defs.php");
27
include("imageid_defs.php");
28 29
chdir("apt");
include("quickvm_sup.php");
30 31 32
include_once("dataset_defs.php");
include_once("instance_defs.php");
include_once("profile_defs.php");
33 34 35 36 37 38 39 40 41 42
# Must be after quickvm_sup.php since it changes the auth domain.
$page_title = "Show Dataset";

#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
$this_idx  = $this_user->uid_idx();
$this_uid  = $this_user->uid();
Leigh Stoller's avatar
Leigh Stoller committed
43
$isadmin   = (ISADMIN() ? 1 : 0);
44 45 46 47 48 49 50 51 52

#
# Verify page arguments.
#
$optargs = RequiredPageArguments("uuid", PAGEARG_UUID);

#
# Either a local lease or a remote dataset. 
#
53 54 55 56
if (!$embedded) {
    $dataset = Dataset::Lookup($uuid);
}
if (!$dataset) {
57 58 59 60 61
    $dataset = Lease::Lookup($uuid);
    if (!$dataset) {
        $dataset = ImageDataset::Lookup($uuid);
    }
}
62 63 64 65 66 67 68 69 70 71
if (!$dataset) {
    SPITUSERERROR("No such dataset!");
}
if (!$dataset->AccessCheck($this_user, $LEASE_ACCESS_READINFO)) {
    SPITUSERERROR("Not enough permission!");
}
# Owner or admin can delete.
$candelete  = (ISADMIN() || $dataset->owner_uid() == $this_uid ? 1 : 0);

# An admin can approve an unapproved lease.
72
$canapprove = ($dataset->islocal() && ISADMIN() &&
73 74
	       $dataset->state() == "unapproved" ? 1 : 0);

Leigh Stoller's avatar
Leigh Stoller committed
75 76 77
# Remote datasets can be refreshed.
$canrefresh = ($dataset->islocal() ? 0 : 1);

78 79 80
# Can an image backed dataset be updated.
$cansnapshot = ($candelete && $dataset->type() == "imdataset" ? 1 : 0);

81 82
$fields = array();
if ($dataset->type() == "stdataset") {
83
    $fields["dataset_type_string"] = "short term";
84 85
}
elseif ($dataset->type() == "ltdataset") {
86
    $fields["dataset_type_string"] = "long term";
87
}
88 89
elseif ($dataset->type() == "imdataset") {
    $fields["dataset_type_string"] = "image backed";
90
}
91
$fields["dataset_type"]     = $dataset->type();
92 93
$fields["dataset_creator"]  = $dataset->owner_uid();
$fields["dataset_pid"]      = $dataset->pid();
Leigh Stoller's avatar
Leigh Stoller committed
94
$fields["dataset_gid"]      = $dataset->gid();
95
$fields["dataset_name"]     = $dataset->id();
96
$fields["dataset_size"]     = $dataset->size() ? $dataset->size() : "0";
Leigh Stoller's avatar
Leigh Stoller committed
97 98 99
$fields["dataset_fstype"]   = ($dataset->fstype() ?
			       $dataset->fstype() : "none");
$fields["dataset_created"]  = DateStringGMT($dataset->created());
100 101
$fields["dataset_updated"]  = ($dataset->updated() ?
			       DateStringGMT($dataset->updated()) : "");
102
$fields["dataset_expires"]  = ($dataset->expires() ?
Leigh Stoller's avatar
Leigh Stoller committed
103
			       DateStringGMT($dataset->expires()) : "");
104
$fields["dataset_lastused"] = ($dataset->last_used() ?
Leigh Stoller's avatar
Leigh Stoller committed
105
			       DateStringGMT($dataset->last_used()) : "");
106
$fields["dataset_uuid"]     = $uuid;
Leigh Stoller's avatar
Leigh Stoller committed
107
$fields["dataset_urn"]      = $dataset->URN();
108 109
$fields["dataset_read"]     = $dataset->read_access();
$fields["dataset_write"]    = $dataset->write_access();
Leigh Stoller's avatar
Leigh Stoller committed
110 111 112
if (ISADMIN()) {
    $fields["dataset_idx"]  = $dataset->idx();
}
113 114 115
if ($dataset->type() == "imdataset") {
    $fields["dataset_url"]  = $dataset->URL();
}
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

#
# The state is a bit of a problem, since local leases do not have
# an "allocating" state. For a remote dataset, we get set to busy.
# Need to unify this. But the main point is that we want to tell
# the user that the dataset is busy allocation.
#
if ($dataset->state() == "busy" ||
    ($dataset->state() == "unapproved" && $dataset->locked())) {
    $fields["dataset_state"] = "allocating";
}
else {
    $fields["dataset_state"] = $dataset->state();
}
SPITHEADER(1);

# Place to hang the toplevel template.
echo "<div id='main-body'></div>\n";

echo "<script type='text/plain' id='fields-json'>\n";
echo htmlentities(json_encode($fields)) . "\n";
echo "</script>\n";

139 140 141 142 143 144 145 146 147 148 149 150 151
#
# Instance list for image backed dataset.
#
if ($cansnapshot && !$embedded) {
    $query_result =
        DBQueryFatal("select uuid from apt_instances as a ".
                     "where creator_idx='$this_idx'");
    $instance_array = array();

    while ($row = mysql_fetch_array($query_result)) {
        $instance     = Instance::Lookup($row["uuid"]);
        $profile      = Profile::Lookup($instance->profile_id(),
                                        $instance->profile_version());
152 153
        if ($instance && $profile) {
            $instance_array[] =
Leigh Stoller's avatar
Leigh Stoller committed
154 155
                array("uuid" => $instance->uuid(),
                      "name" => $instance->name());
156
        }
157 158 159 160 161 162
    }
    echo "<script type='text/plain' id='instances-json'>\n";
    echo htmlentities(json_encode($instance_array));
    echo "</script>\n";
}

163 164 165 166 167
echo "<script type='text/javascript'>\n";
echo "    window.TITLE      = '$page_title';\n";
echo "    window.UUID       = '$uuid';\n";
echo "    window.CANDELETE  = $candelete;\n";
echo "    window.CANAPPROVE = $canapprove;\n";
Leigh Stoller's avatar
Leigh Stoller committed
168
echo "    window.CANREFRESH = $canrefresh;\n";
169
echo "    window.CANSNAPSHOT= $cansnapshot;\n";
170
echo "</script>\n";
171 172 173 174 175 176 177

REQUIRE_UNDERSCORE();
REQUIRE_SUP();
REQUIRE_MOMENT();
REQUIRE_APTFORMS();
REQUIRE_IMAGE();
SPITREQUIRE("js/show-dataset.js",
178
            "<script src='js/lib/jquery-ui.js'></script>\n");            
179 180 181
# For progress bubbles in the imaging modal.
echo "<link rel='stylesheet' href='css/progress.css'>\n";
echo "<link rel='stylesheet' href='css/codemirror.css'>\n";
182 183

AddTemplateList(array("show-dataset", "snapshot-dataset", "oops-modal", "waitwait-modal"));
184 185 186
SPITFOOTER();

?>