edit-dataset.php 4.43 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");
Leigh B Stoller's avatar
Leigh B Stoller committed
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 43 44 45 46 47 48 49 50 51 52
# Must be after quickvm_sup.php since it changes the auth domain.
$page_title = "Modify Dataset";

#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
$this_idx  = $this_user->uid_idx();

#
# Verify page arguments.
#
$optargs = RequiredPageArguments("uuid",        PAGEARG_UUID);
$optargs = OptionalPageArguments("create",      PAGEARG_STRING,
				 "formfields",  PAGEARG_ARRAY);

#
# Either a local lease or a remote dataset. 
#
53 54 55 56 57 58 59
if ($embedded) {
    $dataset = Lease::Lookup($uuid);
    if (!$dataset) {
        $dataset = ImageDataset::Lookup($uuid);
    }
}
else {
60 61 62 63 64 65 66 67 68 69 70 71 72 73
    $dataset = Dataset::Lookup($uuid);
}
if (!$dataset) {
    SPITUSERERROR("No such dataset!");
}
if (!$dataset->AccessCheck($this_user, $LEASE_ACCESS_MODIFY)) {
    SPITUSERERROR("Not enough permission!");
}

#
# Spit the form
#
function SPITFORM($formfields, $errors)
{
74
    global $this_user, $projlist, $embedded, $this_idx;
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    $button_label = "Save";
    $title        = "Modify Dataset";
    $isadmin      = (ISADMIN() ? "true" : "false");

    SPITHEADER(1);

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

    # I think this will take care of XSS prevention?
    echo "<script type='text/plain' id='form-json'>\n";
    echo htmlentities(json_encode($formfields)) . "\n";
    echo "</script>\n";
    echo "<script type='text/plain' id='error-json'>\n";
    echo htmlentities(json_encode($errors));
    echo "</script>\n";
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

    if (!$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)) {
            $uuid         = $row["uuid"];
            $instance     = Instance::Lookup($uuid);
            $profile      = Profile::Lookup($instance->profile_id(),
                                            $instance->profile_version());
            $instance_array[] =
                array("uuid" => $uuid, "name" => $profile->name());
        }
        echo "<script type='text/plain' id='instances-json'>\n";
        echo htmlentities(json_encode($instance_array));
        echo "</script>\n";
    }
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    
    echo "<link rel='stylesheet'
            href='css/jquery-ui.min.css'>\n";
    
    echo "<script type='text/javascript'>\n";
    echo "    window.AJAXURL  = 'server-ajax.php';\n";
    echo "    window.TITLE    = '$title';\n";
    echo "    window.EDITING  = true;\n";
    echo "    window.ISADMIN  = $isadmin;\n";
    echo "    window.BUTTONLABEL = '$button_label';\n";
    echo "</script>\n";

    SPITREQUIRE("create-dataset");
    SPITFOOTER();
}

if (! isset($create)) {
    $errors   = array();
    $fields   = array();

    $fields["dataset_type"]     = $dataset->type();
    $fields["dataset_pid"]      = $dataset->pid();
    $fields["dataset_gid"]      = $dataset->gid();
    $fields["dataset_name"]     = $dataset->id();
    $fields["dataset_size"]     = $dataset->size() . "MiB";
    $fields["dataset_fstype"]   = ($dataset->fstype() ?
				   $dataset->fstype() : "none");
    $fields["dataset_expires"]  = ($dataset->expires() ?
				   DateStringGMT($dataset->expires()) : "");
    $fields["dataset_uuid"]     = $uuid;
140 141
    $fields["dataset_read"]     = $dataset->read_access();
    $fields["dataset_modify"]   = $dataset->write_access();
142 143 144 145 146 147 148

    SPITFORM($fields, $errors);
    return;
}
SPITFORM($formfields, array());

?>