#!/usr/bin/perl use Digest::SHA1 qw(sha1_hex); my $live = "/u01/workunits/live"; my $stage = "/u01/workunits/stage"; if(!$ENV{REMOTE_USER}) { print "Status: 401 Authorization Required\r\n"; print "WWW-Authenticate: Basic realm=\"test\"\r\n"; print "Content-Type: text/html\r\n\r\nGA"; exit(); } # first, try to get a work unit my $hash = &workunit(); # if that didn't work for whatever reason, try moving the stage to live if(length($hash) != 40) { unlink($live); rename($stage,$live); $hash = &workunit(); } # if that failed, or we couldn't open the file, bail if(length($hash) != 40 || !open(WU,"<$live/$hash.wu1")) { print "Status: 500 Uhoh\r\n"; print "Content-type: text/html\r\n\r\nSorry! :(\n$hash\n"; exit(); } # got a workunit, send and whack print "Content-Type: text/plain\r\n\r\n"; while(){ print $_; } close(WU); unlink("$live/$hash.wu1"); my $key = sha1_hex("$hash $ENV{REMOTE_USER}"); print "PUT /arcs/$ENV{REMOTE_USER}.$key.arc.gz HTTP/1.0\r\nHost: soap.grub.org\r\n\r\n"; sub workunit { opendir(DIR,$live); my $wu; my $hash; while($wu = readdir(DIR)) { if($wu =~ /(\w+)\.wu1$/) { $hash = $1; last; } } closedir(DIR); return $hash; }