top2image.php3 2.03 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3 4 5 6
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
# All rights reserved.
#
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
include("defs.php3");

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

#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# Verify page arguments.
# 
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
    USERERROR("You must provide a Project ID.", 1);
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
    USERERROR("You must provide an Experiment ID.", 1);
}
$exp_eid = $eid;
$exp_pid = $pid;

Chad Barb's avatar
Chad Barb committed
35 36 37 38
# if they dont exist, or are non-numeric, use defaults.
# note: one can use is_numeric in php4 instead of ereg.
if (!isset($zoom) || !ereg("^[0-9]{1,50}.?[0-9]{0,50}$", $zoom)) { $zoom = 1; }
if (!isset($detail) || !ereg("^[0-9]{1,50}$", $detail)) { $detail = 0; }
Chad Barb's avatar
 
Chad Barb committed
39
if (!isset($thumb) || !ereg("^[0-9]{1,50}$", $detail)) { $thumb = 0; }
Chad Barb's avatar
Chad Barb committed
40 41 42 43

if ($zoom > 8.0) { $zoom = 8.0; }
if ($zoom <= 0.0) { $zoom = 1.0; }

Chad Barb's avatar
 
Chad Barb committed
44 45
if ($thumb > 1024) { $thumb = 1024; }

46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#
# Check to make sure this is a valid PID/EID tuple.
#
if (! TBValidExperiment($exp_pid, $exp_eid)) {
  USERERROR("The experiment $exp_eid is not a valid experiment ".
            "in project $exp_pid.", 1);
}

#
# Verify Permission.
#
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_READINFO)) {
    USERERROR("You do not have permission to view experiment $exp_eid!", 1);
}

61 62 63 64 65 66 67 68 69 70
#
# XXX If an admin type, then use an appropriate gid so that we can get
# get to the top file. This needs more thought.
#
$gid = "nobody";

if (ISADMIN($uid)) {
    $gid = $exp_pid;
}

Chad Barb's avatar
 
Chad Barb committed
71 72 73 74 75
$arguments = "";

# note that we've already ensured that $detail and $thumb are numeric above.
if ($detail != 0) { $arguments .= " -d $detail"; }
if ($thumb != 0)  { $arguments .= " -t $thumb";  }
Chad Barb's avatar
Chad Barb committed
76

77 78 79
#
# Spit out the image with a content header.
#
Chad Barb's avatar
Chad Barb committed
80

Chad Barb's avatar
 
Chad Barb committed
81
if ($fp = popen("$TBSUEXEC_PATH $uid $gid webvistopology " .
Chad Barb's avatar
 
Chad Barb committed
82
		"$arguments -z $zoom $pid $eid", "r")) {
Chad Barb's avatar
 
Chad Barb committed
83
    header("Content-type: image/png");
84 85 86 87 88 89 90
    fpassthru($fp);
}

#
# No Footer!
# 
?>
Chad Barb's avatar
Chad Barb committed
91 92 93