template_graph.php 2.27 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2006-2011 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
#
include("defs.php3");
25
include_once("template_defs.php");
26 27 28

#
# This script generates the contents of an image. No headers or footers,
29
# just spit back an image. 
30 31 32
#

#
33 34 35 36 37 38
# Capture script errors and report back to user.
#
function SPITERROR($message = "", $death = 1)
{
    header("Content-type: image/gif");
    readfile("coming-soon-thumb.gif");
39
}
40 41 42 43 44 45 46 47
$session_interactive  = 0;
$session_errorhandler = 'SPITERROR';

#
# Verify page arguments.
#
$reqargs = RequiredPageArguments("template", PAGEARG_TEMPLATE);
$optargs = OptionalPageArguments("zoom",     PAGEARG_STRING);
48

49 50 51 52 53 54
if (isset($zoom)) {
    if ($zoom != "in" && $zoom != "out") {
	PAGEARGERROR("Invalid characters in zoom factor!");
    }
}

55
function SPITGRAPH($template)
56
{
57
    $data = NULL;
58

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

68 69 70 71
#
# If the request did not specify a zoom, return whatever we have.
#
if (!isset($zoom)) {
72
    SPITGRAPH($template);
73 74 75 76 77 78 79 80
    return;
}

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

81 82
$pid = $template->pid();
$gid = $template->gid();
83
$unix_gid = $template->UnixGID();
84 85
$project  = $template->GetProject();
$unix_pid = $project->unix_gid();
86

87
$retval = SUEXEC($uid, "$unix_pid,$unix_gid", "webtemplate_graph $optarg $guid",
88 89 90 91 92 93
		 SUEXEC_ACTION_CONTINUE);

if ($retval) {
    SPITERROR();
}
else {
94
    SPITGRAPH($template);
95
}
96 97 98 99 100

#
# No Footer!
# 
?>