File:
[LON-CAPA] /
loncom /
auth /
switchserver.pm
Revision
1.27:
download - view:
text,
annotated -
select for diffs
Tue Jul 20 02:42:33 2010 UTC (14 years, 1 month ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Control hosting of user sessions.
- To accommodate multi-domain library servers, use internet domain names (e.g., msu.edu)
instead of LON-CAPA domains in interface DC uses to set options for session hosting.
- Provide mechanism to retrieve lonHostID for a hostname, so we can tell which
domain determines session hosting config for external users on a multi-domain
machine.
- New routines in lonnet.pm:
&get_server_homeID() -- gets lonHostID for a hostname
&internet_dom() -- gets internet domain name for a LON-CAPA Host ID
&get_internet_names() -- gets internet domain names for all domains
for a server given one of the LC host IDs for the server.
- New file in /home/httpd/lonTabs:
- serverhomeIDs.tab (populated by loncron). : paired hostname:lonHostID
- New subroutine in loncron: &write_serverhomeIDs() -- populates serverhomeIDs.tab
- New subroutine in lond: &server_homeID_handler() -- returns LON-CAPA Host ID of server
- New scalar in lond: $clienthomedom -- set to domain of LON-CAPA Host ID of client
- New subroutine in domainprefs.pm: &build_location_hashes()
-- used to set up options for session hosting as internet domain names
- where two names (e.g., msu.edu, loncapa.org) are controlled by the same
institution these will receive a single checkbox.
1: # The LearningOnline Network
2: # Switch Servers Handler
3: #
4: # $Id: switchserver.pm,v 1.27 2010/07/20 02:42:33 raeburn 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::switchserver;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::lonnet;
34: use Apache::lonmenu;
35: use CGI::Cookie();
36: use Apache::lonlocal;
37:
38: sub init_env {
39: my ($r) = @_;
40:
41: if (-e $env{'user.environment'}) {
42: return $env{'user.environment'};
43: }
44: my $requrl=$r->uri;
45: my $handle= &Apache::lonnet::check_for_valid_session($r);
46: if ($handle ne '') {
47: return undef;
48: }
49: my $lonidsdir=$r->dir_config('lonIDsDir');
50: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
51:
52: return $r->dir_config('lonIDsDir')."/$handle.id";
53: }
54:
55: sub do_redirect {
56: my ($r,$url,$only_body,$extra_text) = @_;
57: $r->send_http_header;
58: my $start_page =
59: &Apache::loncommon::start_page('Switching Server ...',undef,
60: {'redirect' => [0.5,$url],
61: 'only_body' => $only_body,});
62: my $end_page = &Apache::loncommon::end_page();
63: $r->print($start_page.$extra_text.$end_page);
64: return OK;
65:
66: }
67:
68: sub handler {
69: my ($r) = @_;
70:
71: my $handle=&init_env($r);
72: if (!defined($handle)) { return FORBIDDEN; }
73:
74: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
75: ['otherserver','role','origurl','symb']);
76:
77: my $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
78: if (! $env{'form.otherserver'}) {
79: $env{'form.otherserver'} =
80: &Apache::lonnet::find_existing_session($env{'user.domain'},
81: $env{'user.name'});
82: if (! $env{'form.otherserver'}) {
83: $env{'form.otherserver'} =
84: &Apache::lonnet::spareserver(30000,undef,1);
85: }
86:
87: $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
88: }
89:
90: if (!defined($switch_to)) { return FORBIDDEN; }
91:
92: if ($env{'user.name'} eq 'public'
93: && $env{'user.domain'} eq 'public') {
94: my $url = 'http://'.$switch_to.$r->uri;
95: return &do_redirect($r,$url,1)
96: }
97:
98: my $canhost = 1;
99: my $uprimary_id = &Apache::lonnet::domain($env{'user.domain'},'primary');
100: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
101: my @intdoms = &Apache::lonnet::get_internet_names($env{'form.otherserver'});
102: unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
103: my $serverhomeID = &Apache::lonnet::get_server_homeID($switch_to);
104: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
105: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
106: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
107: my $remoterev = &Apache::lonnet::get_server_loncaparev($env{'user.domain'},$env{'form.otherserver'});
108: $canhost =
109: &Apache::lonnet::can_host_session($env{'user.domain'},
110: $env{'form.otherserver'},
111: $remoterev,
112: $udomdefaults{'remotesessions'},
113: $defdomdefaults{'hostedsessions'});
114: }
115:
116: unless ($canhost) { return FORBIDDEN; }
117:
118: if ($env{'form.role'} &&
119: !exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; }
120:
121: #remove session env, and log event
122: unlink($handle);
123: my %temp=('switchserver' => time.':'.$env{'form.otherserver'},
124: $env{'form.role'});
125: &Apache::lonnet::put('email_status',\%temp);
126: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
127: $env{'user.home'},
128: "Switch Server to $env{'form.otherserver'} with role $env{'form.role'} $ENV{'REMOTE_ADDR'}");
129:
130: &Apache::loncommon::content_type($r,'text/html');
131:
132: #expire the cookie
133: my $c = new CGI::Cookie(-name => 'lonID',
134: -value => '',
135: -expires => '-10y',);
136: $r->header_out('Set-cookie' => $c);
137:
138: if ($r->header_only) {
139: $r->send_http_header;
140: return OK;
141: }
142: # -------------------------------------------------------- Menu script and info
143:
144: # ---------------------------------------------------------------- Get handover
145:
146: my %info=('ip' => $ENV{'REMOTE_ADDR'},
147: 'domain' => $env{'user.domain'},
148: 'username' => $env{'user.name'},
149: 'role' => $env{'form.role'},
150: 'server' => $r->dir_config('lonHostID'));
151: if ($env{'form.origurl'}) {
152: $info{'origurl'} = $env{'form.origurl'};
153: }
154: if ($env{'form.symb'}) {
155: $info{'symb'} = $env{'form.symb'};
156: }
157: if ($env{'request.sso.login'}) {
158: $info{'sso.login'} = $env{'request.sso.login'};
159: }
160: if ($env{'request.sso.reloginserver'}) {
161: $info{'sso.reloginserver'} = $env{'request.sso.reloginserver'};
162: }
163: my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'});
164: my $url ='http://'.$switch_to.'/adm/login?'.
165: 'domain='.$env{'user.domain'}.
166: '&username='.$env{'user.name'}.
167: '&token='.$token;
168: # --------------------------------------------------------------- Screen Output
169: &Apache::lonnet::flushcourselogs();
170: return &do_redirect($r, $url, 0);
171: }
172:
173: 1;
174: __END__
175:
176:
177:
178:
179:
180:
181:
182:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>