File:  [LON-CAPA] / loncom / cgi / lonmodulecheck.pl
Revision 1.5: download - view: text, annotated - select for diffs
Sat May 10 13:58:15 2014 UTC (9 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0, HEAD
- Servers in a single domain might have a different LON-CAPA version
  installed from the primary library server in the domain.

    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.5 2014/05/10 13:58:15 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: use LONCAPA;
   41: 
   42: my $perlvar=&LONCAPA::Configuration::read_conf('loncapa.conf');
   43: my ($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost);
   44: if (ref($perlvar) eq 'HASH') {
   45:     $londaemons = $perlvar->{'lonDaemons'};
   46:     $lonlib = $perlvar->{'lonLib'};
   47:     $lonincludes = $perlvar->{'lonIncludes'};
   48:     $lontabdir = $perlvar->{'lonTabDir'};
   49:     $lonhost = $perlvar->{'lonHostID'}; 
   50: }
   51: undef($perlvar);
   52: 
   53: print &LONCAPA::loncgi::cgi_header('text/html',1);
   54: if ($londaemons ne '' && $lonlib ne '' && $lonincludes ne '' && 
   55:     $lontabdir ne '' && $lonhost ne '') {
   56:     &main($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost);
   57: }
   58: 
   59: sub main {
   60:     my ($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost) = @_;
   61:     if (&LONCAPA::lonauthcgi::check_ipbased_access('checksums')) {
   62:         &LONCAPA::loncgi::check_cookie_and_load_env();
   63:     } else {
   64:         if (!&LONCAPA::loncgi::check_cookie_and_load_env()) {
   65:             &Apache::lonlocal::get_language_handle();
   66:             print(&LONCAPA::loncgi::missing_cookie_msg());
   67:             return;
   68:         }
   69: 
   70:         if (!&LONCAPA::lonauthcgi::can_view('checksums')) {
   71:             &Apache::lonlocal::get_language_handle();
   72:             print(&LONCAPA::lonauthcgi::unauthorized_msg('checksums'));
   73:             return;
   74:         }
   75:     }
   76: 
   77:     &print_differences($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost);
   78:     return;
   79: }
   80: 
   81: sub print_differences {
   82:     my ($londaemons,$lonlib,$lonincludes,$lontabdir,$lonhost) = @_;
   83:     my $machine_dom = &Apache::lonnet::host_domain($lonhost);
   84:     my $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);
   85:     my ($version,$timestamp) = split(/\-/,$loncaparev);
   86:     &Apache::lonlocal::get_language_handle();
   87:     print(&Apache::loncommon::start_page('Code integrity check'));
   88:     if ($loncaparev =~ /CVS_HEAD/) {
   89:         print('<h3>'.
   90:               &Apache::lonlocal::mt('Code checking unavailable for LON-CAPA CVS HEAD').
   91:               '</h3>');
   92:     } else {
   93:         print('<h3>'.
   94:               &Apache::lonlocal::mt('Code integrity check -- LON-CAPA version: [_1]',
   95:                                     $version).
   96:               '</h3>');
   97:         my $distro = &LONCAPA::distro();
   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>