Annotation of loncom/interface/loncreateuser.pm, revision 1.4

1.1       www         1: # The LearningOnline Network
                      2: # Create a user
                      3: #
                      4: # (Create a course
                      5: # (My Desk
                      6: #
                      7: # (Internal Server Error Handler
                      8: #
                      9: # (Login Screen
                     10: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
                     11: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
                     12: #
                     13: # 3/1/1 Gerd Kortemeyer)
                     14: #
                     15: # 3/1 Gerd Kortemeyer)
                     16: #
                     17: # 2/14 Gerd Kortemeyer)
                     18: #
1.4     ! www        19: # 2/14,2/17,2/19,2/20,2/21,2/22,2/23,3/2 Gerd Kortemeyer
1.1       www        20: #
                     21: package Apache::loncreateuser;
                     22: 
                     23: use strict;
                     24: use Apache::Constants qw(:common :http);
                     25: use Apache::lonnet;
                     26: 
1.2       www        27: # =================================================================== Phase one
1.1       www        28: 
1.2       www        29: sub phase_one {
                     30:     my $r=shift;
                     31:     my $defdom=$ENV{'user.domain'};
1.1       www        32:     $r->print(<<ENDDOCUMENT);
                     33: <html>
                     34: <head>
                     35: <title>The LearningOnline Network with CAPA</title>
                     36: </head>
                     37: <body bgcolor="#FFFFFF">
                     38: <h1>Create User, Change User Privileges</h1>
1.2       www        39: <form action=/adm/createuser method=post>
                     40: <input type=hidden name=phase value=two>
                     41: Username: <input type=text size=15 name=ccuname><br>
                     42: Domain: <input type=text size=15 name=ccdomain value=$defdom><p>
                     43: <input type=submit value="Continue">
                     44: </form>
1.1       www        45: </body>
                     46: </html>
                     47: ENDDOCUMENT
1.2       www        48: }
                     49: 
                     50: # =================================================================== Phase two
                     51: 
                     52: sub phase_two {
                     53:     my $r=shift;
                     54:     my $ccuname=$ENV{'form.ccuname'};
                     55:     my $ccdomain=$ENV{'form.ccdomain'};
1.4     ! www        56: 
        !            57:     $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
        !            58:     my $krbdefdom=$1;
        !            59:     $krbdefdom=~tr/a-z/A-Z/;
        !            60: 
        !            61:     my $defdom=$ENV{'user.domain'};
        !            62: 
1.2       www        63:     $ccuname=~s/\W//g;
                     64:     $ccdomain=~s/\W//g;
                     65:     $r->print(<<ENDENHEAD);
                     66: <html>
                     67: <head>
                     68: <title>The LearningOnline Network with CAPA</title>
1.3       www        69: <script>
                     70: 
                     71:     function pclose() {
                     72:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                     73:                  "height=350,width=350,scrollbars=no,menubar=no");
                     74:         parmwin.close();
                     75:     }
                     76: 
                     77:     function pjump(type,dis,value,marker,ret,call) {
                     78:         parmwin=window.open("/adm/rat/parameter.html?type="+escape(type)
                     79:                  +"&value="+escape(value)+"&marker="+escape(marker)
                     80:                  +"&return="+escape(ret)
                     81:                  +"&call="+escape(call)+"&name="+escape(dis),"LONCAPAparms",
                     82:                  "height=350,width=350,scrollbars=no,menubar=no");
                     83: 
                     84:     }
                     85: 
                     86:     function dateset() {
                     87:         eval("document.cu."+document.cu.pres_marker.value+
                     88:             ".value=document.cu.pres_value.value");
                     89:         pclose();
                     90:     }
                     91: 
                     92: </script>
1.2       www        93: </head>
                     94: <body bgcolor="#FFFFFF">
                     95: <img align=right src=/adm/lonIcons/lonlogos.gif>
                     96: <h1>Create User, Change User Privileges</h1>
1.3       www        97: <form action=/adm/createuser method=post name=cu>
1.2       www        98: <input type=hidden name=phase value=three>
                     99: <input type=hidden name=ccuname value=$ccuname>
                    100: <input type=hidden name=ccdomain value=$ccdomain>
