--- loncom/auth/restrictedaccess.pm 2006/07/10 03:58:45 1.1 +++ loncom/auth/restrictedaccess.pm 2013/07/15 14:32:47 1.10 @@ -1,6 +1,8 @@ # The LearningOnline Network # Passphrase Entry and Validation for Portfolio files # +# $Id: restrictedaccess.pm,v 1.10 2013/07/15 14:32:47 bisitz Exp $ +# # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). @@ -30,7 +32,6 @@ use strict; use lib '/home/httpd/lib/perl/'; use Apache::Constants qw(:common :http REDIRECT); use CGI::Cookie(); -use Apache::File (); use Apache::lonnet; use Apache::loncommon(); use Apache::lonauth(); @@ -42,73 +43,70 @@ use LONCAPA; sub handler { my $r = shift; - &Apache::loncommon::get_unprocessed_cgi - ($ENV{'QUERY_STRING'}.'&'.$env{'request.querystring'}, - ['origurl']); - - &Apache::lonacc::get_posted_cgi($r); my $origurl = &unescape($env{'form.origurl'}); - my $msg; + if (!defined($origurl)) { + $origurl = $r->uri; + } + my $msg=''; if (exists($env{'form.pass1'})) { my ($result,$end) = &check_pass($r,$origurl); if ($result eq 'ok') { - my $cookie_check = &print_redirect($r,$end,$origurl); - if ($cookie_check eq 'ok') { - $env{'request.state'} = "published"; - $env{'request.filename'} = $origurl; - $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$origurl); - return REDIRECT; - } else { - &print_entryform($r,$origurl,$cookie_check); - } + &Apache::lonnet::allowuploaded('/adm/restrictedaccess', + $origurl); + $env{'request.state'} = "published"; + $env{'request.filename'} = $origurl; + my $newurl = &Apache::lonnet::absolute_url($ENV{'HTTP_HOST'}).$origurl; + $r->header_out(Location => $newurl); + return REDIRECT; } else { - $msg = "Invalid passphrase"; - &print_entryform($r,$origurl,$msg); - } - } else { - &print_entryform($r,$origurl); + $msg = 'Invalid passphrase'; + } } - return OK; -} -sub print_entryform { - my ($r,$origurl,$msg) = @_; - &Apache::lonlocal::get_language_handle($r); &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK if $r->header_only; $r->print(&Apache::loncommon::start_page('Passphrase protected file')); + &print_entryform($r,$origurl,$msg); + + return OK; +} + +sub setup_handler { + my ($r) = @_; + $r->set_handlers('PerlHandler'=> + [\&Apache::restrictedaccess::handler]); + $r->handler('perl-script'); +} + +sub print_entryform { + my ($r,$origurl,$msg) = @_; + $r->print(''); - $r->print(''.$msg.''); + if ($msg ne '') { + $r->print(''.$msg.''); + } $r->print('