image_metadata.php 2.47 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2003-2016 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 28 29 30 31 32 33 34 35
#
include("defs.php3");
include_once("imageid_defs.php");

function SPITERROR($code, $msg)
{
    header("HTTP/1.0 $code $msg");
    exit();
}

#
# Verify page arguments.
#
36
$reqargs = RequiredPageArguments("uuid",    PAGEARG_STRING);
37 38
$optargs = OptionalPageArguments("version", PAGEARG_INTEGER,
                                 "clientversion", PAGEARG_INTEGER);
39 40 41
if (!isset($version)) {
    $version = NULL;
}
42 43 44 45 46 47
if (!isset($clientversion)) {
    $clientversion = 0;
}
elseif ($clientversion < 0) {
    SPITERROR(404, "Bad client version argument!");
}
48

49
$image = Image::LookupByUUID($uuid, $version);
50 51 52
if (! isset($image)) {
    SPITERROR(404, "Could not find $uuid!");
}
53 54 55
if ($image->noexport()) {
    SPITERROR(403, "This image is marked as export restricted");
}
56 57
# We need the dataset metadata, but spew *does* deny it if not global.
if (!$image->isglobal() && !$image->isdataset()) {
58 59
    SPITERROR(403, "No permission to access image");
}
60 61 62
if (!$image->released()) {
    SPITERROR(403, "Not allowed to access unreleased images");
}
63

64
# Pass imageid:version to backend script if its a specific version request.
Leigh Stoller's avatar
Leigh Stoller committed
65
$imagearg = ($image->image_uuid() == $uuid && is_null($version) ?
66 67
    $image->imageid() : $image->versid());

68
$fp = popen("$TBSUEXEC_PATH nobody nobody webdumpdescriptor ".
69
	    "-e -v $clientversion -i " . $imagearg, "r");
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
if (! $fp) {
    SPITERROR(404, "Could not get metadata for $uuid!");
}

header("Content-Type: text/plain; charset=us-ascii");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
flush();

while (!feof($fp)) {
    $string = fgets($fp, 1024);
    echo "$string";
    flush();
}
pclose($fp);
$fp = 0;

?>