template_commit.php 2.77 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
5 6 7 8 9 10
# All rights reserved.
#
include("defs.php3");
include_once("template_defs.php");

#
11
# Only known and logged in users.
12
#
13 14 15
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
16 17 18

#
# Verify page arguments.
19 20 21 22 23
#
$reqargs = RequiredPageArguments("instance",  PAGEARG_INSTANCE);
$optargs = OptionalPageArguments("canceled",  PAGEARG_BOOLEAN,
				 "confirmed", PAGEARG_BOOLEAN);
$template = $instance->GetTemplate();
24 25

# Canceled operation redirects back to template page.
26 27
if (isset($canceled) && $canceled) {
    header("Location: ". CreateURL("template_show", $template));
28 29 30
    return;
}

31 32 33 34 35 36
# Need these below.
$guid = $template->guid();
$vers = $template->vers();
$pid  = $template->pid();
$eid  = $instance->eid();
$unix_gid = $template->UnixGID();
37 38

#
39
# Check permission.
40
#
41 42 43
if (! $template->AccessCheck($this_user, $TB_EXPT_MODIFY)) {
    USERERROR("You do not have permission to commit experiment template ".
	      "$guid/$vers!", 1);
44 45 46 47 48
}

#
# Confirm
#
49
if (!isset($confirmed)) {
50
    PAGEHEADER("Create Template from Instance");
51
    echo $instance->ExpPageHeader();
52 53 54
    
    echo "<center><br><font size=+1>
          Create new Template from instance $eid 
55
             in Template $guid/$vers?</font>\n";
56 57 58 59 60
    
    $template->Show();
    echo "<br>";
    $instance->Show(0);

61 62
    $url = CreateURL("template_commit", $instance);
    echo "<form action='$url' method=post>\n";
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    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");

81
echo $instance->ExpPageHeader();
82 83 84 85 86 87
echo "<br><br>\n";

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

88
STARTBUSY("Starting commit");
89
$retval = SUEXEC($uid, "$pid,$unix_gid",
90
		 "webtemplate_commit -e $eid $guid/$vers",
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
		 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();
?>