1.3       www       101: <input type="hidden" value='' name="pres_value">
                    102: <input type="hidden" value='' name="pres_type">
                    103: <input type="hidden" value='' name="pres_marker">
                    104: 
1.2       www       105: ENDENHEAD
                    106:     my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
                    107:     my %incdomains; 
                    108:     my %inccourses;
                    109:     $incdomains{$ENV{'user.domain'}}=1;
                    110:     map {
                    111: 	if ($_=~/^user\.priv\.cm\.\/(\w+)\/(\w+)/) {
                    112: 	    $inccourses{$1.'_'.$2}=1;
                    113:         }
                    114:     } %ENV;
                    115:     if ($uhome eq 'no_host') {
1.4     ! www       116: 	$r->print(<<ENDNUSER);
        !           117: <h3>New user $ccuname at $ccdomain</h3>
        !           118: <script>
        !           119: function verify(vf) {
        !           120:     var founduname=0;
        !           121:     var foundpwd=0;
        !           122:     var foundname=0;
        !           123:     var foundid=0;
        !           124:     var foundsec=0;
        !           125:     var foundatype=0;
        !           126:     var tw;
        !           127:     var message='';
        !           128:     if ((vf.cuname.value!=undefined) && (vf.cuname.value!='') && 
        !           129: 	(vf.cdomain.value!=undefined) && (vf.cdomain.value!='')) {
        !           130:         founduname=1;
        !           131:     }
        !           132:     if ((vf.cfirst.value!=undefined) && (vf.cfirst.value!='') &&
        !           133: 	(vf.clast.value!=undefined) && (vf.clast.value!='')) {
        !           134:         foundname=1;
        !           135:     }
        !           136:     if ((vf.csec.value!=undefined) && (vf.csec.value!='')) {
        !           137:         foundsec=1;
        !           138:     }
        !           139:     if ((vf.cstid.value!=undefined) && (vf.cstid.value!='')) {
        !           140: 	foundid=1;
        !           141:     }
        !           142:     if (founduname==0) {
        !           143: 	alert('You need to specify at least the username and domain fields');
        !           144:         return;
        !           145:     }
        !           146:     if (vf.login[0].checked) {
        !           147: 	foundatype=1;
        !           148:         if (vf.krbdom.value=='') {
        !           149: 	    alert('You need to specify the Kerberos domain');
        !           150:             return;
        !           151:         }
        !           152:     }
        !           153:     if (vf.login[1].checked) {
        !           154: 	foundatype=1;
        !           155:         if ((vf.intpwd.value=='') && (foundpwd==0)) {
        !           156: 	    alert('You need to specify the initial password');
        !           157:             return;
        !           158:         }
        !           159:     }
        !           160:     if (foundatype==0) {
        !           161: 	alert('You need to set the login type');
        !           162:         return;
        !           163:     }
        !           164:     if (foundname==0) { message='No first and last name specified. '; }
        !           165:     if (foundid==0) { message+='No ID or student number field specified. '; }
        !           166:     if (foundsec==0) { message+='No section or group field specified. '; }
        !           167:     if (vf.startdate.value=='') {
        !           168: 	message+='No starting date set. ';
        !           169:     }
        !           170:     if (vf.enddate.value=='') {
        !           171:         message+='No ending date set. ';
        !           172:     }
        !           173:     if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
        !           174:        if (Math.round(vf.enddate.value)<Math.round(vf.startdate.value)) {
        !           175:           alert('Ending date is before starting date');
        !           176:           return;
        !           177:        }
        !           178:     }
        !           179:     if (message!='') {
        !           180:        message+='Continue enrollment?';
        !           181:        if (confirm(message)) {
        !           182: 	  pclose();
        !           183: 	  vf.submit();
        !           184:        }
        !           185:     } else {
        !           186:       pclose();
        !           187:       vf.submit();
        !           188:     }   
        !           189: }
        !           190: 
        !           191: function setkrb(vf) {
        !           192:     if (vf.krbdom.value!='') {
        !           193:        vf.login[0].checked=true;
        !           194:        vf.krbdom.value=vf.krbdom.value.toUpperCase();
        !           195:        vf.intpwd.value='';
        !           196:    }
        !           197: }
        !           198: 
        !           199: function setint(vf) {
        !           200:     if (vf.intpwd.value!='') {
        !           201:        vf.login[1].checked=true;
        !           202:        vf.krbdom.value='';
        !           203:    }
        !           204: }
        !           205: 
        !           206: function clickkrb(vf) {
        !           207:     vf.krbdom.value='$krbdefdom';
        !           208:     vf.intpwd.value='';
        !           209: }
        !           210: 
        !           211: function clickint(vf) {
        !           212:     vf.krbdom.value='';
        !           213: }
        !           214: </script>
        !           215: <input type=hidden name=makeuser value=1>
        !           216: <h3>Personal Data</h3>
        !           217: First Name: <input type=text name=cfirst size=15><br>
        !           218: Middle Name: <input type=text name=cmiddle size=15><br>
        !           219: Last Name: <input type=text name=clast size=15><br>
        !           220: Generation: <input type=text name=cgen size=5><p>
        !           221: 
        !           222: ID/Student Number: <input type=text name=cstid size=10><p>
        !           223: 
        !           224: Group/Section: <input type=text name=csec size=5><p>
        !           225: 
        !           226: <h3>Login Data</h3>
        !           227: Username: <input type=text name=cuname size=15><p>
        !           228: Domain: <input type=text size=10 value=$defdom name=cdomain><p>
        !           229: Note: login settings below will not take effect if the user already exists<p>
        !           230: 
        !           231: <input type=radio name=login value=krb onClick="clickkrb(this.form);">
        !           232: Kerberos authenticated with domain
        !           233: <input type=text size=10 name=krbdom onChange="setkrb(this.form);"><p>
        !           234: <input type=radio name=login value=int onClick="clickint(this.form);"> 
        !           235: Internally authenticated (with initial password 
        !           236: <input type=text size=10 name=intpwd onChange="setint(this.form);">)
        !           237: ENDNUSER
