#!/usr/bin/perl ############################################################################## # This script takes the argument from POST and duplicates ir codes on the DEC. # It then generates a screenshot of the current DEC screen. # # Author : Philippe Daoust (pdaoust@sympatico.ca) # Last updated : January 5th, 2003 ############################################################################## # Set the path for the system calls $ENV{PATH}='/bin:/usr/bin:/opt/odin/dec/bin/:/usr/X11R6/bin/'; print "Content-type:text/html\n\n"; # The following function seperates the arguments passed by the POST form and puts # them in a hash read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } # Since we are using the arguments passed by POST in system calls # we need to "untaint" the data before Perl will accept to use it. # This is a feature of Perlsec, I think... if ($name =~ /^([-\@\w.]+)$/) { $name = $1; # $data now untainted } else { die "Bad data in $data"; # log this somewhere } # Refreshes the screen... if ($FORM{'refresh'}) { system("/usr/X11R6/bin/xwd -display :0 -root -out /content/screenshot.xwd"); system("/usr/bin/convert -compress JPEG -quality 30 /content/screenshot.xwd ../htdocs/screenshot.jpg"); } # The CD key is not an argument that can be used with the "press" function # so I created my own... elsif ($FORM{'cd'}) { system("/opt/odin/dec/bin/press menu"); # Notice I use "select" instead of "sleep" to create a timeout. This is more precise # and provides finer granularity... select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press select"); select undef, undef, undef, 0.25; system("/usr/X11R6/bin/xwd -display :0 -root -out /content/screenshot.xwd"); system("/usr/bin/convert -compress JPEG -quality 30 /content/screenshot.xwd ../htdocs/screenshot.jpg"); } elsif ($FORM{'library'}) { system("/opt/odin/dec/bin/press menu"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press down"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press select"); select undef, undef, undef, 0.25; system("/usr/X11R6/bin/xwd -display :0 -root -out /content/screenshot.xwd"); system("/usr/bin/convert -compress JPEG -quality 30 /content/screenshot.xwd ../htdocs/screenshot.jpg"); } elsif ($FORM{'iradio'}) { system("/opt/odin/dec/bin/press menu"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press down"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press down"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press select"); select undef, undef, undef, 0.25; system("/usr/X11R6/bin/xwd -display :0 -root -out /content/screenshot.xwd"); system("/usr/bin/convert -compress JPEG -quality 30 /content/screenshot.xwd ../htdocs/screenshot.jpg"); } elsif ($FORM{'iguide'}) { system("/opt/odin/dec/bin/press menu"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press down"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press down"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press down"); select undef, undef, undef, 0.1; system("/opt/odin/dec/bin/press select"); select undef, undef, undef, 0.25; system("/usr/X11R6/bin/xwd -display :0 -root -out /content/screenshot.xwd"); system("/usr/bin/convert -compress JPEG -quality 30 /content/screenshot.xwd ../htdocs/screenshot.jpg"); } else { system("/opt/odin/dec/bin/press $name"); select undef, undef, undef, 0.25; system("/usr/X11R6/bin/xwd -display :0 -root -out /content/screenshot.xwd"); system("/usr/bin/convert -compress JPEG -quality 30 /content/screenshot.xwd ../htdocs/screenshot.jpg"); } # Print out the HTML to the screen... print < Phil's DEC Web Remote
ENDofHTML