--- loncom/interface/loncreateuser.pm 2002/02/12 21:42:18 1.27 +++ loncom/interface/loncreateuser.pm 2002/04/18 20:16:43 1.30 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.27 2002/02/12 21:42:18 matthew Exp $ +# $Id: loncreateuser.pm,v 1.30 2002/04/18 20:16:43 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -47,7 +47,7 @@ # 11/12,11/13,11/15 Scott Harrison # 02/11/02 Matthew Hall # -# $Id: loncreateuser.pm,v 1.27 2002/02/12 21:42:18 matthew Exp $ +# $Id: loncreateuser.pm,v 1.30 2002/04/18 20:16:43 matthew Exp $ ### package Apache::loncreateuser; @@ -70,109 +70,106 @@ BEGIN { $krbdefdom=~tr/a-z/A-Z/; $authformnop=(< - + Do not change login data

END $authformkrb=(< - + Kerberos authenticated with domain - +

END $authformint=(< - + Internally authenticated (with initial password -) +

END $authformfsys=(< - + Filesystem authenticated (with initial password -) +

END $authformloc=(< - + Local Authentication with argument - +

END $loginscript=(< -function setkrb(vf) { - if (vf.krbdom.value!='') { - vf.login[0].checked=true; - vf.krbdom.value=vf.krbdom.value.toUpperCase(); - vf.intpwd.value=''; - vf.fsyspwd.value=''; - vf.locarg.value=''; - } -} - -function setint(vf) { - if (vf.intpwd.value!='') { - vf.login[1].checked=true; - vf.krbdom.value=''; - vf.fsyspwd.value=''; - vf.locarg.value=''; - } -} - -function setfsys(vf) { - if (vf.fsyspwd.value!='') { - vf.login[2].checked=true; - vf.krbdom.value=''; - vf.intpwd.value=''; - vf.locarg.value=''; - } -} -function setloc(vf) { - if (vf.locarg.value!='') { - vf.login[3].checked=true; - vf.krbdom.value=''; - vf.intpwd.value=''; - vf.fsyspwd.value=''; - } -} - -function clicknop(vf) { - vf.krbdom.value=''; - vf.intpwd.value=''; - vf.fsyspwd.value=''; - vf.locarg.value=''; +var authvalues = new Object(); +authvalues.names = new Array('krbarg','intarg','fsysarg','locarg'); +authvalues.defaults = new Array('MSU.EDU','','',''); + +function changed_radio(choice,currentform) { + var choicearg = choice + 'arg'; + if (currentform.elements[choicearg].value == '') { + clear(currentform,authvalues.names); + for (var i=0; i ENDLOGINSCRIPT $generalrule=< - - ENDFORMINFO my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain); my %incdomains; my %inccourses; + my %home_servers = &get_home_servers($ccdomain); foreach (%Apache::lonnet::hostdom) { $incdomains{$_}=1; } @@ -275,6 +271,13 @@ ENDFORMINFO } } if ($uhome eq 'no_host') { + my $home_server_list= + ''."\n"; + foreach (sort keys(%home_servers)) { + $home_server_list.= + '\n"; + } $r->print(<Create New User @@ -295,9 +298,8 @@ $loginscript ID/Student Number

- +Home Server:
-

Login Data

$generalrule $authformkrb @@ -312,71 +314,98 @@ $dochead $forminfo

User "$ccuname" in domain $ccdomain

ENDCHANGEUSER - my $rolesdump=&Apache::lonnet::reply( - "dump:$ccdomain:$ccuname:roles",$uhome); + # Get the users information + my %userenv = &Apache::lonnet::get('environment', + ['firstname','middlename','lastname','generation'], + $ccdomain,$ccuname); + my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname); + $r->print(< + + + + + +END + foreach ('firstname','middlename','lastname','generation') { + if (&Apache::lonnet::allowed('mau',$ccdomain)) { + $r->print(<<"END"); + +END + } else { + $r->print(''); + } + } + $r->print(< +
first namemiddle namelast namegeneration
'.$userenv{$_}.'
+END # Build up table of user roles to allow revocation of a role. - unless ($rolesdump eq 'con_lost' || $rolesdump =~ m/^error/i) { + my ($tmp) = keys(%rolesdump); + unless ($tmp =~ /^(con_lost|error)/i) { my $now=time; $r->print('

Revoke Existing Roles

'. ''. ''); - foreach (split(/&/,$rolesdump)) { - if ($_!~/^rolesdef\&/) { - my ($area,$role)=split(/=/,$_); - my $thisrole=$area; - $area=~s/\_\w\w$//; - my ($role_code,$role_end_time,$role_start_time)=split(/_/,$role); - my $bgcol='ffffff'; - my $allows=0; - if ($area=~/^\/(\w+)\/(\d\w+)/) { - my %coursedata=&Apache::lonnet::coursedescription($1.'_'.$2); - my $carea='Course: '.$coursedata{'description'}; - $inccourses{$1.'_'.$2}=1; - if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) { - $allows=1; - } - # Compute the background color based on $area - $bgcol=$1.'_'.$2; - $bgcol=~s/[^8-9b-e]//g; - $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6); - if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) { - $carea.='
Section/Group: '.$3; - } - $area=$carea; - } else { - # Determine if current user is able to revoke privileges - if ($area=~/^\/(\w+)\//) { - if (&Apache::lonnet::allowed('c'.$role_code,$1)) { - $allows=1; - } + foreach my $area (keys(%rolesdump)) { + if ($area!~/^rolesdef/) { + my $role = $rolesdump{$area}; + my $thisrole=$area; + $area=~s/\_\w\w$//; + my ($role_code,$role_end_time,$role_start_time) = + split(/_/,$role); + my $bgcol='ffffff'; + my $allows=0; + if ($area=~/^\/(\w+)\/(\d\w+)/) { + my %coursedata= + &Apache::lonnet::coursedescription($1.'_'.$2); + my $carea='Course: '.$coursedata{'description'}; + $inccourses{$1.'_'.$2}=1; + if (&Apache::lonnet::allowed('c'.$role_code,$1.'/'.$2)) { + $allows=1; + } + # Compute the background color based on $area + $bgcol=$1.'_'.$2; + $bgcol=~s/[^8-9b-e]//g; + $bgcol=substr($bgcol.$bgcol.$bgcol.'ffffff',0,6); + if ($area=~/^\/(\w+)\/(\d\w+)\/(\w+)/) { + $carea.='
Section/Group: '.$3; + } + $area=$carea; } else { - if (&Apache::lonnet::allowed('c'.$role_code,'/')) { - $allows=1; + # Determine if current user is able to revoke privileges + if ($area=~/^\/(\w+)\//) { + if (&Apache::lonnet::allowed('c'.$role_code,$1)) { + $allows=1; + } + } else { + if (&Apache::lonnet::allowed('c'.$role_code,'/')) { + $allows=1; + } } } - } - - $r->print('\n"); } - $r->print('\n"); - } - } + } # end of foreach (table building loop) $r->print('
RevokeRoleExtentStartEnd
'); - my $active=1; - if (($role_end_time) && ($now>$role_end_time)) { $active=0; } - if (($active) && ($allows)) { - $r->print(''); - } else { - $r->print(' '); + $r->print('
'); + my $active=1; + $active=0 if (($role_end_time) && ($now>$role_end_time)); + if (($active) && ($allows)) { + $r->print(''); + } else { + $r->print(' '); + } + $r->print(''. + &Apache::lonnet::plaintext($role_code). + ''.$area.''. + ($role_start_time ? localtime($role_start_time) + : ' ' ) + .''. + ($role_end_time ? localtime($role_end_time) + : ' ' ) + ."
'.&Apache::lonnet::plaintext($role_code). - ''.$area.''. - ($role_start_time ? localtime($role_start_time) - : ' ' ) - .''. - ($role_end_time ? localtime($role_end_time) - : ' ' ) - ."
'); - } + } # End of unless my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain); if ($currentauth=~/^krb4:/) { $currentauth=~/^krb4:(.*)/; @@ -545,6 +574,8 @@ ENDDROW # ================================================================= Phase Three sub phase_three { my $r=shift; + my $uhome=&Apache::lonnet::homeserver($ENV{'form.ccuname'}, + $ENV{'form.ccdomain'}); # Error messages my $error = 'Error:'; my $end = ''; @@ -558,69 +589,94 @@ sub phase_three { ENDTHREEHEAD # Check Inputs - if (! $ENV{'form.cuname'} ) { + if (! $ENV{'form.ccuname'} ) { $r->print($error.'No login name specified.'.$end); return; } - if ( $ENV{'form.cuname'} =~/\W/) { + if ( $ENV{'form.ccuname'} =~/\W/) { $r->print($error.'Invalid login name. '. 'Only letters, numbers, and underscores are valid.'. $end); return; } - if (! $ENV{'form.cdomain'} ) { + if (! $ENV{'form.ccdomain'} ) { $r->print($error.'No domain specified.'.$end); return; } - if ( $ENV{'form.cdomain'} =~/\W/) { + if ( $ENV{'form.ccdomain'} =~/\W/) { $r->print($error.'Invalid domain name. '. 'Only letters, numbers, and underscores are valid.'. $end); return; } + if (! exists($ENV{'form.makeuser'})) { + # Modifying an existing user, so check the validity of the name + if ($uhome eq 'no_host') { + $r->print($error.'Unable to determine home server for '. + $ENV{'form.ccuname'}.' in domain '. + $ENV{'form.ccdomain'}.'.'); + return; + } + } # Determine authentication method and password for the user being modified my $amode=''; my $genpwd=''; if ($ENV{'form.login'} eq 'krb') { $amode='krb4'; - $genpwd=$ENV{'form.krbdom'}; + $genpwd=$ENV{'form.krbarg'}; } elsif ($ENV{'form.login'} eq 'int') { $amode='internal'; - $genpwd=$ENV{'form.intpwd'}; + $genpwd=$ENV{'form.intarg'}; } elsif ($ENV{'form.login'} eq 'fsys') { $amode='unix'; - $genpwd=$ENV{'form.fsyspwd'}; + $genpwd=$ENV{'form.fsysarg'}; } elsif ($ENV{'form.login'} eq 'loc') { $amode='localauth'; $genpwd=$ENV{'form.locarg'}; $genpwd=" " if (!$genpwd); + } else { + $r->print($error.'Invalid login mode or password'.$end); + return; } if ($ENV{'form.makeuser'}) { # Create a new user $r->print(<Create User -

Creating user "$ENV{'form.cuname'}" in domain "$ENV{'form.cdomain'}"

+

Creating user "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"

ENDNEWUSERHEAD # Check for the authentication mode and password if (! $amode || ! $genpwd) { $r->print($error.'Invalid login mode or password'.$end); return; } + # Determine desired host + my $desiredhost = $ENV{'form.hserver'}; + if (lc($desiredhost) eq 'default') { + $desiredhost = undef; + } else { + my %home_servers = &get_home_servers($ENV{'form.ccdomain'}); + if (! exists($home_servers{$desiredhost})) { + $r->print($error.'Invalid home server specified'); + return; + } + } # Call modifyuser my $result = &Apache::lonnet::modifyuser - ($ENV{'form.cdomain'},$ENV{'form.cuname'}, - $ENV{'form.cstid'},$amode,$genpwd, - $ENV{'form.cfirst'},$ENV{'form.cmiddle'}, - $ENV{'form.clast'},$ENV{'form.cgen'} + ($ENV{'form.ccdomain'},$ENV{'form.ccuname'},$ENV{'form.cstid'}, + $amode,$genpwd,$ENV{'form.cfirst'}, + $ENV{'form.cmiddle'},$ENV{'form.clast'},$ENV{'form.cgen'}, + undef,$desiredhost ); $r->print('Generating user: '.$result); - $r->print('
Home server: '.&Apache::lonnet::homeserver - ($ENV{'form.cuname'},$ENV{'form.cdomain'})); + my $home = &Apache::lonnet::homeserver($ENV{'form.ccuname'}, + $ENV{'form.ccdomain'}); + $r->print('
Home server: '.$home.' '. + $Apache::lonnet::libserv{$home}); } elsif ($ENV{'form.login'} ne '') { # Modify user privileges $r->print(<Change User Privileges -

User "$ENV{'form.cuname'}" in domain "$ENV{'form.cdomain'}"

+

User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"

ENDMODIFYUSERHEAD if (! $amode || ! $genpwd) { $r->print($error.'Invalid login mode or password'.$end); @@ -630,10 +686,10 @@ ENDMODIFYUSERHEAD if (&Apache::lonnet::allowed('mau',$ENV{'user.domain'})) { $r->print('Modifying authentication: '. &Apache::lonnet::modifyuserauth( - $ENV{'form.cdomain'},$ENV{'form.cuname'}, + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $amode,$genpwd)); $r->print('
Home server: '.&Apache::lonnet::homeserver - ($ENV{'form.cuname'},$ENV{'form.cdomain'})); + ($ENV{'form.ccuname'},$ENV{'form.ccdomain'})); } else { # Okay, this is a non-fatal error. $r->print($error.'You do not have the authority to modify '. @@ -641,6 +697,72 @@ ENDMODIFYUSERHEAD } } ## + if (! $ENV{'form.makeuser'} ) { + # Check for need to change + my %userenv = &Apache::lonnet::get + ('environment',['firstname','middlename','lastname','generation'], + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}); + my ($tmp) = keys(%userenv); + if ($tmp =~ /^(con_lost|error)/i) { + %userenv = (); + } + # Check to see if we need to change user information + foreach ('firstname','middlename','lastname','generation') { + # Strip leading and trailing whitespace + $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; + } + if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'}) && + ($ENV{'form.cfirstname'} ne $userenv{'firstname'} || + $ENV{'form.cmiddlename'} ne $userenv{'middlename'} || + $ENV{'form.clastname'} ne $userenv{'lastname'} || + $ENV{'form.cgeneration'} ne $userenv{'generation'} )) { + # Make the change + my %changeHash; + $changeHash{'firstname'} = $ENV{'form.cfirstname'}; + $changeHash{'middlename'} = $ENV{'form.cmiddlename'}; + $changeHash{'lastname'} = $ENV{'form.clastname'}; + $changeHash{'generation'} = $ENV{'form.cgeneration'}; + my $putresult = &Apache::lonnet::put + ('environment',\%changeHash, + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}); + if ($putresult eq 'ok') { + # Tell the user we changed the name + $r->print(<<"END"); + + + + + + + + + + + + + + + + + +
User Information Changed
 firstmiddlelastgeneration
Previous$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} $userenv{'generation'}
Changed To$ENV{'form.cfirstname'} $ENV{'form.cmiddlename'} $ENV{'form.clastname'} $ENV{'form.cgeneration'}
+END + } else { # error occurred + $r->print("

Unable to successfully change environment for ". + $ENV{'form.ccuname'}." in domain ". + $ENV{'form.ccdomain'}."

"); + } + } else { # End of if ($ENV ... ) logic + # They did not want to change the users name but we can + # still tell them what the name is + $r->print(<<"END"); +

User "$ENV{'form.ccuname'}" in domain "$ENV{'form.ccdomain'}"

+

$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'}

+

Generation: $userenv{'generation'}

+END + } + } + ## my $now=time; $r->print('

Modifying Roles

'); foreach (keys (%ENV)) { @@ -649,8 +771,8 @@ ENDMODIFYUSERHEAD if ($_=~/^form\.rev/) { if ($_=~/^form\.rev\:([^\_]+)\_([^\_]+)$/) { $r->print('Revoking '.$2.' in '.$1.': '. - &Apache::lonnet::assignrole($ENV{'form.cdomain'}, - $ENV{'form.cuname'},$1,$2,$now).'
'); + &Apache::lonnet::assignrole($ENV{'form.ccdomain'}, + $ENV{'form.ccuname'},$1,$2,$now).'
'); if ($2 eq 'st') { $1=~/^\/(\w+)\/(\w+)/; my $cid=$1.'_'.$2; @@ -658,8 +780,8 @@ ENDMODIFYUSERHEAD &Apache::lonnet::critical('put:'. $ENV{'course.'.$cid.'.domain'}.':'. $ENV{'course.'.$cid.'.num'}.':classlist:'. - &Apache::lonnet::escape($ENV{'form.cuname'}.':'. - $ENV{'form.cdomain'}).'='. + &Apache::lonnet::escape($ENV{'form.ccuname'}.':'. + $ENV{'form.ccdomain'}).'='. &Apache::lonnet::escape($now.':'), $ENV{'course.'.$cid.'.home'}).'
'); } @@ -681,7 +803,7 @@ ENDMODIFYUSERHEAD # Assign the role and report it $r->print('Assigning: '.$3.' in '.$url.': '. &Apache::lonnet::assignrole( - $ENV{'form.cdomain'},$ENV{'form.cuname'}, + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $url,$3,$end,$start). '
'); # Handle students differently @@ -693,8 +815,8 @@ ENDMODIFYUSERHEAD 'put:'.$ENV{'course.'.$cid.'.domain'}.':'. $ENV{'course.'.$cid.'.num'}.':classlist:'. &Apache::lonnet::escape( - $ENV{'form.cuname'}.':'. - $ENV{'form.cdomain'} ).'='. + $ENV{'form.ccuname'}.':'. + $ENV{'form.ccdomain'} ).'='. &Apache::lonnet::escape($end.':'.$start), $ENV{'course.'.$cid.'.home'}) .'
'); @@ -712,7 +834,7 @@ ENDMODIFYUSERHEAD # Assign the role and report it. $r->print('Assigning: '.$2.' in '.$url.': '. &Apache::lonnet::assignrole( - $ENV{'form.cdomain'},$ENV{'form.cuname'}, + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}, $url,$2,$end,$start) .'
'); } @@ -811,6 +933,20 @@ ENDTABLE } #---------------------------------------------- end functions for &phase_two +#--------------------------------- functions for &phase_two and &phase_three +sub get_home_servers { + my $domain = shift; + my %home_servers; + foreach (keys(%Apache::lonnet::libserv)) { + if ($Apache::lonnet::hostdom{$_} eq $domain) { + $home_servers{$_} = $Apache::lonnet::hostname{$_}; + } + } + return %home_servers; +} + +#--------------------------end of functions for &phase_two and &phase_three + 1; __END__