1.2       www       238:     } else {
                    239: 	$r->print('<h3>Existing user '.$ccuname.' at '.$ccdomain.'</h3>');
                    240:         my $rolesdump=&Apache::lonnet::reply(
                    241:                                   "dump:$ccdomain:$ccuname:roles",$uhome);
                    242:         unless ($rolesdump eq 'con_lost') { 
                    243:            my $now=time;
                    244:            $r->print('<h4>Revoke Existing Roles</h4>'.
                    245:              '<table border=2><tr><th>Revoke</th><th>Role</th><th>Extent</th>'.
                    246: 		     '<th>Start</th><th>End</th>');
                    247:            map {
                    248:              if ($_!~/^rolesdef\&/) {
                    249: 
                    250:               my ($area,$role)=split(/=/,$_);
                    251:               my $thisrole=$area;
                    252:               $area=~s/\_\w\w$//;
                    253:               my ($trole,$tend,$tstart)=split(/_/,$role);
1.3       www       254:               my $bgcol='ffffff';
1.2       www       255:               my $allows=0;
                    256:               if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) {
                    257:                  my %coursedata=&Apache::lonnet::coursedescription($1.'_'.$2);
                    258:                  $area='Course: '.
                    259:                           $coursedata{'description'}.'<br>Section/Group: '.$3;
                    260:                  $inccourses{$1.'_'.$2}=1;
                    261:                  if (&Apache::lonnet::allowed('c'.$trole,$1.'_'.$2)) {
                    262: 		     $allows=1;
                    263:                  }
1.3       www       264:                  $bgcol=$1.'_'.$2;
                    265:                  $bgcol=~s/[^8-9b-e]//g;
                    266:                  $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.2       www       267: 	      } else {
                    268:                  if ($1) {
                    269: 		     $incdomains{$1}=1;
                    270:                      if (&Apache::lonnet::allowed('c'.$trole,$1)) {
                    271: 			 $allows=1;
                    272:                      }
                    273:                  }
                    274: 	      }
                    275: 
                    276:               my $active=1;
                    277:               if (($tend) && ($now>$tend)) { $active=0; }
                    278: 
1.3       www       279:               $r->print('<tr bgcolor=#'.$bgcol.'><td>');
1.2       www       280:               if ($active) {
                    281:                   if ($allows) {
                    282: 		     $r->print(
                    283:                              '<input type=checkbox name="rev:'.$thisrole.'">');
                    284: 		 } else {
                    285:                      $r->print('&nbsp;');
                    286:                  }
                    287:               } else {
                    288:                   $r->print('&nbsp;');
                    289:               }
                    290:               $r->print('</td><td>'.&Apache::lonnet::plaintext($trole).
                    291:                         '</td><td>'.$area.'</td><td>'.
                    292:                         ($tstart?localtime($tstart):'&nbsp;').'</td><td>'.
                    293:                         ($tend?localtime($tend):'&nbsp;')."</td></tr>\n");
                    294: 	     }
                    295: 	   } split(/&/,$rolesdump);
                    296: 	   $r->print('</table>');
                    297:          }   
                    298:     }
                    299:     $r->print('<hr><h4>Add Roles</h4><h5>System Level</h5>');
                    300:     $r->print('<h5>Domain Level</h5>');
                    301:     map {
                    302: 	my $thisdomain=$_;
                    303:         map {
                    304:             if (&Apache::lonnet::allowed('c'.$_,$thisdomain)) {
                    305: 		$r->print($_.' - '.$thisdomain.'<br>');
                    306:             }
                    307:         } ('dc','cc','li','dg','au');
                    308:     } sort keys %incdomains;
