version 1.5, 2011/10/27 14:01:21
|
version 1.6, 2011/10/30 16:01:20
|
Line 38 use LONCAPA qw(:DEFAULT :match);
|
Line 38 use LONCAPA qw(:DEFAULT :match);
|
use Apache::lonlocal; |
use Apache::lonlocal; |
use File::Copy; |
use File::Copy; |
use GDBM_File; |
use GDBM_File; |
|
use DBI; |
|
|
my ($lonusersdir,$londocroot,$londaemons); |
my ($lonusersdir,$londocroot,$londaemons,$lonsqlaccess); |
|
|
BEGIN { |
BEGIN { |
my $perlvar=&LONCAPA::Configuration::read_conf(); |
my $perlvar=&LONCAPA::Configuration::read_conf(); |
Line 47 BEGIN {
|
Line 48 BEGIN {
|
$lonusersdir = $perlvar->{'lonUsersDir'}; |
$lonusersdir = $perlvar->{'lonUsersDir'}; |
$londocroot = $perlvar->{'lonDocRoot'}; |
$londocroot = $perlvar->{'lonDocRoot'}; |
$londaemons = $perlvar->{'lonDaemons'}; |
$londaemons = $perlvar->{'lonDaemons'}; |
|
$lonsqlaccess = $perlvar->{'lonSqlAccess'}; |
} |
} |
undef($perlvar); |
undef($perlvar); |
} |
} |
Line 395 if ($action eq 'undo') {
|
Line 397 if ($action eq 'undo') {
|
|
|
my @allskipped; |
my @allskipped; |
my %allmoved; |
my %allmoved; |
|
my ($dbh,$dbflag); |
|
|
# Iterate over directories in /home |
# Iterate over directories in /home |
if (opendir(my $dir,"/home")) { |
if (opendir(my $dir,"/home")) { |
Line 405 if (opendir(my $dir,"/home")) {
|
Line 408 if (opendir(my $dir,"/home")) {
|
# Is there a public_html-directory? |
# Is there a public_html-directory? |
if (-d "/home/$item/public_html") { |
if (-d "/home/$item/public_html") { |
my $author = $item; |
my $author = $item; |
my ($domain,$skipped,$output); |
my ($domain,$skipped,$output,$stopnow); |
if (ref($allauthors{$author}) eq 'ARRAY') { |
if (ref($allauthors{$author}) eq 'ARRAY') { |
($domain,$skipped) = &choose_domain($action,$author,$allauthors{$author}); |
($domain,$skipped,$stopnow) = |
|
&choose_domain($action,$author,$allauthors{$author}); |
|
if ($stopnow) { |
|
if ($action ne 'dryrun') { |
|
my $output = &mt('Stopped by user at author: [_1].', |
|
"'$author'")/"\n"; |
|
&stop_logging($logfh,$output); |
|
} |
|
if ($dbflag == 1) { |
|
&disconnect_mysql($dbh); |
|
} |
|
print &mt('Stopped.')."\n"; |
|
exit; |
|
} |
} |
} |
if (($domain eq '') && (!$skipped)) { |
if (($domain eq '') && (!$skipped)) { |
if (ref($pubusers{$author}) eq 'ARRAY') { |
if (ref($pubusers{$author}) eq 'ARRAY') { |
($domain,$skipped) = &choose_domain($action,$author,$pubusers{$author}); |
($domain,$skipped,$stopnow) = |
|
&choose_domain($action,$author,$pubusers{$author}); |
|
} |
|
if ($stopnow) { |
|
if ($action ne 'dryrun') { |
|
my $output = &mt('Stopped by user at author: [_1].', |
|
"'$author'")/"\n"; |
|
&stop_logging($logfh,$output); |
|
} |
|
if ($dbflag == 1) { |
|
&disconnect_mysql($dbh); |
|
} |
|
print &mt('Stopped.')."\n"; |
|
exit; |
} |
} |
} |
} |
if (($domain eq '') && (!$skipped)) { |
if (($domain eq '') && (!$skipped)) { |
Line 439 if (opendir(my $dir,"/home")) {
|
Line 468 if (opendir(my $dir,"/home")) {
|
} |
} |
} |
} |
if (@foundauthor > 0) { |
if (@foundauthor > 0) { |
($domain,$skipped) = &choose_domain($action,$author,\@foundauthor); |
($domain,$skipped,$stopnow) = |
|
&choose_domain($action,$author,\@foundauthor); |
|
if ($stopnow) { |
|
if ($action ne 'dryrun') { |
|
my $output = &mt('Stopped by user at author: [_1].', |
|
"'$author'")/"\n"; |
|
&stop_logging($logfh,$output); |
|
} |
|
if ($dbflag == 1) { |
|
&disconnect_mysql($dbh); |
|
} |
|
print &mt('Stopped.')."\n"; |
|
exit; |
|
} |
|
} |
|
} |
|
if (($domain eq '') && (!$skipped)) { |
|
if (!$dbflag) { |
|
($dbh,$dbflag) = &connect_mysql($lonsqlaccess); |
|
} |
|
if (defined($dbh)) { |
|
my $foundusers = &search_allusers($dbh,$author); |
|
if (ref($foundusers) eq 'HASH') { |
|
($domain,$skipped,$stopnow) = |
|
&choose_domain($action,$author,$foundusers); |
|
} |
|
if ($stopnow) { |
|
if ($action ne 'dryrun') { |
|
my $output = &mt('Stopped by user at author: [_1].', |
|
"'$author'")/"\n"; |
|
&stop_logging($logfh,$output); |
|
} |
|
if ($dbflag == 1) { |
|
&disconnect_mysql($dbh); |
|
} |
|
print &mt('Stopped.')."\n"; |
|
exit; |
|
} |
} |
} |
} |
} |
my $source_path="/home/$author/public_html"; |
my $source_path="/home/$author/public_html"; |
Line 496 if (opendir(my $dir,"/home")) {
|
Line 562 if (opendir(my $dir,"/home")) {
|
} |
} |
} else { |
} else { |
print '*** '.&mt('WARNING: [_1] has no domain.',"'$author'")."\n". |
print '*** '.&mt('WARNING: [_1] has no domain.',"'$author'")."\n". |
&mt('Enter [_1]: do nothing, continue.','1')."\n". |
&mt('Enter [_1]: skip this user.','1')."\n". |
&mt('Enter [_1]: stop.','2')."\n". |
&mt('Enter [_1]: stop.','2')."\n". |
&mt('or enter domain for user to be placed into')."\n". |
&mt('or enter domain for user to be placed into')."\n". |
&mt('Your input: '); |
&mt('Your input: '); |
Line 520 if (opendir(my $dir,"/home")) {
|
Line 586 if (opendir(my $dir,"/home")) {
|
"'$author'")/"\n"; |
"'$author'")/"\n"; |
&stop_logging($logfh,$output); |
&stop_logging($logfh,$output); |
} |
} |
|
if ($dbflag == 1) { |
|
&disconnect_mysql($dbh); |
|
} |
exit; |
exit; |
} elsif ($choice =~ /^$match_domain$/) { |
} elsif ($choice =~ /^$match_domain$/) { |
print &mt('You entered:')." $choice\n". |
print &mt('You entered:')." $choice\n". |
&mt('Is this ok? ~[Y/n~] '); |
&mt('Is this ok? ~[Y/n~] '); |
if (!&get_user_selection(1)) { |
if (!&get_user_selection(1)) { |
print &mt('Try again ...')."\n". |
print &mt('Try again ...')."\n". |
&mt('Enter [_1]: do nothing, continue.','1')."\n". |
&mt('Enter [_1]: skip this user.','1')."\n". |
&mt('Enter [_1]: stop.','2')."\n". |
&mt('Enter [_1]: stop.','2')."\n". |
&mt('or enter domain for user to be placed into')."\n". |
&mt('or enter domain for user to be placed into')."\n". |
&mt('Your input: '); |
&mt('Your input: '); |
Line 550 if (opendir(my $dir,"/home")) {
|
Line 619 if (opendir(my $dir,"/home")) {
|
"'$author'")/"\n"; |
"'$author'")/"\n"; |
&stop_logging($logfh,$output); |
&stop_logging($logfh,$output); |
} |
} |
|
if ($dbflag == 1) { |
|
&disconnect_mysql($dbh); |
|
} |
exit; |
exit; |
} elsif ($choice !~ /^$match_domain$/) { |
} elsif ($choice !~ /^$match_domain$/) { |
print &mt('Invalid domain entered:')." $choice\n"; |
print &mt('Invalid domain entered:')." $choice\n"; |
Line 630 $skipcount = scalar(@allskipped);
|
Line 702 $skipcount = scalar(@allskipped);
|
print "\n"; |
print "\n"; |
if ($action ne 'dryrun') { |
if ($action ne 'dryrun') { |
my $output = &mt('You skipped: [_1].',$skipcount)."\n". |
my $output = &mt('You skipped: [_1].',$skipcount)."\n". |
|
join("\n",sort(@allskipped))."\n\n". |
&mt('Moved ... [_1]',$moveinfo); |
&mt('Moved ... [_1]',$moveinfo); |
print $output; |
print $output; |
print $logfh $output; |
print $logfh $output; |
&stop_logging($logfh); |
&stop_logging($logfh); |
} else { |
} else { |
print &mt('You would have skipped: [_1].',$skipcount)."\n". |
print &mt('You would have skipped: [_1].',$skipcount)."\n". |
|
join("\n",sort(@allskipped))."\n\n". |
&mt('You would have moved ... [_1]',$moveinfo); |
&mt('You would have moved ... [_1]',$moveinfo); |
} |
} |
print "\n\n".&mt('Done.')."\n"; |
print "\n\n".&mt('Done.')."\n"; |
|
|
sub choose_domain { |
sub choose_domain { |
my ($action,$author,$domarrayref) = @_; |
my ($action,$author,$domref) = @_; |
my ($domain,$skipped); |
my ($domain,$skipped,$stopnow,@domains); |
if (ref($domarrayref) eq 'ARRAY') { |
if (ref($domref) eq 'ARRAY') { |
if (@{$domarrayref} > 1) { |
@domains = @{$domref}; |
print '*** '.&mt('ERROR: [_1] found in multiple domains.',"'$author'")."\n". |
} elsif (ref($domref) eq 'HASH') { |
&mt('Enter a number to choose what action to take.')."\n"; |
@domains = sort(keys(%{$domref})); |
my $num = 1; |
} |
for (my $i=0; $i<@{$domarrayref}; $i++) { |
if (@domains > 1) { |
print &mt('To use: [_1] enter [_2].',$domarrayref->[$i],$num)."\n"; |
print '*** '.&mt('ERROR: [_1] found in multiple domains.',"'$author'")."\n". |
$num ++; |
&mt('Enter a number to choose what action to take.')."\n"; |
} |
my $num = 1; |
print &mt('To skip this user enter: [_1].',$num)."\n". |
print &mt('Enter [_1]: skip this user.',$num)."\n"; |
&mt('Your choice:').' '; |
for (my $i=0; $i<@domains; $i++) { |
my $choice=<STDIN>; |
my $shown = $domains[$i]; |
chomp($choice); |
if (ref($domref) eq 'HASH') { |
if ($choice =~ /^\d+$/) { |
if ($domref->{$shown} ne '') { |
if (($choice == $num) || ($choice > $num)) { |
$shown .= ' ('.$domref->{$shown}.') '; |
$skipped = 1; |
} |
} elsif (($choice < $num) && ($choice > 0)) { |
} |
$domain = $domarrayref->[$choice-1]; |
$num ++; |
} else { |
print &mt('Enter [_1]: use domain - [_2].',$num,$shown)."\n"; |
print &mt('Invalid choice:')." $choice\n"; |
} |
$skipped = 1; |
$num ++; |
} |
print &mt('Enter [_1]: stop.',$num)."\n"; |
} else { |
print &mt('Your choice:').' '; |
print &mt('Invalid choice:')." $choice\n"; |
my $choice=<STDIN>; |
$skipped = 1; |
chomp($choice); |
} |
if ($choice =~ /^\d+$/) { |
} elsif (@{$domarrayref} == 1) { |
if ($choice == 1) { |
$domain = $domarrayref->[0]; |
$skipped = 1; |
} |
} elsif (($choice < $num) && ($choice > 1)) { |
|
$domain = $domains[$choice-2]; |
|
} elsif ($choice == $num) { |
|
$stopnow = 1; |
|
} else { |
|
print &mt('Invalid choice:')." $choice\n". |
|
&mt('Skipping this user.')."\n"; |
|
$skipped = 1; |
|
} |
|
} else { |
|
print &mt('Invalid choice:')." $choice\n". |
|
&mt('Skipping this user.')."\n"; |
|
$skipped = 1; |
|
} |
|
} elsif (@domains == 1) { |
|
$domain = $domains[0]; |
} |
} |
return ($domain,$skipped); |
return ($domain,$skipped,$stopnow); |
} |
} |
|
|
sub move_priv_to_home { |
sub move_priv_to_home { |
Line 791 sub check_for_restore_files {
|
Line 880 sub check_for_restore_files {
|
return; |
return; |
} |
} |
|
|
|
sub connect_mysql { |
|
my ($lonsqlaccess) = @_; |
|
my ($dbh,$dbflag); |
|
eval { $dbh = DBI->connect("DBI:mysql:loncapa","www", |
|
$lonsqlaccess, |
|
{RaiseError =>0,PrintError=>0}); |
|
}; |
|
if ($@) { |
|
$dbflag = -1; |
|
} else { |
|
if (defined($dbh)) { |
|
$dbflag = 1; |
|
} |
|
} |
|
return ($dbh,$dbflag); |
|
} |
|
|
|
sub disconnect_mysql { |
|
my ($dbh) = @_; |
|
if (ref($dbh)) { |
|
$dbh->disconnect; |
|
} |
|
return; |
|
} |
|
|
|
sub search_allusers { |
|
my ($dbh,$author) = @_; |
|
my %fullnames; |
|
if ((ref($dbh)) && ($author ne '')) { |
|
eval { |
|
my $statement = "SELECT domain, lastname, firstname FROM allusers WHERE username='$author'"; |
|
my $sth = $dbh->prepare($statement); |
|
$sth->execute(); |
|
while ( my ($dom,$last,$first) = $sth->fetchrow_array()) { |
|
if ($dom ne '') { |
|
$fullnames{$dom} = "$first $last"; |
|
} |
|
} |
|
$sth->finish; |
|
}; |
|
} |
|
return \%fullnames; |
|
} |