[LON-CAPA-cvs] cvs: loncom / lonencurl.pm /auth checkauthen.pm lonacc.pm loncacc.pm lonlogin.pm lonlogout.pm publiccheck.pm /interface coursecatalog.pm loncss.pm /lonnet/perl lonrep.pm lonuploadrep.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 02 Oct 2007 01:10:28 -0000


This is a MIME encoded message

--albertel1191287428
Content-Type: text/plain

albertel		Mon Oct  1 21:10:28 2007 EDT

  Modified files:              
    /loncom/lonnet/perl	lonrep.pm lonuploadrep.pm 
    /loncom/auth	lonlogin.pm checkauthen.pm lonlogout.pm publiccheck.pm 
                	loncacc.pm lonacc.pm 
    /loncom	lonencurl.pm 
    /loncom/interface	loncss.pm coursecatalog.pm 
  Log:
  - convert exisiting cookie reads/validations to use 
     lonnet::check_for_valid_session
  
  
--albertel1191287428
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20071001211028.txt"

Index: loncom/lonnet/perl/lonrep.pm
diff -u loncom/lonnet/perl/lonrep.pm:1.13 loncom/lonnet/perl/lonrep.pm:1.14
--- loncom/lonnet/perl/lonrep.pm:1.13	Wed Apr 25 21:18:47 2007
+++ loncom/lonnet/perl/lonrep.pm	Mon Oct  1 21:09:53 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Replication Manager
 #
-# $Id: lonrep.pm,v 1.13 2007/04/26 01:18:47 albertel Exp $
+# $Id: lonrep.pm,v 1.14 2007/10/02 01:09:53 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,7 +32,6 @@
 use Apache::Constants qw(:common :http);
 use Apache::lonnet;
 use Apache::File();
-use CGI::Cookie();
 
 sub update_filename {
     my ($r,$filename) = @_;
@@ -84,10 +83,9 @@
 	      }
               return OK;
           }
