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