template_analyze.php 3.6 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2012 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
#
$reqargs = RequiredPageArguments("instance",  PAGEARG_INSTANCE);
$optargs = OptionalPageArguments("canceled",  PAGEARG_BOOLEAN,
39
				 "referrer",  PAGEARG_STRING,
40 41
				 "confirmed", PAGEARG_BOOLEAN);
$template = $instance->GetTemplate();
42

43 44
if (isset($canceled) && $canceled) {
    header("Location: ". CreateURL("template_show", $template));
45 46 47 48
    return;
}

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

if (! $template->AccessCheck($this_user, $TB_EXPT_READINFO)) {
    USERERROR("You do not have permission to view experiment template ".
	      "$guid/$vers!", 1);
62 63
}

64
if (!isset($confirmed)) {
65 66 67
    PAGEHEADER("Reconstitute");

    echo $instance->PageHeader();
68
    
69 70
    echo "<br><br><center><br><font size=+1>
          Reconstitute database(s) for instance $iid?</font>\n";
71 72 73
    
    $template->Show();

74
    $url = CreateURL("template_analyze", $instance);
75

76 77
    if (!isset($referrer)) {
	$referrer = urlencode($referrer);
78
	$referrer = $_SERVER['HTTP_REFERER'];
79
    }
80

81
    echo "<form action='$url' method=post>\n";
82 83 84
    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";
85
    echo "<input type=hidden name=referrer value=$referrer>\n";
86 87 88 89 90 91 92 93 94 95 96 97
    echo "</form>\n";
    echo "</center>\n";
    
    PAGEFOOTER();
    return;
}

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

98
PAGEHEADER("Reconstitute");
99

100
echo $template->PageHeader();
101 102 103 104 105 106 107 108 109 110 111
echo "<br><br>\n";

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

STARTBUSY("Starting Database Reconstitution");
sleep(1);

#
# Run the backend script
#
112
$retval = SUEXEC($uid, "$unix_pid,$unix_gid",
113
		 "webtemplate_analyze -i $exptidx $guid/$vers",
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
		 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;
}

138 139 140
if (!isset($referrer)) {
    $referrer = CreateURL("template_show", $template);
}
141
# Zap back to template page.
142
PAGEREPLACE($referrer);
143 144 145 146 147 148 149 150 151 152 153 154

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

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