Diff for /loncom/auth/restrictedaccess.pm between versions 1.2 and 1.9

version 1.2, 2006/07/14 21:38:26 version 1.9, 2013/06/02 02:20:33
Line 1 Line 1
 # The LearningOnline Network  # The LearningOnline Network
 # Passphrase Entry and Validation for Portfolio files   # Passphrase Entry and Validation for Portfolio files 
 #  #
   # $Id$
   #
 # Copyright Michigan State University Board of Trustees  # Copyright Michigan State University Board of Trustees
 #  #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).  # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
Line 45  sub handler { Line 47  sub handler {
     if (!defined($origurl)) {      if (!defined($origurl)) {
  $origurl = $r->uri;   $origurl = $r->uri;
     }      }
       my $msg='';
     if (exists($env{'form.pass1'})) {      if (exists($env{'form.pass1'})) {
         my ($result,$end) = &check_pass($r,$origurl);          my ($result,$end) = &check_pass($r,$origurl);
         if ($result eq 'ok') {          if ($result eq 'ok') {
     &Apache::lonnet::appenv(('user.passphrase_access_'.$origurl =>      &Apache::lonnet::allowuploaded('/adm/restrictedaccess',
  $end));     $origurl);
     $env{'request.state'} = "published";      $env{'request.state'} = "published";
     $env{'request.filename'} = $origurl;      $env{'request.filename'} = $origurl;
     $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$origurl);              my $newurl = &Apache::lonnet::absolute_url($ENV{'HTTP_HOST'}).$origurl;
       $r->header_out(Location => $newurl);
     return REDIRECT;      return REDIRECT;
         } else {          } else {
             &print_entryform($r,$origurl,"Invalid passphrase");      $msg = 'Invalid passphrase';
         }   }
     } else {  
         &print_entryform($r,$origurl);  
     }      }
     return OK;  
 }  
   
 sub print_entryform {  
     my ($r,$origurl,$msg) = @_;  
     &Apache::lonlocal::get_language_handle($r);  
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     return OK if $r->header_only;      return OK if $r->header_only;
   
     $r->print(&Apache::loncommon::start_page('Passphrase protected file'));      $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('<script type="text/javascript">      $r->print('<script type="text/javascript">
 function verify() {  function verify() {
     if (document.passform.pass1.value == "") {      if (document.passform.pass1.value == "") {
Line 80  function verify() { Line 92  function verify() {
     document.passform.submit();      document.passform.submit();
 }   } 
 </script>');  </script>');
     $r->print('<span class="LC_error">'.$msg.'</span>');      if ($msg ne '') {
    $r->print('<span class="LC_error">'.$msg.'</span>');
       }
     $r->print('<div align="center"><form name="passform" method="post" '.      $r->print('<div align="center"><form name="passform" method="post" '.
               'action="/adm/restrictedaccess">');                'action="/adm/restrictedaccess">');
     $r->print('<br /><br /><br />');      $r->print('<br /><br /><br />');
     $r->print(&Apache::loncommon::start_data_table());      $r->print(&Apache::loncommon::start_data_table());
     $r->print(&Apache::loncommon::start_data_table_row());           $r->print(&Apache::loncommon::start_data_table_row());     
     $r->print('<td><nobr>'.&mt('Passphrase: ').'</nobr></td>'.      $r->print('<td><span class="LC_nobreak">'.&mt('Passphrase: ').'</span></td>'.
               '<td><input type="password" size="20" name="pass1"></td>');                '<td><input type="password" size="20" name="pass1" /></td>');
     $r->print(&Apache::loncommon::end_data_table_row());      $r->print(&Apache::loncommon::end_data_table_row());
     $r->print(&Apache::loncommon::start_data_table_row());      $r->print(&Apache::loncommon::start_data_table_row());
     $r->print('<td align="center" colspan="2"><br />'.      $r->print('<td align="center" colspan="2"><br />'.
Line 102  function verify() { Line 116  function verify() {
   
 sub check_pass {  sub check_pass {
     my ($r,$origurl) = @_;      my ($r,$origurl) = @_;
     my ($udom,$unum,$group,$file_name,$result,$end);      my (undef,$udom,$unum,$file_name,$group) = 
     if ($origurl =~  m-/+uploaded/([^/]+)/([^/]+)/portfolio(/.+)$-) {   &Apache::lonnet::parse_portfolio_url($origurl);
         $udom = $1;  
         $unum = $2;  
         $file_name = $3;  
     } elsif ($origurl =~ m-/+uploaded/([^/]+)/([^/]+)/groups/([^/]+)/portfolio/(.+)$-) {  
         $udom = $1;  
         $unum = $2;  
         $group = $3;  
         $file_name = $3.'/'.$4;  
     }  
     my $curr_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);      my $curr_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);
     my %acc_controls = &Apache::lonnet::get_access_controls($curr_perms,      my %acc_controls = &Apache::lonnet::get_access_controls($curr_perms,
                                                             $group,$file_name);                                                              $group,$file_name);
     my $access_hash = $acc_controls{$file_name};      my $access_hash = $acc_controls{$file_name};
   
       my ($result,$end);
     foreach my $key (sort(keys(%{$access_hash}))) {      foreach my $key (sort(keys(%{$access_hash}))) {
         if ($key =~ /^[^:]+:guest_(\d+)/) {          if ($key =~ /^[^:]+:guest_(\d+)/) {
             $end = $1;              $end = $1;

Removed from v.1.2  
changed lines
  Added in v.1.9


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