updateaccounts.php3 4.75 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2004, 2006, 2007 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7
include("defs.php3");
8
include("showstuff.php3");
9 10

#
11
# Only known and logged in users.
12
#
13 14 15
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
16 17 18 19 20 21 22 23 24 25 26 27 28 29

#
# Must provide the EID!
# 
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
  USERERROR("The project ID was not provided!", 1);
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
  USERERROR("The experiment ID was not provided!", 1);
}

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
if (isset($nodeid) && strcmp($nodeid, "")) {
    $nodeid = addslashes($nodeid);
}
else {
    unset($nodeid);
}

# Canceled operation redirects back to showexp page. See below.
if ($canceled) {
    header("Location: showexp.php3?pid=$pid&eid=$eid");
    return;
}

#
# Standard Testbed Header
#
PAGEHEADER("Update Experimental Nodes");
47 48 49 50 51 52

#
# Check to make sure thats this is a valid PID/EID tuple.
#
$query_result =
    DBQueryFatal("SELECT * FROM experiments WHERE ".
53
		 "eid='$eid' and pid='$pid'");
54
if (mysql_num_rows($query_result) == 0) {
55 56
  USERERROR("The experiment $eid is not a valid experiment ".
            "in project $pid.", 1);
57 58
}
$row = mysql_fetch_array($query_result);
59
$gid = $row[gid];
60 61 62 63

#
# Verify permissions.
#
64 65
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_UPDATE)) {
    USERERROR("You do not have permission to initiate node updates!", 1);
66
}
67 68 69 70 71 72 73
if (isset($nodeid) && !TBValidNodeName($nodeid)) {
    USERERROR("Node $nodeid is not a valid nodeid!", 1);
}

echo "<font size=+2>Experiment <b>".
     "<a href='showproject.php3?pid=$pid'>$pid</a>/".
     "<a href='showexp.php3?pid=$pid&eid=$eid'>$eid</a></b></font>\n";
74 75 76 77

#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
78
# set. Or, the user can hit the cancel button (see above).
79 80
#
if (!$confirmed) {
81 82 83 84 85 86
    echo "<br><br><b>
          Confirming this operation will initiate various updates to be
          performed, including updating the password and group files,
          adding new mounts, and installing (or updating if modified) tarballs
          and rpms.
          This is sometimes quicker and easier than rebooting nodes.</b>\n";
87

88 89 90 91 92 93 94 95 96 97 98 99
    echo "<center><h2><br>
          Are you sure you want to perform an update on ";

    if (isset($nodeid)) {
	echo "node $nodeid in experiment '$eid?'\n";
    }
    else {
	echo "all of the nodes in experiment '$eid?'\n";
    }
    echo "</h2>\n";

    if (isset($nodeid)) {
100
	SHOWNODE($nodeid, SHOWNODE_SHORT);
101 102 103 104
    }
    else {
	SHOWEXP($pid, $eid, 1);
    }
105 106 107 108
    
    echo "<form action='updateaccounts.php3?pid=$pid&eid=$eid' method=post>";
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
109 110 111
    if (isset($nodeid)) {
	echo "<input type=hidden name=nodeid value=$nodeid>\n";
    }
112 113 114 115
    echo "</form>\n";
    echo "</center>\n";

    echo "<br>
116 117
          <b>NOTE</b> that this operation will consume a small number of CPU
          cycles on
118
          each node. If this would disturb an experiment in progress, you
Jay Lepreau's avatar
typo  
Jay Lepreau committed
119
          should cancel this operation until later.
120 121 122 123 124 125 126 127 128 129 130
          Please note that accounts are automatically updated whenever a node
          reboots, or when an experiment is swapped back in.\n";

    PAGEFOOTER();
    return;
}

#
# We need the unix gid for the project for running the scripts below.
# Note usage of default group in project.
#
131
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
132 133 134 135 136

#
# Start up a script to do this.
#
echo "<center><br>";
137
echo "<h2>Starting node update. Please wait a moment ...
138 139 140 141
      </h2></center>";

flush();

142
$retval = SUEXEC($uid, "$pid,$unix_gid",
143
		 "webnode_update -b $pid $eid" .
144 145
		 (isset($nodeid) ? " $nodeid" : ""),
		 SUEXEC_ACTION_IGNORE);
146

147 148 149 150 151 152 153 154 155 156 157
#
# Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops.
# 
if ($retval < 0) {
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
    die("");
}
158 159

#
160
# Exit status 0 means the operation is proceeding in the background.
161
#
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
echo "<br>\n";
if ($retval) {
    echo "<h3>Node update could not proceed</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
}
else {
    echo "You will be notified via email when the update has completed on
          all of the nodes in your experiment. This might take a just a
          few minutes (if updating only accounts) or it might take longer
          if new tar/rpm files need to be installed. In the meantime, the
          experiment is locked it may not be swapped or modified.\n";

    echo "<br><br>
         If you do not receive
         email notification within a reasonable amount of time,
         please contact $TBMAILADDR.\n";
}
179 180 181 182 183 184

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