Commit d46902e1 authored by Leigh Stoller's avatar Leigh Stoller

A quick hack job to get the webcams onto the web interface.

* Add new DB table "webcams" which hold the id of the webcam, the
  server it is attached to, and the last update time.

* Add new sitevars webcam/anyone_can_view and webcam/admins_can_view.
  Should be obvious what they mean.

* Add trivial script grabwebcams (invoked from cron) to grab the images
  from the servers and stash in /usr/testbed/webcams. The images are
  grabbed with scp, protected by a 5 second timeout. Fine for a couple
  of cameras.

* Add web page stuff to display webcams, linked from the robot mape page.

Permission to view the webcams is currently admin, or in a project that is
allowed to use a robot. We can tighten this up later as needed.
parent 6841d600
......@@ -1908,6 +1908,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
utils/nsgen/GNUmakefile utils/nsgen/webnsgen \
utils/link_config utils/import_commitlog utils/dhcpd_wrapper \
utils/opsreboot utils/deletenode utils/webdeletenode utils/spewleds \
utils/grabwebcams \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
www/swish.conf www/websearch www/garcia-telemetry/GNUmakefile \
vis/GNUmakefile vis/webvistopology vis/dbvistopology \
......
......@@ -684,6 +684,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
utils/nsgen/GNUmakefile utils/nsgen/webnsgen \
utils/link_config utils/import_commitlog utils/dhcpd_wrapper \
utils/opsreboot utils/deletenode utils/webdeletenode utils/spewleds \
utils/grabwebcams \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
www/swish.conf www/websearch www/garcia-telemetry/GNUmakefile \
vis/GNUmakefile vis/webvistopology vis/dbvistopology \
......
......@@ -2033,6 +2033,17 @@ CREATE TABLE vlans (
KEY pid (pid,eid)
) TYPE=MyISAM;
--
-- Table structure for table `webcams`
--
CREATE TABLE webcams (
id int(11) unsigned NOT NULL default '0',
server varchar(64) NOT NULL default '',
last_update datetime default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
--
-- Table structure for table `webdb_table_permissions`
--
......
......@@ -2262,5 +2262,18 @@ last_net_act,last_cpu_act,last_ext_act);
1.296: Fix virt_vtypes table.
alter table virt_vtypes change eid eid varchar(32) NOT NULL default '';
alter table virt_vtypes change eid eid varchar(32) NOT NULL \
default '';
1.297: Add webcams support.
CREATE TABLE webcams (
id int(11) unsigned NOT NULL default '0',
server varchar(64) NOT NULL default '',
last_update datetime default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
......@@ -41,3 +41,5 @@ INSERT INTO sitevariables VALUES ('plab/message',NULL,'','Message to display at
INSERT INTO sitevariables VALUES ('node/ssh_pubkey',NULL,'','Boss SSH public key to install on nodes');
INSERT INTO sitevariables VALUES ('general/autoswap_threshold',NULL,'16','Number of hours before an experiment is forcibly swapped');
INSERT INTO sitevariables VALUES ('general/autoswap_mode',NULL,'0','Control whether autoswap defaults to on or off in the Begin Experiment page');
INSERT INTO sitevariables VALUES ('webcam/anyone_can_view',NULL,'0','Turn webcam viewing on/off for mere users; default is off');
INSERT INTO sitevariables VALUES ('webcam/admins_can_view',NULL,'1','Turn webcam viewing on/off for admin users; default is on');
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -17,7 +17,7 @@ SUBDIRS = nsgen
BIN_SCRIPTS = delay_config sshtb create_image node_admin link_config
SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
eventping grantnodetype import_commitlog dhcpd_wrapper \
opsreboot deletenode node_statewait
opsreboot deletenode node_statewait grabwebcams
LIBEXEC_SCRIPTS = webcreateimage newnode webdeletenode spewleds
#
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
#
# Grab webcam images.
# Currently run as a cron job, but is probably better as a testbed
# daemon.
#
#
# Configure variables
#
my $TB = "@prefix@";
my $WEBCAMDIR = "$TB/webcams";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
my $SCP = "/usr/bin/scp";
# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
my $verbose = 1;
my $debug = 0;
my @failed = ();
#
# Turn off line buffering on output
#
$| = 1;
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libdb;
#
# Only root and admins are allowed to use this script
#
if ($UID != 0) {
die("*** $0:\n".
" You do not have permission to run this script!\n");
}
#
# Grab the webcams from the DB and get the images
#
my $query_result = DBQueryFatal("select * from webcams");
while (my %row = $query_result->fetchhash()) {
my $id = $row{"id"};
my $server = $row{"server"};
my $filename = "/var/tmp/camera-${id}.jpg";
#
# ssh to server, protected by timeout.
#
my $syspid = fork();
if ($syspid) {
local $SIG{ALRM} = sub { kill("TERM", $syspid); };
alarm 5;
waitpid($syspid, 0);
alarm 0;
#
# Any failure, skip to next one.
#
if ($?) {
print "Failed to get webcam image $id from $server\n";
SENDMAIL($TBOPS, "Grab WebCam Image Failure",
"Failed to webcam $id from $server: $?\n");
next;
}
}
else {
exec("$SCP -q ${server}:${filename} $WEBCAMDIR");
exit(0);
}
DBQueryFatal("update webcams set last_update=now() ".
"where $id='$id'");
}
exit(0);
......@@ -1827,7 +1827,7 @@ function TBGetSiteVar($name)
if (isset($defaultvalue)) { return $defaultvalue; }
}
TBERROR("Attempted to fetch unknown site variable '$name'!");
TBERROR("Attempted to fetch unknown site variable '$name'!", 1);
}
#
......@@ -1903,6 +1903,20 @@ function TBExptFirewall($pid, $eid) {
return 1;
}
#
# See if user has enough permission to view the webcams. If not an admin
# person, then must be a project with permission to use the robots.
# Eventually this needs to be a much more restrictive test.
#
function TBWebCamAllowed($uid) {
$query_result =
DBQueryFatal("select distinct class from group_membership as g ".
"left join nodetypeXpid_permissions as p on g.pid=p.pid ".
"left join node_types as nt on nt.type=p.type ".
"where uid='$uid' and class='robot'");
return mysql_num_rows($query_result);
}
#
# DB Interface.
#
......
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004 University of Utah and the Flux Group.
# Copyright (c) 2004, 2005 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
......@@ -205,6 +205,11 @@ echo " Click on the dots below to see information about the robot\n";
echo " <br>\n";
echo " Click elsewhere to get its x,y location.\n";
echo " <br>\n";
if ($isadmin || TBWebdbAllowed($uid)) {
echo " There is a nifty <a href=webcam.php3>webcam image</a> of the";
echo " robots too\n";
echo " <br>\n";
}
if (isset($map_x) && isset($map_y)) {
# $map_y = $max_y - $map_y;
......
<?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.
#
if (!$isadmin && !TBWebdbAllowed($uid)) {
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!");
}
echo "<table cellpadding='0' cellspacing='0' border='0' class='stealth'>\n";
while ($row = mysql_fetch_array($query_result)) {
$id = $row["id"];
$updated = $row["last_update"];
echo "<tr><td align=center>Web Cam $id. Last Update: $updated</td></tr>
<tr><td align=center class='stealth'>
<img src='webcamimg.php3?webcamid=$id' align=center></td></tr>
<tr><tr>\n";
}
echo "</table>\n";
#
# Standard Testbed Footer
#
PAGEFOOTER();
?>
<?php
#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
include("defs.php3");
#
# This script generates the contents of an image. No headers or footers,
# just spit back an image.
#
function MyError($msg)
{
# No Data. Spit back a stub image.
#TBERROR($msg, 1);
header("Content-type: image/gif");
readfile("coming-soon-thumb.gif");
exit(0);
}
#
# Only known and logged in users can end experiments.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);
$isadmin = ISADMIN($uid);
#
# Verify page arguments.
#
if (!isset($webcamid) ||
strcmp($webcamid, "") == 0) {
MyError("You must provide a WebCam ID.");
}
#
# The ID is really just a filename. Make sure it looks okay.
#
if (! preg_match("/^[\d]+$/", $webcamid)) {
MyError("Invalid characters in WebCam ID.");
}
#
# And check for the filename in the webcam directory.
#
$filename = "$TBDIR/webcams/camera-${webcamid}.jpg";
if (!file_exists($filename)) {
MyError("Camera image file is missing!");
}
#
# 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)) {
USERERROR("Webcam Views are currently disabled!", 1);
}
#
# Now check permission.
#
if (!$isadmin && !TBWebdbAllowed($uid)) {
MyError("Not enough permission to view the robot cameras!");
}
# Spit back the image
header("Content-type: image/gif");
readfile("$filename");
#
# No Footer!
#
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment