diff -cr ../telechargements/eprints-2.3.13.1/bin/configure_archive /opt/eprints2/bin/configure_archive
*** ../telechargements/eprints-2.3.13.1/bin/configure_archive	2005-09-20 17:12:05.000000000 +0200
--- /opt/eprints2/bin/configure_archive	2006-04-12 15:18:58.000000000 +0200
***************
*** 175,181 ****
--- 176,184 ----
  my $REGEXP_VARNAME = '^[a-zA-Z][_A-Za-z0-9]*$';
  my $REGEXP_NUMBER = '^[0-9]+$';
  my $REGEXP_YESNO = '^(yes|no)$';
+ my $REGEXP_TRUEFALSE = '^(true|false)$';
  my $REGEXP_ANY = '^.*$';
+ my $REGEXP_DBDRIVER = '^(Pg|mysql)$';
  
  my %config = ();
  
***************
*** 201,206 ****
--- 204,210 ----
  	$archiveid = EPrints::Utils::get_input( $REGEXP_VARNAME, 'Archive ID' );
  }
  
+ 
  my( $configfile ) = EPrints::Config::get( "base_path" )."/archives/".$archiveid.".xml";
  my( $archivedir ) = EPrints::Config::get( "base_path" )."/archives/".$archiveid;
  
***************
*** 218,224 ****
  	}	
  	foreach( keys %{$loaded_config} ) 
  	{ 
! 		$config{$_} = $loaded_config->{$_}; 
  	}
  }
  else
--- 222,236 ----
  	}	
  	foreach( keys %{$loaded_config} ) 
  	{ 
! 		if($loaded_config->{$_})
! 		{
! 			$config{$_} = $loaded_config->{$_}; 
! 		}
! 		else
! 		{
! 			$config{$_} = undef; 
! 		}
! 			
  	}
  }
  else
***************
*** 239,244 ****
--- 251,272 ----
  	$config{archivename} = {};
  	$config{securehost} = undef;
  	$config{securepath} = undef;
+ 	#added for CAS support
+ 	$config{cashost} = undef;
+ 	$config{caspath} = undef;
+ 	$config{casport} = undef;
+ 	$config{caserrorurl} = undef;
+ 	$config{casdbname} = undef;
+ 	$config{casdbhost} = undef;
+ 	$config{casdbport} = undef;
+ 	$config{casdbsock} = undef;
+ 	$config{casdbdriver} = undef;
+ 	$config{casdbuser} = undef;
+ 	$config{casdbpass} = undef;
+ 	$config{cassessioncookiename} = undef;
+ 	$config{cassessiontimeout} = undef;
+ 	$config{casloglevel} = undef;
+ 	$config{casremoveticket} = undef;
  }
  
  
***************
*** 421,426 ****
--- 449,582 ----
  
  print <<END;
  
