Annotation of loncom/lontrans.pm, revision 1.26
1.1 www 1: # The LearningOnline Network
2: # URL translation for User Files
3: #
1.26 ! raeburn 4: # $Id: lontrans.pm,v 1.25 2019/01/20 02:42:35 raeburn Exp $
1.1 www 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::lontrans;
30:
31: use strict;
1.25 raeburn 32: use Apache::Constants qw(:common :remotehost REDIRECT);
1.18 raeburn 33: use Apache::lonnet;
1.1 www 34: use Apache::File();
1.15 raeburn 35: use LONCAPA qw(:DEFAULT :match);
1.2 www 36:
1.1 www 37: sub handler {
38: my $r = shift;
1.25 raeburn 39: # FIXME line remove when mod_perl fixes BUG#4948
1.12 albertel 40: $r->notes->set('error-notes' => '');
1.25 raeburn 41: if ($r->uri=~m{^/raw/}) {
1.15 raeburn 42: my $host = $r->headers_in->get('Host');
43: if ($host) {
44: unless ($host =~ /^internal\-/) {
1.16 raeburn 45: my $remote_ip = $r->get_remote_host();
46: my $lonhost = $r->dir_config('lonHostID');
47: if (&redirect_raw($remote_ip,$lonhost)) {
48: my $location = 'https://internal-'.$host.$r->uri;
49: $r->headers_out->set(Location => $location);
50: return REDIRECT;
1.15 raeburn 51: }
52: }
53: }
54: }
1.7 raeburn 55: if ($r->uri=~m|^(/raw)?/uploaded/|) {
56: my $fn = $r->uri();
57: $fn=~s/^\/raw//;
58: my (undef,undef,$udom,$uname,@ufile)=split(/\//,$fn);
1.10 albertel 59: if (@ufile) { $ufile[-1]=~s/^[\~\.]+//; }
1.7 raeburn 60: my $chome=&Apache::lonnet::homeserver($uname,$udom);
1.9 albertel 61: my $allowed=0;
62: my @ids=&Apache::lonnet::current_machine_ids();
63: foreach my $id (@ids) { if ($id eq $chome) { $allowed=1; } }
64: if ($allowed) {
1.13 albertel 65: $r->filename(&propath($udom,$uname).
66: '/userfiles/'.(join('/',@ufile)));
1.7 raeburn 67: }
1.15 raeburn 68: return OK;
1.26 ! raeburn 69: } elsif ($r->uri =~ m{^\Q/adm/wrapper/ext/https:/\E[^/]}) {
! 70: my $uri = $r->uri;
! 71: $uri =~ s{^(\Q/adm/wrapper/ext/https:/\E)}{$1/};
! 72: $r->uri($uri);
1.15 raeburn 73: }
1.26 ! raeburn 74: return DECLINED;
1.15 raeburn 75: }
76:
77: sub redirect_raw {
78: my ($remote_ip,$lonhost) = @_;
79: my @remhostids = &Apache::lonnet::get_hosts_from_ip($remote_ip);
80: my $redirect;
81: while (@remhostids) {
82: my $try_server = pop(@remhostids);
83: my $remhostname = &Apache::lonnet::hostname($try_server);
84: if ($remhostname) {
85: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$try_server);
86: my ($remmajor,$remminor) = ($remoterev =~ /^(\d+)\.(\d+)/);
87: if (($remmajor > 2) || (($remmajor == 2) && $remminor >= 12)) {
88: my $internet_names = &Apache::lonnet::get_internet_names($try_server);
89: if (ref($internet_names) eq 'ARRAY') {
90: my $intdom = &Apache::lonnet::internet_dom($lonhost);
91: unless (grep(/^\Q$intdom\E$/,@{$internet_names})) {
92: my $lonhostname = &Apache::lonnet::hostname($lonhost);
93: my $serverhomeID = &Apache::lonnet::get_server_homeID($lonhostname);
94: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
95: my %domdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
96: my $replication = $domdefaults{'replication'};
97: if (ref($replication) eq 'HASH') {
98: my $remhomeID = &Apache::lonnet::get_server_homeID($remhostname);
99: my $remhomedom = &Apache::lonnet::host_domain($remhomeID);
100: my $remprimary = &Apache::lonnet::domain($remhomedom,'primary');
101: my $remintdom = &Apache::lonnet::internet_dom($remprimary);
102: if (ref($replication->{'certreq'}) eq 'ARRAY') {
103: if (grep(/^\Q$remintdom\E$/,@{$replication->{'certreq'}})) {
1.24 raeburn 104: $redirect = 0;
105: } else {
1.15 raeburn 106: $redirect = 1;
107: }
108: }
109: if (ref($replication->{'nocertreq'}) eq 'ARRAY') {
110: if (grep(/^\Q$remintdom\E$/,@{$replication->{'nocertreq'}})) {
1.24 raeburn 111: $redirect = 1;
112: } else {
1.15 raeburn 113: $redirect = 0;
114: }
115: }
116: }
117: }
118: }
119: }
120: last;
121: }
122: }
1.24 raeburn 123: return $redirect;
1.1 www 124: }
125:
126: 1;
127: __END__
128:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>