webcam.php3 2.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");

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

#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);

# 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.
#
42
if (!$isadmin && !TBWebCamAllowed($uid)) {
43 44 45 46 47 48 49 50 51 52 53 54 55
    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!");
}

56 57 58 59 60 61 62
if (isset($refreshrate)) {
    echo "<center>
          <a href=webcam.php3>Stop Auto-refresh.</a>
          </center>\n";
}
else {
    echo "<center>
63 64 65
          <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.
66 67 68
          </center>\n";
}

69 70 71 72 73 74 75
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}".
	    "&nocookieauth=${auth}&applet=1";
76

77 78 79 80 81 82 83 84 85 86 87 88
	echo "<applet archive=WebCamApplet.jar
	              code=WebCamApplet.class height=480 width=640>
                      <param name=URL value=$url>
              </applet><br<br>\n";
    }
}
else {
    echo "<table cellpadding='0' cellspacing='0' border='0'
                 class='stealth'>\n";

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

90 91 92 93 94 95 96
	echo "<tr><td align=center>Web Cam $id</td></tr>
              <tr><td align=center class='stealth'>
                     <img src='webcamimg.php3?webcamid=$id'
                          align=center></td></tr>
              <tr><tr>\n";
    }
    echo "</table>\n";
97 98 99 100 101 102 103
}

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