1: # The LearningOnline Network
2: # User Authentication Module
3: # 5/21/99,5/22,5/25,5/26,5/27,5/29,6/2,6/11,6/14,6/15
4: # 16/11,12/16,
5: # 1/14,2/24,2/28,2/29,3/7,5/29,5/30 Gerd Kortemeyer
6:
7: package Apache::lonauth;
8:
9: use Apache::Constants qw(:common);
10: use Apache::File;
11: use CGI qw(:standard);
12: use CGI::Cookie();
13: use Apache::lonnet();
14:
15: # ------------------------------------------------------------ Successful login
16:
17: sub success {
18: my ($r, $username, $domain, $authhost,$lowerurl) = @_;
19: my $lonids=$r->dir_config('lonIDsDir');
20:
21: # See if old ID present, if so, remove
22: my $cookie;
23: while ($cookie=<$lonids/$username\_*\_$domain\_$authhost.id>) {
24: unlink($cookie);
25: }
26:
27: # Give them a new cookie
28:
29: my $now=time;
30: $cookie="$username\_$now\_$domain\_$authhost";
31:
32: # Initialize roles
33:
34: my $userroles=Apache::lonnet::rolesinit($domain,$username,$authhost);
35:
36: # Check browser type and MathML capability
37:
38: my @browsertype=split(/\&/,$r->dir_config("lonBrowsDet"));
39: my %mathcap=split(/\&/,$r->dir_config("lonMathML"));
40: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
41: my $i;
42: my $clientbrowser='unknown';
43: my $clientversion='0';
44: my $clientmathml='';
45: for ($i=0;$i<=$#browsertype;$i++) {
46: my ($bname,$match,$notmatch,$vreg,$minv)=split(/\:/,$browsertype[$i]);
47: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
48: $clientbrowser=$bname;
49: $httpbrowser=~/$vreg/i;
50: $clientversion=$1;
51: $clientmathml=($clientversion>=$minv);
52: }
53: }
54: my $clientos='unknown';
55: if (($httpbrowser=~/linux/i) ||
56: ($httpbrowser=~/unix/i) ||
57: ($httpbrowser=~/ux/i) ||
58: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
59: if (($httpbrowser=~/vax/i) ||
60: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
61: if ($httpbrowser=~/next/i) { $clientos='next'; }
62: if (($httpbrowser=~/mac/i) ||
63: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
64: if ($httpbrowser=~/win/) { $clientos='win'; }
65:
66: # Write first profile
67:
68: {
69: my $idf=Apache::File->new(">$lonids/$cookie.id");
70: print $idf "user.name=$username\n";
71: print $idf "user.domain=$domain\n";
72: print $idf "user.home=$authhost\n";
73: print $idf "browser.type=$clientbrowser\n";
74: print $idf "browser.version=$clientversion\n";
75: print $idf "browser.mathml=$clientmathml\n";
76: print $idf "browser.os=$clientos\n";
77: if ($userroles ne '') { print $idf "$userroles" };
78: }
79:
80: # ------------------------------------------------------------ Get cookie ready
81:
82: $cookie="lonID=$cookie; path=/";
83:
84: # ------------------------------------------------- Output for successful login
85:
86: $r->send_cgi_header(<<ENDHEADER);
87: Content-type: text/html
88: Set-cookie: $cookie
89:
90: ENDHEADER
91: $r->print(<<ENDSUCCESS);
92: <html>
93: <head>
94: <title>Successful Login to the LearningOnline Network with CAPA</title>
95: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$lowerurl">
96: </head>
97: <body bgcolor="#FFFFFF">
98: <h1>Welcome!</h1>
99: </body>
100: </html>
101: ENDSUCCESS
102: }
103:
104: # --------------------------------------------------------------- Failed login!
105:
106: sub failed {
107: my ($r,$message) = @_;
108: $r->send_cgi_header(<<ENDFHEADER);
109: Content-type: text/html
110:
111: ENDFHEADER
112: $r->print(<<ENDFAILED);
113: <html>
114: <head>
115: <title>Unsuccessful Login to the LearningOnline Network with CAPA</title>
116: </head>
117: <html>
118: <body bgcolor="#FFFFFF">
119: <h1>Sorry ...</h1>
120: <h2>$message to use the Learning<i>Online</i> Network with CAPA</h2>
121: </body>
122: </html>
123: ENDFAILED
124: }
125:
126: # ---------------------------------------------------------------- Main handler
127:
128: sub handler {
129: my $r = shift;
130:
131: my $buffer;
132: $r->read($buffer,$r->header_in('Content-length'));
133: my @pairs=split(/&/,$buffer);
134: my $pair; my $name; my $value; my %FORM;
135: foreach $pair (@pairs) {
136: ($name,$value) = split(/=/,$pair);
137: $FORM{$name}=$value;
138: }
139:
140: if ((!$FORM{'uname'}) || (!$FORM{'upass'}) || (!$FORM{'udom'})) {
141: failed($r,'Username, password and domain need to be specified');
142: return OK;
143: }
144: $FORM{'uname'} =~ s/\W//g;
145: $FORM{'udom'} =~ s/\W//g;
146:
147: my $role = $r->dir_config('lonRole');
148: my $domain = $r->dir_config('lonDefDomain');
149: my $prodir = $r->dir_config('lonUsersDir');
150:
151: # ---------------------------------------------------------------- Authenticate
152: my $authhost=Apache::lonnet::authenticate($FORM{'uname'},
153: $FORM{'upass'},
154: $FORM{'udom'});
155:
156: # --------------------------------------------------------------------- Failed?
157:
158: if ($authhost eq 'no_host') {
159: failed($r,'Username and/or password could not be authenticated');
160: return OK;
161: }
162:
163: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
164: my $lonurl=$cookies{'lonURL'};
165: if (!$lonurl) { failed($r,'Cookies need to be activated'); return OK; }
166: my $lowerurl=$lonurl->value;
167:
168: success($r,$FORM{'uname'},$FORM{'udom'},$authhost,$lowerurl);
169: return OK;
170: }
171:
172: 1;
173: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>