#!/usr/bin/perl #------------------------------------------------------------ # SmallMotionWeb (smotion) is a lightweight web interface to motion webcam output # Requires that output directory directly visible to browsers # # Primary idea is that it can run easily in a mobile phone # # smotion assumes following output structure # /etc/motion/thread0.conf # jpeg_filename feed1/%Y%m%d/%H%M%S-%q # snapshot_filename feed1/%Y%m%d/%H%M%S-snapshot # ffmpeg_filename %v-%Y%m%d%H%M%S # timelapse_filename feed1/%Y%m%d/timelapse # # Roger Foskett 09/09/07 #------------------------------------------------------------ use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use Data::Dumper; # config params my $imageroot = "/var/www/webcam"; # dir where motion outputs files my $webroot = "/webcam"; # virtual url to imageroot my $boxcolor = "lightblue"; # box colour my $C = new CGI; my %P = $C->Vars; map { $P{$_} = $C->param($_) } $C->param; my $URL = $C->url(); my $redirect = $P{play} ? "onload='play()'" : ""; print header(-expires=>'now'); print < smotion
EOF my @feeds = sort map { $_ =~ /([^\\\/]+)$/; $1 } grep { -d } glob ("$imageroot/*"); fatal("No feeds directories found below $imageroot!") if $#feeds<0; $P{feed} ||= 0; $P{feed} = 0 if !defined $feeds[$P{feed}]; my $feed = $feeds[$P{feed}]; my $navhtml = (join " ",map { $P{feed}eq$_?$_:"$_" } (0..$#feeds))." "; $navhtml = "" if $#feeds == 0; my $feeddir = "$imageroot/$feed"; my @dates = map { $_ =~ /([^\\\/]+)$/; $1 } grep { -d } glob ("$feeddir/*"); fatal("No dates found below $feeddir!") if $#dates<0; $P{date} = $#dates if !defined $P{date}; $P{date} = $#dates if !defined $dates[$P{date}]; my $date = $dates[$P{date}]; $navhtml .= "< $date ". ">"; my $datedir = "$feeddir/$date"; my @pics = sort map { $_ =~ /([^\\\/]+)$/; $1 } glob ("$datedir/*.jpg"); $P{pic} = $#pics if !defined $P{pic}; $P{pic} = $#pics if !defined $pics[$P{pic}]; my $pic = $pics[$P{pic}]; my $picname = $pic; $picname =~ s/\.jpg$//; my $loc="$URL?feed=$P{feed}&date=$P{date}"; my $picfile = "$datedir/$pic"; # only play if valid images next my $nextpic = $P{reverse} ? $P{pic}-1 : $P{pic}+1; my $runfunc = $P{pic} >= 0 && defined $pics[$P{pic}] ? 'setTimeout("nextimage()",1000);' : ''; $runfunc = '' if $P{pic} == 0 && $P{play} && $P{reverse}; $runfunc = '' if $P{pic} == $#pics && $P{play}; my $revparam = $P{reverse} ? '&reverse=1' : ''; if ($P{play} && defined $pics[$nextpic]) { print < EOF } my $picnav = "R "; $picnav .= "|< ". "< $P{pic}/$#pics ". "> ". ">| "; $picnav .= "P"; my $motionhome = "http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome"; my $about = "? "; print box("",$about.$navhtml,$picnav); print "$date-$pic"; #-------------------------------------------------------------------- sub box { my ($content,$title,$link) = @_; my $html = ""; if (defined $title) { $link = defined $link ? "             $link" : ''; $html .= "\n"; } $html .= "
\n". "\n". "
 $title$link
\n". "
\n$content\n". "
\n\n"; return $html; } #-------------------------------------------------------------------- sub fatal { my ($msg) = @_; print box($msg,"ERROR:"); exit; } #-------------------------------------------------------------------- sub pdump { print box("
".Dumper(@_)."
"); }