+ Eprints can help you to configure a secure host.
+ 
+ END
+ my $previous_answer="no";
+ if(defined $config{securehost}){ #if a securehost is defined, it was configured
+ 	$previous_answer="yes";
+ }
+ my $makesh = EPrints::Utils::get_input( $REGEXP_YESNO, "Configure secure host? ", $previous_answer );
+ if( $makesh eq "yes" )
+ {
+ print <<END;
+ 
+ Please enter the fully qualified secure hostname of the archive. 
+ 
+ Default will use the previous normal hostname provided.
+ 
+ END
+ 
+ if(!$config{securehost}){
+ $config{securehost}=$config{host};
+ }
+ 
+ $config{securehost} = EPrints::Utils::get_input( $REGEXP_HOSTNAME_FULL, 'Secure hostname', $config{securehost} );
+ 
+ print <<END;
+ 
+ If you want to redirect any access to your sercure host to a specific path, type it now.
+ END
+ 
+ $config{securepath} = EPrints::Utils::get_input( $REGEXP_ANY, 'Securised Webserver Path', $config{securepath} );
+ 
+ print <<END;
+ 
+ Eprints can use a CAS server to authenticate users with your secure host.
+ 
+ END
+ 
+ my $previous_answer="no";
+ if(defined $config{cashost}){ #if a cashost is defined, it was configured
+ 	$previous_answer="yes";
+ }
+ 	my $makecas = EPrints::Utils::get_input( $REGEXP_YESNO, "Configure Eprints to enable authenticate through a CAS server", $previous_answer );
+ if( $makecas eq "yes" )
+ {
+ print <<END;
+ 
+ Please enter the fully qualified CAS server hostname of the archive. 
+ 
+ Example: cas-$archiveid.u-strasbg.fr
+ 
+ END
+ 
+ $config{cashost} = EPrints::Utils::get_input( $REGEXP_HOSTNAME_FULL, 'CAS hostname', $config{cashost} );
+ 
+ $config{caspath} = EPrints::Utils::get_input( $REGEXP_ANY, 'CAS server Path', $config{caspath} );
+ 
+ if(!$config{casport}) { $config{casport}="443";}#default port
+ $config{casport} = EPrints::Utils::get_input( $REGEXP_NUMBER, 'CAS server Port', $config{casport} );
+ 
+ $config{caserrurl} = EPrints::Utils::get_input( $REGEXP_ANY, 'URL where a client is redirected to when an error occurs', $config{caserrurl} );
+ 
+ if(!$config{cassessioncookiename}) { $config{cassessioncookiename}="APACHECAS";}
+ $config{cassessioncookiename} = EPrints::Utils::get_input( $REGEXP_VARNAME, 'Name of the cookie that will be used for CAS sessions', $config{cassessioncookiename} );
+ 
+ if(!$config{cassessiontimeout}) { $config{cassessiontimeout}="1800";}
+ $config{cassessiontimeout} = EPrints::Utils::get_input( $REGEXP_NUMBER, 'Max time before a session expires (in seconds)', $config{cassessiontimeout} );
+ 
+ if(!$config{casloglevel}) { $config{casloglevel}="4";}
+ $config{casloglevel} = EPrints::Utils::get_input( '\d', 'Level of logging', $config{casloglevel} );
+ 
+ if(!$config{casremoveticket}) { $config{casremoveticket}="false";}
+ $config{casremoveticket} = EPrints::Utils::get_input( $REGEXP_TRUEFALSE, 'Should we perform a redirect, stripping the service ticket once a session was allready created for the client (true/false)', $config{casremoveticket} );
+ 
+ 
+ print <<END;
+ 
+ The Apache::AuthCAS module use a database to store cookies. 
+ You can use your archive database to store this cookie or use a different database.
+ 
+ 
+ END
+ 
+ my $makecasdb = EPrints::Utils::get_input( $REGEXP_YESNO, "Should Eprints use the archive database to store CAS cookies", "yes" );
+ if( $makecasdb eq "yes" )
+ {
+ 
+ $config{casdbname}=$config{dbname};
+ $config{casdbhost}=$config{dbhost};
+ $config{casdbport}=$config{dbport};
+ $config{casdbsock}=$config{dbsock};
+ $config{casdbdriver}="mysql";
+ $config{casdbuser}=$config{dbuser};
+ $config{casdbpass}=$config{dbpass};
+ 
+ }
+ 
+ else
+ {
+ if(!$config{casdbname}) { $config{casdbname}=$config{dbname};}
+ $config{casdbname} = EPrints::Utils::get_input( $REGEXP_VARNAME, 'CAS database name', $config{casdbname} );
+ 
+ if(!$config{casdbhost}) { $config{casdbhost}=$config{dbhost};}
+ $config{casdbhost} = EPrints::Utils::get_input( $REGEXP_HOSTNAME, 'CAS database host', $config{casdbhost} );
+ 
+ if(!$config{casdbport}) {$config{casdbport}=$config{dbport};}
+ $config{casdbport} =	EPrints::Utils::get_input( $REGEXP_NUMBER, 'CAS database port', $config{casdbport} );
+ 
+ if(!$config{casdbsock}) {$config{casdbsock}=$config{dbsock};}
+ $config{casdbsock} =	EPrints::Utils::get_input( $REGEXP_NUMBER, 'CAS database sock', $config{casdbsock} );
+ 
+ #should work on an postgres support for the whole eprints system
+ #to do that easily, scripts use Eprints tools to access db.
+ #So currently, no choice: you must use mysql! ;P
+ #if(!$config{casdbdriver}) { $config{casdbdriver}="mysql";}
+ #$config{casdbdriver} = EPrints::Utils::get_input( $REGEXP_DBDRIVER, 'CAS database driver (Pg/mysql)', $config{casdbdriver} );
+ $config{casdbdriver}="mysql";
+ 
+ if(!$config{casdbuser}) { $config{casdbuser}=$config{dbuser};}
+ $config{casdbuser} = EPrints::Utils::get_input( $REGEXP_VARNAME, 'CAS database user', $config{casdbuser} );
+ 
+ if(!$config{casdbpass}) { $config{casdbpass}=$config{dbpass};}
+ $config{casdbpass} = EPrints::Utils::get_input( $REGEXP_VARNAME, 'CAS database password', $config{casdbpass} );
+ }
+ 
+ }#makecas
+ }#makesh
+ print <<END;
+ 
  EPrints can create the database, and grant the correct permissions.
  
  END
***************
*** 428,433 ****
--- 584,630 ----
  my $makedb = EPrints::Utils::get_input( $REGEXP_YESNO, "Create database \"$config{dbname}\"", $exists?"no":"yes" );
  if( $makedb eq "yes" )
  {
+ 	create_db(
+ 	$config{dbsock},
+ 	$config{dbport},
+ 	$config{dbhost},
+ 	$config{dbuser},
+ 	$config{dbpass},
+ 	$config{dbname}
+ 	);
+ }
+ if( defined $config{casdbname} and $config{casdbname} ne $config{dbname})
+ {
+ print <<END;
+ 
+ EPrints can create the AuthCAS module database, and grant the correct permissions.
+ 
+ END
+ 
+ my $makecasdb = EPrints::Utils::get_input( $REGEXP_YESNO, "Create database \"$config{casdbname}\"", $exists?"no":"yes" );
+ if( $makecasdb eq "yes" )
+ {
+ 	#create the db for AuthCAS cookie
+ 	create_db(
+ 	$config{casdbsock},
+ 	$config{casdbport},
+ 	$config{casdbhost},
+ 	$config{casdbuser},
+ 	$config{casdbpass},
+ 	$config{casdbname}
+ 	);
+ }
+ }
+ sub create_db
+ {
+ 	(
+ 	my $DBSOCK,
+ 	my $DBPORT,
+ 	my $DBHOST,
+ 	my $DBUSER,
+ 	my $DBPASS,
+ 	my $DBNAME
+ 	)=@_;
  	#cjg hide password from display?
  	print <<END;
  
***************
*** 441,449 ****
  	my $dbh = DBI->connect(
  		EPrints::Database::build_connection_string(
  			dbname=>"mysql",
! 			dbsock=>$config{dbsock},
! 			dbport=>$config{dbport},
! 			dbhost=>$config{dbhost} ),
  		"root",
  		$mysqlrootpass );
  
--- 638,646 ----
  	my $dbh = DBI->connect(
  		EPrints::Database::build_connection_string(
  			dbname=>"mysql",
! 			dbsock=>$DBSOCK,
! 			dbport=>$DBPORT,
! 			dbhost=>$DBHOST ),
  		"root",
  		$mysqlrootpass );
  
***************
*** 474,507 ****
  		my @row;
  		while( @row = $sth->fetchrow_array )
  		{
! 			$dbexists = 1 if $row[0] eq $config{dbname};
  		}
  		if( $dbexists )
  		{
! 			print "Hmm. A database called $config{dbname} already exists, oh well.\n\n";
  		}
  		else
  		{
! 			my $SQL = "CREATE DATABASE ".$config{dbname};
  			print "DOING: $SQL\n";
  			$dbh->do( $SQL );
  		}
  		print "Setting MySQL privs\n";
  		#cjg @localhost ??? what about remote mysql's?
  
! 		#my $SQL = 'GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE, ALTER ON '.$config{dbname}.'.* TO '.$config{dbuser}.'@localhost IDENTIFIED BY "'.$config{dbpass}.'"';
  		my $SQL;
! 		$SQL = 'GRANT ALL ON '.$config{dbname}.'.* TO '.$config{dbuser}.'@localhost';
  		print "DOING: $SQL\n";
  		$dbh->do( $SQL );
! 		my $pass = '"'.$config{dbpass}.'"';
  		if( $oldpasswords ) 
  		{
  			$pass = "OLD_PASSWORD($pass)";
  		} else {
  			$pass = "PASSWORD($pass)";
  		}
! 		$SQL = 'SET PASSWORD FOR '.$config{dbuser}.'@localhost = '.$pass;
  		print "DOING: $SQL\n";
  		$dbh->do( $SQL );
  
--- 671,704 ----
  		my @row;
  		while( @row = $sth->fetchrow_array )
  		{
! 			$dbexists = 1 if $row[0] eq $DBNAME;
  		}
  		if( $dbexists )
  		{
! 			print "Hmm. A database called $DBNAME already exists, oh well.\n\n";
  		}
  		else
  		{
! 			my $SQL = "CREATE DATABASE ".$DBNAME;
  			print "DOING: $SQL\n";
  			$dbh->do( $SQL );
  		}
  		print "Setting MySQL privs\n";
  		#cjg @localhost ??? what about remote mysql's?
  
! 		#my $SQL = 'GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE, ALTER ON '.$DBNAME.'.* TO '.$DBUSER.'@localhost IDENTIFIED BY "'.$DBPASS.'"';
  		my $SQL;
! 		$SQL = 'GRANT ALL ON '.$DBNAME.'.* TO '.$DBUSER.'@localhost';
  		print "DOING: $SQL\n";
  		$dbh->do( $SQL );
! 		my $pass = '"'.$DBPASS.'"';
  		if( $oldpasswords ) 
  		{
  			$pass = "OLD_PASSWORD($pass)";
  		} else {
  			$pass = "PASSWORD($pass)";
  		}
! 		$SQL = 'SET PASSWORD FOR '.$DBUSER.'@localhost = '.$pass;
  		print "DOING: $SQL\n";
  		$dbh->do( $SQL );
  
***************
*** 538,545 ****
  	$t_archive->appendChild( info_tag( $doc, "language", $_) );
  }
  foreach( "port", "urlpath", "archiveroot", "configmodule",
! 	 "dbname","dbhost","dbport","dbsock","dbuser","dbpass", 
! 	"defaultlanguage", "adminemail", "securehost", "securepath" )
  {
  	$config{$_}='' if( !defined $config{$_} );
  	$t_archive->appendChild( info_tag( $doc, $_, $config{$_} ) );
--- 735,746 ----
  	$t_archive->appendChild( info_tag( $doc, "language", $_) );
  }
  foreach( "port", "urlpath", "archiveroot", "configmodule",
! 	 "dbname","dbhost","dbport","dbsock","dbuser","dbpass",
! 	 "defaultlanguage", "adminemail", "securehost", "securepath",
! 	 "cashost", "caspath","casport","caserrorurl","casdbname",
! 	 "casdbhost","casdbport","casdbdriver","casdbuser","casdbpass",
! 	 "cassessioncookiename","cassessiontimeout","casloglevel",
! 	 "casremoveticket")
  {
  	$config{$_}='' if( !defined $config{$_} );
  	$t_archive->appendChild( info_tag( $doc, $_, $config{$_} ) );
***************
*** 669,675 ****
  	foreach(@files)
  	{
  		open(INFILE, "$dir/$_");
! 		open(OUTFILE, ">$dest/$_") or die "Can't write to $dest/$_";
  		while(my $line=<INFILE>)
  		{
  			if( $_ eq "ArchiveConfig.pm" && $line=~m/^package/ )
--- 870,876 ----
  	foreach(@files)
  	{
  		open(INFILE, "$dir/$_");
! 		open(OUTFILE, ">$dest/$_" ) or die "Can't write to $dest/$_";
  		while(my $line=<INFILE>)
  		{
  			if( $_ eq "ArchiveConfig.pm" && $line=~m/^package/ )
diff -cr ../telechargements/eprints-2.3.13.1/bin/generate_apacheconf /opt/eprints2/bin/generate_apacheconf
*** ../telechargements/eprints-2.3.13.1/bin/generate_apacheconf	2005-09-20 17:12:05.000000000 +0200
--- /opt/eprints2/bin/generate_apacheconf	2006-04-11 13:14:14.000000000 +0200
***************
*** 211,217 ****
  	if( $file =~ m/^auto-.*\.conf$/ )
  	{
  		my $fn = EPrints::Config::get( "sys_path" ).'/'.$file;
! 		unlink( $fn );
  	}
  }
  
--- 211,217 ----
  	if( $file =~ m/^auto-.*\.conf$/ )
  	{
  		my $fn = EPrints::Config::get( "sys_path" ).'/'.$file;
! 		#unlink( $fn );
  	}
  }
  
***************
*** 409,415 ****
  my $urlpath = $archive->get_conf( "urlpath" );
  my $userhome = $archive->get_conf( "userhome" );
  my $securehost = $archive->get_conf( "securehost" );
! my $securepath = '';
  if( EPrints::Utils::is_set( $securehost ) )
  {
  	$securepath = $archive->get_conf( "securepath" );
--- 409,429 ----
  my $urlpath = $archive->get_conf( "urlpath" );
  my $userhome = $archive->get_conf( "userhome" );
  my $securehost = $archive->get_conf( "securehost" );
! my $securepath = $archive->get_conf( "securepath" );
! my $cashost = $archive->get_conf( "cashost" );
! my $caspath = $archive->get_conf( "caspath" );
! my $casport = $archive->get_conf( "casport" );
! my $caserrorurl = $archive->get_conf( "caserrorurl" );
! my $casdbname = $archive->get_conf( "casdbname" );
! my $casdbhost = $archive->get_conf( "casdbhost" );
! my $casdbport = $archive->get_conf( "casdbport" );
! my $casdbdriver = $archive->get_conf( "casdbdriver" );
! my $casdbuser = $archive->get_conf( "casdbuser" );
! my $casdbpass = $archive->get_conf( "casdbpass" );
! my $cassessioncookiename = $archive->get_conf( "cassessioncookiename" );
! my $cassessiontimeout = $archive->get_conf( "cassessiontimeout" );
! my $casloglevel = $archive->get_conf( "casloglevel" );
! my $casremoveticket = $archive->get_conf( "casremoveticket" );
  if( EPrints::Utils::is_set( $securehost ) )
  {
  	$securepath = $archive->get_conf( "securepath" );
***************
*** 556,563 ****
    </Directory>
  
  END
  
! my $secureconfig = <<END;
    <Directory "$cgidir/users">
      AuthName "User Area"
      AuthType "Basic"
--- 570,620 ----
    </Directory>
  
  END
+ my $secureconfig = "";
+ if (defined $cashost)
+ {
+ 	my $casdbportline="";#if no port specified, use default AuthCAS setting
+ 	my $caserrorurlline="";#if no error url specified...
+ 	if($casdbport){
+ 		$casdbportline="\n    PerlSetVar CASDatabasePort \"$casdbport\"";
+ 	}
+ 	if($caserrorurl){
+ 		$caserrorurlline="\n    PerlSetVar CASErrorURL \"$caserrorurl\"";
+ 	}
+ $secureconfig = <<END;
+   <Directory "$cgidir/users">
+     AuthName "User Area"
+     #CAS configuration
+     AuthType Apache::AuthCAS
+     AuthName "CAS"
+     PerlAuthenHandler Apache::AuthCAS->authenticate
+     PerlSetVar CASHost "$cashost" 
+     PerlSetVar CASPort $casport$caserrorurlline
+     PerlSetVar CASDatabaseName "$casdbname"
+     PerlSetVar CASDatabaseHost "$casdbhost"$casdbportline
+     PerlSetVar CASDatabaseDriver "$casdbdriver"
+     PerlSetVar CASDatabaseUser "$casdbuser"
+     PerlSetVar CASDatabasePass "$casdbpass"
+     PerlSetVar CASSessionCookieName "$cassessioncookiename"
+     PerlSetVar CASSessionTimeout "$cassessiontimeout"
+     PerlSetVar CASLogLevel "$casloglevel"
+     PerlSetVar CASRemoveTicket "$casremoveticket"
+ 
+     PerlAuthzHandler EPrints::Auth::authz
+     PerlSetVar EPrints_Security_Area User
+     require valid-user
+ 
+     SetHandler perl-script
+     PerlHandler $registry_module
+     PerlSendHeader Off
+     Options ExecCGI FollowSymLinks
+   </Directory>
  
! END
! }
! else
! {
! $secureconfig = <<END;
    <Directory "$cgidir/users">
      AuthName "User Area"
      AuthType "Basic"
***************
*** 571,576 ****
--- 628,637 ----
      PerlSendHeader Off
      Options ExecCGI FollowSymLinks
    </Directory>
+ 
+ END
+ }
+ $secureconfig .= <<END;
    <Directory "$cgidir/users/awstats">
      PerlSendHeader On
    </Directory>
diff -cr ../telechargements/eprints-2.3.13.1/perl_lib/EPrints/Config.pm /opt/eprints2/perl_lib/EPrints/Config.pm
*** ../telechargements/eprints-2.3.13.1/perl_lib/EPrints/Config.pm	2005-09-20 17:12:05.000000000 +0200
--- /opt/eprints2/perl_lib/EPrints/Config.pm	2006-04-12 14:28:39.000000000 +0200
***************
*** 277,283 ****
  			"host", "urlpath", "configmodule", "port", 
  			"archiveroot", "dbname", "dbhost", "dbport",
  			"dbsock", "dbuser", "dbpass", "defaultlanguage",
! 			"adminemail", "securehost", "securepath", "index" )
  	{
  		my $tag = ($conf_tag->getElementsByTagName( $tagname ))[0];
  		if( !defined $tag )
--- 277,288 ----
  			"host", "urlpath", "configmodule", "port", 
  			"archiveroot", "dbname", "dbhost", "dbport",
  			"dbsock", "dbuser", "dbpass", "defaultlanguage",
! 			"adminemail", "securehost", "securepath", "index",
! 			"cashost", "caspath","casport","caserrorurl",
! 			"casdbname", "casdbhost","casdbport", "casdbdriver",
! 			"casdbuser","casdbpass", "cassessioncookiename",
! 			"cassessiontimeout","casloglevel", "casremoveticket",
! 		 	"casdbsock")
  	{
  		my $tag = ($conf_tag->getElementsByTagName( $tagname ))[0];
  		if( !defined $tag )
diff -cr ../telechargements/eprints-2.3.13.1/perl_lib/EPrints/Session.pm /opt/eprints2/perl_lib/EPrints/Session.pm
*** ../telechargements/eprints-2.3.13.1/perl_lib/EPrints/Session.pm	2005-09-20 17:12:05.000000000 +0200
--- /opt/eprints2/perl_lib/EPrints/Session.pm	2006-04-12 16:05:09.000000000 +0200
***************
*** 100,105 ****
--- 100,106 ----
  
  use URI::Escape;
  use CGI;
+ use CGI qw(:standard -nph);	#raw_cookie
  
  use strict;
  #require 'sys/syscall.ph';
***************
*** 131,144 ****
  	my( $class, $mode, $param, $noise, $nocheckdb ) = @_;
  	# mode = 0    - We are online (CGI script)
  	# mode = 1    - We are offline (bin script) param is archiveid
! 	# mode = 2    - We are online (auth) param is host and path.	
  	my $self = {};
  	bless $self, $class;
- 
  	$mode = 0 unless defined( $mode );
  	$noise = 0 unless defined( $noise );
  	$self->{noise} = $noise;
! 
  	if( $mode == 0 || !defined $mode )
  	{
  		$self->{request} = EPrints::AnApache::get_request();
--- 132,145 ----
  	my( $class, $mode, $param, $noise, $nocheckdb ) = @_;
  	# mode = 0    - We are online (CGI script)
  	# mode = 1    - We are offline (bin script) param is archiveid
! 	# mode = 2    - We are online (auth with CAS)  
  	my $self = {};
  	bless $self, $class;
  	$mode = 0 unless defined( $mode );
  	$noise = 0 unless defined( $noise );
  	$self->{noise} = $noise;
! 	my $user_ticket=raw_cookie('APACHECAS');
! 	
  	if( $mode == 0 || !defined $mode )
  	{
  		$self->{request} = EPrints::AnApache::get_request();
***************
*** 161,166 ****
--- 162,169 ----
  			return undef;
  		}
  	}
+ 
+ 
  	else
  	{
  		print STDERR "Unknown session mode: $mode\n";
***************
*** 171,177 ****
  
  	if( $self->{noise} >= 2 ) { print "\nStarting EPrints Session.\n"; }
  
! 	if( $self->{offline} )
  	{
  		# Set a script to use the default language unless it 
  		# overrides it
--- 174,180 ----
  
  	if( $self->{noise} >= 2 ) { print "\nStarting EPrints Session.\n"; }
  
! 	if( $self->{offline} or $mode==2)
  	{
  		# Set a script to use the default language unless it 
  		# overrides it
***************
*** 2062,2074 ****
  	# in doing it again.
  	unless( defined $self->{currentuser} )
  	{	
! 		my $username = $ENV{'REMOTE_USER'};
  
! 		if( defined $username && $username ne "" )
  		{
  			$self->{currentuser} = 
! 				EPrints::User::user_with_username( $self, $username );
  		}
  	}
  
  	return $self->{currentuser};
--- 2065,2103 ----
  	# in doing it again.
  	unless( defined $self->{currentuser} )
  	{	
! 		my $username ="";
! 		my $user_ticket="";
! 		if( defined $ENV{HTTP_CAS_FILTER_USER})#just connected with cas, no cookie set 
! 		{
! 			$username = $ENV{HTTP_CAS_FILTER_USER};
! 		}
! 		elsif ( defined $self->{archive}->get_conf("cassessioncookiename") )#cas auth seems configured...
! 		{
! 			$user_ticket=raw_cookie($self->{archive}->get_conf("cassessioncookiename"));
! 			if( $user_ticket ne "" )#Indeed we've get a cookie :)
! 			{
! 				my $sql = "SELECT uid FROM cas_sessions where id='$user_ticket'";
! 				my $sth = $self->{database}->prepare( $sql );
! 				$self->{database}->execute( $sth, $sql );
! 
! 				while( my @info = $sth->fetchrow_array ) {
! 					my @list = split(":",$info[0]);
! 					foreach( @list ) {$username=$_;}
! 				}
! 				$sth->finish;
! 			}
! 		}
! 		else#using default eprints authentication
! 		{
! 			$username = $ENV{'REMOTE_USER'};
! 		}	
  
! 		if( $username ne "" )
  		{
  			$self->{currentuser} = 
! 			EPrints::User::user_with_username( $self, $username );
  		}
+ 		
  	}
  
  	return $self->{currentuser};
