spewlogfile.php3 2.22 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5 6
# All rights reserved.
#
7 8 9
include("defs.php3");

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

#
# Verify page arguments.
#
19 20
$optargs = OptionalPageArguments("experiment", PAGEARG_EXPERIMENT,
				 "template",   PAGEARG_TEMPLATE);
21

22 23
if (! (isset($experiment) || isset($template))) {
    PAGEARGERROR("Must provide either an experiment or a template");
24 25 26
}

#
27
# Verify permission and sure there is a logfile.
28
#
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
if (isset($experiment)) {
    if (!$experiment->AccessCheck($this_user, $TB_EXPT_READINFO)) {
	USERERROR("You do not have permission to view logs for $pid/$eid!", 1);
    }
    if (! $experiment->logfile()) {
	USERERROR("Experiment $pid/$eid is no longer in transition!", 1);
    }
}
else {
    if (!$template->AccessCheck($this_user, $TB_EXPT_READINFO)) {
	USERERROR("You do not have permission to view logs for ".
		  "$guid/$vers!", 1);
    }
    if (! $template->logfile()) {
	USERERROR("Template $guid/$vers is no longer in transition!", 1);
    }
45 46
}

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#
# 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();
}
63
ignore_user_abort(1);
64 65
register_shutdown_function("SPEWCLEANUP");

66 67 68 69 70 71 72 73 74 75
if (isset($experiment)) {
    $args = "-e " . $experiment->pid() . "/" . $experiment->eid();
    $pid  = $experiment->pid();
}
else {
    $args = "-t " . $template->guid() . "/" . $template->vers();
    $pid  = $template->pid();
}

if ($fp = popen("$TBSUEXEC_PATH $uid $pid spewlogfile -w $args", "r")) {
76 77 78 79 80 81 82 83
    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);
84 85 86 87 88 89 90
	echo "$string";
	flush();
    }
    pclose($fp);
    $fp = 0;
}
else {
91 92 93 94
    if (isset($experiment))
	USERERROR("Experiment $pid/$eid is no longer in transition!", 1);
    else
	USERERROR("Template $guid/$vers is no longer in transition!", 1);
95 96 97
}

?>