Annotation of loncom/auth/lonauth.pm, revision 1.2
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
! 4: # 16/11 Gerd Kortemeyer
1.1 albertel 5:
6: package Apache::lonauth;
7:
8: use Apache::Constants qw(:common);
9: use Apache::File;
10: use CGI qw(:standard);
11: use CGI::Cookie();
12: use Apache::lonnet();
13:
14: # ------------------------------------------------------------ Successful login
15:
16: sub success {
17: my ($r, $lowerurl, $username, $domain, $authhost) = @_;
18: my $lonids=$r->dir_config('lonIDsDir');
19: # See if old ID present, but overlooked
20: my $cookie;
21: if ($cookie=<$lonids/$username\_*\_$domain\_$authhost.id>) {
22: $cookie=~s/\.id//;
23: $cookie=~s/$lonids\///;
24: } else {
25: my $now=time;
26: $cookie="$username\_$now\_$domain\_$authhost";
27: {
28: my $idf=Apache::File->new(">$lonids/$cookie.id");
1.2 ! www 29: print $idf "username=$username\n";
! 30: print $idf "userdomain=$domain\n";
! 31: print $idf "userhome=$authhost\n";
1.1 albertel 32: }
33: }
34: $cookie="lonID=$cookie; path=/";
35: $r->send_cgi_header(<<ENDHEADER);
36: Content-type: text/html
37: Set-cookie: $cookie
38:
39: ENDHEADER
40: $r->print(<<ENDSUCCESS);
41: <html>
42: <head>
43: <title>Successful Login to the LearningOnline Network</title>
44: </head>
45: <frameset rows="80,*" border=0>
46: <frame scrolling="no" name="loncontrol" src="/adm/menu">
47: <frame name="loncontent" src="$lowerurl">
48: </frameset>
49: </html>
50: ENDSUCCESS
51: }
52:
53: # --------------------------------------------------------------- Failed login!
54:
55: sub failed {
56: my ($r,$message) = @_;
57: $r->send_cgi_header(<<ENDFHEADER);
58: Content-type: text/html
59:
60: ENDFHEADER
61: $r->print(<<ENDFAILED);
62: <html>
63: <head>
64: <title>Unsuccessful Login to the LearningOnline Network</title>
65: </head>
66: <html>
67: <body bgcolor="#FFFFFF">
68: <h1>Sorry ...</h1>
69: <h2>$message to use the Learning<i>Online</i> Network</h2>
70: </body>
71: </html>
72: ENDFAILED
73: }
74:
75: # ---------------------------------------------------------------- Main handler
76:
77: sub handler {
78: my $r = shift;
79:
80: my $buffer;
81: $r->read($buffer,$r->header_in('Content-length'));
82: my @pairs=split(/&/,$buffer);
83: my $pair; my $name; my $value; my %FORM;
84: foreach $pair (@pairs) {
85: ($name,$value) = split(/=/,$pair);
86: $FORM{$name}=$value;
87: }
88:
89: if ((!$FORM{'uname'}) || (!$FORM{'upass'}) || (!$FORM{'udom'})) {
90: failed($r,'Username, password and domain need to be specified');
91: return OK;
92: }
93: $FORM{'uname'} =~ s/\W//g;
94: $FORM{'upass'} =~ s/\W//g;
95: $FORM{'udom'} =~ s/\W//g;
96:
97: my $role = $r->dir_config('lonRole');
98: my $domain = $r->dir_config('lonDefDomain');
99: my $prodir = $r->dir_config('lonUsersDir');
100:
101: # ---------------------------------------------------------------- Authenticate
102: my $authhost=Apache::lonnet::authenticate($FORM{'uname'},
103: $FORM{'upass'},
104: $FORM{'udom'});
105:
106: # --------------------------------------------------------------------- Failed?
107:
108: if ($authhost eq 'no_host') {
109: failed($r,'Username and/or password could not be authenticated');
110: return OK;
111: }
112:
113: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
114: my $lonurl=$cookies{'lonURL'};
115: if (!$lonurl) { failed($r,'Cookies need to be activated'); return OK; }
116: my $lowerurl=$lonurl->value;
117:
118: success($r,$lowerurl,$FORM{'uname'},$FORM{'udom'},$authhost);
119: return OK;
120: }
121:
122: 1;
123: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>