--- loncom/interface/loncreateuser.pm 2002/03/22 22:23:23 1.28 +++ loncom/interface/loncreateuser.pm 2002/08/21 17:18:08 1.40 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.28 2002/03/22 22:23:23 matthew Exp $ +# $Id: loncreateuser.pm,v 1.40 2002/08/21 17:18:08 www 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.28 2002/03/22 22:23:23 matthew Exp $ +# $Id: loncreateuser.pm,v 1.40 2002/08/21 17:18:08 www Exp $ ### package Apache::loncreateuser; @@ -68,119 +68,16 @@ BEGIN { $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/; my $krbdefdom=$1; $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=''; -} - -function clickkrb(vf) { - vf.krbdom.value='$krbdefdom'; - vf.intpwd.value=''; - vf.fsyspwd.value=''; - vf.locarg.value=''; -} - -function clickint(vf) { - vf.krbdom.value=''; - vf.fsyspwd.value=''; - vf.locarg.value=''; -} - -function clickfsys(vf) { - vf.krbdom.value=''; - vf.intpwd.value=''; - vf.locarg.value=''; -} - -function clickloc(vf) { - vf.krbdom.value=''; - vf.intpwd.value=''; - vf.fsyspwd.value=''; -} - -ENDLOGINSCRIPT - $generalrule=< -As a general rule, only authors or co-authors should be filesystem -authenticated (which allows access to the server filesystem). -

-END + my %param = ( formname => 'document.cu', + kerb_def_dom => $krbdefdom + ); + $loginscript = &Apache::loncommon::authform_header(%param); + $generalrule = &Apache::loncommon::authform_authorwarning(%param); + $authformnop = &Apache::loncommon::authform_nochange(%param); + $authformkrb = &Apache::loncommon::authform_kerberos(%param); + $authformint = &Apache::loncommon::authform_internal(%param); + $authformfsys = &Apache::loncommon::authform_filesystem(%param); + $authformloc = &Apache::loncommon::authform_local(%param); } # =================================================================== Phase one @@ -188,17 +85,22 @@ END sub phase_one { my $r=shift; my $defdom=$ENV{'user.domain'}; - $r->print(<print(<<"ENDDOCUMENT"); The LearningOnline Network with CAPA - -

Create User, Change User Privileges

+$bodytag
+

Username:
-Domain:

+Domain: $domform +

