version 1.43, 2006/09/15 20:49:24
|
version 1.48, 2010/07/06 07:48:38
|
Line 43 use LONCAPA::lonssl;
|
Line 43 use LONCAPA::lonssl;
|
|
|
|
|
my $DebugLevel=0; |
my $DebugLevel=0; |
my %hostshash; |
|
my %perlvar; |
my %perlvar; |
my $LocalDns = ""; # Need not be defined for managers. |
|
my $InsecureOk; |
my $InsecureOk; |
|
|
# |
# |
Line 71 sub ReadConfig {
|
Line 69 sub ReadConfig {
|
|
|
my $perlvarref = read_conf('loncapa.conf'); |
my $perlvarref = read_conf('loncapa.conf'); |
%perlvar = %{$perlvarref}; |
%perlvar = %{$perlvarref}; |
my $hoststab = read_hosts( |
|
"$perlvar{lonTabDir}/hosts.tab") || |
|
die "Can't read host table!!"; |
|
%hostshash = %{$hoststab}; |
|
$ConfigRead = 1; |
$ConfigRead = 1; |
|
|
my $myLonCapaName = $perlvar{lonHostID}; |
|
Debug(8, "My loncapa name is $myLonCapaName"); |
|
|
|
if(defined $hostshash{$myLonCapaName}) { |
|
Debug(8, "My loncapa name is in hosthash"); |
|
my @ConfigLine = @{$hostshash{$myLonCapaName}}; |
|
$LocalDns = $ConfigLine[3]; |
|
Debug(8, "Got local name $LocalDns"); |
|
} |
|
$InsecureOk = $perlvar{loncAllowInsecure}; |
|
|
|
Debug(3, "ReadConfig - LocalDNS = $LocalDns"); |
|
} |
|
|
|
# |
|
# Read a foreign configuration. |
|
# This sub is intended for the cases where the package |
|
# will be read from outside the LonCAPA environment, in that case |
|
# the client will need to explicitly provide: |
|
# - A file in hosts.tab format. |
|
# - Some idea of the 'lonCAPA' name of the local host (for building |
|
# the encryption key). |
|
# |
|
# Parameters: |
|
# MyHost - Name of this host as far as LonCAPA is concerned. |
|
# Filename - Name of a hosts.tab formatted file that will be used |
|
# to build up the hosts table. |
|
# |
|
sub ReadForeignConfig { |
|
|
|
my ($MyHost, $Filename) = @_; |
|
|
|
&Debug(4, "ReadForeignConfig $MyHost $Filename\n"); |
|
|
|
$perlvar{lonHostID} = $MyHost; # Rmember my host. |
|
my $hosttab = read_hosts($Filename) || |
|
die "Can't read hosts table!!"; |
|
%hostshash = %{$hosttab}; |
|
if($DebugLevel > 3) { |
|
foreach my $host (keys %hostshash) { |
|
print STDERR "host $host => $hostshash{$host}\n"; |
|
} |
|
} |
|
$ConfigRead = 1; |
|
|
|
my $myLonCapaName = $perlvar{lonHostID}; |
|
|
|
if(defined $hostshash{$myLonCapaName}) { |
|
my @ConfigLine = @{$hostshash{$myLonCapaName}}; |
|
$LocalDns = $ConfigLine[3]; |
|
} |
|
$InsecureOk = $perlvar{loncAllowInsecure}; |
$InsecureOk = $perlvar{loncAllowInsecure}; |
|
|
Debug(3, "ReadForeignConfig - LocalDNS = $LocalDns"); |
|
|
|
} |
} |
|
|
sub Debug { |
sub Debug { |
Line 213 host the remote lond is on. This host is
|
Line 153 host the remote lond is on. This host is
|
=cut |
=cut |
|
|
sub new { |
sub new { |
my ($class, $DnsName, $Port) = @_; |
my ($class, $DnsName, $Port, $lonid) = @_; |
|
|
if (!$ConfigRead) { |
if (!$ConfigRead) { |
ReadConfig(); |
ReadConfig(); |
$ConfigRead = 1; |
$ConfigRead = 1; |
} |
} |
&Debug(4,$class."::new( ".$DnsName.",".$Port.")\n"); |
&Debug(4,$class."::new( ".$DnsName.",".$Port.",".$lonid.")\n"); |
|
|
# The host must map to an entry in the hosts table: |
# The host must map to an entry in the hosts table: |
# We connect to the dns host that corresponds to that |
# We connect to the dns host that corresponds to that |
Line 227 sub new {
|
Line 167 sub new {
|
# negotion. In the objec these become the Host and |
# negotion. In the objec these become the Host and |
# LoncapaHim fields of the object respectively. |
# LoncapaHim fields of the object respectively. |
# |
# |
if (!exists $hostshash{$DnsName}) { |
|
&Debug(8, "No Such host $DnsName"); |
|
return undef; # No such host!!! |
|
} |
|
my @ConfigLine = @{$hostshash{$DnsName}}; |
|
my $Hostname = $ConfigLine[0]; # 0'th item is the msu id of host. |
|
Debug(5, "Connecting to ".$DnsName); |
|
# if it is me use loopback for connection |
# if it is me use loopback for connection |
if ($DnsName eq $LocalDns) { $DnsName="127.0.0.1"; } |
if ($DnsName eq &main::my_hostname()) { $DnsName="127.0.0.1"; } |
Debug(8, "Connecting to $DnsName I am $LocalDns"); |
Debug(9, "Connecting to $DnsName"); |
# Now create the object... |
# Now create the object... |
my $self = { Host => $DnsName, |
my $self = { Host => $DnsName, |
LoncapaHim => $Hostname, |
LoncapaHim => $lonid, |
Port => $Port, |
Port => $Port, |
State => "Initialized", |
State => "Initialized", |
AuthenticationMode => "", |
AuthenticationMode => "", |
Line 251 sub new {
|
Line 184 sub new {
|
TimeoutCallback => undef, |
TimeoutCallback => undef, |
TransitionCallback => undef, |
TransitionCallback => undef, |
Timeoutable => 0, |
Timeoutable => 0, |
TimeoutValue => 30, |
TimeoutValue => 300, |
TimeoutRemaining => 0, |
TimeoutRemaining => 0, |
LocalKeyFile => "", |
LocalKeyFile => "", |
CipherKey => "", |
CipherKey => "", |
Line 308 sub new {
|
Line 241 sub new {
|
if((defined $ca) && (defined $cert) && (defined $sslkeyfile)) { |
if((defined $ca) && (defined $cert) && (defined $sslkeyfile)) { |
|
|
$self->{AuthenticationMode} = "ssl"; |
$self->{AuthenticationMode} = "ssl"; |
$self->{TransactionRequest} = "init:ssl\n"; |
$self->{TransactionRequest} = "init:ssl:$perlvar{'lonVersion'}\n"; |
} else { |
} else { |
if($InsecureOk) { # Allowed to do insecure: |
if($InsecureOk) { # Allowed to do insecure: |
$self->{AuthenticationMode} = "insecure"; |
$self->{AuthenticationMode} = "insecure"; |
$self->{TransactionRequest} = "init\n"; |
$self->{TransactionRequest} = "init::$perlvar{'lonVersion'}\n"; |
} |
} |
else { # Not allowed to do insecure... |
else { # Not allowed to do insecure... |
$socket->close; |
$socket->close; |
Line 630 sub Writable {
|
Line 563 sub Writable {
|
($errno == POSIX::EAGAIN) || |
($errno == POSIX::EAGAIN) || |
($errno == POSIX::EINTR) || |
($errno == POSIX::EINTR) || |
($errno == 0)) { |
($errno == 0)) { |
|
$self->{TimeoutRemaining} = $self->{TimeoutValue}; |
substr($self->{TransactionRequest}, 0, $nwritten) = ""; # rmv written part |
substr($self->{TransactionRequest}, 0, $nwritten) = ""; # rmv written part |
if(length $self->{TransactionRequest} == 0) { |
if(length $self->{TransactionRequest} == 0) { |
$self->{InformWritable} = 0; |
$self->{InformWritable} = 0; |
Line 1136 sub CompleteInsecure {
|
Line 1070 sub CompleteInsecure {
|
} |
} |
} |
} |
|
|
=pod |
|
|
|
=head2 GetHostIterator |
|
|
|
Returns a hash iterator to the host information. Each get from |
|
this iterator returns a reference to an array that contains |
|
information read from the hosts configuration file. Array elements |
|
are used as follows: |
|
|
|
[0] - LonCapa host id. |
|
[1] - LonCapa domain name. |
|
[2] - Loncapa role (e.g. library or access). |
|
[3] - DNS name server hostname. |
|
[4] - IP address (result of e.g. nslookup [3]). |
|
[5] - Maximum connection count. |
|
[6] - Idle timeout for reducing connection count. |
|
[7] - Minimum connection count. |
|
|
|
=cut |
|
|
|
sub GetHostIterator { |
|
|
|
return HashIterator->new(\%hostshash); |
|
} |
|
|
|
########################################################### |
########################################################### |
# |
# |
# The following is an unashamed kludge that is here to |
# The following is an unashamed kludge that is here to |
Line 1217 sub read_conf
|
Line 1126 sub read_conf
|
return $perlvarref; |
return $perlvarref; |
} |
} |
|
|
#---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab |
|
# formatted configuration file. |
|
# |
|
my $RequiredCount = 4; # Required item count in hosts.tab. |
|
my $DefaultMaxCon = 5; # Default value for maximum connections. |
|
my $DefaultIdle = 1000; # Default connection idle time in seconds. |
|
my $DefaultMinCon = 0; # Default value for minimum connections. |
|
|
|
sub read_hosts { |
|
my $Filename = shift; |
|
my %HostsTab; |
|
|
|
open(CONFIG,'<'.$Filename) or die("Can't read $Filename"); |
|
while (my $line = <CONFIG>) { |
|
if ($line !~ /^\s*\#/) { |
|
$line=~s/\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[3]} = \@list; |
|
} |
|
} |
|
} |
|
} |
|
close(CONFIG); |
|
my $hostref = \%HostsTab; |
|
return ($hostref); |
|
} |
|
# |
# |
# Get the version of our peer. Note that this is only well |
# Get the version of our peer. Note that this is only well |
# defined if the state machine has hit the idle state at least |
# defined if the state machine has hit the idle state at least |
Line 1461 true if the current state requires a wri
|
Line 1331 true if the current state requires a wri
|
|
|
true if the current state requires timeout support. |
true if the current state requires timeout support. |
|
|
=item GetHostIterator: |
|
|
|
Returns an iterator into the host file hash. |
|
|
|
=cut |
=cut |