--- loncom/auth/lonacc.pm 2006/04/07 22:42:00 1.75 +++ loncom/auth/lonacc.pm 2006/04/13 19:07:33 1.76 @@ -1,7 +1,7 @@ # The LearningOnline Network # Cookie Based Access Handler # -# $Id: lonacc.pm,v 1.75 2006/04/07 22:42:00 albertel Exp $ +# $Id: lonacc.pm,v 1.76 2006/04/13 19:07:33 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,6 +51,91 @@ sub goodbye { return DONE; } +############################################### + +sub get_posted_cgi { + my ($r) = @_; + + my $buffer; + if ($r->header_in('Content-length')) { + $r->read($buffer,$r->header_in('Content-length'),0); + } + unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) { + my @pairs=split(/&/,$buffer); + my $pair; + foreach $pair (@pairs) { + my ($name,$value) = split(/=/,$pair); + $value =~ tr/+/ /; + $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; + $name =~ tr/+/ /; + $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; + &add_to_env("form.$name",$value); + } + } else { + my $contentsep=$1; + my @lines = split (/\n/,$buffer); + my $name=''; + my $value=''; + my $fname=''; + my $fmime=''; + my $i; + for ($i=0;$i<=$#lines;$i++) { + if ($lines[$i]=~/^$contentsep/) { + if ($name) { + chomp($value); + if ($fname) { + $env{"form.$name.filename"}=$fname; + $env{"form.$name.mimetype"}=$fmime; + } else { + $value=~s/\s+$//s; + } + &add_to_env("form.$name",$value); + } + if ($i<$#lines) { + $i++; + $lines[$i]=~ + /Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i; + $name=$1; + $value=''; + if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) { + $fname=$1; + if + ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) { + $fmime=$1; + $i++; + } else { + $fmime=''; + } + } else { + $fname=''; + $fmime=''; + } + $i++; + } + } else { + $value.=$lines[$i]."\n"; + } + } + } +# +# Digested POSTed values +# +# Remember the way this was originally done (GET or POST) +# + $env{'request.method'}=$ENV{'REQUEST_METHOD'}; +# +# There may also be stuff in the query string +# Tell subsequent handlers that this was GET, not POST, so they can access query string. +# Also, unset POSTed content length to cover all tracks. +# + + $r->method_number(M_GET); + + $r->method('GET'); + $r->headers_in->unset('Content-length'); +} + + sub handler { my $r = shift; my $requrl=$r->uri; @@ -103,7 +188,7 @@ sub handler { $env{'request.noversionuri'} = &Apache::lonnet::deversion($requrl); # -------------------------------------------------------- Load POST parameters - &Apache::loncommon::get_posted_cgi($r); + &Apache::lonacc::get_posted_cgi($r); # ---------------------------------------------------------------- Check access @@ -208,7 +293,7 @@ sub handler { &Apache::lonauth::success($r,'public','public','public'); my $lonidsdir=$r->dir_config('lonIDsDir'); &Apache::lonnet::transfer_profile_to_env($lonidsdir,$cookie); - &Apache::loncommon::get_posted_cgi($r); + &Apache::lonacc::get_posted_cgi($r); $env{'request.state'} = "published"; $env{'request.publicaccess'} = 1; $env{'request.filename'} = $r->filename;