File:  [LON-CAPA] / loncom / auth / restrictedaccess.pm
Revision 1.10: download - view: text, annotated - select for diffs
Mon Jul 15 14:32:47 2013 UTC (10 years, 9 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, HEAD
XHTML: JavaScript event handlers in lower case

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

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