ledpipe.php3 2.29 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2000-2007 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/>.
# 
# }}}
23 24
#
include("defs.php3");
25
include_once("node_defs.php");
26 27

#
28
# Only known and logged in users can watch LEDs
29
#
30 31 32
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
33 34

# Verify page arguments.
35
$reqargs = RequiredPageArguments("node", PAGEARG_STRING);
36 37 38 39 40

if (!TBvalid_node_id($node)) {
    USERERROR("Invalid node ID.", 1);
}

41
if (! ($target_node = Node::Lookup($node))) {
42 43 44
    USERERROR("Invalid node ID.", 1);
}

45
if (!$target_node->AccessCheck($this_user, $TB_NODEACCESS_READINFO)) {
46 47 48 49 50 51 52 53 54
    USERERROR("Not enough permission.", 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();

55 56 57 58 59 60 61 62 63 64 65
#for ($lpc = 0; $lpc < 30; $lpc++) {
    #	sleep(1);
    #	$on_off = $lpc % 2;
    #	echo "$on_off";
    #	flush();
    #}

#
# Silly, I can't get php to get the buffering behavior I want with a socket, so
# we'll open a pipe to a perl process
#
66
$socket = fsockopen("$node", 1812);
67 68 69 70 71 72 73 74 75 76 77 78 79 80
if (!$socket) {
    USERERROR("Error opening $node - $errstr",1);
}

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

    if (!$socket || !connection_aborted()) {
	exit();
    }
81
    fclose($socket);
82 83
    exit();
}
84
# ignore_user_abort(1);
85 86 87 88 89
register_shutdown_function("SPEWCLEANUP");

#
# Just loop forver reading from the socket
#
90
do {
91 92 93 94
    # Bad rob! No biscuit!
    $onoff = fread($socket,6);
    echo "$onoff";
    flush();
95
} while ($onoff != "");
96
fclose($socket);
97 98

?>