Annotation of loncom/auth/lonauth.pm, revision 1.15
1.1 albertel 1: # The LearningOnline Network
2: # User Authentication Module
1.2 www 3: # 5/21/99,5/22,5/25,5/26,5/27,5/29,6/2,6/11,6/14,6/15
1.4 www 4: # 16/11,12/16,
1.9 www 5: # 1/14,2/24,2/28,2/29,3/7,5/29,5/30,5/31,6/1,6/5,6/29,
1.15 ! www 6: # 7/1,7/10,10/2,10/5,10/9,10/26 Gerd Kortemeyer
1.1 albertel 7:
8: package Apache::lonauth;
9:
10: use Apache::Constants qw(:common);
11: use Apache::File;
12: use CGI qw(:standard);
13: use CGI::Cookie();
1.8 www 14: use Crypt::DES;
1.1 albertel 15: use Apache::lonnet();
1.12 www 16: use Apache::lonmenu();
1.1 albertel 17:
18: # ------------------------------------------------------------ Successful login
19:
20: sub success {
1.6 www 21: my ($r, $username, $domain, $authhost,$lowerurl) = @_;
1.1 albertel 22: my $lonids=$r->dir_config('lonIDsDir');
1.4 www 23:
24: # See if old ID present, if so, remove
1.1 albertel 25: my $cookie;
1.4 www 26: while ($cookie=<$lonids/$username\_*\_$domain\_$authhost.id>) {
27: unlink($cookie);
28: }
29:
30: # Give them a new cookie
31:
1.5 www 32: my $now=time;
33: $cookie="$username\_$now\_$domain\_$authhost";
34:
35: # Initialize roles
36:
37: my $userroles=Apache::lonnet::rolesinit($domain,$username,$authhost);
38:
1.7 www 39: # ------------------------------------ Check browser type and MathML capability
1.6 www 40:
41: my @browsertype=split(/\&/,$r->dir_config("lonBrowsDet"));
42: my %mathcap=split(/\&/,$r->dir_config("lonMathML"));
43: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
44: my $i;
45: my $clientbrowser='unknown';
46: my $clientversion='0';
47: my $clientmathml='';
48: for ($i=0;$i<=$#browsertype;$i++) {
49: my ($bname,$match,$notmatch,$vreg,$minv)=split(/\:/,$browsertype[$i]);
50: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
51: $clientbrowser=$bname;
52: $httpbrowser=~/$vreg/i;
53: $clientversion=$1;
54: $clientmathml=($clientversion>=$minv);
55: }
56: }
57: my $clientos='unknown';
58: if (($httpbrowser=~/linux/i) ||
59: ($httpbrowser=~/unix/i) ||
60: ($httpbrowser=~/ux/i) ||
61: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
62: if (($httpbrowser=~/vax/i) ||
63: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
64: if ($httpbrowser=~/next/i) { $clientos='next'; }
65: if (($httpbrowser=~/mac/i) ||
66: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.10 www 67: if ($httpbrowser=~/win/i) { $clientos='win'; }
1.6 www 68:
1.11 www 69: # ------------------------------------------------------------- Get environment
70:
71: my $userenv=Apache::lonnet::reply("dump:$domain:$username:environment",
72: $authhost);
73: if (($userenv eq 'con_lost') ||
74: ($userenv =~ /^error\:/)) {
75: $userenv='';
76: }
77: $userenv=~s/\&/\nenvironment\./g;
78: if ($userenv ne '') {
79: $userenv='environment.'.$userenv;
80: }
1.7 www 81: # --------------------------------------------------------- Write first profile
1.5 www 82:
83: {
1.1 albertel 84: my $idf=Apache::File->new(">$lonids/$cookie.id");
1.11 www 85: if ($userenv ne '') { print $idf "$userenv\n"; }
1.4 www 86: print $idf "user.name=$username\n";
87: print $idf "user.domain=$domain\n";
88: print $idf "user.home=$authhost\n";
1.6 www 89: print $idf "browser.type=$clientbrowser\n";
90: print $idf "browser.version=$clientversion\n";
91: print $idf "browser.mathml=$clientmathml\n";
92: print $idf "browser.os=$clientos\n";
1.15 ! www 93: print $idf "request.course.fn=\n";
! 94: print $idf "request.course.uri=\n";
! 95: print $idf "request.course.sec=\n";
! 96: print $idf "request.role=cm\n";
1.11 www 97: if ($userroles ne '') { print $idf "$userroles"; }
1.1 albertel 98: }
1.11 www 99:
1.7 www 100: # -------------------------------------------------------------------- Log this
101:
102: &Apache::lonnet::log($domain,$username,$authhost,
103: "Login $ENV{'REMOTE_ADDR'}");
1.4 www 104:
1.14 www 105: # ------------------------------------------------- Check for critical messages
106:
107: my @what=&Apache::lonnet::dump('critical');
108: if ($what[0]) {
109: if ($what[0] ne 'con_lost') {
110: $lowerurl='/adm/email/critical/'.$what[0];
111: }
112: }
113:
1.5 www 114: # ------------------------------------------------------------ Get cookie ready
115:
1.1 albertel 116: $cookie="lonID=$cookie; path=/";
1.12 www 117: # -------------------------------------------------------- Menu script and info
1.5 www 118:
1.12 www 119: my $windowinfo=&Apache::lonmenu::open();
1.5 www 120: # ------------------------------------------------- Output for successful login
121:
1.1 albertel 122: $r->send_cgi_header(<<ENDHEADER);
123: Content-type: text/html
124: Set-cookie: $cookie
125:
126: ENDHEADER
127: $r->print(<<ENDSUCCESS);
128: <html>
129: <head>
1.4 www 130: <title>Successful Login to the LearningOnline Network with CAPA</title>
1.6 www 131: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$lowerurl">
1.1 albertel 132: </head>
1.6 www 133: <body bgcolor="#FFFFFF">
1.12 www 134: $windowinfo
1.6 www 135: <h1>Welcome!</h1>
136: </body>
1.1 albertel 137: </html>
138: ENDSUCCESS
139: }
140:
141: # --------------------------------------------------------------- Failed login!
142:
143: sub failed {
144: my ($r,$message) = @_;
145: $r->send_cgi_header(<<ENDFHEADER);
146: Content-type: text/html
147:
148: ENDFHEADER
149: $r->print(<<ENDFAILED);
150: <html>
151: <head>
1.4 www 152: <title>Unsuccessful Login to the LearningOnline Network with CAPA</title>
1.1 albertel 153: </head>
154: <html>
155: <body bgcolor="#FFFFFF">
156: <h1>Sorry ...</h1>
1.4 www 157: <h2>$message to use the Learning<i>Online</i> Network with CAPA</h2>
1.1 albertel 158: </body>
159: </html>
160: ENDFAILED
161: }
162:
163: # ---------------------------------------------------------------- Main handler
164:
165: sub handler {
166: my $r = shift;
167:
168: my $buffer;
169: $r->read($buffer,$r->header_in('Content-length'));
170: my @pairs=split(/&/,$buffer);
171: my $pair; my $name; my $value; my %FORM;
172: foreach $pair (@pairs) {
173: ($name,$value) = split(/=/,$pair);
1.7 www 174: $value =~ tr/+/ /;
175: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.1 albertel 176: $FORM{$name}=$value;
177: }
178:
179: if ((!$FORM{'uname'}) || (!$FORM{'upass'}) || (!$FORM{'udom'})) {
180: failed($r,'Username, password and domain need to be specified');
181: return OK;
182: }
183: $FORM{'uname'} =~ s/\W//g;
184: $FORM{'udom'} =~ s/\W//g;
185:
186: my $role = $r->dir_config('lonRole');
187: my $domain = $r->dir_config('lonDefDomain');
188: my $prodir = $r->dir_config('lonUsersDir');
189:
1.8 www 190: # ---------------------------------------- Get the information from login token
191:
192: my $tmpinfo=Apache::lonnet::reply('tmpget:'.$FORM{'logtoken'},
193: $FORM{'serverid'});
194:
195: if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
196: failed($r,'Login token missing, inaccessible or expired');
197: return OK;
198: }
199:
1.9 www 200: my ($key,$firsturl)=split(/&/,$tmpinfo);
1.8 www 201:
202: my $keybin=pack("H16",$key);
203:
204: my $cipher=new DES $keybin;
205:
206: my $upass=$cipher->decrypt(
207: unpack("a8",pack("H16",substr($FORM{'upass'},0,16))));
208:
209: $upass.=$cipher->decrypt(
210: unpack("a8",pack("H16",substr($FORM{'upass'},16,16))));
211:
212: $upass=substr($upass,1,ord(substr($upass,0,1)));
213:
1.1 albertel 214: # ---------------------------------------------------------------- Authenticate
215: my $authhost=Apache::lonnet::authenticate($FORM{'uname'},
1.8 www 216: $upass,
1.1 albertel 217: $FORM{'udom'});
218:
219: # --------------------------------------------------------------------- Failed?
220:
221: if ($authhost eq 'no_host') {
222: failed($r,'Username and/or password could not be authenticated');
223: return OK;
224: }
225:
1.13 www 226: if (($firsturl eq '') || ($firsturl eq '/adm/logout')) {
1.8 www 227: $firsturl='/res/adm/pages/index.html';
1.7 www 228: }
1.1 albertel 229:
1.8 www 230: success($r,$FORM{'uname'},$FORM{'udom'},$authhost,$firsturl);
1.1 albertel 231: return OK;
232: }
233:
234: 1;
235: __END__
1.7 www 236:
237:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>