From 52881aed94982859772cb2f8923b82d2a0d6a655 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Fri, 26 Mar 2010 06:26:14 +0000 Subject: [PATCH] freeze cam pic for webpage --- sensor_graph/freeze_realraum_picture.pl | 67 +++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 sensor_graph/freeze_realraum_picture.pl diff --git a/sensor_graph/freeze_realraum_picture.pl b/sensor_graph/freeze_realraum_picture.pl new file mode 100755 index 0000000..7802378 --- /dev/null +++ b/sensor_graph/freeze_realraum_picture.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl -w +# +# +use strict; +use utf8; +use CGI; +my $q = CGI->new; +require LWP::UserAgent; +my $ua = LWP::UserAgent->new(env_proxy => 1, + keep_alive => 1, + timeout => 30, + ); +use HTTP::Cookies; +use LWP; +$ua->cookie_jar({}); + +############### +$cam::url = "http://slug.realraum.at:8088/?action=snapshot"; +#$cam::get = {action=>"snapshot"}; +$cam::localpath = "/tmp/realraum-freeze.jpg"; +############### + +sub output_saved_image +{ + return 0 if ( not -e $cam::localpath); + my $fh; + print STDOUT header("image/jpeg"); + open($fh,"<$cam::localpath") or exit; + while (<$fh>) {print $_}; + close($fh); + return 1; +} + +sub save_remote_image +{ + my $response; + $response = $ua->get($cam::url); + if (defined $response and $response->content =~ /^\xff\xd8/) + { + my $fh; + open($fh,">$cam::localpath"); + print $fh $response->content; + close($fh); + + print STDOUT header("text/html"); + print STDOUT "done\n"; + return 1; + } + return 0; +} + +sub output_error +{ + print STDOUT header("text/html","404 Not Found"); + print STDOUT "

Sorry

The picture you requested could not be found

\n"; + return 1; +} + +if ($q->param('freeze') eq "98VB9s") +{ + exit if (&save_remote_image); +} +elsif (-e $cam::localpath and -M $cam::localpath) +{ + exit if (&output_saved_image); +} +&output_error; -- 1.7.10.4