loadimage.php3 4.95 KB
Newer Older
Chad Barb's avatar
Chad Barb committed
1 2
<?php
#
3
# Copyright (c) 2000-2014 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/>.
# 
# }}}
Chad Barb's avatar
Chad Barb committed
23 24
#
include("defs.php3");
25 26
include_once("imageid_defs.php");
include_once("node_defs.php");
Chad Barb's avatar
Chad Barb committed
27

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

35 36 37
# This will not return if its a sajax request.
include("showlogfile_sup.php3");

38 39 40 41
#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("image",     PAGEARG_IMAGE);
42
$optargs = OptionalPageArguments("target",    PAGEARG_STRING,
43 44 45
				 "canceled",  PAGEARG_STRING,
				 "confirmed", PAGEARG_STRING);

Chad Barb's avatar
Chad Barb committed
46 47 48
#
# Standard Testbed Header
#
49
PAGEHEADER("Snapshot Node Disk into New or Existing Image");
Chad Barb's avatar
Chad Barb committed
50

51 52 53 54 55 56
# Need these below.
$imageid    = $image->imageid();
$image_pid  = $image->pid();
$image_gid  = $image->gid();
$image_name = $image->imagename();
$image_path = $image->path();
Chad Barb's avatar
Chad Barb committed
57

58
if (!$image->AccessCheck($this_user, $TB_IMAGEID_MODIFYINFO )) {
Chad Barb's avatar
Chad Barb committed
59 60 61
    USERERROR("You do not have permission to modify image '$imageid'.", 1);
}

62
if (! isset($target) || isset($canceled)) {
Chad Barb's avatar
Chad Barb committed
63 64
    echo "<center>";

65 66
    if (isset($canceled)) {
	echo "<h3>Operation canceled.</h3>";
Chad Barb's avatar
Chad Barb committed
67
    }
Leigh Stoller's avatar
Leigh Stoller committed
68 69 70
    else {
	$target = "";
    }
Chad Barb's avatar
Chad Barb committed
71 72
    echo "<br />";

73 74 75
    $url = CreateURL("loadimage", $image); 

    echo "<form action='$url' method='post'>\n".
76
	 "<font size=+1>Node to snapshot into image '$image_name':</font> ".
77
	 "<input type='text'   name='target' value='$target' size=32></input>\n".
Chad Barb's avatar
Chad Barb committed
78
	 "<input type='submit' name='submit'  value='Go!'></input>\n".
79
	 "</form><br>";
80
    echo "<font size=+1>Information for Image Descriptor '$image_name':</font>\n";
81 82
    
    $image->Show();
Chad Barb's avatar
Chad Barb committed
83 84 85 86 87 88

    echo "</center>";
    PAGEFOOTER();
    return;
}

89 90 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
#
# A node or something else to pass through?
#
if (preg_match("/^[-\w]+$/", "$target")) {
    $node = Node::Lookup($target);
    if (!$node) {
	USERERROR("No such node $node_id!", 1);

    }
    if (!$node->AccessCheck($this_user, $TB_NODEACCESS_LOADIMAGE)) {
	USERERROR("You do not have permission to ".
		  "snapshot an image from node '$node_id'.", 1);
    }
    $experiment = $node->Reservation();
    if (!$experiment) {
	USERERROR("$node_id is not currently reserved to an experiment!", 1);
    }
    $node_pid = $experiment->pid();
    $unix_gid = $experiment->UnixGID();
    $project  = $experiment->Project();
    $unix_groups = $project->unix_gid() . "," . $unix_gid;
    if ($project->pid() != $node_pid) {
	$unix_groups = "$unix_groups,$node_pid";
    }
}
elseif (preg_match("/^[-\w\@\.\+]+$/", "$target")) {
    $unix_groups = "$image_pid,$image_gid";
Chad Barb's avatar
Chad Barb committed
116
}
117 118
else {
    USERERROR("Illegal characters in '$target'.", 1);
119
}
120

Chad Barb's avatar
Chad Barb committed
121
# Should check for file file_exists($image_path),
122
# but too messy.
Chad Barb's avatar
Chad Barb committed
123

124 125
if (! isset($confirmed)) {
    $url = CreateURL("loadimage", $image);
126
    $newurl = CreateURL("newimageid_ez", "node_id", $target);
127
    
128
    echo "<br><center><form action='$url' method='post'>\n".
129
	 "<b>Doing a snapshot of '$target' into image '$image_name' ".
130 131
	 "will overwrite any previous snapshot for that image.<br><br> ".
	 "Are you sure you want to continue?</b><br>".
132
         "<input type='hidden' name='target'    value='$target'></input>".
Chad Barb's avatar
Chad Barb committed
133 134
         "<input type='submit' name='confirmed' value='Confirm'></input>".
         "&nbsp;".
135
         "<input type='submit' name='canceled' value='Cancel'></input>\n".    
136 137 138
         "</form>".
         "<br>".
	 "If you do not want to overwrite this image, then ".
139 140
	 "<a href='$newurl'>create a new image</a> based on the image ".
	 "that is currently loaded on $target. ".
141
	 "</center>";
Chad Barb's avatar
Chad Barb committed
142 143 144 145 146 147

    PAGEFOOTER();
    return;
}

echo "<br>
148
      Taking a snapshot of '$target' into image '$image_name' ...
Chad Barb's avatar
Chad Barb committed
149 150 151
      <br><br>\n";
flush();

152
SUEXEC($uid,
153
       $unix_groups,
154
       "webclone_image $image_name " . escapeshellarg($target),
155
       SUEXEC_ACTION_DUPDIE);
Chad Barb's avatar
Chad Barb committed
156

157 158 159 160 161
echo "This will take as little as 10 minutes or as much as an hour;
      you will receive email
      notification when the image is complete. In the meantime,
      <b>PLEASE DO NOT</b> delete the imageid or mess with
      the node at all!<br>\n";
Chad Barb's avatar
Chad Barb committed
162

163
flush();
164 165 166 167 168

#
# When doing image provenance the most recent unreleased version is
# is what we are really working on. 
#
Leigh Stoller's avatar
Leigh Stoller committed
169
$image = $image->LookupUnreleased();
170 171 172 173
$logfile = $image->GetLogfile();
if ($logfile) {
    STARTLOG($logfile);
}
174

Chad Barb's avatar
Chad Barb committed
175 176 177 178 179
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>