Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.851 and 1.852

version 1.851, 2007/03/28 00:05:45 version 1.852, 2007/03/28 00:12:58
Line 7587  BEGIN { Line 7587  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 7605  BEGIN { Line 7621  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 7627  BEGIN { Line 7655  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 7683  BEGIN { Line 7735  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;

Removed from v.1.851  
changed lines
  Added in v.1.852


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>