spewevents.php 1.37 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2006, 2007 University of Utah and the Flux Group.
5 6 7 8 9 10 11
# All rights reserved.
#
include("defs.php3");

#
# Only known and logged in users.
#
12 13 14
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
15 16 17 18

#
# Verify page arguments.
#
19
$reqargs = RequiredPageArguments("experiment", PAGEARG_EXPERIMENT);
20

21 22 23
# Need these below.
$pid = $experiment->pid();
$eid = $experiment->eid();
24 25 26 27

#
# Verify permission.
#
28 29
if (!$experiment->AccessCheck($this_user, $TB_EXPT_READINFO)) {
    USERERROR("You do not have permission to view events for $pid/$eid!", 1);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
}

#
# A cleanup function to keep the child from becoming a zombie, since
# the script is terminated, but the children are left to roam.
#
$fp = 0;

function SPEWCLEANUP()
{
    global $fp;

    if (!$fp || !connection_aborted()) {
	exit();
    }
    pclose($fp);
    exit();
}
register_shutdown_function("SPEWCLEANUP");

50
if ($fp = popen("$TBSUEXEC_PATH $uid $pid webspewevents -w $pid $eid", "r")) {
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    header("Content-Type: text/plain");
    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;
}
else {
    USERERROR("Experiment $pid/$eid is no longer in transition!", 1);
}

?>