Diff for /loncom/lontrans.pm between versions 1.15 and 1.18

version 1.15, 2016/07/25 19:49:45 version 1.18, 2018/01/12 13:34:08
Line 29 Line 29
 package Apache::lontrans;  package Apache::lontrans;
   
 use strict;  use strict;
 use Apache::Constants qw(:common :remotehost REDIRECT);  use Apache::Constants qw(:common :remotehost REDIRECT :http);
 use Apache::lonnet();  use Apache::lonnet;
 use Apache::File();  use Apache::File();
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   
Line 38  sub handler { Line 38  sub handler {
     my $r = shift;      my $r = shift;
     # FIXME line remove when mod_perl fixes BUG#4948       # FIXME line remove when mod_perl fixes BUG#4948 
     $r->notes->set('error-notes' => '');      $r->notes->set('error-notes' => '');
     if ($r->uri=~m{^/raw/}) {      if ($r->uri =~ m{^/adm/lti/(.+)$}) {
           my $realuri = $1;
           my %user;
           my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user);
           if (($handle ne '') && ($user{'lti'})) {
               if ($realuri =~ m{^uploaded/$match_domain/$match_courseid/(default|supplemental)(|_\d+)\.(?:sequence|page)___\d+___.+$}) {
                   my ($map,$resid,$url) = split(/___/,$realuri);
                   $realuri = &Apache::lonnet::clutter($url).'?symb='.$realuri;
               } elsif ($realuri =~ m{^tiny/$match_domain/\w+$}) {
                   $realuri = '/'.$realuri;    
               } elsif ($realuri =~ m{($match_domain)/($match_courseid)$}) {
                   $realuri = '/adm/navmaps';
               } else {
                   $realuri = '/'.$realuri;
                   if ($realuri =~ m{/default_\d+\.sequence$}) {
                       $realuri .= (($realuri =~/\?/)?'&':'?').'navmap=1';
                   }
               }
               my $host = $r->headers_in->get('Host');
               if ($host) {
                   my $protocol = 'http';
                   if ($r->get_server_port == 443) {
                       $protocol = 'https';
                   }
                   my $location = $protocol.'://'.$host.$realuri;
                   $r->headers_out->set(Location => $location);
                   return REDIRECT;
               }
           }
       } elsif ($r->uri =~ m{^/+tiny/+($match_domain)/+(\w+)$}) {
           my ($cdom,$key) = ($1,$2);
           if (&Apache::lonnet::domain($cdom) ne '') {
               my %user;
               my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user);
               if ($handle ne '') {
                   my $lonidsdir=$r->dir_config('lonIDsDir');
                   &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
                   if ($env{'request.course.id'}) {
                       my $tinyurl;
                       my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key);
                       if (defined($cached)) {
                           $tinyurl = $result;
                       } else {
                           my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
                           my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname);
                           if ($currtiny{$key} ne '') {
                               $tinyurl = $currtiny{$key};
                               &Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600);
                           }
                       }
                       if ($tinyurl ne '') {
                           my ($cnum,$symb) = split(/\&/,$tinyurl);
                           if (($cnum =~ /^$match_courseid$/) &&
                               (&Apache::lonnet::homeserver($cnum,$cdom) ne 'no_host')) {
                               if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
                                   my ($map,$resid,$url) = &Apache::lonnet::decode_symb($symb);
                                   if (&Apache::lonnet::is_on_map($url)) {
                                       my $realuri;
                                       if ((&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) &&
                                           (!$env{'request.role.adv'})) {
                                           $env{'user.error.msg'}=$r->uri.':bre:1:1:Access to resource denied';
                                           return HTTP_NOT_ACCEPTABLE;
                                       }
                                       if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) &&
                                           (!$env{'request.role.adv'})) {
                                           $realuri = &Apache::lonenc::encrypted(&Apache::lonnet::clutter($url)).
                                                      '?symb='.&Apache::lonenc::encrypted($symb);
                                       } else {
                                           $realuri = &Apache::lonnet::clutter($url).'?symb='.$symb;
                                       }
                                       my $host = $r->headers_in->get('Host');
                                       if ($host) {
                                           my $protocol = 'http';
                                           if ($r->get_server_port == 443) {
                                               $protocol = 'https';
                                           }
                                           my $location = $protocol.'://'.$host.$realuri;
                                           $r->headers_out->set(Location => $location);
                                           return REDIRECT;
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
           }
       } elsif ($r->uri=~m{^/raw/}) {
         my $host = $r->headers_in->get('Host');          my $host = $r->headers_in->get('Host');
         if ($host) {          if ($host) {
             unless ($host =~ /^internal\-/) {              unless ($host =~ /^internal\-/) {
                 my $c = $r->connection;                  my $remote_ip = $r->get_remote_host();
                 if (ref($c)) {                  my $lonhost = $r->dir_config('lonHostID');
                     my $remote_ip = $c->remote_ip;                  if (&redirect_raw($remote_ip,$lonhost)) {
                     my $lonhost = $r->dir_config('lonHostID');                      my $location = 'https://internal-'.$host.$r->uri;
                     if (&redirect_raw($remote_ip,$lonhost)) {                      $r->headers_out->set(Location => $location);
                         my $location = 'https://internal-'.$host.$r->uri;                      return REDIRECT;
                         $r->headers_out->set(Location => $location);  
                         return REDIRECT;  
                     }  
                 }                  }
             }              }
         }          }
Line 69  sub handler { Line 153  sub handler {
  '/userfiles/'.(join('/',@ufile)));   '/userfiles/'.(join('/',@ufile)));
         }          }
         return OK;          return OK;
     } else {       } else {
         return DECLINED;          return DECLINED;
     }      }
 }  }
Line 126  sub redirect_raw { Line 210  sub redirect_raw {
 1;  1;
 __END__  __END__
   
   
   
   
   
   
   

Removed from v.1.15  
changed lines
  Added in v.1.18


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