-          my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-          my $lonid=$cookies{'lonID'};
-          if ($lonid) {
-	     $r->log_reason('Replication failed for '.$lonid->value);
+          my $handle = &Apache::lonnet::check_for_valid_session($r);
+          if ($handle) {
+	     $r->log_reason('Replication failed for '.$handle);
              return $response;
 	  } else {
 	     $r->log_reason('Replication failed for unknown user'); 
Index: loncom/lonnet/perl/lonuploadrep.pm
diff -u loncom/lonnet/perl/lonuploadrep.pm:1.9 loncom/lonnet/perl/lonuploadrep.pm:1.10
--- loncom/lonnet/perl/lonuploadrep.pm:1.9	Wed Dec 20 17:41:07 2006
+++ loncom/lonnet/perl/lonuploadrep.pm	Mon Oct  1 21:09:53 2007
@@ -30,7 +30,6 @@
 use Apache::Constants qw(:common :http);
 use Apache::lonrep();
 use Apache::lonnet;
-use CGI::Cookie();
 use LONCAPA();
 
 sub handler {
@@ -59,10 +58,9 @@
             return OK;
         }
     }
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonid=$cookies{'lonID'};
-    if ($lonid) {
-        $r->log_reason('Copying failed in lonuploadrep for '.$lonid->value);
+    my $handle = &Apache::lonnet::check_for_valid_session($r);
+    if ($handle) {
+        $r->log_reason('Copying failed in lonuploadrep for '.$handle);
         return HTTP_NOT_FOUND;
     } else {
         $r->log_reason('Copying failed in lonuploadrep for unknown user'); 
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.95 loncom/auth/lonlogin.pm:1.96
--- loncom/auth/lonlogin.pm:1.95	Mon Oct  1 17:52:50 2007
+++ loncom/auth/lonlogin.pm	Mon Oct  1 21:09:59 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Login Screen
 #
-# $Id: lonlogin.pm,v 1.95 2007/10/01 21:52:50 albertel Exp $
+# $Id: lonlogin.pm,v 1.96 2007/10/02 01:09:59 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,7 +30,6 @@
 
 use strict;
 use Apache::Constants qw(:common);
-use CGI::Cookie();
 use Apache::File ();
 use Apache::lonnet;
 use Apache::loncommon();
Index: loncom/auth/checkauthen.pm
diff -u loncom/auth/checkauthen.pm:1.11 loncom/auth/checkauthen.pm:1.12
--- loncom/auth/checkauthen.pm:1.11	Wed Apr 11 17:36:58 2007
+++ loncom/auth/checkauthen.pm	Mon Oct  1 21:09:59 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # checks for a cokkie to authenticate a user
 #
-# $Id: checkauthen.pm,v 1.11 2007/04/11 21:36:58 raeburn Exp $
+# $Id: checkauthen.pm,v 1.12 2007/10/02 01:09:59 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,17 +61,12 @@
 	}
     }
 
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonid=$cookies{'lonID'};
-    my $handle;
-    if ($lonid) {
-      	$handle=&LONCAPA::clean_handle($lonid->value);
-        $handle = $r->dir_config('lonIDsDir')."/$handle.id";
-    } else {
+    my $handle = &Apache::lonnet::check_for_valid_session($r);
+    if ($handle eq '') {
         $handle = $env{'user.environment'};
     }
 
-    if (($handle ne '') && (-e $handle)) {
+    if ($handle ne '') {
         return OK;
     }
 
Index: loncom/auth/lonlogout.pm
diff -u loncom/auth/lonlogout.pm:1.28 loncom/auth/lonlogout.pm:1.29
--- loncom/auth/lonlogout.pm:1.28	Mon Oct  1 16:36:37 2007
+++ loncom/auth/lonlogout.pm	Mon Oct  1 21:09:59 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Logout Handler
 #
-# $Id: lonlogout.pm,v 1.28 2007/10/01 20:36:37 albertel Exp $
+# $Id: lonlogout.pm,v 1.29 2007/10/02 01:09:59 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -41,23 +41,16 @@
 
     #Check for cookie
     my $requrl=$r->uri;
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonid=$cookies{'lonID'};
-    my $cookie;
-    if (!$lonid) {
-	return FORBIDDEN;
-    }
-
+    my $handle = &Apache::lonnet::check_for_valid_session($r);
     #check if cookie still valid
-    my $handle=&LONCAPA::clean_handle($lonid->value);
-    my $lonidsdir=$r->dir_config('lonIDsDir');
-    if ((!-e "$lonidsdir/$handle.id") || ($handle eq '')) {
+    if ($handle eq '') {
 	$r->log_reason("Cookie $handle not valid", $r->filename); 
 	return FORBIDDEN;
     }
 
     #we've got a valid user
     my @profile;
+    my $lonidsdir=$r->dir_config('lonIDsDir');
     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
     unlink("$lonidsdir/$handle.id");
     my %temp=('logout' => time);
Index: loncom/auth/publiccheck.pm
diff -u loncom/auth/publiccheck.pm:1.14 loncom/auth/publiccheck.pm:1.15
--- loncom/auth/publiccheck.pm:1.14	Wed Apr 11 17:36:58 2007
+++ loncom/auth/publiccheck.pm	Mon Oct  1 21:09:59 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: publiccheck.pm,v 1.14 2007/04/11 21:36:58 raeburn Exp $
+# $Id: publiccheck.pm,v 1.15 2007/10/02 01:09:59 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -34,7 +34,6 @@
 use Apache::lonnet;
 use Apache::loncommon();
 use Apache::lonlocal;
-use CGI::Cookie();
 use Fcntl qw(:flock);
 use Apache::lonacc();
 use LONCAPA();
@@ -46,17 +45,14 @@
     if (&Apache::lonnet::is_domainimage($requrl)) {
         return OK;
     }
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonid=$cookies{'lonID'};
-    if ($lonid) {
-	my $handle=&LONCAPA::clean_handle($lonid->value);
+
+    my $handle = &Apache::lonnet::check_for_valid_session($r);
+    if ($handle ne '') {
         my $lonidsdir=$r->dir_config('lonIDsDir');
-        if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
-	    &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
-	    if ($env{'user.name'} ne 'public'
-		&& $env{'user.domain'} ne 'public') {
-		return OK;
-	    }
+	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
+	if ($env{'user.name'} ne 'public'
+	    && $env{'user.domain'} ne 'public') {
+	    return OK;
 	}
     }
     if ($requrl=~m|^/public/|
Index: loncom/auth/loncacc.pm
diff -u loncom/auth/loncacc.pm:1.45 loncom/auth/loncacc.pm:1.46
--- loncom/auth/loncacc.pm:1.45	Thu Feb  1 02:13:59 2007
+++ loncom/auth/loncacc.pm	Mon Oct  1 21:09:59 2007
@@ -2,7 +2,7 @@
 # Cookie Based Access Handler for Construction Area
 # (lonacc: 5/21/99,5/22,5/29,5/31 Gerd Kortemeyer)
 #
-# $Id: loncacc.pm,v 1.45 2007/02/01 07:13:59 albertel Exp $
+# $Id: loncacc.pm,v 1.46 2007/10/02 01:09:59 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,7 +31,6 @@
 
 use strict;
 use Apache::Constants qw(:common :http :methods REDIRECT);
-use CGI::Cookie();
 use Fcntl qw(:flock);
 use Apache::lonlocal;
 use Apache::lonnet;
@@ -66,40 +65,35 @@
     my $r = shift;
     my $requrl=$r->uri;
     $env{'request.editurl'}=$requrl;
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonid=$cookies{'lonID'};
-    my $cookie;
-    if ($lonid) {
-      	my $handle=&LONCAPA::clean_handle($lonid->value);
-        my $lonidsdir=$r->dir_config('lonIDsDir');
-        if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
 
-# ------------------------------------------------------ Initialize Environment
+    my $handle =  &Apache::lonnet::check_for_valid_session($r);
+    if ($handle ne '') {
 
-            &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
+# ------------------------------------------------------ Initialize Environment
+        my $lonidsdir=$r->dir_config('lonIDsDir');
+	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
 
 # --------------------------------------------------------- Initialize Language
  
- 	    &Apache::lonlocal::get_language_handle($r);
+	&Apache::lonlocal::get_language_handle($r);
 
 # -------------------------------------------------------------- Resource State
 
-            $env{'request.state'}    = "construct";
-            $env{'request.filename'} = $r->filename;
+	$env{'request.state'}    = "construct";
+	$env{'request.filename'} = $r->filename;
 
-            unless (&constructaccess($requrl,$r->dir_config('lonDefDomain'))) {
-                $r->log_reason("Unauthorized $requrl", $r->filename); 
-	        return HTTP_NOT_ACCEPTABLE;
-            }
+	unless (&constructaccess($requrl,$r->dir_config('lonDefDomain'))) {
+	    $r->log_reason("Unauthorized $requrl", $r->filename); 
+	    return HTTP_NOT_ACCEPTABLE;
+	}
 
 # -------------------------------------------------------- Load POST parameters
 
-	    &Apache::lonacc::get_posted_cgi($r);
+	&Apache::lonacc::get_posted_cgi($r);
 
-            return OK; 
-        } else { 
-            $r->log_reason("Cookie $handle not valid", $r->filename) 
-        };
+	return OK; 
+    } else { 
+	$r->log_reason("Cookie $handle not valid", $r->filename) 
     }
 
 # ----------------------------------------------- Store where they wanted to go
Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.110 loncom/auth/lonacc.pm:1.111
--- loncom/auth/lonacc.pm:1.110	Fri Apr 27 18:03:02 2007
+++ loncom/auth/lonacc.pm	Mon Oct  1 21:09:59 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.110 2007/04/27 22:03:02 banghart Exp $
+# $Id: lonacc.pm,v 1.111 2007/10/02 01:09:59 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -37,7 +37,6 @@
 use Apache::lonlocal;
 use Apache::restrictedaccess();
 use Apache::blockedaccess(); 
-use CGI::Cookie();
 use Fcntl qw(:flock);
 use LONCAPA;
 
@@ -145,12 +144,12 @@
 # returns OK if it was a SSO and user was handled
 #         undef if not SSO or no means to hanle the user
 sub sso_login {
-    my ($r,$lonid,$handle) = @_;
+    my ($r,$handle) = @_;
 
     my $lonidsdir=$r->dir_config('lonIDsDir');
     if (!($r->user 
 	  && (!defined($env{'user.name'}) && !defined($env{'user.domain'}))
-	  && (!$lonid || !-e "$lonidsdir/$handle.id" || $handle eq ''))) {
+	  && ($handle eq ''))) {
 	# not an SSO case or already logged in
 	return undef;
     }
@@ -210,17 +209,11 @@
     if (&Apache::lonnet::is_domainimage($requrl)) {
         return OK;
     }
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonid=$cookies{'lonID'};
-    my $cookie;
-    my $lonidsdir=$r->dir_config('lonIDsDir');
 
-    my $handle;
-    if ($lonid) {
-	$handle=&LONCAPA::clean_handle($lonid->value);
-    }
+    
+    my $handle = &Apache::lonnet::check_for_valid_session($r);
 
-    my $result = &sso_login($r,$lonid,$handle);
+    my $result = &sso_login($r,$handle);
     if (defined($result)) {
 	return $result
     }
@@ -233,10 +226,10 @@
     
     if ($handle eq '') {
 	$r->log_reason("Cookie $handle not valid", $r->filename); 
-    } elsif ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
+    } elsif ($handle ne '') {
 
 # ------------------------------------------------------ Initialize Environment
-
+	my $lonidsdir=$r->dir_config('lonIDsDir');
 	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
 
 # --------------------------------------------------------- Initialize Language
Index: loncom/lonencurl.pm
diff -u loncom/lonencurl.pm:1.3 loncom/lonencurl.pm:1.4
--- loncom/lonencurl.pm:1.3	Mon Dec  4 21:55:56 2006
+++ loncom/lonencurl.pm	Mon Oct  1 21:10:16 2007
@@ -1,7 +1,8 @@
+
 # The LearningOnline Network
 # URL translation for encrypted filenames
 #
-# $Id: lonencurl.pm,v 1.3 2006/12/05 02:55:56 albertel Exp $
+# $Id: lonencurl.pm,v 1.4 2007/10/02 01:10:16 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,28 +31,24 @@
 
 use strict;
 use Apache::Constants qw(:common :remotehost);
-use CGI::Cookie();
 use Apache::lonnet;
 use Apache::lonenc;
 
 sub handler {
     my $r = shift;
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonid=$cookies{'lonID'};
-    my $cookie;
-    if ($lonid) {
-	my $handle=&LONCAPA::clean_handle($lonid->value);
-        my $lonidsdir=$r->dir_config('lonIDsDir');
-	$env{'request.enc'}=1;
-        if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
+
+    $env{'request.enc'}=1;
+
+    my $handle = &Apache::lonnet::check_for_valid_session($r);
+    if ($handle ne '') {
 # Initialize Environment
-            &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
+	my $lonidsdir=$r->dir_config('lonIDsDir');
+	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
 # Decrypt URL and redirect
-	    my $redirect=&Apache::lonenc::unencrypted($r->uri);
-	    if ($r->args) { $redirect.='?'.$r->args; }
-	    $r->internal_redirect($redirect);
-	    return OK;
-	} 
+	my $redirect=&Apache::lonenc::unencrypted($r->uri);
+	if ($r->args) { $redirect.='?'.$r->args; }
+	$r->internal_redirect($redirect);
+	return OK;
     }
     return FORBIDDEN;
 }
Index: loncom/interface/loncss.pm
diff -u loncom/interface/loncss.pm:1.6 loncom/interface/loncss.pm:1.7
--- loncom/interface/loncss.pm:1.6	Mon Nov 27 11:47:16 2006
+++ loncom/interface/loncss.pm	Mon Oct  1 21:10:27 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # gerenates a lon-capa CSS response
 #
-# $Id: loncss.pm,v 1.6 2006/11/27 16:47:16 albertel Exp $
+# $Id: loncss.pm,v 1.7 2007/10/02 01:10:27 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -32,7 +32,6 @@
 use Apache::loncommon;
 use Apache::Constants qw(:common);
 use POSIX qw(strftime);
-use CGI::Cookie();
 use LONCAPA;
 
 sub handler {
@@ -49,16 +48,9 @@
     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time+86400));
     $r->header_out("Expires" => $date);
 
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonidsdir=$r->dir_config('lonIDsDir');
-
-    my $handle;
-    if ($cookies{'lonID'}) {
-	$handle=&LONCAPA::clean_handle($cookies{'lonID'}->value);
-    }
-
-    if ($handle ne '' 
-	&& -e $r->dir_config('lonIDsDir')."/$handle.id") {
+    
+    my $handle = &Apache::lonnet::check_for_valid_session($r);
+    if ($handle ne '' ) {
 	&Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
 						 $handle);
     }
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.20 loncom/interface/coursecatalog.pm:1.21
--- loncom/interface/coursecatalog.pm:1.20	Wed Mar  7 20:58:44 2007
+++ loncom/interface/coursecatalog.pm	Mon Oct  1 21:10:27 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.20 2007/03/08 01:58:44 albertel Exp $
+# $Id: coursecatalog.pm,v 1.21 2007/10/02 01:10:27 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -46,14 +46,9 @@
     if ($r->header_only) {
         return OK;
     }
-    my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
-    my $lonid=$cookies{'lonID'};
+    my $handle = &Apache::lonnet::check_for_valid_session($r);
     my $lonidsdir=$r->dir_config('lonIDsDir');
-    my $handle;
-    if ($lonid) {
-	$handle=&LONCAPA::clean_handle($lonid->value);
-    }
-    if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
+    if ($handle ne '') {
         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
     }
     &Apache::lonacc::get_posted_cgi($r);

--albertel1191287428--