Annotation of loncom/auth/lonauth.pm, revision 1.6
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.6 ! www 5: # 1/14,2/24,2/28,2/29,3/7,5/29,5/30 Gerd Kortemeyer
1.1 albertel 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 {
1.6 ! www 18: my ($r, $username, $domain, $authhost,$lowerurl) = @_;
1.1 albertel 19: my $lonids=$r->dir_config('lonIDsDir');
1.4 www 20:
21: # See if old ID present, if so, remove
1.1 albertel 22: my $cookie;
1.4 www 23: while ($cookie=<$lonids/$username\_*\_$domain\_$authhost.id>) {
24: unlink($cookie);
25: }
26:
27: # Give them a new cookie
28:
1.5 www 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:
1.6 ! www 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:
1.5 www 66: # Write first profile
67:
68: {
1.1 albertel 69: my $idf=Apache::File->new(">$lonids/$cookie.id");
1.4 www 70: print $idf "user.name=$username\n";
71: print $idf "user.domain=$domain\n";
72: print $idf "user.home=$authhost\n";
1.6 ! www 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";
1.4 www 77: if ($userroles ne '') { print $idf "$userroles" };
1.1 albertel 78: }
1.4 www 79:
1.5 www 80: # ------------------------------------------------------------ Get cookie ready
81:
1.1 albertel 82: $cookie="lonID=$cookie; path=/";
1.5 www 83:
84: # ------------------------------------------------- Output for successful login
85:
1.1 albertel 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>
1.4 www 94: <title>Successful Login to the LearningOnline Network with CAPA</title>
1.6 ! www 95: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$lowerurl">
1.1 albertel 96: </head>
1.6 ! www 97: <body bgcolor="#FFFFFF">
! 98: <h1>Welcome!</h1>
! 99: </body>
1.1 albertel 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>
1.4 www 115: <title>Unsuccessful Login to the LearningOnline Network with CAPA</title>
1.1 albertel 116: </head>
117: <html>
118: <body bgcolor="#FFFFFF">
119: <h1>Sorry ...</h1>
1.4 www 120: <h2>$message to use the Learning<i>Online</i> Network with CAPA</h2>
1.1 albertel 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:
1.6 ! www 168: success($r,$FORM{'uname'},$FORM{'udom'},$authhost,$lowerurl);
1.1 albertel 169: return OK;
170: }
171:
172: 1;
173: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>