updateaccounts.php3 4.71 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2004 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 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

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

#
# 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);
}

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
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");
46 47 48 49 50 51

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

#
# Verify permissions.
#
63 64
if (! TBExptAccessCheck($uid, $pid, $eid, $TB_EXPT_UPDATE)) {
    USERERROR("You do not have permission to initiate node updates!", 1);
65
}
66 67 68 69 70 71 72
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";
73 74 75 76

#
# 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
77
# set. Or, the user can hit the cancel button (see above).
78 79
#
if (!$confirmed) {
80 81 82 83 84 85
    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";
86

87 88 89 90 91 92 93 94 95 96 97 98
    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)) {
99
	SHOWNODE($nodeid, SHOWNODE_SHORT);
100 101 102 103
    }
    else {
	SHOWEXP($pid, $eid, 1);
    }
104 105 106 107
    
    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";
108 109 110
    if (isset($nodeid)) {
	echo "<input type=hidden name=nodeid value=$nodeid>\n";
    }
111 112 113 114
    echo "</form>\n";
    echo "</center>\n";

    echo "<br>
115 116
          <b>NOTE</b> that this operation will consume a small number of CPU
          cycles on
117
          each node. If this would disturb an experiment in progress, you
Jay Lepreau's avatar
typo  
Jay Lepreau committed
118
          should cancel this operation until later.
119 120 121 122 123 124 125 126 127 128 129
          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.
#
130
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);
131 132 133 134 135

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

flush();

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

146 147 148 149 150 151 152 153 154 155 156
#
# 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("");
}
157 158

#
159
# Exit status 0 means the operation is proceeding in the background.
160
#
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
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";
}
178 179 180 181 182 183

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