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
# All rights reserved.
#
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 19 20 21 22 23 24 25
#
# Verify page arguments
#
$optargs = OptionalPageArguments("camheight",   PAGEARG_INTEGER,
				 "camwidth",    PAGEARG_INTEGER,
				 "camfps",      PAGEARG_INTEGER,
				 "refreshrate", PAGEARG_INTEGER,
				 "camera",      PAGEARG_INTEGER,
				 "applet",      PAGEARG_BOOLEAN);

26 27 28 29 30 31
#
# Standard Testbed Header
#
PAGEHEADER("Robot Web Cams");

#
32
# Helper function.
33
#
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
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.
#
54
if (!$isadmin && !$this_user->WebCamAllowed()) {
55 56 57 58 59 60 61 62 63 64 65 66 67
    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!");
}

68 69 70 71 72 73 74 75 76 77 78 79 80
$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";
}

81 82 83 84 85 86 87
if (isset($refreshrate)) {
    echo "<center>
          <a href=webcam.php3>Stop Auto-refresh.</a>
          </center>\n";
}
else {
    echo "<center>
88 89 90
          <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.
91 92 93
          </center>\n";
}

94 95 96 97 98 99
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}".
100
	    "&nocookieauth=${auth}&applet=1" . $extra_url;
101

102 103 104 105 106 107
	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";
	}
108 109 110 111 112 113 114 115
    }
}
else {
    echo "<table cellpadding='0' cellspacing='0' border='0'
                 class='stealth'>\n";

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

117 118 119 120 121 122 123
	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";
	}
124 125
    }
    echo "</table>\n";
126 127 128 129 130 131 132
}

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