template_graph.php 1.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2006 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
include("template_defs.php");

#
# This script generates the contents of an image. No headers or footers,
# just spit back an image. The thumbs are public, so no checking is done.
# To obfuscate, do not use pid/eid, but rather use the resource index. 
#

#
# Verify page arguments.
# 
if (!isset($guid) ||
    strcmp($guid, "") == 0) {
    USERERROR("You must provide a Template ID.", 1);
}
if (!TBvalid_guid($guid)) {
    PAGEARGERROR("Invalid characters in GUID!");
}

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
if (isset($zoom)) {
    if ($zoom != "in" && $zoom != "out") {
	PAGEARGERROR("Invalid characters in zoom factor!");
    }
}
else {
    unset($zoom);
}

function SPITERROR()
{
    header("Content-type: image/gif");
    readfile("coming-soon-thumb.gif");
}

function SPITGRAPH($guid)
{
    #
    # Get the data from the DB.
    #
    $query_result =
	DBQueryWarn("select image from experiment_template_graphs ".
		    "where parent_guid='$guid'");
50

51 52 53 54 55
    if (!$query_result || !mysql_num_rows($query_result)) {
        # No Data. Spit back a stub image.
	SPITERROR();
	return;
    }
56 57 58
    $row  = mysql_fetch_array($query_result);
    $data = $row['image'];

59
    if ($data != "") {
60 61
	header("Content-type: image/png");
	echo "$data";
62 63 64
    }
    else {
	SPITERROR();
65 66
    }
}
67
    
68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#
# If the request did not specify a zoom, return whatever we have.
#
if (!isset($zoom)) {
    SPITGRAPH($guid);
    return;
}

#
# Otherwise regen the picture, zooming in or out.
#
$optarg = "-z " . ($zoom == "in" ? "in" : "out");

if (! TBGuid2PidGid($guid, $pid, $gid)) {
    TBERROR("Could not get template pid,gid for template $guid", 0);
    SPITERROR();
}
TBGroupUnixInfo($pid, $gid, $unix_gid, $unix_name);

$retval = SUEXEC($uid, "$pid,$unix_gid", "webtemplate_graph $optarg $guid",
		 SUEXEC_ACTION_CONTINUE);

if ($retval) {
    SPITERROR();
}
else {
    SPITGRAPH();
}
97 98 99 100 101

#
# No Footer!
# 
?>