ENDNEWUSER
} else { # user already exists
$r->print(<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
# 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
'.
- '
Revoke
Role
Extent
'.
- '
Start
End
');
- 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 {
- 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('
+END
+ foreach my $area (keys(%rolesdump)) {
+ 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)) {
+ $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('
');
- }
+ } # End of unless
my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
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
@@ -390,23 +345,27 @@ ENDCHANGEUSER
if (&Apache::lonnet::allowed('mau',$ENV{'user.domain'})) {
$r->print(<
+
ERROR:
This user has an unrecognized authentication scheme ($currentauth).
Please specify login data below.
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.
@@ -418,40 +377,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="
";
}
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=<
@@ -467,11 +409,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
@@ -543,150 +487,280 @@ 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 = '';
+ # Print header
$r->print(<The LearningOnline Network with CAPA
-
-
Create User, Change User Privileges
+
ENDTHREEHEAD
- $r->print('
'.$ENV{'form.cuname'}.' at '.$ENV{'form.cdomain'}.'
');
- if ($ENV{'form.makeuser'}) {
- $r->print('
Creating User
');
- if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
- ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
- my $amode='';
- my $genpwd='';
- if ($ENV{'form.login'} eq 'krb') {
- $amode='krb4';
- $genpwd=$ENV{'form.krbdom'};
- } elsif ($ENV{'form.login'} eq 'int') {
- $amode='internal';
- $genpwd=$ENV{'form.intpwd'};
- } elsif ($ENV{'form.login'} eq 'fsys') {
- $amode='unix';
- $genpwd=$ENV{'form.fsyspwd'};
- } elsif ($ENV{'form.login'} eq 'loc') {
- $amode='localauth';
- $genpwd=$ENV{'form.locarg'};
- if (!$genpwd) { $genpwd=" "; }
- }
- if (($amode) && ($genpwd)) {
- $r->print('Generating user: '.&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'}));
- $r->print(' Home server: '.&Apache::lonnet::homeserver
- ($ENV{'form.cuname'},$ENV{'form.cdomain'}));
-
- } else {
- $r->print('Invalid login mode or password');
- }
+ # Check Inputs
+ if (! $ENV{'form.ccuname'} ) {
+ $r->print($error.'No login name specified.'.$end);
+ return;
+ }
+ if ( $ENV{'form.ccuname'} =~/\W/) {
+ $r->print($error.'Invalid login name. '.
+ 'Only letters, numbers, and underscores are valid.'.
+ $end);
+ return;
+ }
+ if (! $ENV{'form.ccdomain'} ) {
+ $r->print($error.'No domain specified.'.$end);
+ return;
+ }
+ 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.krbarg'};
+ } elsif ($ENV{'form.login'} eq 'int') {
+ $amode='internal';
+ $genpwd=$ENV{'form.intarg'};
+ } elsif ($ENV{'form.login'} eq 'fsys') {
+ $amode='unix';
+ $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('Invalid username or domain');
+ $r->print($error.'Invalid login mode or password'.$end);
+ return;
}
- }
- if (!$ENV{'form.makeuser'} and $ENV{'form.login'} ne 'nop') {
- $r->print('
Changing User Login Data
');
- if (($ENV{'form.cuname'})&&($ENV{'form.cuname'}!~/\W/)&&
- ($ENV{'form.cdomain'})&&($ENV{'form.cdomain'}!~/\W/)) {
- my $amode='';
- my $genpwd='';
- if ($ENV{'form.login'} eq 'krb') {
- $amode='krb4';
- $genpwd=$ENV{'form.krbdom'};
- } elsif ($ENV{'form.login'} eq 'int') {
- $amode='internal';
- $genpwd=$ENV{'form.intpwd'};
- } elsif ($ENV{'form.login'} eq 'fsys') {
- $amode='unix';
- $genpwd=$ENV{'form.fsyspwd'};
- } elsif ($ENV{'form.login'} eq 'loc') {
- $amode='localauth';
- $genpwd=$ENV{'form.locarg'};
- if (!$genpwd) { $genpwd=" "; }
+ if ($ENV{'form.makeuser'}) {
+ # Create a new user
+ $r->print(<Create User
+
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.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);
+ 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.ccuname'}" in domain "$ENV{'form.ccdomain'}"
+ENDMODIFYUSERHEAD
+ if (! $amode || ! $genpwd) {
+ $r->print($error.'Invalid login mode or password'.$end);
+ return;
}
- if (($amode) && ($genpwd)) {
+ # Only allow authentification modification if the person has authority
+ 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 {
- $r->print('Invalid login mode or password');
- }
- } else {
- $r->print('Invalid username or domain');
+ # Okay, this is a non-fatal error.
+ $r->print($error.'You do not have the authority to modify '.
+ 'this users authentification information.');
+ }
}
- }
+ ##
+ 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
+
+
first
+
middle
+
last
+
generation
+
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'}"