#!/usr/bin/suidperl

$DIR="Rollover";

$| = 1;

sub error {
  print "Content-type: text/plain\n\nCGIWrap error: @_\n";
  print "PATH_INFO was $ENV{PATH_INFO}\n";
  exit -1;
}

sub http_die {
    print "Content-type: text/plain\n\n@_\n";
    exit -1;
}

if ($>) { &error("cgiwrap must run as root"); }

if ($ENV{PATH_INFO} eq "/") { &error("nothing to do!"); }

($scr) = $ENV{PATH_INFO} =~ /\/(.+)$/;
$scr = substr($ENV{PATH_INFO}, rindex($ENV{PATH_INFO}, "/") + 1,
              length($ENV{PATH_INFO}));
$script = "/www/$DIR/cgi-bin/$scr";

if (! -f $script) { &error("$script does not exit!"); }
($dev,$ino,$mode,$nlink,$uid) = stat($script);

open(STDERR,">&STDOUT");

($<, $>) = ($uid, $uid);
open (SCRIPT,"|$script") || &http_die("can't connect to script: $!\n");
print SCRIPT <STDIN>;
close (SCRIPT);
exit 0;
