show-profile.php 6.4 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2018 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

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

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

114 115 116 117 118 119 120 121
# Place to hang the genilib-editor template.
echo "<div id='genilib-editor-body'></div>\n";

# These two modals live outside so that genilib-editor can
# use them as well.
echo "<div id='waitwait_div'></div>
      <div id='oops_div'></div>";

122 123 124
echo "<link rel='stylesheet'
            href='css/jquery-ui-1.10.4.custom.min.css'>\n";
echo "<link rel='stylesheet' href='css/codemirror.css'>\n";
125
echo "<link rel='stylesheet' href='css/genilib-editor.css'>\n";
126 127 128 129 130 131

# 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";

132 133 134 135 136
# Needed for genilib-editor
echo "<script src='https://cdn.jsdelivr.net/ace/1.2.3/noconflict/ace.js'></script>\n";
echo "<script src='https://cdn.jsdelivr.net/ace/1.2.3/noconflict/keybinding-vim.js'></script>\n";
echo "<script src='https://cdn.jsdelivr.net/ace/1.2.3/noconflict/keybinding-emacs.js'></script>\n";

Leigh Stoller's avatar
Leigh Stoller committed
137 138
$am_array = Instance::DefaultAggregateList();
$amlist   = array();
139 140
$amdefault = "";
if (($ISCLOUD || ISADMIN() || STUDLY())) {
141 142 143 144
    while (list($index, $aggregate) = each($am_array)) {
        $urn = $aggregate->urn();
        $am  = $aggregate->name();
        
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
	$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";
160 161
echo "    window.AJAXURL      = 'server-ajax.php';\n";
echo "    window.ISADMIN      = $isadmin;\n";
162
echo "    window.CANEDIT      = $canedit;\n";
163
echo "    window.DISABLED     = $disabled;\n";
164
echo "    window.HISTORY      = $history;\n";
165
echo "    window.ISPPPROFILE  = $ispp;\n";
166
echo "    window.WITHPUBLISHING = $WITHPUBLISHING;\n";
167
echo "    window.EDITOR_READONLY = true;\n";
168 169 170 171
echo "</script>\n";

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

172 173 174
REQUIRE_UNDERSCORE();
REQUIRE_SUP();
REQUIRE_MOMENT();
175
REQUIRE_APTFORMS();
176
REQUIRE_MARKED();
177
REQUIRE_GENILIB_EDITOR();
178
AddLibrary("js/gitrepo.js");
179
SPITREQUIRE("js/show-profile.js",
180 181
            "<script src='js/lib/jquery-ui.js'></script>\n".
            "<script src='js/lib/jquery.appendGrid-1.3.1.min.js'></script>");
182

183
AddTemplateList(array("show-profile", "waitwait-modal", "renderer-modal", "showtopo-modal", "rspectextview-modal", "instantiate-modal", "oops-modal", "share-modal", "gitrepo-picker", "copy-repobased-profile"));
184 185 186
SPITFOOTER();

?>