version 1.103.2.4, 2019/07/07 16:15:24
|
version 1.103.2.8, 2020/05/09 19:24:25
|
Line 42 use IO::Socket;
|
Line 42 use IO::Socket;
|
use HTML::Entities; |
use HTML::Entities; |
use Getopt::Long; |
use Getopt::Long; |
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 488 sub clean_lonIDs {
|
Line 490 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>"); |
} |
} |
|
|
|
# -------------------------------------------------------- clean out balanceIDs |
|
|
|
sub clean_balanceIDs { |
|
my ($fh)=@_; |
|
&log($fh,'<hr /><a name="balcookies" /><h2>Session Tokens</h2>'); |
|
my $cleaned=0; |
|
my $active=0; |
|
if (-d $perlvar{'lonBalanceDir'}) { |
|
while (my $fname=<$perlvar{'lonBalanceDir'}/*.id>) { |
|
my ($dev,$ino,$mode,$nlink, |
|
$uid,$gid,$rdev,$size, |
|
$atime,$mtime,$ctime, |
|
$blksize,$blocks)=stat($fname); |
|
my $now=time; |
|
my $since=$now-$mtime; |
|
if ($since>$perlvar{'lonExpire'}) { |
|
$cleaned++; |
|
&log($fh,"Unlinking $fname<br />"); |
|
unlink("$fname"); |
|
} else { |
|
$active++; |
|
} |
|
} |
|
} |
|
&log($fh,"<p>Cleaned up ".$cleaned." stale balancer files</p>"); |
|
&log($fh,"<h3>$active unexpired balancer files</h3>"); |
|
} |
|
|
# ------------------------------------------------ clean out webDAV Session IDs |
# ------------------------------------------------ clean out webDAV Session IDs |
sub clean_webDAV_sessionIDs { |
sub clean_webDAV_sessionIDs { |
my ($fh)=@_; |
my ($fh)=@_; |
Line 865 sub write_hostips {
|
Line 914 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 878 sub write_hostips {
|
Line 927 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 896 sub write_hostips {
|
Line 945 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 1002 sub main () {
|
Line 1051 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"); |
Line 1078 sub main () {
|
Line 1128 sub main () {
|
&log_machine_info($fh); |
&log_machine_info($fh); |
&clean_tmp($fh); |
&clean_tmp($fh); |
&clean_lonIDs($fh); |
&clean_lonIDs($fh); |
|
&clean_balanceIDs($fh); |
&clean_webDAV_sessionIDs($fh); |
&clean_webDAV_sessionIDs($fh); |
&check_httpd_logs($fh); |
&check_httpd_logs($fh); |
&rotate_lonnet_logs($fh); |
&rotate_lonnet_logs($fh); |