Annotation of loncom/lonenc.pm, revision 1.1

1.1     ! www         1: # The LearningOnline Network
        !             2: # URL translation for encrypted filenames
        !             3: #
        !             4: # $Id: lontrans.pm,v 1.6 2003/11/12 21:37:07 albertel 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::lonenc;
        !            30: 
        !            31: use strict;
        !            32: use Apache::Constants qw(:common :remotehost);
        !            33: use Apache::lonnet();
        !            34: use Apache::File();
        !            35: use Apache::loncommon;
        !            36: use Crypt::IDEA;
        !            37: 
        !            38: sub handler {
        !            39:     my $r = shift;
        !            40:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
        !            41:     my $lonid=$cookies{'lonID'};
        !            42:     my $cookie;
        !            43:     if ($lonid) {
        !            44: 	my $handle=$lonid->value;
        !            45:         $handle=~s/\W//g;
        !            46:         my $lonidsdir=$r->dir_config('lonIDsDir');
        !            47:         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
        !            48: # Initialize Environment
        !            49:             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
        !            50: # Decrypt URL and redirect
        !            51: 	    $r->internal_redirect(&unencrypted($r->uri));
        !            52: 	    return OK;
        !            53: 	} 
        !            54:     }
        !            55:     return FORBIDDEN;
        !            56: }
        !            57: 
        !            58: sub unencrypted {
        !            59:     my $uri=shift;
        !            60:     $uri=~s/^\/enc\/(\d+)\///;
        !            61:     &Apache::lonnet::logthis($uri);
        !            62:     my $cmdlength=$1;
        !            63:     unless ($ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'}) {
        !            64: 	return '/'.$uri;
        !            65:     }
        !            66:     $uri=&Apache::lonnet::unescape($uri);
        !            67:     my $cipher=
        !            68: 	new IDEA $ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'};
        !            69:     &Apache::lonnet::logthis($ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'});
        !            70:     my $decuri='';
        !            71:     for (my $encidx=0;$encidx<length($uri);$encidx+=16) {
        !            72: 	$decuri.=$cipher->decrypt(
        !            73: 				  pack("H16",substr($uri,$encidx,16))
        !            74: 				  );
        !            75:     }
        !            76:     return substr($decuri,0,$cmdlength);
        !            77: }
        !            78: 
        !            79: sub encrypted {
        !            80:     my $uri=shift;
        !            81:     my $cmdlength=length($uri);
        !            82:     my $encuri='';
        !            83:     my $cipher=
        !            84: 	new IDEA $ENV{'course.'.$ENV{'request.course.id'}.'.internal.encseed'};
        !            85:     for (my $encidx=0;$encidx<=$cmdlength;$encidx+=8) {
        !            86: 	$encuri.=unpack("H16",
        !            87: 			$cipher->encrypt(substr($uri,$encidx,8)));
        !            88:     }
        !            89:     return '/enc/'.$cmdlength.'/'.&Apache::lonnet::escape($encuri);
        !            90: }
        !            91: 
        !            92: 1;
        !            93: __END__
        !            94: 
        !            95: 
        !            96: 
        !            97: 
        !            98: 
        !            99: 
        !           100: 

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