template_commit.php 3.53 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2011 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 27
#
include("defs.php3");
include_once("template_defs.php");

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

#
# Verify page arguments.
36 37 38 39 40
#
$reqargs = RequiredPageArguments("instance",  PAGEARG_INSTANCE);
$optargs = OptionalPageArguments("canceled",  PAGEARG_BOOLEAN,
				 "confirmed", PAGEARG_BOOLEAN);
$template = $instance->GetTemplate();
41 42

# Canceled operation redirects back to template page.
43 44
if (isset($canceled) && $canceled) {
    header("Location: ". CreateURL("template_show", $template));
45 46 47
    return;
}

48 49 50 51 52 53
# Need these below.
$guid = $template->guid();
$vers = $template->vers();
$pid  = $template->pid();
$eid  = $instance->eid();
$unix_gid = $template->UnixGID();
54 55
$project  = $template->GetProject();
$unix_pid = $project->unix_gid();
56 57

#
58
# Check permission.
59
#
60 61 62
if (! $template->AccessCheck($this_user, $TB_EXPT_MODIFY)) {
    USERERROR("You do not have permission to commit experiment template ".
	      "$guid/$vers!", 1);
63 64 65 66 67
}

#
# Confirm
#
68
if (!isset($confirmed)) {
69
    PAGEHEADER("Create Template from Instance");
70
    echo $instance->ExpPageHeader();
71 72 73
    
    echo "<center><br><font size=+1>
          Create new Template from instance $eid 
74
             in Template $guid/$vers?</font>\n";
75 76 77 78 79
    
    $template->Show();
    echo "<br>";
    $instance->Show(0);

80 81
    $url = CreateURL("template_commit", $instance);
    echo "<form action='$url' method=post>\n";
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    echo "<br>\n";
    echo "<br>\n";
    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;
}

#
# Avoid SIGPROF in child.
#
set_time_limit(0);

PAGEHEADER("Create Template from Instance");

100
echo $instance->ExpPageHeader();
101 102 103 104 105 106
echo "<br><br>\n";

echo "<script type='text/javascript' language='javascript' ".
	"        src='template_sup.js'>\n";
echo "</script>\n";

107
STARTBUSY("Starting commit");
108
$retval = SUEXEC($uid, "$unix_pid,$unix_gid",
109
		 "webtemplate_commit -e $eid $guid/$vers",
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
		 SUEXEC_ACTION_IGNORE);

/* Clear the 'loading' indicators above */
if ($retval) {
    CLEARBUSY();
}
else {
    STOPBUSY();
}

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

# User error. Tell user and exit.
if ($retval) {
    SUEXECERROR(SUEXEC_ACTION_USERERROR);
    return;
}

# Zap to the newly created template page.
$template->Refresh();

PAGEREPLACE("template_show.php?guid=$guid&version=". $template->child_vers());

#
# In case the above fails.
#
echo "<center><b>Done!</b></center>";
echo "<br><br>\n";

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