version 1.2, 2002/08/03 17:06:21
|
version 1.19, 2004/09/01 16:28:26
|
Line 1
|
Line 1
|
#!/usr/bin/perl |
#!/usr/bin/perl -w |
|
# |
|
# The LearningOnline Network with CAPA |
|
# |
|
# $Id$ |
|
# |
|
# Copyright Michigan State University Board of Trustees |
|
# |
|
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
|
# |
|
# LON-CAPA is free software; you can redistribute it and/or modify |
|
# it under the terms of the GNU General Public License as published by |
|
# the Free Software Foundation; either version 2 of the License, or |
|
# (at your option) any later version. |
|
# |
|
# LON-CAPA is distributed in the hope that it will be useful, |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
# GNU General Public License for more details. |
|
# |
|
# You should have received a copy of the GNU General Public License |
|
# along with LON-CAPA; if not, write to the Free Software |
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
# |
|
# /home/httpd/html/adm/gpl.txt |
|
# |
|
# http://www.lon-capa.org/ |
|
# |
|
# (Navigate problems for statistical reports |
|
# |
|
|
=pod |
=pod |
|
|
=head1 NAME |
=head1 NAME |
|
|
B<CHECKRPMS> - automated status report about RPMs on a system |
B<CHECKRPMS> - automated status report about RPMs on a system. |
|
|
=head1 SYNOPSIS |
|
|
|
./CHECKRPMS |
|
|
|
or |
|
|
|
perl CHECKRPMS |
|
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
This file automates the usage of Martin Siegert's "check-rpms" |
Runs Martin Seigert's checkrpms script. See |
script. It runs through a list of possible mirror sites |
http://www.sfu.ca/acs/security/linux/check-rpms.html for more information. |
until it finds one with a reasonably good FTP connection. |
|
|
|
=head2 Future directions |
|
|
|
Eventually, this script may have a simple argument format |
|
that allows the user to VIEW, DOWNLOAD, or AUTOUPDATE their |
|
computer. Or, this script may evolve into an interactive |
|
series of steps: For example, there may be questions like this: |
|
|
|
=over 4 |
|
|
|
=item * |
|
|
|
Do you want to (D)ownload or (A)utoupdate the RPMs |
|
in the list above? |
|
|
|
=item * |
|
|
|
Specify a download location for the RPMs |
|
(default=/tmp/update_my_rpms/)? |
|
|
|
=back |
|
|
|
Note that there are no current plans to automate a software upgrade of the |
Must be run as root or www. |
kernel. This step should be performed by a qualified system administrator. |
|
|
|
=head1 AUTHOR |
|
|
|
Scott Harrison, sharrison@users.sourceforge.net, 2002 |
|
|
|
=cut |
=cut |
|
|
# =================================================== GENERAL INITIAL VARIABLES |
use strict; |
# ---------------- The FTP servers (and their directory paths) to check against |
use lib '/home/httpd/lib/perl/'; |
my @serverpaths_to_try=( |
use LONCAPA::Configuration; |
'spock.lite.msu.edu/linux/redhat/linux/updates/', |
# |
'mirror234.pa.msu.edu/linux/redhat/linux/updates/', |
# Determine who we email |
'mirror.pa.msu.edu/linux/redhat/linux/updates/', |
my %perlvar=%{LONCAPA::Configuration::read_conf('loncapa.conf')}; |
'rufus.w3.org/linux/redhat/linux/updates/', |
my $emailto = "$perlvar{'lonAdmEMail'}"; |
'distro.ibiblio.org/pub/linux/distributions/redhat/updates/', |
my $subj=$perlvar{'lonHostID'}.' rpm status'; |
'limestone.uoregon.edu/redhat/updates/', |
|
'opnsrc.support.compaq.com/linux/redhat/updates.redhat.com/', |
my $checkrpms = '/usr/local/bin/check-rpms'; |
); |
# |
|
# Check that checkrpms is installed and is the proper version... |
my $RHversion = (split /\s/, `cat /etc/redhat-release`)[4]; # - 6.2 or 7.3 or ? |
my $mailmsg = ''; |
my $checkcommand='check-rpms -ftp '; # -------- use check-rpms command this way |
if (! -e $checkrpms) { |
|
$mailmsg = <<END; |
my $FTPSERVER; # ------------------------- the server portion of the serverpath |
|
my $FTPUPDATES; # ----------------------------- the actual update root location |
Unable to locate check-rpms on your system. Please go to |
my @rpms; # ---------------------------------- this will store the list of RPMs |
http://www.sfu.ca/acs/security/linux/check-rpms.html, download and |
my $goodoutput; # ------------------------------------ good stuff was returned! |
install check-rpms on this system. |
my $reallygoodoutput; # ------------------------------- you are 100% up-to-date |
|
|
|
# ----------------------------------------- Find the check-rpms script location |
|
if (-e './check-rpms') { |
|
$commandpre='perl ./'; |
|
} |
|
elsif (-e 'loncom/build/check-rpms') { |
|
$commandpre='perl loncom/build/'; |
|
} |
|
else { |
|
die("**** ERROR **** CANNOT FIND THE check-rpms SCRIPT\n"); |
|
} |
|
|
|
$checkcommand=$commandpre.$checkcommand; |
|
|
|
# =============== Go through all the servers until a decent connection is found |
|
print(<<END); |
|
THIS SCRIPT IS NOW PROBING SEVERAL FTP SERVERS.... |
|
PLEASE BE PATIENT, THIS MAY TAKE A FEW MINUTES. |
|
END |
END |
|
|
SERVERLOOP: foreach my $serverpath (@serverpaths_to_try) { |
|
$serverpath=~/^(.*?)\//; |
|
$FTPSERVER=$1; |
|
print "Trying $FTPSERVER...\n"; |
|
`ping -q -c 1 $FTPSERVER 2>/dev/null`; |
|
if ($?==0) { |
|
`ncftpls ftp://$FTPSERVER`; |
|
if ($?==0) { |
|
$FTPUPDATES="$serverpath$RHversion/en/os"; |
|
print "$checkcommand $FTPUPDATES\n"; |
|
@rpms=`$checkcommand $FTPUPDATES`; |
|
my $rpmtext=join('',@rpms); |
|
if ($rpmtext=~/This account is currently not/) { # ---------- uh-oh |
|
print "...strange error, moving on ($FTPSERVER)\n"; |
|
} |
|
else { # ------------------------------------- the output is "good" |
|
$goodoutput=$rpmtext; |
|
unless (@rpms) { |
|
$reallygoodoutput=<<END; |
|
**** NOTE **** All RPMS on your system appear to be up to date. |
|
END |
|
} |
|
last SERVERLOOP; |
|
} |
|
} |
|
print "...cannot establish an ftp session with $FTPSERVER\n"; |
|
} |
|
else { |
|
print "...cannot find $FTPSERVER on the network\n"; |
|
} |
|
} |
|
if (!$goodoutput) { |
|
print "**** ERROR **** Cannot find a working ftp server.\n"; |
|
exit(1); |
|
} |
|
elsif ($reallygoodoutput) { |
|
print $reallygoodoutput; |
|
} |
} |
else { |
|
my $rpmcount=scalar(@rpms); |
|
print(<<END); |
|
**** WARNING **** You need to update at least $rpmcount RPMS shown in |
|
the list below. THIS IS IMPORTANT FOR SECURITY. |
|
|
|
END |
# |
print $goodoutput; |
# Run check-rpms and capture its output |
print(<<END); |
$mailmsg = `$checkrpms`; |
|
|
|
# |
|
# Email the user the output of checkrpms |
|
if ($mailmsg ne '') { |
|
$mailmsg =<<"END"; |
|
checkrpms checked the status of the packages on your system and |
|
produced the following output: |
|
------------------------------------------------------- |
|
$mailmsg |
|
------------------------------------------------------- |
|
If there are rpms which need to be installed, please log into |
|
$perlvar{'lonHostID'} and run the following command |
|
|
|
$checkrpms --update |
|
|
|
If there are kernel packages to be installed, use |
|
|
|
$checkrpms --update --install-kernel |
|
|
|
Keeping your system up to date is very important. |
|
Ensuring you are using up to date software is a prerequisite for a |
|
secure system. |
|
|
Please visit ftp://$FTPUPDATES |
|
and download the RPMS you need. |
|
For instructions on working with (and upgrading) RPMS, please |
|
visit http://www.rpm.org/max-rpm/. |
|
END |
END |
|
my $mail_file = '/tmp/CHECKRPMS.'.$$; |
|
open(MAILFILE,">$mail_file") || die("Unable to write to ".$mail_file); |
|
print MAILFILE $mailmsg.$/; |
|
close(MAILFILE); |
|
my $mailcommand = "mail -s '$subj' $emailto <$mail_file"; |
|
print STDERR $mailcommand; |
|
system($mailcommand); |
} |
} |
|
|
|
exit; |