--- loncom/configuration/Configuration.pm 2003/04/09 00:52:37 1.9 +++ loncom/configuration/Configuration.pm 2007/08/30 20:19:35 1.14 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Configuration file reader # -# $Id: Configuration.pm,v 1.9 2003/04/09 00:52:37 foxr Exp $ +# $Id: Configuration.pm,v 1.14 2007/08/30 20:19:35 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -34,37 +34,58 @@ package LONCAPA::Configuration; -$VERSION = sprintf("%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/); +$VERSION = sprintf("%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/); use strict; -my $confdir='/etc/httpd/conf/'; +my @confdirs=('/etc/httpd/conf/','/etc/apache2/'); # ------------------- Subroutine read_conf: read LON-CAPA server configuration. # This subroutine reads PerlSetVar values out of specified web server # configuration files. -sub read_conf - { +sub read_conf { my (@conf_files)=@_; - my %perlvar; - foreach my $filename (@conf_files,'loncapa_apache.conf') - { - open(CONFIG,'<'.$confdir.$filename) or - die("Can't read $confdir$filename"); - while (my $configline=) - { - if ($configline =~ /^[^\#]*PerlSetVar/) - { - my ($unused,$varname,$varvalue)=split(/\s+/,$configline); - chomp($varvalue); - $perlvar{$varname}=$varvalue; - } - } - close(CONFIG); - } - my $perlvarref=\%perlvar; - return ($perlvarref); - } + my (%perlvar,%configdirs); + foreach my $filename (@conf_files,'loncapa_apache.conf') { + my $configdir = ''; + $configdirs{$filename} = [@confdirs]; + while ($configdir eq '' && @{$configdirs{$filename}} > 0) { + my $testdir = shift(@{$configdirs{$filename}}); + if (-e $testdir.$filename) { + $configdir = $testdir; + } + } + if ($configdir eq '') { + die("Couldn't find a directory containing $filename"); + } + &process_file($configdir.$filename,\%perlvar); + if ($filename eq 'loncapa_apache.conf') { + my @files = glob($configdir.'loncapa_apache_local*.conf'); + foreach my $file (@files) { + &process_file($file,\%perlvar); + } + } + } + return (\%perlvar); +} + +# --------------- Subroutine process_file: helper routine +# This subroutine does the actual file reading and reads PerlSetVar discovery +# specified file, arguments are the filename and a ref to a hash to +# place the values in +sub process_file { + my ($file,$perlvar) = @_; + open(my $config,'<',$file) or + die("Can't read $file"); + while (my $configline=<$config>) { + if ($configline =~ /^[^\#]*PerlSetVar/) { + my ($unused,$varname,$varvalue)=split(/\s+/,$configline); + chomp($varvalue); + $perlvar->{$varname}=$varvalue; + } + } + close($config); +} #---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab # formatted configuration file. @@ -79,20 +100,24 @@ sub read_hosts { open(CONFIG,'<'.$Filename) or die("Can't read $Filename"); while (my $line = ) { - my @items = split(/:/, $line); - if (scalar @items == $RequiredCount) { # Have only all required items: - $items[$RequiredCount] = $DefaultMaxCon; - } - if(scalar @items == $RequiredCount + 1) { # Have up through maxcon. - $items[$RequiredCount+1] = $DefaultIdle; - } - if(scalar @items == $RequiredCount + 2) { # Have up through idle. - $items[$RequiredCount+2] = $DefaultMinCon; - } - { - my @list = @items; # probably not needed but I'm unsure of - # about the scope of item so... - $HostsTab{@list[0]} = \@list; + if (!($line =~ /^\s*\#/)) { + my @items = split(/:/, $line); + if(scalar @items >= $RequiredCount) { + if (scalar @items == $RequiredCount) { # Only required items: + $items[$RequiredCount] = $DefaultMaxCon; + } + if(scalar @items == $RequiredCount + 1) { # up through maxcon. + $items[$RequiredCount+1] = $DefaultIdle; + } + if(scalar @items == $RequiredCount + 2) { # up through idle. + $items[$RequiredCount+2] = $DefaultMinCon; + } + { + my @list = @items; # probably not needed but I'm unsure of + # about the scope of item so... + $HostsTab{$list[0]} = \@list; + } + } } } close(CONFIG);