version 1.168, 2003/12/22 12:01:54
|
version 1.175, 2004/02/17 20:07:25
|
Line 46 use Authen::Krb5;
|
Line 46 use Authen::Krb5;
|
use lib '/home/httpd/lib/perl/'; |
use lib '/home/httpd/lib/perl/'; |
use localauth; |
use localauth; |
use File::Copy; |
use File::Copy; |
|
use LONCAPA::ConfigFileEdit; |
|
|
my $DEBUG = 0; # Non zero to enable debug log entries. |
my $DEBUG = 0; # Non zero to enable debug log entries. |
|
|
Line 349 sub InstallFile {
|
Line 350 sub InstallFile {
|
|
|
return 1; |
return 1; |
} |
} |
|
# |
|
# ConfigFileFromSelector: converts a configuration file selector |
|
# (one of host or domain at this point) into a |
|
# configuration file pathname. |
|
# |
|
# Parameters: |
|
# selector - Configuration file selector. |
|
# Returns: |
|
# Full path to the file or undef if the selector is invalid. |
|
# |
|
sub ConfigFileFromSelector { |
|
my $selector = shift; |
|
my $tablefile; |
|
|
|
my $tabledir = $perlvar{'lonTabDir'}.'/'; |
|
if ($selector eq "hosts") { |
|
$tablefile = $tabledir."hosts.tab"; |
|
} elsif ($selector eq "domain") { |
|
$tablefile = $tabledir."domain.tab"; |
|
} else { |
|
return undef; |
|
} |
|
return $tablefile; |
|
|
|
} |
# |
# |
# PushFile: Called to do an administrative push of a file. |
# PushFile: Called to do an administrative push of a file. |
# - Ensure the file being pushed is one we support. |
# - Ensure the file being pushed is one we support. |
Line 379 sub PushFile {
|
Line 404 sub PushFile {
|
# part of some elaborate spoof that managed somehow to authenticate. |
# part of some elaborate spoof that managed somehow to authenticate. |
# |
# |
|
|
my $tablefile = $perlvar{'lonTabDir'}.'/'; # need to precede with dir. |
|
if ($filename eq "host") { |
my $tablefile = ConfigFileFromSelector($filename); |
$tablefile .= "hosts.tab"; |
if(! (defined $tablefile)) { |
} elsif ($filename eq "domain") { |
|
$tablefile .= "domain.tab"; |
|
} else { |
|
return "refused"; |
return "refused"; |
} |
} |
# |
# |
Line 508 sub isValidEditCommand {
|
Line 530 sub isValidEditCommand {
|
} else { |
} else { |
return 1; # Valid syntax. |
return 1; # Valid syntax. |
} |
} |
} elsif (($command eq "append") || ($command eq "replace")) { |
} elsif ($command eq "replace") { |
# |
# |
# key and newline: |
# key and newline: |
# |
# |
Line 517 sub isValidEditCommand {
|
Line 539 sub isValidEditCommand {
|
} else { |
} else { |
return 1; |
return 1; |
} |
} |
|
} elsif ($command eq "append") { |
|
if (($key ne "") && ($newline eq "")) { |
|
return 1; |
|
} else { |
|
return 0; |
|
} |
} else { |
} else { |
return 0; # Invalid command. |
return 0; # Invalid command. |
} |
} |
return 0; # Should not get here!!! |
return 0; # Should not get here!!! |
} |
} |
|
# |
|
# ApplyEdit - Applies an edit command to a line in a configuration |
|
# file. It is the caller's responsiblity to validate the |
|
# edit line. |
|
# Parameters: |
|
# $directive - A single edit directive to apply. |
|
# Edit directives are of the form: |
|
# append|newline - Appends a new line to the file. |
|
# replace|key|newline - Replaces the line with key value 'key' |
|
# delete|key - Deletes the line with key value 'key'. |
|
# $editor - A config file editor object that contains the |
|
# file being edited. |
|
# |
|
sub ApplyEdit { |
|
my $directive = shift; |
|
my $editor = shift; |
|
|
|
# Break the directive down into its command and its parameters |
|
# (at most two at this point. The meaning of the parameters, if in fact |
|
# they exist depends on the command). |
|
|
|
my ($command, $p1, $p2) = split(/\|/, $directive); |
|
|
|
if($command eq "append") { |
|
$editor->Append($p1); # p1 - key p2 null. |
|
} elsif ($command eq "replace") { |
|
$editor->ReplaceLine($p1, $p2); # p1 - key p2 = newline. |
|
} elsif ($command eq "delete") { |
|
$editor->DeleteLine($p1); # p1 - key p2 null. |
|
} else { # Should not get here!!! |
|
die "Invalid command given to ApplyEdit $command" |
|
} |
|
} |
|
# |
|
# AdjustOurHost: |
|
# Adjusts a host file stored in a configuration file editor object |
|
# for the true IP address of this host. This is necessary for hosts |
|
# that live behind a firewall. |
|
# Those hosts have a publicly distributed IP of the firewall, but |
|
# internally must use their actual IP. We assume that a given |
|
# host only has a single IP interface for now. |
|
# Formal Parameters: |
|
# editor - The configuration file editor to adjust. This |
|
# editor is assumed to contain a hosts.tab file. |
|
# Strategy: |
|
# - Figure out our hostname. |
|
# - Lookup the entry for this host. |
|
# - Modify the line to contain our IP |
|
# - Do a replace for this host. |
|
sub AdjustOurHost { |
|
my $editor = shift; |
|
|
|
# figure out who I am. |
|
|
|
my $myHostName = $perlvar{'lonHostID'}; # LonCAPA hostname. |
|
|
|
# Get my host file entry. |
|
|
|
my $ConfigLine = $editor->Find($myHostName); |
|
if(! (defined $ConfigLine)) { |
|
die "AdjustOurHost - no entry for me in hosts file $myHostName"; |
|
} |
|
# figure out my IP: |
|
# Use the config line to get my hostname. |
|
# Use gethostbyname to translate that into an IP address. |
|
# |
|
my ($id,$domain,$role,$name,$ip,$maxcon,$idleto,$mincon) = split(/:/,$ConfigLine); |
|
my $BinaryIp = gethostbyname($name); |
|
my $ip = inet_ntoa($ip); |
|
# |
|
# Reassemble the config line from the elements in the list. |
|
# Note that if the loncnew items were not present before, they will |
|
# be now even if they would be empty |
|
# |
|
my $newConfigLine = $id; |
|
foreach my $item ($domain, $role, $name, $ip, $maxcon, $idleto, $mincon) { |
|
$newConfigLine .= ":".$item; |
|
} |
|
# Replace the line: |
|
|
|
$editor->ReplaceLine($id, $newConfigLine); |
|
|
|
} |
|
# |
|
# ReplaceConfigFile: |
|
# Replaces a configuration file with the contents of a |
|
# configuration file editor object. |
|
# This is done by: |
|
# - Copying the target file to <filename>.old |
|
# - Writing the new file to <filename>.tmp |
|
# - Moving <filename.tmp> -> <filename> |
|
# This laborious process ensures that the system is never without |
|
# a configuration file that's at least valid (even if the contents |
|
# may be dated). |
|
# Parameters: |
|
# filename - Name of the file to modify... this is a full path. |
|
# editor - Editor containing the file. |
|
# |
|
sub ReplaceConfigFile { |
|
my $filename = shift; |
|
my $editor = shift; |
|
|
|
CopyFile ($filename, $filename.".old"); |
|
|
|
my $contents = $editor->Get(); # Get the contents of the file. |
|
|
|
InstallFile($filename, $contents); |
|
} |
# |
# |
# |
# |
# Called to edit a configuration table file |
# Called to edit a configuration table file |
Line 560 sub EditFile {
|
Line 695 sub EditFile {
|
} |
} |
|
|
# Execute the edit operation. |
# Execute the edit operation. |
|
# - Create a config file editor for the appropriate file and |
|
# - execute each command in the script: |
|
# |
|
my $configfile = ConfigFileFromSelector($filetype); |
|
if (!(defined $configfile)) { |
|
return "refused\n"; |
|
} |
|
my $editor = ConfigFileEdit->new($configfile); |
|
|
|
for (my $i = 0; $i < $linecount; $i++) { |
|
ApplyEdit($scriptlines[$i], $editor); |
|
} |
|
# If the file is the host file, ensure that our host is |
|
# adjusted to have our ip: |
|
# |
|
if($filetype eq "host") { |
|
AdjustOurHost($editor); |
|
} |
|
# Finally replace the current file with our file. |
|
# |
|
ReplaceConfigFile($configfile, $editor); |
|
|
return "ok\n"; |
return "ok\n"; |
} |
} |
Line 662 my $children = 0; #
|
Line 817 my $children = 0; #
|
sub REAPER { # takes care of dead children |
sub REAPER { # takes care of dead children |
$SIG{CHLD} = \&REAPER; |
$SIG{CHLD} = \&REAPER; |
&status("Handling child death"); |
&status("Handling child death"); |
my $pid = wait; |
my $pid; |
if (defined($children{$pid})) { |
do { |
&logthis("Child $pid died"); |
$pid = waitpid(-1,&WNOHANG()); |
$children --; |
if (defined($children{$pid})) { |
delete $children{$pid}; |
&logthis("Child $pid died"); |
} else { |
$children --; |
&logthis("Unknown Child $pid died"); |
delete $children{$pid}; |
} |
} else { |
|
&logthis("Unknown Child $pid died"); |
|
} |
|
} while ( $pid > 0 ); |
&status("Finished Handling child death"); |
&status("Finished Handling child death"); |
} |
} |
|
|
Line 865 sub logstatus {
|
Line 1023 sub logstatus {
|
my $docdir=$perlvar{'lonDocRoot'}; |
my $docdir=$perlvar{'lonDocRoot'}; |
{ |
{ |
my $fh=IO::File->new(">>$docdir/lon-status/londstatus.txt"); |
my $fh=IO::File->new(">>$docdir/lon-status/londstatus.txt"); |
print $fh $$."\t".$currenthostid."\t".$status."\t".$lastlog."\n"; |
print $fh $$."\t".$clientname."\t".$currenthostid."\t".$status."\t".$lastlog."\n"; |
$fh->close(); |
$fh->close(); |
} |
} |
&status("Finished londstatus.txt"); |
&status("Finished londstatus.txt"); |
Line 1538 sub make_new_child {
|
Line 1696 sub make_new_child {
|
unless (mkdir($fpnow,0777)) { |
unless (mkdir($fpnow,0777)) { |
$fperror="error: ".($!+0) |
$fperror="error: ".($!+0) |
." mkdir failed while attempting " |
." mkdir failed while attempting " |
."makeuser\n"; |
."makeuser"; |
} |
} |
} |
} |
} |
} |
Line 2569 sub make_new_child {
|
Line 2727 sub make_new_child {
|
# -------------------------------------------------------------------------- ls |
# -------------------------------------------------------------------------- ls |
} elsif ($userinput =~ /^ls/) { |
} elsif ($userinput =~ /^ls/) { |
if(isClient) { |
if(isClient) { |
|
my $obs; |
|
my $rights; |
my ($cmd,$ulsdir)=split(/:/,$userinput); |
my ($cmd,$ulsdir)=split(/:/,$userinput); |
my $ulsout=''; |
my $ulsout=''; |
my $ulsfn; |
my $ulsfn; |
Line 2576 sub make_new_child {
|
Line 2736 sub make_new_child {
|
if(-d $ulsdir) { |
if(-d $ulsdir) { |
if (opendir(LSDIR,$ulsdir)) { |
if (opendir(LSDIR,$ulsdir)) { |
while ($ulsfn=readdir(LSDIR)) { |
while ($ulsfn=readdir(LSDIR)) { |
|
undef $obs, $rights; |
my @ulsstats=stat($ulsdir.'/'.$ulsfn); |
my @ulsstats=stat($ulsdir.'/'.$ulsfn); |
$ulsout.=$ulsfn.'&'. |
#We do some obsolete checking here |
join('&',@ulsstats).':'; |
if(-e $ulsdir.'/'.$ulsfn.".meta") { |
|
open(FILE, $ulsdir.'/'.$ulsfn.".meta"); |
|
my @obsolete=<FILE>; |
|
foreach my $obsolete (@obsolete) { |
|
if($obsolete =~ m|(<obsolete>)(on)|) { $obs = 1; } |
|
if($obsolete =~ m|(<copyright>)(default)|) { $rights = 1; } |
|
} |
|
} |
|
$ulsout.=$ulsfn.'&'.join('&',@ulsstats); |
|
if($obs eq '1') { $ulsout.="&1"; } |
|
else { $ulsout.="&0"; } |
|
if($rights eq '1') { $ulsout.="&1:"; } |
|
else { $ulsout.="&0:"; } |
} |
} |
closedir(LSDIR); |
closedir(LSDIR); |
} |
} |
Line 2689 sub ManagePermissions
|
Line 2862 sub ManagePermissions
|
my $authtype= shift; |
my $authtype= shift; |
|
|
# See if the request is of the form /$domain/_au |
# See if the request is of the form /$domain/_au |
&logthis("ruequest is $request"); |
|
if($request =~ /^(\/$domain\/_au)$/) { # It's an author rolesput... |
if($request =~ /^(\/$domain\/_au)$/) { # It's an author rolesput... |
my $execdir = $perlvar{'lonDaemons'}; |
my $execdir = $perlvar{'lonDaemons'}; |
my $userhome= "/home/$user" ; |
my $userhome= "/home/$user" ; |