Annotation of loncom/cgi/lonmodulecheck.pl, revision 1.1

1.1     ! raeburn     1: #!/usr/bin/perl
        !             2: $|=1;
        !             3: # Compares checksums for most installed files with expected values
        !             4: # and reports discrepancies.
        !             5: #
        !             6: # $Id: lonmodulecheck.pl,v 1.1 2013/01/30 10:10:02 raeburn Exp $
        !             7: #
        !             8: # Copyright Michigan State University Board of Trustees
        !             9: #
        !            10: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !            11: #
        !            12: # LON-CAPA is free software; you can redistribute it and/or modify
        !            13: # it under the terms of the GNU General Public License as published by
        !            14: # the Free Software Foundation; either version 2 of the License, or
        !            15: # (at your option) any later version.
        !            16: #
        !            17: # LON-CAPA is distributed in the hope that it will be useful,
        !            18: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            19: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            20: # GNU General Public License for more details.
        !            21: #
        !            22: # You should have received a copy of the GNU General Public License
        !            23: # along with LON-CAPA; if not, write to the Free Software
        !            24: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            25: #
        !            26: # /home/httpd/html/adm/gpl.txt
        !            27: #
        !            28: # http://www.lon-capa.org/
        !            29: #
        !            30: 
        !            31: use strict;
        !            32: 
        !            33: use lib '/home/httpd/lib/perl/';
        !            34: use Apache::lonnet();
        !            35: use Apache::lonlocal();
        !            36: use LONCAPA::Configuration();
        !            37: use LONCAPA::loncgi();
        !            38: use LONCAPA::lonauthcgi();
        !            39: use LONCAPA::Checksumming();
        !            40: 
        !            41: my $perlvar=&LONCAPA::Configuration::read_conf('loncapa.conf');
        !            42: my ($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost);
        !            43: if (ref($perlvar) eq 'HASH') {
        !            44:     $londaemons = $perlvar->{'lonDaemons'};
        !            45:     $lonlib = $perlvar->{'lonLib'};
        !            46:     $lonincludes = $perlvar->{'lonIncludes'};
        !            47:     $lontabdir = $perlvar->{'lonTabDir'};
        !            48:     $lonhost = $perlvar->{'lonHostID'}; 
        !            49: }
        !            50: undef($perlvar);
        !            51: 
        !            52: print &LONCAPA::loncgi::cgi_header('text/html',1);
        !            53: if ($londaemons ne '' && $lonlib ne '' && $lonincludes ne '' && 
        !            54:     $lontabdir ne '' && $lonhost ne '') {
        !            55:     &main($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost);
        !            56: }
        !            57: 
        !            58: sub main {
        !            59:     my ($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost) = @_;
        !            60:     if (!&LONCAPA::lonauthcgi::check_ipbased_access('checksums')) {
        !            61:         if (!&LONCAPA::loncgi::check_cookie_and_load_env()) {
        !            62:             &Apache::lonlocal::get_language_handle();
        !            63:             print(&LONCAPA::loncgi::missing_cookie_msg());
        !            64:             return;
        !            65:         }
        !            66: 
        !            67:         if (!&LONCAPA::lonauthcgi::can_view('checksums')) {
        !            68:             &Apache::lonlocal::get_language_handle();
        !            69:             print(&LONCAPA::lonauthcgi::unauthorized_msg('checksums'));
        !            70:             return;
        !            71:         }
        !            72:     }
        !            73: 
        !            74:     &Apache::lonlocal::get_language_handle();
        !            75:     &print_differences($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost);
        !            76:     return;
        !            77: }
        !            78: 
        !            79: sub print_differences {
        !            80:     my ($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost) = @_;
        !            81:     my $machine_dom = &Apache::lonnet::host_domain($lonhost);
        !            82:     my $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);
        !            83:     my ($version,$timestamp) = split(/\-/,$loncaparev);
        !            84:     print(&Apache::loncommon::start_page('LON-CAPA code integrity checking'));
        !            85:     if ($loncaparev =~ /CVS_HEAD/) {
        !            86:         print(&Apache::lonlocal::mt('Code checking unavailable for LON-CAPA CVS HEAD').
        !            87:               "\n");
        !            88:     } else {
        !            89:         print('<h2>'.
        !            90:               &Apache::lonlocal::mt('Code integrity check -- LONCAPA version: [_1]',
        !            91:                                     $version).
        !            92:               '</h2>');
        !            93:         my $distro;
        !            94:         if (open(my $disth,"$londaemons/distprobe |")) {
        !            95:             $distro = <$disth>;
        !            96:             close($disth);
        !            97:         }
        !            98:         if ($distro) {
        !            99:             my ($serversums,$serverversions) =
        !           100:                 &LONCAPA::Checksumming::get_checksums($distro,$londaemons,$lonlib,
        !           101:                                                       $lonincludes,$lontabdir);
        !           102:             if ((ref($serversums) eq 'HASH') && (ref($serverversions) eq 'HASH')) {
        !           103:                 if (keys(%{$serversums}) > 0) {
        !           104:                     my ($result,$numchg) =
        !           105:                         &LONCAPA::Checksumming::compare_checksums('web',$lonhost,
        !           106:                                                                   $version,
        !           107:                                                                   $serversums,
        !           108:                                                                   $serverversions);
        !           109:                     print($result);
        !           110:                 } else {
        !           111:                     print(&Apache::lonlocal::mt('No comparison attempted - failed to retrieve checksums for installed files.'));
        !           112:                 }
        !           113:             } else {
        !           114:                 print(&Apache::lonlocal::mt('No comparison attempted - failed to retrieve checksums for installed files.'));
        !           115:             }
        !           116:         } else {
        !           117:             print(&Apache::lonlocal::mt('No comparison attempted - unable to determine Linux distribution.'));
        !           118:         }
        !           119:     }
        !           120:     print(&Apache::loncommon::end_page());
        !           121:     return;
        !           122: }
        !           123: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>