File:
[LON-CAPA] /
loncom /
auth /
switchserver.pm
Revision
1.22:
download - view:
text,
annotated -
select for diffs
Tue Apr 14 23:52:07 2009 UTC (15 years, 3 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_99_1,
version_2_8_99_0,
bz6209-base,
bz6209,
bz5969,
bz2851,
HEAD,
GCI_3,
GCI_2,
BZ5971-printing-apage,
BZ5434-fox
- HTML documents uploaded directly to a course can be edited by a Course Coordinator (mdc priv).
- "Edit this resource" link displayed in inline menu.
- Link will switch server to course's home server if session is currently hoosted elsewehere (unless a lock is in place).
- Deep linking:
- origurl and symb args can be included in query string for switchserver call, so switched session will go to the same resource on the new server.
Work in progress.
Logging needed: changes, and by whom.
1: # The LearningOnline Network
2: # Switch Servers Handler
3: #
4: # $Id: switchserver.pm,v 1.22 2009/04/14 23:52:07 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: 'no_inline_link' => 1,
62: 'only_body' => $only_body,});
63: my $end_page = &Apache::loncommon::end_page();
64: $r->print($start_page.$extra_text.$end_page);
65: return OK;
66:
67: }
68:
69: sub handler {
70: my ($r) = @_;
71:
72: my $handle=&init_env($r);
73: if (!defined($handle)) { return FORBIDDEN; }
74:
75: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
76: ['otherserver','role','origurl','symb']);
77:
78: my $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
79: if (! $env{'form.otherserver'}) {
80: $env{'form.otherserver'} =
81: &Apache::lonnet::find_existing_session($env{'user.domain'},
82: $env{'user.name'});
83: if (! $env{'form.otherserver'}) {
84: $env{'form.otherserver'} =
85: &Apache::lonnet::spareserver(30000,undef,1);
86: }
87:
88: $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
89: }
90:
91: if (!defined($switch_to)) { return FORBIDDEN; }
92:
93: if ($env{'user.name'} eq 'public'
94: && $env{'user.domain'} eq 'public') {
95: my $url = 'http://'.$switch_to.$r->uri;
96: return &do_redirect($r,$url,1)
97: }
98:
99: if ($env{'form.role'} &&
100: !exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; }
101:
102: #remove session env, and log event
103: unlink($handle);
104: my %temp=('switchserver' => time.':'.$env{'form.otherserver'},
105: $env{'form.role'});
106: &Apache::lonnet::put('email_status',\%temp);
107: &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
108: $env{'user.home'},
109: "Switch Server to $env{'form.otherserver'} with role $env{'form.role'} $ENV{'REMOTE_ADDR'}");
110:
111: &Apache::loncommon::content_type($r,'text/html');
112:
113: #expire the cookie
114: my $c = new CGI::Cookie(-name => 'lonID',
115: -value => '',
116: -expires => '-10y',);
117: $r->header_out('Set-cookie' => $c);
118:
119: if ($r->header_only) {
120: $r->send_http_header;
121: return OK;
122: }
123: # -------------------------------------------------------- Menu script and info
124:
125: my $windowinfo=
126: &Apache::lonmenu::close().
127: &Apache::lonnavmaps::close();
128: # ---------------------------------------------------------------- Get handover
129:
130: my %info=('ip' => $ENV{'REMOTE_ADDR'},
131: 'domain' => $env{'user.domain'},
132: 'username' => $env{'user.name'},
133: 'role' => $env{'form.role'},
134: 'server' => $r->dir_config('lonHostID'));
135: if ($env{'form.origurl'}) {
136: $info{'origurl'} = $env{'form.origurl'};
137: }
138: if ($env{'form.symb'}) {
139: $info{'symb'} = $env{'form.symb'};
140: }
141: if ($env{'request.sso.login'}) {
142: $info{'sso.login'} = $env{'request.sso.login'};
143: }
144: if ($env{'request.sso.reloginserver'}) {
145: $info{'sso.reloginserver'} = $env{'request.sso.reloginserver'};
146: }
147: my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'});
148: my $url ='http://'.$switch_to.'/adm/login?'.
149: 'domain='.$env{'user.domain'}.
150: '&username='.$env{'user.name'}.
151: '&token='.$token;
152: # --------------------------------------------------------------- Screen Output
153: &Apache::lonnet::flushcourselogs();
154: return &do_redirect($r,$url,0,$windowinfo);
155: }
156:
157: 1;
158: __END__
159:
160:
161:
162:
163:
164:
165:
166:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>