Annotation of loncom/auth/lonauth.pm, revision 1.7
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.7 ! www 5: # 1/14,2/24,2/28,2/29,3/7,5/29,5/30,5/31,6/1,6/5 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.7 ! www 36: # ------------------------------------ Check browser type and MathML capability
1.6 www 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.7 ! www 66: # --------------------------------------------------------- Write first profile
1.5 www 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.7 ! www 79: # -------------------------------------------------------------------- Log this
! 80:
! 81: &Apache::lonnet::log($domain,$username,$authhost,
! 82: "Login $ENV{'REMOTE_ADDR'}");
1.4 www 83:
1.5 www 84: # ------------------------------------------------------------ Get cookie ready
85:
1.1 albertel 86: $cookie="lonID=$cookie; path=/";
1.5 www 87:
88: # ------------------------------------------------- Output for successful login
89:
1.1 albertel 90: $r->send_cgi_header(<<ENDHEADER);
91: Content-type: text/html
92: Set-cookie: $cookie
93:
94: ENDHEADER
95: $r->print(<<ENDSUCCESS);
96: <html>
97: <head>
1.4 www 98: <title>Successful Login to the LearningOnline Network with CAPA</title>
1.6 www 99: <meta HTTP-EQUIV="Refresh" CONTENT="1; url=$lowerurl">
1.1 albertel 100: </head>
1.6 www 101: <body bgcolor="#FFFFFF">
1.7 ! www 102: <script>
! 103: menu=window.open("/res/adm/pages/menu.html","LONCAPAmenu",
! 104: "height=350,width=150,scrollbars=no,menubar=no");
! 105: </script>
1.6 www 106: <h1>Welcome!</h1>
107: </body>
1.1 albertel 108: </html>
109: ENDSUCCESS
110: }
111:
112: # --------------------------------------------------------------- Failed login!
113:
114: sub failed {
115: my ($r,$message) = @_;
116: $r->send_cgi_header(<<ENDFHEADER);
117: Content-type: text/html
118:
119: ENDFHEADER
120: $r->print(<<ENDFAILED);
121: <html>
122: <head>
1.4 www 123: <title>Unsuccessful Login to the LearningOnline Network with CAPA</title>
1.1 albertel 124: </head>
125: <html>
126: <body bgcolor="#FFFFFF">
127: <h1>Sorry ...</h1>
1.4 www 128: <h2>$message to use the Learning<i>Online</i> Network with CAPA</h2>
1.1 albertel 129: </body>
130: </html>
131: ENDFAILED
132: }
133:
134: # ---------------------------------------------------------------- Main handler
135:
136: sub handler {
137: my $r = shift;
138:
139: my $buffer;
140: $r->read($buffer,$r->header_in('Content-length'));
141: my @pairs=split(/&/,$buffer);
142: my $pair; my $name; my $value; my %FORM;
143: foreach $pair (@pairs) {
144: ($name,$value) = split(/=/,$pair);
1.7 ! www 145: $value =~ tr/+/ /;
! 146: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.1 albertel 147: $FORM{$name}=$value;
148: }
149:
150: if ((!$FORM{'uname'}) || (!$FORM{'upass'}) || (!$FORM{'udom'})) {
151: failed($r,'Username, password and domain need to be specified');
152: return OK;
153: }
154: $FORM{'uname'} =~ s/\W//g;
155: $FORM{'udom'} =~ s/\W//g;
156:
157: my $role = $r->dir_config('lonRole');
158: my $domain = $r->dir_config('lonDefDomain');
159: my $prodir = $r->dir_config('lonUsersDir');
160:
161: # ---------------------------------------------------------------- Authenticate
162: my $authhost=Apache::lonnet::authenticate($FORM{'uname'},
163: $FORM{'upass'},
164: $FORM{'udom'});
165:
166: # --------------------------------------------------------------------- Failed?
167:
168: if ($authhost eq 'no_host') {
169: failed($r,'Username and/or password could not be authenticated');
170: return OK;
171: }
172:
1.7 ! www 173: if ($FORM{'firsturl'} eq '') {
! 174: $FORM{'firsturl'}='/res/index.html';
! 175: }
1.1 albertel 176:
1.7 ! www 177: success($r,$FORM{'uname'},$FORM{'udom'},$authhost,$FORM{'firsturl'});
1.1 albertel 178: return OK;
179: }
180:
181: 1;
182: __END__
1.7 ! www 183:
! 184:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>