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