servicepipe.php3 1.44 KB
Newer Older
1 2 3
<?php
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2005, 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 can watch LEDs
#
12 13 14
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
15 16 17 18

#
# Verify page arguments.
#
19 20 21
$reqargs = RequiredPageArguments("node",    PAGEARG_NODE,
				 "service", PAGEARG_STRING,
				 "init",    PAGEARG_STRING);
22

23
if (!$node->AccessCheck($this_user, $TB_NODEACCESS_READINFO)) {
24 25 26 27 28 29 30 31 32 33 34 35 36 37
    USERERROR("Not enough permission.", 1);
}

$port = "";
$initPacket = "";

if ($service == "telemetry") {
    $port = 2531;
    $initPacket = base64_decode($init);
}
else {
    USERERROR("Unknown service: $service.", 1);
}

38
if ($node->NodeStatus() != "up") {
39 40 41 42 43 44 45 46 47
    USERERROR("Node is down.", 1);
}

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();

48
$socket = fsockopen("$node_id", $port);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

#
# Clean up when the remote user disconnects
#
function SPEWCLEANUP()
{
    global $socket;

    if (!$socket || !connection_aborted()) {
	exit();
    }
    fclose($socket);
    exit();
}
# ignore_user_abort(1);
register_shutdown_function("SPEWCLEANUP");

if ($initPacket != "") {
     fwrite($socket, $initPacket);
     fflush($socket);
}

do {
    $bits = fread($socket, 512);
    echo "$bits";
    flush();
} while($bits != "");

fclose($socket);

?>