request_idleinfo.php3 4.62 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2005-2009 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{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/>.
# 
# }}}
23 24 25 26
#
include("defs.php3");

#
27
# Only known and logged in users.
28
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32 33 34 35

#
# Only admins can do this!
#
36
if (!$isadmin) {
37 38 39 40
    USERERROR("Only TB admins can do this!", 1);
}

#
41
# Verify page arguments.
42
#
43
$reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT);
44
$optargs = OptionalPageArguments("message",    PAGEARG_ANYTHING,
45
				 "canceled",   PAGEARG_STRING,
46
				 "confirmed",  PAGEARG_STRING);
47

48 49 50 51 52
#
# Standard Testbed Header
#
PAGEHEADER("Request info about possibly Idle experiment");

53
#
54
# Need these below
55
#
56 57 58 59 60 61 62 63 64
$pid = $experiment->pid();
$eid = $experiment->eid();
$pcs = $experiment->PCCount();

echo $experiment->PageHeader();
echo "<br>";

if (!$pcs) {
    echo "<center><h3>Idle info request canceled because there are no PCs!</h3>
65 66 67 68 69 70
          </center>\n";
    PAGEFOOTER();
    return;
}

#
71 72 73 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
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
if (isset($canceled) && $canceled) {
    echo "<center><h3>Idle info request canceled!</h3>
78 79 80 81 82
          </center>\n";
    PAGEFOOTER();
    return;
}

83
if (!isset($confirmed)) {
84
    echo "<br><center><h3>
85
          Are you <b>SURE</b> you want to send an Idle Info request
86
          email message to the swapper of $pid/$eid?
87
          </h3>\n";
88 89 90

    #
    # Dump experiment record.
91 92 93 94
    #
    $experiment->Show();

    $url = CreateURL("request_idleinfo", $experiment);
95 96 97 98 99 100 101 102 103 104 105 106 107
   
    echo "<br>\n";
    echo "<form action='$url' method=post>\n";
    echo "<table align=center border=1>\n";
    echo "  <tr><td><center>Additional message to user?</center></td></tr>
	    <tr><td><textarea rows=2 cols=50 name=message></textarea>
	      </td></tr>
	    <tr><td><center>\n";
    echo "    <input type=submit name=confirmed value=Confirm>\n";
    echo "    &nbsp; &nbsp;\n";
    echo "    <input type=submit name=canceled value=Cancel>\n";
    echo "    </center></td></tr>\n";
    echo "</table>\n";
108 109 110 111 112 113 114 115
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

# Info about experiment.
116
$seconds = $experiment->SwapSeconds();
117 118
$hours   = intval($seconds / 3600);

119 120
if (! ($creator = $experiment->GetCreator())) {
    TBERROR("Could not lookup object for experiment creator!", 1);
121
}
122 123
if (! ($swapper = $experiment->GetSwapper())) {
    TBERROR("Could not lookup object for experiment swapper!", 1);
124 125 126 127 128
}
if (! ($group = $experiment->Group())) {
    TBERROR("Could not lookup object for experiment group!", 1);
}

129
# Lots of email addresses!
130
$allleaders    = $group->LeaderMailList();
131 132 133 134 135
$swapper_name  = $swapper->name();
$swapper_email = $swapper->email();
$creator_name  = $creator->name();
$creator_email = $creator->email();
if (! $swapper->SameUser($creator)) {
136 137
    $allleaders .= ", \"$creator_name\" <$creator_email>";
}
138 139

# And send email
140
TBMAIL("$swapper_name <$swapper_email>",
141
       "Experiment $pid/$eid - Please tell us about it",
142 143 144 145 146
       "Hi. We noticed that your experiment '$pid/$eid' has been\n".
       "swapped in for $hours hours and is using $pcs nodes.\n".
       "\n".
       "Such long running experiments are unusual so we want to make sure\n".
       "this experiment is still doing useful work.\n".
147
       (isset($message) && $message !== "" ? "\n$message\n\n" : "\n").
148 149 150 151 152
       "Please respond to this message letting us know; if we do not hear\n".
       "from you within a couple of hours, we will be forced to swap your\n".
       "experiment out so that others can use the nodes.\n\n".
       "Thanks very much!\n",
       "From: $TBMAIL_OPS\n".
153
       "Cc: $allleaders\n".
154
       "Cc: $TBMAIL_OPS\n".
155 156 157 158 159 160 161 162 163 164
       "Errors-To: $TBMAIL_WWW");

echo "<center><h2>Message sent!</h2>
      </center>\n";

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