# Module of TWiki Enterprise Collaboration Platform, http://TWiki.org/ # # Copyright (C) 2000-2018 Peter Thoeny, peter[at]thoeny.org # and TWiki Contributors. All Rights Reserved. TWiki Contributors # are listed in the AUTHORS file in the root of this distribution. # NOTE: Please extend that file, not this notice. # # Additional copyrights apply to some or all of the code in this # file as follows: # # This program 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 3 # of the License, or (at your option) any later version. For # more details read LICENSE in the root of this distribution. # # This program 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. # # As per the GPL, removal of this notice is prohibited. package TWiki::Configure::Checkers::CGISetup; use strict; use base 'TWiki::Configure::Checker'; use File::Spec; sub untaintUnchecked { my ( $string ) = @_; if ( defined( $string) && $string =~ /^(.*)$/ ) { return $1; } return $string; # Can't happen. } sub ui { my $this = shift; my $block = ''; # Detect whether mod_perl was loaded into Apache $TWiki::cfg{DETECTED}{ModPerlLoaded} = ( exists $ENV{SERVER_SOFTWARE} && ( $ENV{SERVER_SOFTWARE} =~ /mod_perl/ )); # Detect whether we are actually running under mod_perl # - test for MOD_PERL alone, which is enough. $TWiki::cfg{DETECTED}{UsingModPerl} = ( exists $ENV{MOD_PERL} ); $TWiki::cfg{DETECTED}{ModPerlVersion} = eval 'use mod_perl; return $mod_perl::VERSION'; # Get the version of mod_perl if it's being used if ( $TWiki::cfg{DETECTED}{UsingModPerl} ) { $block .= $this->setting( '', $this->WARN(<configure with mod_perl. This is risky because mod_perl will remember old values of configuration variables. You are *highly* recommended not to run configure under mod_perl (though the rest of TWiki can be run with mod_perl, of course) HERE } # Check for potential CGI.pm module upgrade # CGI.pm version, on some platforms - actually need CGI 2.93 for # mod_perl 2.0 and CGI 2.90 for Cygwin Perl 5.8.0. See # http://perl.apache.org/products/apache-modules.html#Porting_CPAN_modules_to_mod_perl_2_0_Status if( $CGI::VERSION < 2.93 ) { if ( $Config::Config{osname} eq 'cygwin' && $] >= 5.008 ) { # Recommend CGI.pm upgrade if using Cygwin Perl 5.8.0 $block .= $this->setting( '', $this->WARN( <= 1.99 ) { # Recommend CGI.pm upgrade if using mod_perl 2.0, which # is reported as version 1.99 and implies Apache 2.0 $block .= $this->setting( '', $this->WARN( <setting("Operating system", $n); # Perl version and type $n = $]; $n .= " ($Config::Config{osname})"; $n .= $this->NOTE(<WARN(<setting('Perl version', $n); # Perl @INC (lib path) $block .= $this->setting( '@INC library path', join(CGI::br(), @INC ). $this->NOTE(<setting( 'CGI bin directory', $this->_checkBinDir()); # Turn off fatalsToBrowser while checking module loads, to avoid # load errors in browser in some environments. $CGI::Carp::WRAP = 0; # Avoid warnings... # Check that the TWiki.pm module can be found, but don't croak on # bogus configuration settings $TWiki::cfg{ConfigurationFinished} = 1; eval 'require TWiki'; my $mess = ''; if ($@) { $mess = $@; $mess = $this->ERROR( 'TWiki.pm could not be loaded. The error was:'). CGI::pre($mess). $this->ERROR(<twiki/lib and check that LocalSite.cfg is present and readable HERE } else { $mess = 'TWiki.pm (Version: '.$TWiki::VERSION.') found'; } $block .= $this->setting( 'TWiki module in @INC path', $mess); # Check that each of the required Perl modules can be loaded, and # print its version number. my $set; my $perlModules = $this->_loadDEPENDENCIES(); if (ref($perlModules)) { $set = $this->checkPerlModules( $perlModules ); } else { $set = $this->ERROR($perlModules); } $block .= $this->setting("Perl modules", CGI::start_table({width=>'100%'}). $set.CGI::end_table()); # All module checks done, OK to enable fatalsToBrowser import CGI::Carp qw( fatalsToBrowser ); # PATH_INFO my $url = $TWiki::query->url(); $block .= $this->setting(CGI::a({name=>'PATH_INFO'},'PATH_INFO'), $TWiki::query->path_info(). $this->NOTE(<$url/foo/bar, the correct PATH_INFO is /foo/bar, without any prefixed path components. Test PATH_INFO now - particularly if you are using mod_perl, Apache or IIS, or are using a web hosting provider. Look at the new path info here. It should be /foo/bar. HERE )); # mod_perl if( $TWiki::cfg{DETECTED}{UsingModPerl} ) { $n = "Used for this script"; } else { $n = "Not used for this script"; } $n .= $this->NOTE( 'mod_perl is ', $TWiki::cfg{DETECTED}{ModPerlLoaded} ? '' : 'not', ' loaded into Apache' ); if ( $TWiki::cfg{DETECTED}{ModPerlVersion} ) { $n .= $this->NOTE( 'mod_perl version ', $TWiki::cfg{DETECTED}{ModPerlVersion} ); } # Check for a broken version of mod_perl 2.0 if ( $TWiki::cfg{DETECTED}{UsingModPerl} && $TWiki::cfg{DETECTED}{ModPerlVersion} =~ /1\.99_?11/ ) { # Recommend mod_perl upgrade if using a mod_perl 2.0 version # with PATH_INFO bug (see Support.RegistryCookerBadFileDescriptor # and Bugs:Item82) $n .= $this->ERROR(<setting('mod_perl', $n); $block .= $this->setting( 'CGI user', 'userid = '.$::WebServer_uid.' groups = '. $::WebServer_gid.''. $this->NOTE( 'Your CGI scripts are executing as this user.')); $block .= $this->setting( 'Original PATH', $TWiki::cfg{DETECTED}{originalPath}. $this->NOTE(<setting("Current PATH", $currentPath, $this->NOTE(<foldableBlock( CGI::em( 'CGI Setup' ), '(read only) ', $block); }; sub _checkBinDir { my $this = shift; my $dir = $ENV{SCRIPT_FILENAME} || '.'; $dir =~ s(/+configure[^/]*$)(); my $ext = $TWiki::cfg{ScriptSuffix} || ''; my $errs = ''; opendir(D, $dir) || return $this->ERROR(<WARN(<splitdir( $from ); pop(@dir); # Cutting off trailing TWiki.spec gives us lib dir $from = File::Spec->catfile(@dir, 'DEPENDENCIES'); my $d; open($d, '<'.$from) || return 'Failed to load DEPENDENCIES: '.$!; my @perlModules; foreach my $line ( <$d> ) { next unless $line; my @row = split(/,\s*/, $line, 4); next unless (scalar(@row) == 4 && $row[2] eq 'cpan'); my $ver = $row[1]; $ver =~ s/[<>=]//g; $row[0] =~ /([\w:]+)/; # check and untaint my $modname = $1; my ($dispo,$usage) = $row[3] =~ /^\s*(\w+).?(.*)$/; push(@perlModules, { name => $modname, usage => $usage, minimumVersion => $ver, disposition => lc($dispo) }); } close($d); return \@perlModules; } 1;