File:  [LON-CAPA] / loncom / auth / restrictedaccess.pm
Revision 1.6: download - view: text, annotated - select for diffs
Sat Jul 22 23:10:45 2006 UTC (17 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_8_X, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_99_3, version_2_1_99_2, HEAD, GCI_1
The second argument in $r->set_handlers() needs to be an array reference. Also need to use $r->handler('perl-script') to ensure the Perl Handler is actually used.

    1: # The LearningOnline Network
    2: # Passphrase Entry and Validation for Portfolio files 
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: 
   27: package Apache::restrictedaccess;
   28: 
   29: use strict;
   30: use lib '/home/httpd/lib/perl/';
   31: use Apache::Constants qw(:common :http REDIRECT);
   32: use CGI::Cookie();
   33: use Apache::lonnet;
   34: use Apache::loncommon();
   35: use Apache::lonauth();
   36: use Apache::lonlocal;
   37: use Apache::lonacc;
   38: use Fcntl qw(:flock);
   39: use LONCAPA;
   40: 
   41: sub handler {
   42:     my $r = shift;
   43: 
   44:     my $origurl = &unescape($env{'form.origurl'});
   45:     if (!defined($origurl)) {
   46: 	$origurl = $r->uri;
   47:     }
   48:     my $msg='';
   49:     if (exists($env{'form.pass1'})) {
   50:         my ($result,$end) = &check_pass($r,$origurl);
   51:         if ($result eq 'ok') {
   52: 	    &Apache::lonnet::allowuploaded('/adm/restrictedaccess',
   53: 					   $origurl);
   54: 	    $env{'request.state'} = "published";
   55: 	    $env{'request.filename'} = $origurl;
   56: 	    $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$origurl);
   57: 	    return REDIRECT;
   58:         } else {
   59: 	    $msg = 'Invalid passphrase';
   60: 	}
   61:     }
   62: 
   63:     &Apache::loncommon::content_type($r,'text/html');
   64:     $r->send_http_header;
   65:     return OK if $r->header_only;
   66: 
   67:     $r->print(&Apache::loncommon::start_page('Passphrase protected file'));
   68:     &print_entryform($r,$origurl,$msg);
   69: 
   70:     return OK;
   71: }
   72: 
   73: sub setup_handler {
   74:     my ($r) = @_;
   75:     $r->set_handlers('PerlHandler'=> 
   76: 		     [\&Apache::restrictedaccess::handler]);
   77:     $r->handler('perl-script');		    
   78: }
   79: 
   80: sub print_entryform {
   81:     my ($r,$origurl,$msg) = @_;
   82: 
   83:     $r->print('<script type="text/javascript">
   84: function verify() {
   85:     if (document.passform.pass1.value == "") {
   86:         alert("You must enter a passphrase");
   87:         return;
   88:     }
   89:     document.passform.submit();
   90: } 
   91: </script>');
   92:     if ($msg ne '') {
   93: 	$r->print('<span class="LC_error">'.$msg.'</span>');
   94:     }
   95:     $r->print('<div align="center"><form name="passform" method="post" '.
   96:               'action="/adm/restrictedaccess">');
   97:     $r->print('<br /><br /><br />');
   98:     $r->print(&Apache::loncommon::start_data_table());
   99:     $r->print(&Apache::loncommon::start_data_table_row());     
  100:     $r->print('<td><nobr>'.&mt('Passphrase: ').'</nobr></td>'.
  101:               '<td><input type="password" size="20" name="pass1" /></td>');
  102:     $r->print(&Apache::loncommon::end_data_table_row());
  103:     $r->print(&Apache::loncommon::start_data_table_row());
  104:     $r->print('<td align="center" colspan="2"><br />'.
  105:               '<input type="button" name="sendpass" value="'.
  106:               &mt('Submit passphrase').'" onClick="verify()" /></td>');
  107:     $r->print(&Apache::loncommon::end_data_table_row());
  108:     $r->print(&Apache::loncommon::end_data_table());
  109:     $r->print('<input type="hidden" name="origurl" value="'.
  110:               &escape($origurl).'" /></form></div>');
  111:     $r->print(&Apache::loncommon::end_page());
  112: }
  113: 
  114: sub check_pass {
  115:     my ($r,$origurl) = @_;
  116:     my (undef,$udom,$unum,$file_name,$group) = 
  117: 	&Apache::lonnet::parse_portfolio_url($origurl);
  118: 
  119:     my $curr_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);
  120:     my %acc_controls = &Apache::lonnet::get_access_controls($curr_perms,
  121:                                                             $group,$file_name);
  122:     my $access_hash = $acc_controls{$file_name};
  123: 
  124:     my ($result,$end);
  125:     foreach my $key (sort(keys(%{$access_hash}))) {
  126:         if ($key =~ /^[^:]+:guest_(\d+)/) {
  127:             $end = $1;
  128:             if ($env{'form.pass1'} eq $access_hash->{$key}{'password'}) {
  129:                 $result = 'ok';
  130:             } else {
  131:                 $result = 'fail';
  132:             }
  133:             last;
  134:         }
  135:     }
  136:     return ($result,$end);
  137: }
  138: 
  139: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>