1.3       www       309:     $r->print('<h5>Course Level</h5>'.
                    310:     '<table border=2><tr><th>Activate</th><th>Role</th><th>Extent</th>'.
                    311:     '<th>Group/Section</th><th>Start</th><th>End</th></tr>');
1.2       www       312:     map {
                    313: 	my $thiscourse=$_;
1.3       www       314:         my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
                    315:         my $area=$coursedata{'description'};
                    316:         my $bgcol=$thiscourse;
                    317:         $bgcol=~s/[^8-9b-e]//g;
                    318:         $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6);
1.2       www       319:         map {
                    320:             if (&Apache::lonnet::allowed('c'.$_,$thiscourse)) {
1.3       www       321:                my $plrole=&Apache::lonnet::plaintext($_);
                    322:                $r->print(<<ENDROW);
                    323: <tr bgcolor=#$bgcol>
                    324: <td><input type=checkbox name="act_$thiscourse\_$_"></td>
                    325: <td>$plrole</td>
                    326: <td>$area</td>
                    327: <td><input type=text size=5 name="sec_$thiscourse\_$_"></td>
                    328: <td><input type=hidden name="start_$thiscourse\_$_" value=''>
                    329: <a href=
                    330: "javascript:pjump('date_start','Start Date $plrole',document.cu.start_$thiscourse\_$_.value,'start_$thiscourse\_$_','cu.pres','dateset')">Set Start Date</a></td>
                    331: <td><input type=hidden name="end_$thiscourse\_$_" value=''>
                    332: <a href=
                    333: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$thiscourse\_$_.value,'end_$thiscourse\_$_','cu.pres','dateset')">Set End Date</a></td>
                    334: </tr>
                    335: ENDROW
                    336: 
1.2       www       337:             }
                    338:         } ('st','ta','ep','ad','in');
                    339:     } sort keys %inccourses;
1.3       www       340:     $r->print('</table>');
1.4     ! www       341:     $r->print('<input type=submit value="Modify Roles">');
1.2       www       342:     $r->print('</form></body></html>');
                    343: }
