expaccess.php3 3.77 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
include("defs.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Manage Shared Access to your Experiment");

#
# Only known and logged in users can do this. 
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# We must get a valid PID/EID.
# 
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
  USERERROR("You must provide a valid project ID!", 1);
}
if (!isset($eid) ||
    strcmp($eid, "") == 0) {
  USERERROR("You must provide a valid Experiment ID!", 1);
}

$query_result = mysql_db_query($TBDBNAME,
	"select e.shared,e.expt_head_uid,p.head_uid from experiments as e, ".
	"projects as p ".
	"where e.eid='$eid' and e.pid='$pid' and p.pid='$pid'");

if (!$query_result) {
    TBERROR("DB error getting experiment record $pid/$eid", 1);
}
if (($row = mysql_fetch_array($query_result)) == 0) {
    USERERROR("No such experiment $eid in project $pid!", 1);
}
if (!$row[0]) {
    USERERROR("Experiment $eid in project $pid is not shared", 1);
}

#
# Admin users get to do anything they want, of course. Otherwise, only
# the experiment creator or the project leader has permission to mess
# with this. 
#
if (! ($isadmin = ISADMIN($uid))) {
    #
    # One of them better be you!
    #
    if (strcmp($row[1], $uid) && strcmp($row[2], $uid)) {
	USERERROR("You must be either the experiment creator or the project ".
		  "leader under which the experiment was created, to change ".
		  "experiment/project access permissions!", 1);
    }
}
    
#
# Get the current set of projects that have been granted share access to
# this experiment.
#
$query_result = mysql_db_query($TBDBNAME,
	"select pid from exppid_access ".
	"where exp_eid='$eid' and exp_pid='$pid'");

if (mysql_num_rows($query_result)) {
    #
    # For each one, make sure the checkbox was checked. If not, delete
    # it from the table.
    # 
    while ($row = mysql_fetch_array($query_result)) {
	$foo = "access_$row[0]";
	
	if (! isset($$foo)) {
	    $update_result = mysql_db_query($TBDBNAME,
		"delete from exppid_access ".
		"where exp_eid='$eid' and exp_pid='$pid' and pid='$row[0]'");
	    if (! $update_result) {
		TBERROR("DB Error deleting $row[0] from experiment access ".
			"for eid=$eid and pid=$pid!", 1);
	    }
	}
    }
}

#
# Add the new PID (if provided), but only if not already a member.
#
if (isset($addpid) && strcmp($addpid, "")) {
    #
    # Make sure a valid PID.
    #
    $query_result = mysql_db_query($TBDBNAME,
	   "select pid from projects where pid='$addpid'");
    if (! $query_result) {
	TBERROR("DB Error getting project info for $addpid!", 1);
    }
    if (! mysql_num_rows($query_result)) {
	USERERROR("No such project $addpid!", 1);
    }
    
    $query_result = mysql_db_query($TBDBNAME,
	"replace into exppid_access (exp_pid, exp_eid, pid) ".
	"VALUES ('$pid', '$eid', '$addpid')");

    if (! $query_result) {
	TBERROR("DB Error adding experiment access for project $addpid ".
		"to eid=$eid and pid=$pid!", 1);
    }
}

Leigh Stoller's avatar
Leigh Stoller committed
117 118 119 120 121 122
#
# Grab the unix GID for running scripts.
#
TBGroupUnixInfo($pid, $pid, $unix_gid, $unix_name);

SUEXEC($uid, $unix_gid, "webnodeupdate -b $pid $eid", 1);
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

echo "<center>
      <h3>Access Permissions Changed.</h3>
      </center>\n";

echo "<p>
      You will be notified via email when the update has completed on
      all of the nodes in your experiment. Since this involves rebuilding
      the accounts database on each node, it should be just a few minutes
      before you receive notification.\n";

#
# Back links for convenience.
#
echo "<p>
      <a href='expaccess_form.php3?pid=$pid&eid=$eid'>
         Back to access management page</a>\n";

echo "<p>
Leigh Stoller's avatar
Leigh Stoller committed
142
      <a href='showexp.php3?pid=$pid&eid=$eid'>
143 144 145 146 147 148 149
         Back to experiment information page</a>\n";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>