webcam.php3 3.18 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 12 13 14
# All rights reserved.
#
include("defs.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Robot Web Cams");

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

21 22 23 24 25 26 27 28 29 30
#
# Verify page arguments
#
$optargs = OptionalPageArguments("camheight",   PAGEARG_INTEGER,
				 "camwidth",    PAGEARG_INTEGER,
				 "camfps",      PAGEARG_INTEGER,
				 "refreshrate", PAGEARG_INTEGER,
				 "camera",      PAGEARG_INTEGER,
				 "applet",      PAGEARG_BOOLEAN);

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# Helper function.
function MyError($msg)
{
    # No Data. Spit back a stub image.
    USERERROR($msg, 1);
    exit(0);
}

#
# Check sitevar to make sure mere users are allowed to peek at us.
#
$anyone_can_view = TBGetSiteVar("webcam/anyone_can_view");
$admins_can_view = TBGetSiteVar("webcam/admins_can_view");

if (!$admins_can_view || (!$anyone_can_view && !$isadmin)) {
    MyError("Webcam Views are currently disabled!", 1);
}

#
# Now check permission.
#
52
if (!$isadmin && !$this_user->WebCamAllowed()) {
53 54 55 56 57 58 59 60 61 62 63 64 65
    MyError("Not enough permission to view the robot cameras!");
}

#
# Get the set of webcams, and present a simple table of images, with titles.
#
$query_result =
    DBQueryFatal("select * from webcams");

if (!$query_result || !mysql_num_rows($query_result)) {
    MyError("There are no webcams to view!");
}

66 67 68 69 70 71 72 73 74 75 76 77 78
$extra_url = "&fromtracker=1";
if (!isset($camwidth) || !TBvalid_integer($camwidth)) {
    $camwidth = "640";
}
$extra_url .= "&camwidth=$camwidth";
if (!isset($camheight) || !TBvalid_integer($camheight)) {
    $camheight = "480";
}
$extra_url .= "&camheight=$camheight";
if (isset($camfps) && TBvalid_integer($camfps)) {
    $extra_url .= "&camfps=$camfps";
}

79 80 81 82 83 84 85
if (isset($refreshrate)) {
    echo "<center>
          <a href=webcam.php3>Stop Auto-refresh.</a>
          </center>\n";
}
else {
    echo "<center>
86 87 88
          <a href=webcam.php3?refreshrate=2>Auto-refresh</a> images at two
             second interval, or<br>
          <a href=webcam.php3?applet=1>Live Image</a> using a java applet.
89 90 91
          </center>\n";
}

92 93 94 95 96 97
if (isset($applet)) {
    $auth    = $HTTP_COOKIE_VARS[$TBAUTHCOOKIE];
    
    while ($row = mysql_fetch_array($query_result)) {
	$id  = $row["id"];
	$url = "webcamimg.php3?webcamid=${id}&nocookieuid=${uid}".
98
	    "&nocookieauth=${auth}&applet=1" . $extra_url;
99

100 101 102 103 104 105
	if (!isset($camera) || $camera == $id) {
	    echo "<applet archive=WebCamApplet.jar
	                  code=WebCamApplet.class height=$camheight width=$camwidth>
                          <param name=URL value=$url>
                  </applet><br<br>\n";
	}
106 107 108 109 110 111 112 113
    }
}
else {
    echo "<table cellpadding='0' cellspacing='0' border='0'
                 class='stealth'>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$id      = $row["id"];
114

115 116 117 118 119 120 121
	if (!isset($camera) || $camera == $id) {
	    echo "<tr><td align=center>Web Cam $id</td></tr>
        	  <tr><td align=center class='stealth'>
                	<img src='webcamimg.php3?webcamid=${id}${extra_url}'
                        	align=center></td></tr>
	          <tr><tr>\n";
	}
122 123
    }
    echo "</table>\n";
124 125 126 127 128 129 130
}

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>