Commit 18217eb3 authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

New admin pages for experiment listing and project approval.

1. Get rid of the old myexperiments page and change all uses to the user
   dashboard or landing page.

   Replaced with admins only page for listing all experiments, pending
   extensions, locked down, expires, and older then 45 days.

2. New page for approving projects using modern technology, as per Rob's
   request in issue #304.
parent 53465b19
<?php
#
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
#
# {{{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("..");
chdir("apt");
include_once("profile_defs.php");
include_once("instance_defs.php");
include_once("ajax-routines.ajax");
# This is set in CheckPageArgs();
$project = null;
#
# Need to check the permission, since we allow admins to mess with
# other accounts.
#
function CheckPageArgs()
{
global $this_user;
global $ajax_args, $project;
if (!ISADMIN()) {
SPITAJAX_ERROR(-1, "Not enough permission");
return -1;
}
if (!isset($ajax_args["pid"])) {
SPITAJAX_ERROR(-1, "Must supply project");
return -1;
}
$project = Project::LookupByPid($ajax_args["pid"]);
if (!$project) {
SPITAJAX_ERROR(-1, "No such project");
return -1;
}
return 0;
}
function Do_ProjectList()
{
global $this_user;
global $ajax_args;
$results = array();
if (!ISADMIN()) {
SPITAJAX_ERROR(-1, "Not enough permission");
return;
}
#
# Look in the projects table to see which projects have not been approved.
#
$projlist = Project::PendingProjectList();
foreach ($projlist as $project) {
$blob = array();
$leader = $project->GetLeader();
$portal = $project->portal();
if (!$portal) {
$portal = "Classic";
}
$blob["pid"] = $project->pid();
$blob["pid_idx"] = $project->pid_idx();
$blob["created"] = DateStringGMT($project->created());
$blob["description"] = $project->name();
if ($project->URL() && $project->URL() != "") {
if (preg_match("/^http[s]?:\/\//", $project->URL())) {
$blob["url"] = $project->URL();
}
else {
$blob["url"] = "http://" . $project->URL();
}
}
$blob["portal"] = $portal;
$blob["why"] = $project->why();
$blob["leader"] = $project->head_uid();
$blob["leader_idx"] = $project->head_idx();
$blob["leader_name"] = $leader->name();
$blob["leader_affil"] = $leader->affil();
$blob["leader_email"] = $leader->email();
$results[$project->pid()] = $blob;
}
SPITAJAX_RESPONSE($results);
}
#
# Save new project description.
#
function Do_SaveDescription()
{
global $this_user;
global $ajax_args, $project;
if (CheckPageArgs()) {
return;
}
if (!isset($ajax_args["description"])) {
SPITAJAX_ERROR(-1, "Must supply description");
return;
}
$description = $ajax_args["description"];
if (!TBvalid_why($description)) {
SPITAJAX_ERROR(-1, "Not a valid description: " + TBFieldErrorString());
return;
}
$pid_idx = $project->pid_idx();
$safe_why = addslashes($description);
if (!DBQueryWarn("update projects set why='$safe_why' ".
"where pid_idx='$pid_idx'")) {
SPITAJAX_ERROR(-1, "Error saving new description");
return;
}
SPITAJAX_RESPONSE(0);
}
#
# Request more info.
#
function Do_MoreInfo()
{
global $this_user;
global $ajax_args, $project;
if (CheckPageArgs()) {
return;
}
if (!isset($ajax_args["message"])) {
SPITAJAX_ERROR(-1, "Must supply message");
return;
}
$message = $ajax_args["message"];
if (! ($leader = $project->GetLeader())) {
TBERROR("Error getting leader for $pid", 0);
SPITAJAX_ERROR(-1, "Internal error getting project leader");
}
$headuid = $project->head_uid();
$headuid_email = $leader->email();
$headname = $leader->name();
$pid = $project->pid();
SendProjAdminMail
($project, "ADMIN", "$headname '$headuid' <$headuid_email>",
"Request for more info about project '$pid'",
"This message is to notify you that your project application\n".
"for $pid has been postponed until we have more information\n".
"or you take certain actions. You can just reply to this message\n".
"to provide that information or report your actions.\n".
"----------------------------------------------------------------\n".
"\n".
$message.
"\n\n".
"Thanks!\n");
SPITAJAX_RESPONSE(0);
}
#
# Approve
#
function Do_Approve()
{
global $this_user;
global $ajax_args, $project, $TBADMINGROUP, $suexec_output;
if (CheckPageArgs()) {
return;
}
if (!isset($ajax_args["message"])) {
SPITAJAX_ERROR(-1, "Must supply message");
return;
}
$message = $ajax_args["message"];
if (! ($leader = $project->GetLeader())) {
TBERROR("Error getting leader for $pid", 0);
SPITAJAX_ERROR(-1, "Internal error getting project leader");
return;
}
$curstatus = $leader->status();
$headuid = $project->head_uid();
$headuid_email = $leader->email();
$headname = $leader->name();
$pid = $project->pid();
# See if we are in an initial Emulab setup.
$FirstInitState= (TBGetFirstInitState() == "approveproject" ? 1 : 0);
$optargs = "";
# Sanity check the leader status.
if ($curstatus != TBDB_USERSTATUS_ACTIVE &&
$curstatus != TBDB_USERSTATUS_UNAPPROVED) {
SPITAJAX_ERROR(-1, "Invalid $headuid status $curstatus");
return;
}
# Optional message passed along.
if ($message != "") {
$filename = tempnam("/tmp", "approveproject");
$fp = fopen($filename, "w");
if (!$fp) {
SPITAJAX_ERROR(-1, "Could not create temporary file for message");
return;
}
fwrite($fp, $message);
fclose($fp);
$optargs = " -f " . escapeshellarg($filename);
}
$retval = SUEXEC($this_user->uid(), $TBADMINGROUP,
"webmkproj $optargs $pid", SUEXEC_ACTION_CONTINUE);
if (isset($filename)) {
unlink($filename);
}
if ($retval) {
SPITAJAX_ERROR(-1, "Internal error creating project, ".
"see the email sent to your testbed-ops list");
return;
}
#
# Page throws up a message.
#
if ($FirstInitState) {
#
# Move to next phase.
#
TBSetFirstInitState("Ready");
SPITAJAX_RESPONSE(1);
return;
}
SPITAJAX_RESPONSE(0);
}
#
# Deny
#
function Do_Deny()
{
global $this_user;
global $ajax_args, $project, $TBADMINGROUP, $suexec_output;
$this_uid = $this_user->uid();
if (CheckPageArgs()) {
return;
}
if (!isset($ajax_args["message"])) {
SPITAJAX_ERROR(-1, "Must supply message");
return;
}
if (!isset($ajax_args["deleteuser"])) {
SPITAJAX_ERROR(-1, "Must supply deleteuser");
return;
}
$message = $ajax_args["message"];
$deleteuser = ($ajax_args["deleteuser"] == 1 ? 1 : 0);
if (! ($leader = $project->GetLeader())) {
TBERROR("Error getting leader for $pid", 0);
SPITAJAX_ERROR(-1, "Internal error getting project leader");
return;
}
$curstatus = $leader->status();
$headuid = $project->head_uid();
$headuid_email = $leader->email();
$headname = $leader->name();
$pid = $project->pid();
$optargs = "";
if ($deleteuser) {
#
# Take the user out of the project group first.
#
$retval = SUEXEC($this_uid, $TBADMINGROUP,
"webmodgroups -r $pid:$pid $headuid",
SUEXEC_ACTION_CONTINUE);
if ($retval) {
SPITAJAX_ERROR(-1, "Internal error removing user from project");
return;
}
#
# See if user is in any other projects (even unapproved).
#
$project_list = $leader->ProjectMembershipList();
#
# If yes, then we cannot safely delete the user account.
#
if (! count($project_list)) {
#
# No other project membership. If the user is unapproved/newuser,
# it means he was never approved in any project, and so will
# likely not be missed. He will be unapproved if he did his
# verification.
#
if ($curstatus == TBDB_USERSTATUS_NEWUSER ||
$curstatus == TBDB_USERSTATUS_UNAPPROVED) {
$retval = SUEXEC($this_uid, $TBADMINGROUP,
"webrmuser -n -p $pid $headuid",
SUEXEC_ACTION_CONTINUE);
if ($retval) {
SPITAJAX_ERROR(-1, "Internal error removing user");
return;
}
}
}
}
$retval = SUEXEC($this_uid, $TBADMINGROUP,
"webrmproj $pid", SUEXEC_ACTION_CONTINUE);
if ($retval) {
SPITAJAX_ERROR(-1, "Internal error removing project, ".
"see the email sent to your testbed-ops list");
return;
}
# This works cause we still have the project object in memory.
SendProjAdminMail
($project, "ADMIN", "$headname '$headuid' <$headuid_email>",
"Project application '$pid' has been denied!",
"This message is to notify you that your project application\n".
"for $pid has been denied.\n".
($message == "" ? "" :
"----------------------------------------------------------------\n".
"\n".
$message . "\n"));
SPITAJAX_RESPONSE(0);
}
# Local Variables:
# mode:php
# End:
?>
<?php
#
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
#
# {{{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("geni_defs.php");
chdir("apt");
include("quickvm_sup.php");
$page_title = "Approve Projects";
#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
$isadmin = (ISADMIN() ? 1 : 0);
if (!ISADMIN()) {
SPITUSERERROR("You do not have permission to view this page");
}
SPITHEADER(1);
echo "<link rel='stylesheet'
href='css/tablesorter.css'>\n";
# Place to hang the toplevel template.
echo "<div id='page-body'></div>\n";
echo "<script src='js/lib/jquery-2.0.3.min.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.min.js'></script>\n";
echo "<script src='js/lib/jquery.tablesorter.widgets.min.js'></script>\n";
REQUIRE_UNDERSCORE();
REQUIRE_SUP();
REQUIRE_MOMENT();
SPITREQUIRE("js/approve-projects.js");
AddTemplateList(array("approve-projects", "project-approval-list",
"waitwait-modal", "oops-modal"));
SPITFOOTER();
?>
<?php
#
# Copyright (c) 2000-2016 University of Utah and the Flux Group.
# Copyright (c) 2000-2017 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -22,111 +22,39 @@
# }}}
#
chdir("..");
include("defs.php3");
include_once("geni_defs.php");
chdir("apt");
include("quickvm_sup.php");
include_once("profile_defs.php");
include_once("instance_defs.php");
$page_title = "My Experiments";
$dblink = GetDBLink("sa");
include_once("ajax-routines.ajax");
#
# Verify page arguments.
# Need to check the permission, since we allow admins to mess with
# other accounts.
#
$optargs = OptionalPageArguments("target_user", PAGEARG_USER,
"all", PAGEARG_BOOLEAN,
"extend", PAGEARG_BOOLEAN);
if (!isset($all)) {
$all = 0;
}
# Admin only.
if (!isset($extend)) {
$extend = 0;
}
#
# Get current user.
#
RedirectSecure();
$this_user = CheckLoginOrRedirect();
function CheckPageArgs()
{
global $this_user;
global $ajax_args;
if (!isset($target_user)) {
$target_user = $this_user;
}
if (!$this_user->SameUser($target_user)) {
if (!ISADMIN()) {
SPITUSERERROR("You do not have permission to view ".
"target user's profiles");
exit();
if (!(ISADMIN() || ISFOREIGN_ADMIN())) {
SPITAJAX_ERROR(-1, "Not enough permission");
return -1;
}
return 0;
}
$target_idx = $target_user->uid_idx();
$target_uuid = $target_user->uuid();
SPITHEADER(1);
echo "<link rel='stylesheet'
href='css/tablesorter.css'>\n";
$query_result1 = null;
$query_result2 = null;
function Do_ExperimentList()
{
global $this_user, $urn_mapping;
global $ajax_args;
$results = array();
if (($all || $extend) && (ISADMIN() || ISFOREIGN_ADMIN())) {
$where = "";
$order = "order by expired,a.name";
if ($extend) {
$where = "where a.extension_requested=1 or a.admin_lockdown=1";
$order = "order by s.expires asc";
if (CheckPageArgs()) {
return;
}
$query_result1 =
DBQueryFatal("select a.*,s.expires,s.hrn,u.email,users.usr_name, ".
" (UNIX_TIMESTAMP(now()) > ".
" UNIX_TIMESTAMP(s.expires)) as expired, ".
" truncate(a.physnode_count * ".
" ((UNIX_TIMESTAMP(now()) - ".
" UNIX_TIMESTAMP(a.created)) / 3600.0),2) as phours, ".
" IFNULL(aggs.count,0) as aggrows, ".
" agg.aggregate_urn as aggrow_urn ".
" from apt_instances as a ".
"left join (".
" select uuid, COUNT(*) AS count ".
" from apt_instance_aggregates group by uuid) AS aggs ".
" on aggs.uuid=a.uuid ".
"left join apt_instance_aggregates as agg ".
" on agg.uuid=a.uuid ".
"left join geni.geni_slices as s on ".
" s.uuid=a.slice_uuid ".
"left join geni.geni_users as u on u.uuid=a.creator_uuid ".
"left join users on users.uid_idx=a.creator_idx ".
"$where $order");
}
else {
$query_result1 =
DBQueryFatal("select a.*,s.expires,s.hrn,u.email,users.usr_name, ".
" (UNIX_TIMESTAMP(now()) > ".
" UNIX_TIMESTAMP(s.expires)) as expired, ".
" truncate(a.physnode_count * ".
" ((UNIX_TIMESTAMP(now()) - ".
" UNIX_TIMESTAMP(a.created)) / 3600.0),2) as phours, ".
" IFNULL(aggs.count,0) as aggrows, ".
" agg.aggregate_urn as aggrow_urn".
" from apt_instances as a ".
"left join (".
" select uuid, COUNT(*) AS count ".
" from apt_instance_aggregates group by uuid) AS aggs ".
" on aggs.uuid=a.uuid ".
"left join apt_instance_aggregates as agg ".
" on agg.uuid=a.uuid ".
"left join geni.geni_slices as s on ".
" s.uuid=a.slice_uuid ".
"left join geni.geni_users as u on u.uuid=a.creator_uuid ".
"left join users on users.uid_idx=a.creator_idx ".
"where a.creator_uuid='$target_uuid'");
$query_result2 =
DBQueryFatal("select distinct a.*,s.expires,s.hrn,u.email, ".
" users.usr_name, ".
$query_result =
DBQueryFatal("select a.*,s.expires,s.hrn,u.email,users.usr_name, ".
" (UNIX_TIMESTAMP(now()) > ".
" UNIX_TIMESTAMP(s.expires)) as expired, ".
" truncate(a.physnode_count * ".
......@@ -144,43 +72,9 @@ else {
"left join geni.geni_slices as s on ".
" s.uuid=a.slice_uuid ".
"left join geni.geni_users as u on u.uuid=a.creator_uuid ".
"left join group_membership as g on ".
" g.uid_idx='$target_idx' and ".
" g.pid_idx=a.pid_idx ".
"left join users on users.uid_idx=a.creator_idx ".
"where a.creator_uuid='$target_uuid' or ".
" g.uid_idx is not null ".
"order by a.creator");
}
"left join users on users.uid_idx=a.creator_idx");
function SPITROWS($showall, $name, $result)
{
global $TBBASE, $urn_mapping, $all, $extend;
echo "<input class='form-control search' type='search' data-column='all'
id='experiment_search_${name}' placeholder='Search'>\n";
echo " <table class='tablesorter' id='tablesorter_${name}'>
<thead>
<tr>
<th>Name</th>
<th>Profile</th>\n";
if ($showall || $all) {
echo " <th>Creator</th>\n";
}
echo " <th>Project</th>
<th>Status</th>
<th>Cluster</th>
<th>PCs</th>
<th>PHours<b>[1]</b></th>
<th>VMs</th>\n";
echo " <th>Created</th>
<th>Expires</th>
</tr>
</thead>
<tbody>\n";
while ($row = mysql_fetch_array($result)) {
while ($row = mysql_fetch_array($query_result)) {
$profile_id = $row["profile_id"];
$version = $row["profile_version"];
$uuid = $row["uuid"];
......@@ -189,35 +83,28 @@ function SPITROWS($showall, $name, $result)
$canceled = $row["canceled"];
$created = DateStringGMT($row["created"]);
$expires = DateStringGMT($row["expires"]);
$expired = $row["expired"];
$creator_idx = $row["creator_idx"];
$profile_name = "$profile_id:$version";
$creator_uid = $row["creator"];
$creator_name = $row["usr_name"];
$pid = $row["pid"];
$pcount = $row["physnode_count"];
$vcount = $row["virtnode_count"];
$extending = $row["extension_requested"];
$lockdown = $row["admin_lockdown"] || $row["user_lockdown"] ? 1 : 0;
$user_lockdown= $row["user_lockdown"];
$admin_lockdown= $row["admin_lockdown"];