webcam.php3 3.85 KB
Newer Older
1 2
<?php
#
3
# Copyright (c) 2005-2013 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 25 26
#
include("defs.php3");

#
27
# Only known and logged in users.
28
#
29 30 31
$this_user = CheckLoginOrDie();
$uid       = $this_user->uid();
$isadmin   = ISADMIN();
32

33 34 35 36 37 38 39 40 41 42
#
# Verify page arguments
#
$optargs = OptionalPageArguments("camheight",   PAGEARG_INTEGER,
				 "camwidth",    PAGEARG_INTEGER,
				 "camfps",      PAGEARG_INTEGER,
				 "refreshrate", PAGEARG_INTEGER,
				 "camera",      PAGEARG_INTEGER,
				 "applet",      PAGEARG_BOOLEAN);

43 44 45 46 47 48
#
# Standard Testbed Header
#
PAGEHEADER("Robot Web Cams");

#
49
# Helper function.
50
#
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
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.
#
71
if (!$isadmin && !$this_user->WebCamAllowed()) {
72 73 74 75 76 77 78 79 80 81 82 83 84
    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!");
}

85 86 87 88 89 90 91 92 93 94 95 96 97
$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";
}

98 99 100 101 102 103 104
if (isset($refreshrate)) {
    echo "<center>
          <a href=webcam.php3>Stop Auto-refresh.</a>
          </center>\n";
}
else {
    echo "<center>
105 106 107
          <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.
108 109 110
          </center>\n";
}

111
if (isset($applet)) {
112
    $auth    = $_COOKIE[$TBAUTHCOOKIE];
113 114 115 116
    
    while ($row = mysql_fetch_array($query_result)) {
	$id  = $row["id"];
	$url = "webcamimg.php3?webcamid=${id}&nocookieuid=${uid}".
117
	    "&nocookieauth=${auth}&applet=1" . $extra_url;
118

119 120 121 122 123 124
	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";
	}
125 126 127 128 129 130 131 132
    }
}
else {
    echo "<table cellpadding='0' cellspacing='0' border='0'
                 class='stealth'>\n";

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

134 135 136 137 138 139 140
	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";
	}
141 142
    }
    echo "</table>\n";
143 144 145 146 147 148 149
}

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