show-profile.php 5.24 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 27 28
# 
# {{{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("webtask.php");
chdir("apt");
include("quickvm_sup.php");
29 30
include_once("profile_defs.php");
include_once("instance_defs.php");
31 32 33 34 35 36
$page_title = "Show Profile";

#
# Get current user.
#
RedirectSecure();
37
$this_user = CheckLoginOrRedirect(CHECKLOGIN_WEBONLY);
38 39 40 41 42 43
$this_idx  = $this_user->uid_idx();
$isadmin   = (ISADMIN() ? 1 : 0);

#
# Verify page arguments.
#
44 45 46 47
$optargs = OptionalPageArguments("uuid",   PAGEARG_STRING,
                                 "profile",PAGEARG_STRING,
                                 "project",PAGEARG_PROJECT,
                                 "source", PAGEARG_BOOLEAN,
48
                                 "rspec",  PAGEARG_BOOLEAN);
49 50 51 52 53 54 55 56
if (isset($uuid))  {
    $profile = Profile::Lookup($uuid);
}
elseif (isset($project) && isset($profile)) {
    $profile = Profile::LookupByName($project, $profile);
}    
else {
    SPITUSERERROR("Must provide a uuid or project/profile name!");
57 58 59 60
}
if (!$profile) {
    SPITUSERERROR("No such profile!");
}
61
if (!$profile->CanView($this_user) && !(ISADMIN() || ISFOREIGN_ADMIN())) {
62 63
    SPITUSERERROR("Not enough permission!");
}
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
# For the download source button.
if ($source || $rspec) {
    $filename = $profile->name() . ".xml";
    $stuff    = $profile->rspec();

    if ($source && $profile->script() && $profile->script() != "") {
        $stuff = $profile->script();
        $filename = $profile->name() . ".py";
    }
    header("Content-Type: text/plain");
    header("Content-Disposition: attachment; filename='${filename}'");
    echo $stuff;
    return;
}
SPITHEADER(1);
echo "<div id='ppviewmodal_div'></div>\n";

81 82
$profile_uuid = $profile->profile_uuid();
$version_uuid = $profile->uuid();
83
$ispp         = ($profile->isParameterized() ? 1 : 0);
84
$history      = ($profile->HasHistory() ? 1 : 0);
85
$canedit      = ($profile->CanEdit($this_user) ? 1 : 0);
86
$disabled     = ($profile->isDisabled() ? 1 : 0);
87 88 89 90 91 92

$defaults = array();
$defaults["profile_name"]        = $profile->name();
$defaults["profile_rspec"]       = $profile->rspec();
$defaults["profile_version"]     = $profile->version();
$defaults["profile_creator"]     = $profile->creator();
93
$defaults["profile_updater"]     = $profile->updater();
94
$defaults["profile_pid"]         = $profile->pid();
95
$defaults["profile_created"]     = DateStringGMT($profile->created());
96
$defaults["profile_published"]   = DateStringGMT($profile->published());
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
$defaults["profile_version_url"] = $profile->URL();
$defaults["profile_profile_url"] = $profile->ProfileURL();
if ($profile->script() && $profile->script() != "") {
    $defaults["profile_script"] = $profile->script();
}

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

echo "<link rel='stylesheet'
            href='css/jquery-ui-1.10.4.custom.min.css'>\n";
echo "<link rel='stylesheet' href='css/codemirror.css'>\n";

# I think this will take care of XSS prevention?
echo "<script type='text/plain' id='form-json'>\n";
echo htmlentities(json_encode($defaults)) . "\n";
echo "</script>\n";

Leigh B Stoller's avatar
Leigh B Stoller committed
115 116
$am_array = Instance::DefaultAggregateList();
$amlist   = array();
117 118
$amdefault = "";
if (($ISCLOUD || ISADMIN() || STUDLY())) {
Leigh B Stoller's avatar
Leigh B Stoller committed
119
    while (list($am) = each($am_array)) {
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
	$amlist[] = $am;
    }
    $amdefault = $DEFAULT_AGGREGATE;
    # Temporary override until constraint system in place.
    if ($profile->BestAggregate()) {
	$amdefault = $profile->BestAggregate();
    }
}
echo "<script type='text/plain' id='amlist-json'>\n";
echo htmlentities(json_encode($amlist));
echo "</script>\n";

echo "<script type='text/javascript'>\n";
echo "    window.PROFILE_UUID = '$profile_uuid';\n";
echo "    window.VERSION_UUID = '$version_uuid';\n";
135 136
echo "    window.AJAXURL      = 'server-ajax.php';\n";
echo "    window.ISADMIN      = $isadmin;\n";
137
echo "    window.CANEDIT      = $canedit;\n";
138
echo "    window.DISABLED     = $disabled;\n";
139
echo "    window.HISTORY      = $history;\n";
140
echo "    window.ISPPPROFILE  = $ispp;\n";
Leigh B Stoller's avatar
Leigh B Stoller committed
141
echo "    window.WITHPUBLISHING = $WITHPUBLISHING;\n";
142 143 144 145
echo "</script>\n";

echo "<script src='js/lib/codemirror-min.js'></script>\n";

146 147 148 149 150
REQUIRE_UNDERSCORE();
REQUIRE_SUP();
REQUIRE_MOMENT();
REQUIRE_MARKED();
SPITREQUIRE("js/show-profile.js",
151 152
            "<script src='js/lib/jquery-ui.js'></script>\n".
            "<script src='js/lib/jquery.appendGrid-1.3.1.min.js'></script>");
153 154

AddTemplateList(array("show-profile", "waitwait-modal", "renderer-modal", "showtopo-modal", "rspectextview-modal", "guest-instantiate", "instantiate-modal", "oops-modal", "share-modal"));
155 156 157
SPITFOOTER();

?>