@@ -215,6 +117,10 @@ sub phase_two { $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/; my $krbdefdom=$1; $krbdefdom=~tr/a-z/A-Z/; + my %param = ( formname => 'document.cu', + kerb_def_dom => $krbdefdom + ); + $loginscript = &Apache::loncommon::authform_header(%param); my $defdom=$ENV{'user.domain'}; @@ -224,7 +130,7 @@ sub phase_two { The LearningOnline Network with CAPA - - - ENDDOCHEAD + $r->print(&Apache::loncommon::bodytag( + 'Create Users, Change User Privileges')); my $forminfo =<<"ENDFORMINFO";
@@ -260,8 +166,6 @@ ENDDOCHEAD - - ENDFORMINFO my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain); my %incdomains; @@ -275,12 +179,18 @@ ENDFORMINFO } } if ($uhome eq 'no_host') { + my $home_server_list= + ''."\n". + &Apache::loncommon::home_server_option_list($ccdomain); + $r->print(<Create New User $forminfo

New user "$ccuname" in domain $ccdomain

+

Personal Data

@@ -295,13 +205,14 @@ $loginscript ID/Student Number

+Home Server:

Login Data

-$generalrule -$authformkrb -$authformint -$authformfsys -$authformloc +

$generalrule

+

$authformkrb

+

$authformint

+

$authformfsys

+

$authformloc

ENDNEWUSER } else { # user already exists $r->print(<print('

Revoke Existing Roles

'. - ''. - ''); + $r->print(< +

Revoke Existing Roles

+
RevokeRoleExtentStartEnd
+ +END 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+)/) { + next 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 $allowed=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)) { + $allowed=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; - } - } else { - if (&Apache::lonnet::allowed('c'.$role_code,'/')) { - $allows=1; - } - } - } - $r->print('\n"); - } + } + $area=$carea; + } else { + # Determine if current user is able to revoke privileges + if ($area=~ /^\/(\w+)\//) { + if (&Apache::lonnet::allowed('c'.$role_code,$1)) { + $allowed=1; + } + } else { + if (&Apache::lonnet::allowed('c'.$role_code,'/')) { + $allowed=1; + } + } + } + # I have no idea what the hell the above code does + # So the following is a check: + if ($allowed) { + # If we are looking at a co-author role, make sure it is + # for the current users construction space before we let + # them revoke it. + if (($role_code eq 'ca') && + ($ENV{'request.role'} !~ /^dc/)) { + if ($area !~ + /^\/$ENV{'user.domain'}\/$ENV{'user.name'}/) { + $allowed = 0; + } + } + } + my $row = ''; + $row.='\n"; + $r->print($row); } # end of foreach (table building loop) $r->print('
RevokeRoleExtentStartEnd
'); - 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) - : ' ' ) - ."
'; + my $active=1; + $active=0 if (($role_end_time) && ($now>$role_end_time)); + if (($active) && ($allowed)) { + $row.= ''; + } else { + $row.=' '; + } + $row.= ''.&Apache::lonnet::plaintext($role_code). + ''.$area. + ''.($role_start_time?localtime($role_start_time) + : ' ' ). + ''.($role_end_time ?localtime($role_end_time) + : ' ' ) + ."
'); } # End of unless @@ -406,7 +332,10 @@ END if ($currentauth=~/^krb4:/) { $currentauth=~/^krb4:(.*)/; my $krbdefdom2=$1; - $loginscript=~s/vf\.krbdom\.value='.*?';/vf.krbdom.value='$krbdefdom2';/; + my %param = ( formname => 'document.cu', + kerb_def_dom => $krbdefdom + ); + $loginscript = &Apache::loncommon::authform_header(%param); } # Check for a bad authentication type unless ($currentauth=~/^krb4:/ or @@ -417,23 +346,27 @@ END if (&Apache::lonnet::allowed('mau',$ENV{'user.domain'})) { $r->print(< + ERROR: This user has an unrecognized authentication scheme ($currentauth). Please specify login data below.

Login Data

-$generalrule -$authformkrb -$authformint -$authformfsys -$authformloc +

$generalrule

+

$authformkrb

+

$authformint

+

$authformfsys

+

$authformloc

ENDBADAUTH } else { # This user is not allowed to modify the users # authentication scheme, so just notify them of the problem $r->print(< + ERROR: This user has an unrecognized authentication scheme ($currentauth). Please alert a domain coordinator of this situation. @@ -445,40 +378,23 @@ ENDBADAUTH my $authform_other=''; if ($currentauth=~/^krb4:/) { $authformcurrent=$authformkrb; - $authform_other=$authformint.$authformfsys.$authformloc; - # embarrassing script hack here - $loginscript=~s/login\[3\]/login\[4\]/; # loc - $loginscript=~s/login\[2\]/login\[3\]/; # fsys - $loginscript=~s/login\[1\]/login\[2\]/; # int - $loginscript=~s/login\[0\]/login\[1\]/; # krb4 + $authform_other="

$authformint

\n". + "

$authformfsys

$authformloc

"; } elsif ($currentauth=~/^internal:/) { $authformcurrent=$authformint; - $authform_other=$authformkrb.$authformfsys.$authformloc; - # embarrassing script hack here - $loginscript=~s/login\[3\]/login\[4\]/; # loc - $loginscript=~s/login\[2\]/login\[3\]/; # fsys - $loginscript=~s/login\[1\]/login\[1\]/; # int - $loginscript=~s/login\[0\]/login\[2\]/; # krb4 + $authform_other="

$authformkrb

". + "

$authformfsys

$authformloc

"; } elsif ($currentauth=~/^unix:/) { $authformcurrent=$authformfsys; - $authform_other=$authformkrb.$authformint.$authformloc; - # embarrassing script hack here - $loginscript=~s/login\[3\]/login\[4\]/; # loc - $loginscript=~s/login\[1\]/login\[3\]/; # int - $loginscript=~s/login\[2\]/login\[1\]/; # fsys - $loginscript=~s/login\[0\]/login\[2\]/; # krb4 + $authform_other="

$authformkrb

". + "

$authformint

$authformloc;

"; } elsif ($currentauth=~/^localauth:/) { $authformcurrent=$authformloc; - $authform_other=$authformkrb.$authformint.$authformfsys; - # embarrassing script hack here - $loginscript=~s/login\[3\]/login\[loc\]/; # loc - $loginscript=~s/login\[2\]/login\[4\]/; # fsys - $loginscript=~s/login\[1\]/login\[3\]/; # int - $loginscript=~s/login\[0\]/login\[2\]/; # krb4 - $loginscript=~s/login\[loc\]/login\[1\]/; # loc + $authform_other="

$authformkrb

". + "

$authformint

$authformfsys

"; } $authformcurrent=< @@ -494,11 +410,13 @@ ENDCURRENTAUTH # Current user has login modification privileges $r->print(< +

Change Current Login Data

-$generalrule -$authformnop -$authformcurrent +

$generalrule

+

$authformnop

+

$authformcurrent

Enter New Login Data

$authform_other ENDOTHERAUTHS @@ -570,6 +488,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 = ''; @@ -579,86 +499,122 @@ sub phase_three { The LearningOnline Network with CAPA - - ENDTHREEHEAD + my $title; + if (exists($ENV{'form.makeuser'})) { + $title='Set Privileges for New User'; + } else { + $title='Modify User Privileges'; + } + $r->print(&Apache::loncommon::bodytag($title)); # 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); + } elsif (($ENV{'form.login'} eq 'nochange') || + ($ENV{'form.login'} eq '' )) { + # There is no need to tell the user we did not change what they + # did not ask us to change. + # If they are creating a new user but have not specified login + # information this will be caught below. + } 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 = &Apache::loncommon::get_library_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'})); - } elsif ($ENV{'form.login'} ne '') { + 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 'nochange') && + ($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); return; } # Only allow authentification modification if the person has authority - if (&Apache::lonnet::allowed('mau',$ENV{'user.domain'})) { + if (&Apache::lonnet::allowed('mau',$ENV{'form.ccdomain'})) { $r->print('Modifying authentication: '. - &Apache::lonnet::modifyuserauth( - $ENV{'form.cdomain'},$ENV{'form.cuname'}, + &Apache::lonnet::modifyuserauth( + $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 '. @@ -670,7 +626,7 @@ ENDMODIFYUSERHEAD # Check for need to change my %userenv = &Apache::lonnet::get ('environment',['firstname','middlename','lastname','generation'], - $ENV{'form.cdomain'},$ENV{'form.cuname'}); + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}); my ($tmp) = keys(%userenv); if ($tmp =~ /^(con_lost|error)/i) { %userenv = (); @@ -680,7 +636,7 @@ ENDMODIFYUSERHEAD # Strip leading and trailing whitespace $ENV{'form.c'.$_} =~ s/(\s+$|^\s+)//g; } - if (&Apache::lonnet::allowed('mau',$ENV{'form.cdomain'}) && + 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'} || @@ -693,7 +649,7 @@ ENDMODIFYUSERHEAD $changeHash{'generation'} = $ENV{'form.cgeneration'}; my $putresult = &Apache::lonnet::put ('environment',\%changeHash, - $ENV{'form.cdomain'},$ENV{'form.cuname'}); + $ENV{'form.ccdomain'},$ENV{'form.ccuname'}); if ($putresult eq 'ok') { # Tell the user we changed the name $r->print(<<"END"); @@ -718,14 +674,14 @@ ENDMODIFYUSERHEAD END } else { # error occurred $r->print("

Unable to successfully change environment for ". - $ENV{'form.cuname'}." in domain ". - $ENV{'form.cdomain'}."

"); + $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.cuname'}" in domain "$ENV{'form.cdomain'}"

+

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

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

Generation: $userenv{'generation'}

END @@ -740,8 +696,8 @@ END 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; @@ -749,8 +705,8 @@ END &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'}).'
'); } @@ -772,7 +728,7 @@ END # 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 @@ -784,8 +740,8 @@ END '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'}) .'
'); @@ -803,7 +759,7 @@ END # 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) .'
'); } @@ -902,6 +858,10 @@ ENDTABLE } #---------------------------------------------- end functions for &phase_two +#--------------------------------- functions for &phase_two and &phase_three + +#--------------------------end of functions for &phase_two and &phase_three + 1; __END__