top2image.php3 3.51 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2013 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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
24 25 26 27 28 29 30 31
include("defs.php3");

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

#
32
# Only known and logged in users.
33
#
34 35 36
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
37 38 39

#
# Verify page arguments.
40 41 42 43
#
$reqargs = RequiredPageArguments("experiment",   PAGEARG_EXPERIMENT);
$optargs = OptionalPageArguments("zoom",         PAGEARG_NUMERIC,
				 "detail",       PAGEARG_BOOLEAN,
44
				 "svg",          PAGEARG_BOOLEAN,
45
				 "thumb",        PAGEARG_INTEGER);
46

47
#
48
# Need these below
49
#
50 51
$pid = $experiment->pid();
$eid = $experiment->eid();
52
$unix_gid = $experiment->UnixGID();
53 54 55 56

# if they dont exist, or are non-numeric, use defaults.
if (!isset($zoom))       { $zoom   = 1; }
if (!isset($detail))     { $detail = 0; }
57
if (!isset($svg))        { $svg    = 0; }
58 59 60 61
if (!isset($thumb))      { $thumb  = 0; }
if ($zoom > 8.0)   { $zoom = 8.0; }
if ($zoom <= 0.0)  { $zoom = 1.0; }
if ($thumb > 1024) { $thumb = 1024; }
62 63 64 65

#
# Verify Permission.
#
66 67
if (!$experiment->AccessCheck($this_user, $TB_EXPT_READINFO)) {
    USERERROR("You do not have permission to view experiment $eid!", 1);
68 69
}

70
#
71
# See if any vis data. If not, then the renderer has not finished yet.
72
#
73 74 75
$query_result =
    DBQueryFatal("select vname from vis_nodes ".
		 "where pid='$pid' and eid='$eid' limit 1");
76

77 78 79 80 81
if (!$query_result || !mysql_num_rows($query_result)) {
    # No Data. Spit back a stub image.
    header("Content-type: image/gif");
    readfile("coming-soon-thumb.gif");
    return;
82 83
}

Leigh Stoller's avatar
Leigh Stoller committed
84 85 86 87 88 89 90 91 92 93 94 95 96
#
# See if we have a copy of the image in the desired zoom/detail level
# cached in the DB. If so, that is what we return.
#
$query_result =
    DBQueryFatal("select image from vis_graphs ".
		 "where pid='$pid' and eid='$eid' and ".
		 "      zoom='$zoom' and detail='$detail'");

if (mysql_num_rows($query_result)) {
    $row   = mysql_fetch_array($query_result);
    $image = $row['image'];
    
97 98 99 100 101 102
    if (strncmp($image, "<svg", 4) == 0) {
	header("Content-type: image/svg+xml");
    }
    else {   
	header("Content-type: image/png");
    }
Leigh Stoller's avatar
Leigh Stoller committed
103 104 105 106
    echo $image;
    return;
}

107 108 109 110
#
# Run in the project group.
#
$gid = $pid;
111 112
$arguments = "";

113
# note that we already ensured that $detail and $thumb are numeric above.
114 115
if ($detail != 0) { $arguments .= " -d $detail"; }
if ($thumb != 0)  { $arguments .= " -t $thumb";  }
116
if ($svg != 0 || $TBMAINSITE)    { $arguments .= " -x "; }
Chad Barb's avatar
Chad Barb committed
117

118 119 120
#
# Spit out the image with a content header.
#
Chad Barb's avatar
Chad Barb committed
121

122
if ($fp = popen("$TBSUEXEC_PATH $uid $unix_gid webvistopology " .
123
		"$arguments -z $zoom $pid $eid", "r")) {
124
    header("Content-type: image/svg+xml");
125 126
    fpassthru($fp);
}
127 128 129 130 131
else {
    # No Data. Spit back a stub image.
    header("Content-type: image/gif");
    readfile("coming-soon-thumb.gif");
}
132 133 134 135 136

#
# No Footer!
# 
?>
Chad Barb's avatar
Chad Barb committed
137 138 139