freenode.php3 3.08 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2007 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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24
include("defs.php3");
25
include_once("node_defs.php");
26 27 28 29

#
# Only known and logged in users can do this.
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
33 34

#
35
# Verify page arguments.
36
#
37 38 39
$reqargs = RequiredPageArguments("node", PAGEARG_NODE);
$optargs = OptionalPageArguments("canceled", PAGEARG_BOOLEAN,
				 "confirmed", PAGEARG_BOOLEAN);
40 41

#
42
# Has to be reserved of course.
43
#
44
$experiment = $node->Reservation();
45

46 47
if (! $experiment) {
    USERERROR($node->node_id() . " is not currently reserved!", 1);
48
}
49 50 51 52 53

# Need these below.
$node_id = $node->node_id();
$pid     = $experiment->pid();
$eid     = $experiment->eid();
54

55 56 57 58
#
# Perm check.
#
if (! ($isadmin || (OPSGUY()) && $pid == $TBOPSPID)) {
59
    USERERROR("Not enough permission to free nodes!", 1);
60 61
}

62 63 64 65 66
#
# Standard Testbed Header
#
PAGEHEADER("Free Node");

67 68 69 70 71 72
#
# 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.
#
73
if (isset($canceled) && $canceled) {
74 75 76 77 78 79 80 81
    echo "<center><h3><br>
          Operation canceled!
          </h3></center>\n";
    
    PAGEFOOTER();
    return;
}

82
if (!isset($confirmed)) {
83 84 85 86 87
    echo "<center><h2><br>
          Are you <b>REALLY</b>
          sure you want to free node '$node_id?'
          </h2>\n";

88 89 90
    $node->Show(SHOWNODE_NOFLAGS);

    $url = CreateURL("freenode", $node);
91
    
92
    echo "<form action='$url' method=post>";
93 94 95 96 97 98 99 100 101 102 103 104
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

#
# Pass it off to the script.
#
105 106 107
STARTBUSY("Releasing node $node_id");
SUEXEC($uid, "nobody", "webnfree $pid $eid $node_id", SUEXEC_ACTION_DIE);
STOPBUSY();
108 109 110 111

#
# And send an audit message.
#
112 113
$uid_name  = $this_user->name();
$uid_email = $this_user->email();
114 115 116 117 118 119 120

TBMAIL($TBMAIL_AUDIT,
       "Node Free: $node_id",
       "$node_id was deallocated via the web interface by $uid ($uid_name).\n",
       "From: $uid_name <$uid_email>\n".
       "Errors-To: $TBMAIL_WWW");

Leigh Stoller's avatar
Leigh Stoller committed
121 122
PAGEREPLACE(CreateUrl("shownode", $node));

123
#
Leigh Stoller's avatar
Leigh Stoller committed
124
# Standard Testbed Footer
125
# 
Leigh Stoller's avatar
Leigh Stoller committed
126
PAGEFOOTER();
127
?>