version 1.16, 2010/03/21 21:06:00
|
version 1.25, 2022/01/14 16:27:20
|
Line 28
|
Line 28
|
use strict; |
use strict; |
use lib '/home/httpd/lib/perl'; |
use lib '/home/httpd/lib/perl'; |
use localenroll; |
use localenroll; |
|
use GDBM_File; |
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon; |
use Apache::loncommon; |
use Apache::lonlocal; |
use Apache::lonlocal; |
Line 36
|
Line 37
|
use LONCAPA; |
use LONCAPA; |
|
|
my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $perlvarref = LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $logfile = $$perlvarref{'lonDaemons'}.'/logs/autoupdate.log'; |
exit if (ref($perlvarref) ne 'HASH'); |
|
my $logfile = $perlvarref->{'lonDaemons'}.'/logs/autoupdate.log'; |
|
exit if ($perlvarref->{'lonRole'} ne 'library'); |
my $hostid = $perlvarref->{'lonHostID'}; |
my $hostid = $perlvarref->{'lonHostID'}; |
if (!&Apache::lonnet::is_library($hostid)) { |
|
exit; |
|
} |
|
my @info = ('inststatus','lockedname','internalname','lastname', |
my @info = ('inststatus','lockedname','internalname','lastname', |
'firstname','middlename','generation','id','permanentemail'); |
'firstname','middlename','generation','id','permanentemail'); |
# Initialize language handler |
# Initialize language handler |
Line 53
|
Line 54
|
#only run if configured to |
#only run if configured to |
my $run_update = 0; |
my $run_update = 0; |
my $settings; |
my $settings; |
|
my $allowed_inactivity; |
|
my $check_unexpired; |
if (ref($domconfig{'autoupdate'}) eq 'HASH') { |
if (ref($domconfig{'autoupdate'}) eq 'HASH') { |
$settings = $domconfig{'autoupdate'}; |
$settings = $domconfig{'autoupdate'}; |
if ($settings->{'run'} eq '1') { |
if ($settings->{'run'} eq '1') { |
$run_update = 1; |
$run_update = 1; |
} |
} |
|
if ($settings->{'lastactive'} =~/^\d+$/) { |
|
$allowed_inactivity = 86400 * $settings->{'lastactive'}; |
|
} |
|
if ($settings->{'unexpired'}) { |
|
$check_unexpired = 1; |
|
} |
} |
} |
next if (!$run_update); |
next if (!$run_update); |
open(my $fh,">>$logfile"); |
open(my $fh,">>$logfile"); |
print $fh ("********************\n".localtime(time).' '.&mt('Autoupdate messages start for domain: [_1]',$dom).' --'."\n"); |
print $fh ("********************\n".&Apache::lonlocal::locallocaltime(time).' '.&mt('Autoupdate messages start for domain: [_1]',$dom).' --'."\n"); |
# get courseIDs for domain |
# get courseIDs for domain |
my %courses=&Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,[$hostid],'.'); |
my %courses=&Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',1,[$hostid],'.'); |
# get user information |
# get user information |
my (%instusers,%instids); |
my (%users,%instusers,%instids,%counts); |
next if (&localenroll::allusers_info($dom,\%instusers,\%instids) ne 'ok'); |
my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom; |
my (%users,%unamechg,%possnames); |
&descend_tree($dom,$dir,0,\%users,\%courses,$allowed_inactivity,$check_unexpired); |
|
my $resp = &localenroll::allusers_info($dom,\%instusers,\%instids,\%users,\%counts); |
|
if ($resp ne 'ok') { |
|
print $fh &mt('Problem retrieving institutional data for users in domain: [_1].',$dom)."\n". |
|
&mt('Error: [_1].',$resp)."\n". |
|
"-- \n".&Apache::lonlocal::locallocaltime(time).' '. |
|
&mt('Autoupdate messages end')."\n*******************\n\n"; |
|
close($fh); |
|
next; |
|
} else { |
|
if (keys(%counts)) { |
|
foreach my $key (sort(keys(%counts))) { |
|
if ($counts{$key} ne '') { |
|
print $fh "Count for $key = $counts{$key}\n"; |
|
} |
|
} |
|
} |
|
} |
|
my (%unamechg,%possnames); |
my @types = ('active','future'); |
my @types = ('active','future'); |
my @roles = ('st'); |
my @roles = ('st'); |
my @cdoms = ($dom); |
my @cdoms = ($dom); |
my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom; |
foreach my $uname (sort(keys(%users))) { |
&descend_tree($dir,0,\%users); |
|
foreach my $uname (keys(%users)) { |
|
next if ($courses{$dom.'_'.$uname}); |
|
my %userhash = &Apache::lonnet::userenvironment($dom,$uname,@info); |
my %userhash = &Apache::lonnet::userenvironment($dom,$uname,@info); |
my (@inststatuses); |
my (@inststatuses); |
if (!$userhash{'internalname'}) { |
if (!$userhash{'internalname'}) { |
Line 185
|
Line 209
|
} |
} |
|
|
sub descend_tree { |
sub descend_tree { |
my ($dir,$depth,$alldomusers) = @_; |
my ($dom,$dir,$depth,$alldomusers,$coursesref,$allowed_inactivity,$check_unexpired) = @_; |
if (-d $dir) { |
if (-d $dir) { |
opendir(DIR,$dir); |
opendir(DIR,$dir); |
my @contents = grep(!/^\./,readdir(DIR)); |
my @contents = grep(!/^\./,readdir(DIR)); |
closedir(DIR); |
closedir(DIR); |
$depth ++; |
$depth ++; |
foreach my $item (@contents) { |
foreach my $item (@contents) { |
if ($depth < 4) { |
if (($depth < 4) && (length($item) == 1)) { |
&descend_tree($dir.'/'.$item,$depth,$alldomusers); |
&descend_tree($dom,$dir.'/'.$item,$depth,$alldomusers,$coursesref, |
} else { |
$allowed_inactivity,$check_unexpired); |
|
} elsif (-e $dir.'/'.$item.'/passwd') { |
|
if (ref($coursesref) eq 'HASH') { |
|
next if (exists($coursesref->{$dom.'_'.$item})); |
|
} |
|
if ($allowed_inactivity) { |
|
my $now = time; |
|
my $aclog = $dir.'/'.$item.'/activity.log'; |
|
my $roledb = $dir.'/'.$item.'/roles.db'; |
|
if (-e $aclog) { |
|
my $lastac=(stat($aclog))[9]; |
|
if (($now - $lastac) > $allowed_inactivity) { |
|
if (-e $roledb) { |
|
my $lastrolechg=(stat($roledb))[9]; |
|
next if (($now - $lastrolechg) > $allowed_inactivity); |
|
} else { |
|
next; |
|
} |
|
} |
|
} elsif (-e $roledb) { |
|
my $lastrolechg=(stat($roledb))[9]; |
|
next if (($now - $lastrolechg) > $allowed_inactivity); |
|
} else { |
|
next; |
|
} |
|
} |
|
if ($check_unexpired) { |
|
my $roledb = $dir.'/'.$item.'/roles.db'; |
|
my $unexpired = 0; |
|
my $now = time; |
|
if (-e $roledb) { |
|
my $roleshash = &LONCAPA::tie_user_hash($dom,$item,'roles',&GDBM_READER()) or next; |
|
if (ref($roleshash)) { |
|
while (my ($key,$value) = each(%$roleshash)) { |
|
next if ($key =~ /^rolesdef/); |
|
my ($role,$roleend,$rolestart) = split(/\_/,$value); |
|
next if ($role =~ /^gr\//); |
|
if (!$roleend || $roleend > $now) { |
|
$unexpired = 1; |
|
last; |
|
} |
|
} |
|
&LONCAPA::untie_user_hash($roleshash); |
|
next unless ($unexpired); |
|
} else { |
|
next; |
|
} |
|
} else { |
|
next; |
|
} |
|
} |
$$alldomusers{$item} = ''; |
$$alldomusers{$item} = ''; |
} |
} |
} |
} |