1.1       www       344: 
1.4     ! www       345: # ================================================================= Phase Three
        !           346: 
        !           347: sub phase_three {
        !           348:     my $r=shift;
        !           349:     $r->print(<<ENDTHREEHEAD);
        !           350: <html>
        !           351: <head>
        !           352: <title>The LearningOnline Network with CAPA</title>
        !           353: </head>
        !           354: <body bgcolor="#FFFFFF">
        !           355: <img align=right src=/adm/lonIcons/lonlogos.gif>
        !           356: <h1>Create User, Change User Privileges</h1>
        !           357: ENDTHREEHEAD
        !           358:    if ($ENV{'form.makeuser'}) {
        !           359:     $r->print('<h3>Creating User</h3>');
        !           360:     if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
        !           361:         ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
        !           362: 	my $amode='';
        !           363:         my $genpwd='';
        !           364:         if ($ENV{'form.login'} eq 'krb') {
        !           365:            $amode='krb4';
        !           366:            $genpwd=$ENV{'form.krbdom'};
        !           367:         } elsif ($ENV{'form.login'} eq 'int') {
        !           368:            $amode='internal';
        !           369:            $genpwd=$ENV{'form.intpwd'};
        !           370:         }
        !           371:         if (($amode) && ($genpwd)) {
        !           372:  	  &dropstudent($ENV{'form.cdomain'},$ENV{'form.cuname'},
        !           373: 		       $ENV{'request.course.id'},$ENV{'form.csec'});
        !           374:           $r->print(&Apache::lonnet::modifystudent(
        !           375:                       $ENV{'form.cdomain'},$ENV{'form.cuname'},
        !           376:                       $ENV{'form.cstid'},$amode,$genpwd,
        !           377:  	              $ENV{'form.cfirst'},$ENV{'form.cmiddle'},
        !           378:                       $ENV{'form.clast'},$ENV{'form.cgen'},
        !           379:                       $ENV{'form.csec'},$ENV{'form.enddate'},
        !           380:                       $ENV{'form.startdate'}));
        !           381: 	} else {
        !           382:            $r->print('Invalid login mode or password');    
        !           383:         }          
        !           384:     } else {
        !           385:         $r->print('Invalid username or domain');
        !           386:     }
        !           387:    }
        !           388:     $r->print('<h4>'.$ENV{'form.cuname'}.' at '.$ENV{'form.cdomain'}.'</h4>');
        !           389:     my $now=time;
        !           390: # sub assignrole {
        !           391: #    my ($udom,$uname,$url,$role,$end,$start)=@_;
        !           392:     map {
        !           393: 	if (($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
        !           394:            $r->print('Revoking '.$2.' in '.$1.': '.
        !           395:           &Apache::lonnet::assignrole($ENV{'form.cdomain'},$ENV{'form.cuname'},
        !           396:                                       $1,$2,$now).'<br>');
        !           397: 	}
        !           398:     } keys %ENV;
        !           399:     $r->print('</body></html>');
        !           400:     map {
        !           401: 	if (($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_([^\_]+)$/) && ($ENV{$_})) {
        !           402: 	    $r->print('a:'.$_.': '.$1.' '.$2.' '.$3.'<br>');
        !           403: 	}
        !           404:     } keys %ENV;
        !           405: }
        !           406: 
1.2       www       407: # ================================================================ Main Handler
                    408: sub handler {
                    409:     my $r = shift;
                    410: 
                    411:     if ($r->header_only) {
                    412:        $r->content_type('text/html');
                    413:        $r->send_http_header;
                    414:        return OK;
                    415:     }
                    416: 
                    417:     if ((&Apache::lonnet::allowed('cta',$ENV{'request.course.id'})) ||
                    418:         (&Apache::lonnet::allowed('cin',$ENV{'request.course.id'})) || 
                    419:         (&Apache::lonnet::allowed('ccr',$ENV{'request.course.id'})) || 
                    420:         (&Apache::lonnet::allowed('cep',$ENV{'request.course.id'})) ||
                    421:         (&Apache::lonnet::allowed('mau',$ENV{'user.domain'}))) {
                    422:        $r->content_type('text/html');
                    423:        $r->send_http_header;
                    424:        unless ($ENV{'form.phase'}) {
                    425: 	   &phase_one($r);
                    426:        }
                    427:        if ($ENV{'form.phase'} eq 'two') {
                    428:            &phase_two($r);
1.4     ! www       429:        } elsif ($ENV{'form.phase'} eq 'three') {
        !           430:            &phase_three($r);
1.2       www       431:        }
1.1       www       432:    } else {
                    433:       $ENV{'user.error.msg'}=
1.2       www       434:         "/adm/createcourse:mau:0:0:Cannot modify user data";
1.1       www       435:       return HTTP_NOT_ACCEPTABLE; 
                    436:    }
                    437:    return OK;
                    438: } 
                    439: 
                    440: 1;
                    441: __END__
1.2       www       442: 
                    443: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>