Commit 16905e40 authored by Leigh Stoller's avatar Leigh Stoller

Add updated privacy settings and admin only option to set

the aggregate to use.
parent 8346949c
......@@ -82,6 +82,10 @@ if (isset($ajax_request)) {
$profile_default = "OneVM";
$profile_array = array();
$am_array = array('Utah DDC' =>
"urn:publicid:IDN+utahddc.geniracks.net+authority+cm",
'Utah PG' =>
"urn:publicid:IDN+emulab.net+authority+cm");
#
# if using the super secret URL, make sure the profile exists, and
......@@ -110,7 +114,7 @@ if (isset($profile)) {
# Must be public or belong to user.
#
if (! ($obj->ispublic() ||
$obj->creator_idx == $this_user->uid_idx())) {
$obj->creator_idx() == $this_user->uid_idx())) {
SPITUSERERROR("No permission to use profile: $profile");
exit();
}
......@@ -147,7 +151,7 @@ while ($row = mysql_fetch_array($query_result)) {
function SPITFORM($formfields, $newuser, $errors)
{
global $TBBASE, $TBMAIL_OPS;
global $profile_array, $this_user, $profilename, $profile;
global $profile_array, $this_user, $profilename, $profile, $am_array;
# XSS prevention.
while (list ($key, $val) = each ($formfields)) {
......@@ -285,6 +289,21 @@ function SPITFORM($formfields, $newuser, $errors)
# Needs more work.
echo "<input type='hidden' name='profile' value='$profile'>\n";
}
if (isset($this_user) && ISADMIN()) {
$am_options = "";
while (list($am, $urn) = each($am_array)) {
$selected = "";
if ($formfields["where"] == $am) {
$selected = "selected";
}
$am_options .=
"<option $selected value='$am'>$am</option>\n";
}
$formatter("where",
"<br><select name=\"formfields[where]\"
id='profile_where' class='form-control'>".
"$am_options</select>");
}
echo "</fieldset>
<button class='btn btn-success pull-right'
type='submit' name='create'>Create!
......@@ -332,6 +351,7 @@ if (!isset($create)) {
$defaults["email"] = "";
$defaults["sshkey"] = "";
$defaults["profile"] = (isset($profile) ? $profile : $profile_default);
$defaults["where"] = 'Utah DDC';
#
# Look for current user or cookie that tells us who the user is.
......@@ -416,6 +436,22 @@ else {
}
}
#
# Allow admin users to select the Aggregate. Experimental.
#
$aggregate_urn = "";
if ($this_user && ISADMIN()) {
if (isset($formfields["where"]) && $formfields["where"] != "") {
if (array_key_exists($formfields["where"], $am_array)) {
$aggregate_urn = $am_array[$formfields["where"]];
}
else {
$errors["where"] = "Invalid Aggregate";
}
}
}
if (count($errors)) {
SPITFORM($formfields, false, $errors);
SPITFOOTER();
......@@ -539,7 +575,8 @@ if (count($errors)) {
# This option is used to tell the backend that it is okay to look
# in the emulab users table.
#
$opt = ($this_user ? "-l" : "");
$opt = ($this_user ? "-l" : "");
$opt .= ($aggregate_urn != "" ? " -a '$aggregate_urn'" : "");
$retval = SUEXEC("nobody", "nobody",
"webquickvm $opt -u $quickvm_uuid $xmlname",
......
......@@ -84,14 +84,15 @@ function SPITFORM($formfields, $errors)
echo " </label>\n";
};
$formatter = function($field, $label, $html, $help = null)
use ($errors, $format_label) {
$formatter = function($field, $label, $html, $help = null, $compact = 0)
use ($errors, $format_label) {
$class = "form-group";
if ($errors && array_key_exists($field, $errors)) {
$class .= " has-error";
}
$size = 12;
echo "<div class='$class'>\n";
$margin = ($compact ? 5 : 15);
echo "<div class='$class' style='margin-bottom: ${margin}px;'>\n";
if ($label) {
$format_label($field, $label, $help);
$size = 10;
......@@ -281,27 +282,72 @@ function SPITFORM($formfields, $errors)
"Briefly describe how to use this profile after it starts. ".
"Double click to see it rendered.");
echo "<div class='row'>\n";
# Hide this until the steps table is initialized from the rspec.
echo "<div class='row hidden' id='profile_steps_div'>\n";
$format_label("profile_steps", "Steps");
echo "<div class='col-sm-10'>\n";
echo "<table id='profile_steps' class='col-sm-12'></table>\n";
echo "</div></div>\n";
$formatter("profile_listed", "Listed?",
"<div class='checkbox'>
echo "<div class='row'>\n";
echo "<div class='col-sm-10 col-sm-offset-2'>\n";
$formatter("profile_listed", null,
"<div class='checkbox' >
<label><input name=\"formfields[profile_listed]\" ".
$formfields["profile_listed"] .
" id='profile_listed' value=checked
type=checkbox> ".
"List on the public page for anyone to use?</label></div>");
"List on the home page for anyone to view.</label></div>",
null, true);
echo " </div>\n";
echo "</div>\n";
echo "<div class='row'>\n";
echo "<div class='col-sm-10 col-sm-offset-2'>\n";
echo "Who can instantiate your profile?";
echo " </div>\n";
echo "</div>\n";
echo "<div class='row'>\n";
echo " <div class='col-sm-9 col-sm-offset-3'>\n";
$formatter("profile_who", null,
"<div class='radio'>
<label>
<input type='radio' name='formfields[profile_who]' " .
($formfields["profile_who"] == 'public' ? "checked " : " ") .
"value='public'>
<em>Anyone</em> on the internet (guest users)
</label>
</div>
<div class='radio'>
<label>
<input type='radio' name='formfields[profile_who]' ".
($formfields["profile_who"] == 'shared' ? "checked " : " ") .
"value='shared'>
Only registered users of the APT website
</label>
</div>
<div class='radio'>
<label>
<input type='radio' name='formfields[profile_who]' ".
($formfields["profile_who"] == 'private' ? "checked " : " ") .
"value='private'>
Only members of your project
</label>
</div>",
null, false);
echo " </div>\n";
echo "</div>\n";
if ($editing) {
$formatter("profile_url", "Public URL",
$formatter("profile_url", "Shared URL",
"<input name=\"formfields[profile_url]\"
id='profile_url' readonly
value='" . $formfields["profile_url"] . "'
class='form-control'
placeholder='' type='text'>");
placeholder='' type='text'>",
"Anyone with this URL can instantiate this profile",
false);
}
echo " </fieldset>\n";
......@@ -461,6 +507,9 @@ if (! isset($create)) {
$defaults["profile_url"] = $profile->url();
$defaults["profile_listed"] =
($profile->listed() ? "checked" : "");
$defaults["profile_who"] =
($profile->shared() ? "shared" :
($profile->ispublic() ? "public" : "private"));
#
# If we are displaying after a successful edit, and it
......@@ -554,6 +603,19 @@ if (!$project->IsMember($this_user, $isapproved) || !$isapproved) {
$errors["profile_pid"] = "Illegal project";
}
#
# Convert profile_who to arguments.
#
if (!isset($formfields["profile_who"]) || $formfields["profile_who"] == "") {
$errors["profile_who"] = "Missing value";
}
else {
$who = $formfields["profile_who"];
if (! ($who == "private" || $who == "shared" || $who == "public")) {
$errors["profile_who"] = "Illegal value";
}
}
# Present these errors before we call out to do anything else.
if (count($errors)) {
SPITFORM($formfields, $errors);
......@@ -571,10 +633,15 @@ $xmlname = tempnam("/tmp", "newprofile");
if (! $xmlname) {
TBERROR("Could not create temporary filename", 0);
$errors["error"] = "Internal error; Could not create temp file";
SPITFORM($formfields, $errors);
return;
}
elseif (! ($fp = fopen($xmlname, "w"))) {
TBERROR("Could not open temp file $xmlname", 0);
$errors["error"] = "Internal error; Could not open temp file";
SPITFORM($formfields, $errors);
unlink($xmlname);
return;
}
else {
fwrite($fp, "<profile>\n");
......@@ -597,15 +664,14 @@ else {
fwrite($fp, "0");
}
fwrite($fp, "</value></attribute>\n");
fwrite($fp, "<attribute name='profile_shared'><value>" .
($who == "shared" ? 1 : 0) . "</value></attribute>\n");
fwrite($fp, "<attribute name='profile_public'><value>" .
($who == "public" ? 1 : 0) . "</value></attribute>\n");
fwrite($fp, "</profile>\n");
fclose($fp);
chmod($xmlname, 0666);
}
if (count($errors)) {
unlink($xmlname);
SPITFORM($formfields, $errors);
return;
}
#
# Call out to the backend.
......@@ -635,11 +701,12 @@ if ($retval) {
}
}
}
unlink($xmlname);
if (count($errors)) {
unlink($xmlname);
SPITFORM($formfields, $errors);
return;
}
#
# Need the index to pass back through.
#
......
......@@ -133,7 +133,8 @@ echo " <th>Project</th>
<th>Description</th>
<th>Show</th>
<th>Created</th>
<th>Public</th>
<th>Listed</th>
<th>Privacy</th>
</tr>
</thead>
<tbody>\n";
......@@ -145,8 +146,17 @@ while ($row = mysql_fetch_array($query_result)) {
$desc = $row["description"];
$created = $row["created"];
$public = $row["public"];
$listed = ($row["listed"] ? "Yes" : "No");
$shared = $row["shared"];
$creator = $row["creator"];
$rspec = $row["rspec"];;
$rspec = $row["rspec"];
if ($public)
$privacy = "Public";
elseif ($shared)
$privacy = "Shared";
else
$privacy = "Private";
$parsed_xml = simplexml_load_string($rspec);
if ($parsed_xml &&
......@@ -169,7 +179,8 @@ while ($row = mysql_fetch_array($query_result)) {
Show</button>
</td>
<td>$created</td>
<td>$public</td>
<td>$listed</td>
<td>$privacy</td>
</tr>\n";
}
echo " </tbody>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment