version 1.40, 2018/04/14 02:30:11
|
version 1.43, 2018/11/28 05:05:30
|
Line 32 use strict;
|
Line 32 use strict;
|
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common); |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::lonmenu; |
use Apache::lonmenu; |
|
use Digest::MD5 qw(md5_hex); |
use CGI::Cookie(); |
use CGI::Cookie(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use LONCAPA qw(:DEFAULT :match); |
use LONCAPA qw(:DEFAULT :match); |
Line 49 sub init_env {
|
Line 50 sub init_env {
|
} |
} |
my $lonidsdir=$r->dir_config('lonIDsDir'); |
my $lonidsdir=$r->dir_config('lonIDsDir'); |
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); |
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); |
|
|
return $r->dir_config('lonIDsDir')."/$handle.id"; |
return $r->dir_config('lonIDsDir')."/$handle.id"; |
} |
} |
|
|
Line 101 sub handler {
|
Line 102 sub handler {
|
if ($Apache::lonnet::protocol{$env{'form.otherserver'}} eq 'https') { |
if ($Apache::lonnet::protocol{$env{'form.otherserver'}} eq 'https') { |
$protocol = $Apache::lonnet::protocol{$env{'form.otherserver'}}; |
$protocol = $Apache::lonnet::protocol{$env{'form.otherserver'}}; |
} |
} |
} |
} |
|
|
if ($env{'user.name'} eq 'public' |
if ($env{'user.name'} eq 'public' |
&& $env{'user.domain'} eq 'public') { |
&& $env{'user.domain'} eq 'public') { |
Line 166 sub handler {
|
Line 167 sub handler {
|
} |
} |
|
|
#remove session env, and log event |
#remove session env, and log event |
unlink($handle); |
if (unlink($handle)) { |
if ($env{'user.linkedenv'} ne '') { |
if ($env{'user.linkedenv'} ne '') { |
my $lonidsdir=$r->dir_config('lonIDsDir'); |
my $lonidsdir=$r->dir_config('lonIDsDir'); |
if ((-l $env{'user.linkedenv'}) && |
if (($env{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) && |
(readlink($env{'user.linkedenv'}) eq "$lonidsdir/$handle.id")) { |
(-l "$lonidsdir/$env{'user.linkedenv'}.id") && |
unlink($env{'user.linkedenv'}); |
(readlink("$lonidsdir/$env{'user.linkedenv'}.id") eq $handle)) { |
|
unlink("$lonidsdir/$env{'user.linkedenv'}.id"); |
|
} |
} |
} |
} |
} |
my %temp=('switchserver' => time.':'.$env{'form.otherserver'}, |
my $now = time; |
|
my %temp=('switchserver' => $now.':'.$env{'form.otherserver'}, |
$env{'form.role'}); |
$env{'form.role'}); |
&Apache::lonnet::put('email_status',\%temp); |
&Apache::lonnet::put('email_status',\%temp); |
my $logmsg = "Switch Server to $env{'form.otherserver'}"; |
my $logmsg = "Switch Server to $env{'form.otherserver'}"; |
Line 193 sub handler {
|
Line 197 sub handler {
|
|
|
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
|
|
#expire the cookie |
#expire the cookies |
my $c = new CGI::Cookie(-name => 'lonID', |
my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); |
-value => '', |
foreach my $name (keys(%cookies)) { |
-expires => '-10y',); |
next unless ($name =~ /^lon(|S|Link|Pub)ID$/); |
$r->headers_out->add('Set-cookie' => $c); |
my $c = new CGI::Cookie(-name => $name, |
if ($env{'user.linkedenv'}) { |
-value => '', |
my $linked = new CGI::Cookie(-name => 'lonLinkID', |
-expires => '-10y',); |
-value => '', |
$r->headers_out->add('Set-cookie' => $c); |
-expires => '-10y',); |
|
$r->headers_out->add('Set-cookie' => $linked); |
|
} |
} |
|
|
if ($r->header_only) { |
if ($r->header_only) { |
$r->send_http_header; |
$r->send_http_header; |
return OK; |
return OK; |
Line 213 sub handler {
|
Line 214 sub handler {
|
|
|
# ---------------------------------------------------------------- Get handover |
# ---------------------------------------------------------------- Get handover |
|
|
my ($is_balancer) = &Apache::lonnet::check_loadbalancing($env{'user.name'},$env{'user.domain'}); |
my $newcookieid; |
my %info=('ip' => $ENV{'REMOTE_ADDR'}, |
my ($is_balancer,$posshost,$setcookie,$offloadto,$dom_balancers) = |
'domain' => $env{'user.domain'}, |
&Apache::lonnet::check_loadbalancing($env{'user.name'},$env{'user.domain'}); |
'username' => $env{'user.name'}, |
if ($is_balancer && $setcookie && $env{'form.otherserver'}) { |
'role' => $env{'form.role'}, |
|
'server' => $r->dir_config('lonHostID'), |
# Set a balancer cookie unless browser already sent LON-CAPA load balancer |
'balancer' => $is_balancer); |
# cookie which points at the target server |
|
my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1); |
|
|
|
unless (($found_server eq $env{'form.otherserver'}) && |
|
($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) { |
|
my @hosts = &Apache::lonnet::current_machine_ids(); |
|
my $desthost = $env{'form.otherserver'}; |
|
unless (grep(/^\Q$desthost\E$/,@hosts)) { |
|
my $balancedir=$r->dir_config('lonBalanceDir'); |
|
$newcookieid = &md5_hex(&md5_hex($now.{}.rand().$$)); |
|
my $cookie = $env{'user.domain'}.'_'.$env{'user.name'}.'_'.$newcookieid; |
|
my $balcookie = "balanceID=$cookie; path=/; HttpOnly;"; |
|
if (open(my $fh,'>',"$balancedir/$cookie.id")) { |
|
print $fh $env{'form.otherserver'}; |
|
close($fh); |
|
} |
|
$r->headers_out->add('Set-cookie' => $balcookie); |
|
} |
|
} |
|
} |
|
|
|
my %info=('ip' => $ENV{'REMOTE_ADDR'}, |
|
'domain' => $env{'user.domain'}, |
|
'username' => $env{'user.name'}, |
|
'home' => $env{'user.home'}, |
|
'role' => $env{'form.role'}, |
|
'server' => $r->dir_config('lonHostID'), |
|
'balancer' => $is_balancer, |
|
'dom_balancers' => $dom_balancers, |
|
'offloadto' => ''); |
|
if (ref($offloadto) eq 'HASH') { |
|
foreach my $key (keys(%{$offloadto})) { |
|
if (ref($offloadto->{$key}) eq 'ARRAY') { |
|
$info{'offloadto'} .= $key.'='.join(',',@{$offloadto->{$key}}).'&'; |
|
} |
|
} |
|
$info{'offloadto'} =~ s/\&$//; |
|
} elsif (ref($offloadto) eq 'ARRAY') { |
|
$info{'offloadto'} = join(',',@{$offloadto}); |
|
} |
|
if ($newcookieid) { |
|
$info{'balcookie'} = $newcookieid; |
|
} |
if ($env{'form.origurl'}) { |
if ($env{'form.origurl'}) { |
$info{'origurl'} = $env{'form.origurl'}; |
$info{'origurl'} = $env{'form.origurl'}; |
} |
} |