version 1.849, 2007/03/17 04:11:51
|
version 1.853, 2007/03/28 20:28:31
|
Line 144 sub logperm {
|
Line 144 sub logperm {
|
return 1; |
return 1; |
} |
} |
|
|
|
sub create_connection { |
|
my ($hostname,$lonid) = @_; |
|
my $client=IO::Socket::UNIX->new(Peer => $perlvar{'lonSockCreate'}, |
|
Type => SOCK_STREAM, |
|
Timeout => 10); |
|
return 0 if (!$client); |
|
print $client ("$hostname:$lonid\n"); |
|
my $result = <$client>; |
|
chomp($result); |
|
return 1 if ($result eq 'done'); |
|
return 0; |
|
} |
|
|
|
|
# -------------------------------------------------- Non-critical communication |
# -------------------------------------------------- Non-critical communication |
sub subreply { |
sub subreply { |
my ($cmd,$server)=@_; |
my ($cmd,$server)=@_; |
Line 170 sub subreply {
|
Line 184 sub subreply {
|
Timeout => 10); |
Timeout => 10); |
if($client) { |
if($client) { |
last; # Connected! |
last; # Connected! |
|
} else { |
|
&create_connection(&hostname($server),$server); |
} |
} |
sleep(1); # Try again later if failed connection. |
sleep(1); # Try again later if failed connection. |
} |
} |
my $answer; |
my $answer; |
if ($client) { |
if ($client) { |
Line 7410 sub hreflocation {
|
Line 7426 sub hreflocation {
|
} |
} |
|
|
sub current_machine_domains { |
sub current_machine_domains { |
my $hostname=&hostname($perlvar{'lonHostID'}); |
return &machine_domains(&hostname($perlvar{'lonHostID'})); |
|
} |
|
|
|
sub machine_domains { |
|
my ($hostname) = @_; |
my @domains; |
my @domains; |
my %hostname = &all_hostnames(); |
my %hostname = &all_hostnames(); |
while( my($id, $name) = each(%hostname)) { |
while( my($id, $name) = each(%hostname)) { |
Line 7423 sub current_machine_domains {
|
Line 7443 sub current_machine_domains {
|
} |
} |
|
|
sub current_machine_ids { |
sub current_machine_ids { |
my $hostname=&hostname($perlvar{'lonHostID'}); |
return &machine_ids(&hostname($perlvar{'lonHostID'})); |
|
} |
|
|
|
sub machine_ids { |
|
my ($hostname) = @_; |
|
$hostname ||= &hostname($perlvar{'lonHostID'}); |
my @ids; |
my @ids; |
my %hostname = &all_hostnames(); |
my %hostname = &all_hostnames(); |
while( my($id, $name) = each(%hostname)) { |
while( my($id, $name) = each(%hostname)) { |
Line 7571 BEGIN {
|
Line 7596 BEGIN {
|
%perlvar = (%perlvar,%{$configvars}); |
%perlvar = (%perlvar,%{$configvars}); |
} |
} |
|
|
|
sub get_dns { |
|
my ($url,$func) = @_; |
|
open(my $config,"<$perlvar{'lonTabDir'}/hosts.tab"); |
|
foreach my $dns (<$config>) { |
|
next if ($dns !~ /^\^(\S*)/x); |
|
$dns = $1; |
|
my $ua=new LWP::UserAgent; |
|
my $request=new HTTP::Request('GET',"http://$dns$url"); |
|
my $response=$ua->request($request); |
|
next if ($response->is_error()); |
|
my @content = split("\n",$response->content); |
|
&$func(\@content); |
|
} |
|
close($config); |
|
} |
# ------------------------------------------------------------ Read domain file |
# ------------------------------------------------------------ Read domain file |
{ |
{ |
|
my $loaded; |
my %domain; |
my %domain; |
|
|
my $fh; |
sub parse_domain_tab { |
if (open($fh,"<".$Apache::lonnet::perlvar{'lonTabDir'}.'/domain.tab')) { |
my ($lines) = @_; |
while (my $line = <$fh>) { |
foreach my $line (@$lines) { |
next if ($line =~ /^(\#|\s*$ )/); |
next if ($line =~ /^(\#|\s*$ )/x); |
|
|
chomp($line); |
chomp($line); |
my ($name,@elements) = split(/:/,$line,9); |
my ($name,@elements) = split(/:/,$line,9); |
my %this_domain; |
my %this_domain; |
foreach my $field ('description', 'auth_def', 'auth_arg_def', |
foreach my $field ('description', 'auth_def', 'auth_arg_def', |
'lang_def', 'city', 'longi', 'lati', |
'lang_def', 'city', 'longi', 'lati', |
Line 7589 BEGIN {
|
Line 7630 BEGIN {
|
$this_domain{$field} = shift(@elements); |
$this_domain{$field} = shift(@elements); |
} |
} |
$domain{$name} = \%this_domain; |
$domain{$name} = \%this_domain; |
# &logthis("Domain.tab: $domain ".$domaindescription{$domain} ); |
&logthis("Domain.tab: $name ".$domain{$name}{'description'} ); |
|
} |
|
} |
|
|
|
sub load_domain_tab { |
|
&get_dns('/adm/dns/domain',\&parse_domain_tab); |
|
my $fh; |
|
if (open($fh,"<".$perlvar{'lonTabDir'}.'/domain.tab')) { |
|
my @lines = <$fh>; |
|
&parse_domain_tab(\@lines); |
} |
} |
|
close($fh); |
|
$loaded = 1; |
} |
} |
close ($fh); |
|
|
|
sub domain { |
sub domain { |
|
&load_domain_tab() if (!$loaded); |
|
|
my ($name,$what) = @_; |
my ($name,$what) = @_; |
return if ( !exists($domain{$name}) ); |
return if ( !exists($domain{$name}) ); |
|
|
Line 7611 BEGIN {
|
Line 7664 BEGIN {
|
my %hostname; |
my %hostname; |
my %hostdom; |
my %hostdom; |
my %libserv; |
my %libserv; |
open(my $config,"<$perlvar{'lonTabDir'}/hosts.tab"); |
my $loaded; |
|
|
while (my $configline=<$config>) { |
sub parse_hosts_tab { |
next if ($configline =~ /^(\#|\s*$)/); |
my ($file) = @_; |
chomp($configline); |
foreach my $configline (@$file) { |
my ($id,$domain,$role,$name)=split(/:/,$configline); |
next if ($configline =~ /^(\#|\s*$ )/x); |
$name=~s/\s//g; |
next if ($configline =~ /^\^/); |
if ($id && $domain && $role && $name) { |
chomp($configline); |
$hostname{$id}=$name; |
my ($id,$domain,$role,$name)=split(/:/,$configline); |
$hostdom{$id}=$domain; |
$name=~s/\s//g; |
if ($role eq 'library') { $libserv{$id}=$name; } |
if ($id && $domain && $role && $name) { |
} |
$hostname{$id}=$name; |
|
$hostdom{$id}=$domain; |
|
if ($role eq 'library') { $libserv{$id}=$name; } |
|
} |
|
&logthis("Hosts.tab: $name ".$id ); |
|
} |
} |
} |
close($config); |
|
|
sub load_hosts_tab { |
|
&get_dns('/adm/dns/hosts',\&parse_hosts_tab); |
|
open(my $config,"<$perlvar{'lonTabDir'}/hosts.tab"); |
|
my @config = <$config>; |
|
&parse_hosts_tab(\@config); |
|
close($config); |
|
$loaded=1; |
|
} |
|
|
# FIXME: dev server don't want this, production servers _do_ want this |
# FIXME: dev server don't want this, production servers _do_ want this |
#&get_iphost(); |
#&get_iphost(); |
|
|
sub hostname { |
sub hostname { |
|
&load_hosts_tab() if (!$loaded); |
|
|
my ($lonid) = @_; |
my ($lonid) = @_; |
return $hostname{$lonid}; |
return $hostname{$lonid}; |
} |
} |
|
|
sub all_hostnames { |
sub all_hostnames { |
|
&load_hosts_tab() if (!$loaded); |
|
|
return %hostname; |
return %hostname; |
} |
} |
|
|
sub is_library { |
sub is_library { |
|
&load_hosts_tab() if (!$loaded); |
|
|
return exists($libserv{$_[0]}); |
return exists($libserv{$_[0]}); |
} |
} |
|
|
sub all_library { |
sub all_library { |
|
&load_hosts_tab() if (!$loaded); |
|
|
return %libserv; |
return %libserv; |
} |
} |
|
|
sub get_servers { |
sub get_servers { |
|
&load_hosts_tab() if (!$loaded); |
|
|
my ($domain,$type) = @_; |
my ($domain,$type) = @_; |
my %possible_hosts = ($type eq 'library') ? %libserv |
my %possible_hosts = ($type eq 'library') ? %libserv |
: %hostname; |
: %hostname; |
Line 7667 BEGIN {
|
Line 7744 BEGIN {
|
} |
} |
|
|
sub host_domain { |
sub host_domain { |
|
&load_hosts_tab() if (!$loaded); |
|
|
my ($lonid) = @_; |
my ($lonid) = @_; |
return $hostdom{$lonid}; |
return $hostdom{$lonid}; |
} |
} |
|
|
sub all_domains { |
sub all_domains { |
|
&load_hosts_tab() if (!$loaded); |
|
|
my %seen; |
my %seen; |
my @uniq = grep(!$seen{$_}++, values(%hostdom)); |
my @uniq = grep(!$seen{$_}++, values(%hostdom)); |
return @uniq; |
return @uniq; |