version 1.119, 2019/07/18 18:28:40
|
version 1.123, 2020/05/06 14:31:59
|
Line 46 use GDBM_File;
|
Line 46 use GDBM_File;
|
use Storable qw(thaw); |
use Storable qw(thaw); |
use File::ReadBackwards; |
use File::ReadBackwards; |
use File::Copy; |
use File::Copy; |
|
use Sys::Hostname::FQDN(); |
|
|
#globals |
#globals |
use vars qw (%perlvar %simplestatus $errors $warnings $notices $totalcount); |
use vars qw (%perlvar %simplestatus $errors $warnings $notices $totalcount); |
|
|
Line 495 sub clean_lonIDs {
|
Line 497 sub clean_lonIDs {
|
my $cleaned=0; |
my $cleaned=0; |
my $active=0; |
my $active=0; |
while (my $fname=<$perlvar{'lonIDsDir'}/*>) { |
while (my $fname=<$perlvar{'lonIDsDir'}/*>) { |
my ($dev,$ino,$mode,$nlink, |
my $now=time; |
$uid,$gid,$rdev,$size, |
if (-l $fname) { |
$atime,$mtime,$ctime, |
my $linkfname = readlink($fname); |
$blksize,$blocks)=stat($fname); |
if (-f $linkfname) { |
my $now=time; |
if ($linkfname =~ m{^$perlvar{'lonIDsDir'}/[^/]+\.id$}) { |
my $since=$now-$mtime; |
my @data = stat($linkfname); |
if ($since>$perlvar{'lonExpire'}) { |
my $mtime = $data[9]; |
$cleaned++; |
my $since=$now-$mtime; |
&log($fh,"Unlinking $fname<br />"); |
if ($since>$perlvar{'lonExpire'}) { |
unlink("$fname"); |
if (unlink($linkfname)) { |
} else { |
$cleaned++; |
$active++; |
&log($fh,"Unlinking $linkfname<br />"); |
} |
unlink($fname); |
|
} |
|
} |
|
} |
|
} else { |
|
unlink($fname); |
|
} |
|
} elsif (-f $fname) { |
|
my @data = stat($fname); |
|
my $mtime = $data[9]; |
|
my $since=$now-$mtime; |
|
if ($since>$perlvar{'lonExpire'}) { |
|
if (unlink($fname)) { |
|
$cleaned++; |
|
&log($fh,"Unlinking $fname<br />"); |
|
} |
|
} else { |
|
$active++; |
|
} |
|
} |
} |
} |
&log($fh,"<p>Cleaned up ".$cleaned." stale session token(s).</p>"); |
&log($fh,"<p>Cleaned up ".$cleaned." stale session token(s).</p>"); |
&log($fh,"<h3>$active open session(s)</h3>"); |
&log($fh,"<h3>$active open session(s)</h3>"); |
Line 1096 sub write_hostips {
|
Line 1117 sub write_hostips {
|
if (keys(%prevhosts) && keys(%currhosts)) { |
if (keys(%prevhosts) && keys(%currhosts)) { |
foreach my $key (keys(%prevhosts)) { |
foreach my $key (keys(%prevhosts)) { |
unless ($currhosts{$key} eq $prevhosts{$key}) { |
unless ($currhosts{$key} eq $prevhosts{$key}) { |
$ipchange{$key} = $prevhosts{$key}.'|'.$currhosts{$key}; |
$ipchange{$key} = $prevhosts{$key}.' | '.$currhosts{$key}; |
} |
} |
} |
} |
foreach my $key (keys(%currhosts)) { |
foreach my $key (keys(%currhosts)) { |
Line 1109 sub write_hostips {
|
Line 1130 sub write_hostips {
|
if (keys(%ipchange)) { |
if (keys(%ipchange)) { |
if (open(my $fh,'>>',$perlvar{'lonDaemons'}.'/logs/hostip.log')) { |
if (open(my $fh,'>>',$perlvar{'lonDaemons'}.'/logs/hostip.log')) { |
print $fh "********************\n".localtime(time).' Changes --'."\n". |
print $fh "********************\n".localtime(time).' Changes --'."\n". |
"Hostname | Previous IP | New IP\n". |
"| Hostname | Previous IP | New IP |\n". |
"--------------------------------\n"; |
" --------------------------------- \n"; |
foreach my $hostname (sort(keys(%ipchange))) { |
foreach my $hostname (sort(keys(%ipchange))) { |
print $fh "$hostname | $ipchange{$hostname}\n"; |
print $fh "| $hostname | $ipchange{$hostname} |\n"; |
} |
} |
print $fh "\n*******************\n\n"; |
print $fh "\n*******************\n\n"; |
close($fh); |
close($fh); |
Line 1127 sub write_hostips {
|
Line 1148 sub write_hostips {
|
"MIME-Version: 1.0\n\n". |
"MIME-Version: 1.0\n\n". |
"Host/IP changes\n". |
"Host/IP changes\n". |
" \n". |
" \n". |
"Hostname | Previous IP | New IP\n". |
"| Hostname | Previous IP | New IP |\n". |
"--------------------------------\n"; |
" --------------------------------- \n"; |
foreach my $hostname (sort(keys(%ipchange))) { |
foreach my $hostname (sort(keys(%ipchange))) { |
$chgmail .= "$hostname | $ipchange{$hostname}\n"; |
$chgmail .= "| $hostname | $ipchange{$hostname} |\n"; |
} |
} |
$chgmail .= "\n\n"; |
$chgmail .= "\n\n"; |
if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) { |
if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) { |
Line 1545 sub main () {
|
Line 1566 sub main () {
|
if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) { |
if ('{[[[[lonHostID]]]]}' eq $perlvar{'lonHostID'}) { |
print("Unconfigured machine.\n"); |
print("Unconfigured machine.\n"); |
my $emailto=$perlvar{'lonSysEMail'}; |
my $emailto=$perlvar{'lonSysEMail'}; |
my $hostname=`/bin/hostname`; |
my $hostname = Sys::Hostname::FQDN::fqdn(); |
chop $hostname; |
$hostname=~s/\.+/./g; |
$hostname=~s/[^\w\.]//g; # make sure is safe to pass through shell |
$hostname=~s/\-+/-/g; |
|
$hostname=~s/[^\w\.-]//g; # make sure is safe to pass through shell |
my $subj="LON: Unconfigured machine $hostname"; |
my $subj="LON: Unconfigured machine $hostname"; |
system("echo 'Unconfigured machine $hostname.' |". |
system("echo 'Unconfigured machine $hostname.' |". |
" mail -s '$subj' $emailto > /dev/null"); |
" mail -s '$subj' $emailto > /dev/null"); |