Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.885 and 1.890.2.1

version 1.885, 2007/06/07 22:09:59 version 1.890.2.1, 2007/06/25 23:30:27
Line 149  sub create_connection { Line 149  sub create_connection {
      Type    => SOCK_STREAM,       Type    => SOCK_STREAM,
      Timeout => 10);       Timeout => 10);
     return 0 if (!$client);      return 0 if (!$client);
     print $client (join(':',$hostname,$lonid,&machine_ids($lonid))."\n");      print $client (join(':',$hostname,$lonid,&machine_ids($hostname))."\n");
     my $result = <$client>;      my $result = <$client>;
     chomp($result);      chomp($result);
     return 1 if ($result eq 'done');      return 1 if ($result eq 'done');
Line 1739  sub extract_embedded_items { Line 1739  sub extract_embedded_items {
     while (my $t=$p->get_token()) {      while (my $t=$p->get_token()) {
  if ($t->[0] eq 'S') {   if ($t->[0] eq 'S') {
     my ($tagname, $attr) = ($t->[1],$t->[2]);      my ($tagname, $attr) = ($t->[1],$t->[2]);
     push (@state, $tagname);      push(@state, $tagname);
             if (lc($tagname) eq 'allow') {              if (lc($tagname) eq 'allow') {
                 &add_filetype($allfiles,$attr->{'src'},'src');                  &add_filetype($allfiles,$attr->{'src'},'src');
             }              }
     if (lc($tagname) eq 'img') {      if (lc($tagname) eq 'img') {
  &add_filetype($allfiles,$attr->{'src'},'src');   &add_filetype($allfiles,$attr->{'src'},'src');
     }      }
       if (lc($tagname) eq 'a') {
    &add_filetype($allfiles,$attr->{'href'},'href');
       }
             if (lc($tagname) eq 'script') {              if (lc($tagname) eq 'script') {
                 if ($attr->{'archive'} =~ /\.jar$/i) {                  if ($attr->{'archive'} =~ /\.jar$/i) {
                     &add_filetype($allfiles,$attr->{'archive'},'archive');                      &add_filetype($allfiles,$attr->{'archive'},'archive');
Line 7597  sub machine_ids { Line 7600  sub machine_ids {
     my ($hostname) = @_;      my ($hostname) = @_;
     $hostname ||= &hostname($perlvar{'lonHostID'});      $hostname ||= &hostname($perlvar{'lonHostID'});
     my @ids;      my @ids;
     my %hostname = &all_hostnames();      my %name_to_host = &all_names();
     while( my($id, $name) = each(%hostname)) {      if (ref($name_to_host{$hostname}) eq 'ARRAY') {
 # &logthis("-$id-$name-$hostname-");   return @{ $name_to_host{$hostname} };
  if ($hostname eq $name) {  
     push(@ids,$id);  
  }  
     }      }
     return @ids;      return;
 }  }
   
 sub additional_machine_domains {  sub additional_machine_domains {
Line 7648  sub declutter { Line 7648  sub declutter {
   
 sub clutter {  sub clutter {
     my $thisfn='/'.&declutter(shift);      my $thisfn='/'.&declutter(shift);
     if ($thisfn !~ m{^/(uploaded|editupload|userfiles|ext|raw|priv|public)/}      if ($thisfn !~ m{^/(uploaded|editupload|adm|userfiles|ext|raw|priv|public)/}
  || $thisfn =~ m{^/adm/(includes|pages)} ) {    || $thisfn =~ m{^/adm/(includes|pages)} ) { 
        $thisfn='/res'.$thisfn;          $thisfn='/res'.$thisfn; 
     }      }
Line 7832  sub get_dns { Line 7832  sub get_dns {
     my %hostdom;      my %hostdom;
     my %libserv;      my %libserv;
     my $loaded;      my $loaded;
       my %name_to_host;
   
     sub parse_hosts_tab {      sub parse_hosts_tab {
  my ($file) = @_;   my ($file) = @_;
Line 7843  sub get_dns { Line 7844  sub get_dns {
     $name=~s/\s//g;      $name=~s/\s//g;
     if ($id && $domain && $role && $name) {      if ($id && $domain && $role && $name) {
  $hostname{$id}=$name;   $hostname{$id}=$name;
    push(@{$name_to_host{$name}}, $id);
  $hostdom{$id}=$domain;   $hostdom{$id}=$domain;
  if ($role eq 'library') { $libserv{$id}=$name; }   if ($role eq 'library') { $libserv{$id}=$name; }
     }      }
Line 7852  sub get_dns { Line 7854  sub get_dns {
     sub reset_hosts_info {      sub reset_hosts_info {
  &reset_domain_info();   &reset_domain_info();
  &reset_hosts_ip_info();   &reset_hosts_ip_info();
    undef(%name_to_host);
  undef(%hostname);   undef(%hostname);
  undef(%hostdom);   undef(%hostdom);
  undef(%libserv);   undef(%libserv);
Line 7881  sub get_dns { Line 7884  sub get_dns {
  return %hostname;   return %hostname;
     }      }
   
       sub all_names {
    &load_hosts_tab() if (!$loaded);
   
    return %name_to_host;
       }
   
     sub is_library {      sub is_library {
  &load_hosts_tab() if (!$loaded);   &load_hosts_tab() if (!$loaded);
   
Line 7937  sub get_dns { Line 7946  sub get_dns {
     my %name_to_ip;      my %name_to_ip;
     my %lonid_to_ip;      my %lonid_to_ip;
   
     my %valid_ip;  
     sub valid_ip {  
  my ($ip) = @_;  
  if (exists($iphost{$ip}) || exists($valid_ip{$ip})) {  
     return 1;  
  }  
  my $name = gethostbyip($ip);  
  my $lonid = &hostname($name);  
  if (defined($lonid)) {  
     $valid_ip{$ip} = $lonid;  
     return 1;  
  }  
  my %iphosts = &get_iphost();  
  if (ref($iphost{$ip})) {  
     return 1;  
  }  
     }  
   
     sub get_hosts_from_ip {      sub get_hosts_from_ip {
  my ($ip) = @_;   my ($ip) = @_;
  my %iphosts = &get_iphost();   my %iphosts = &get_iphost();
Line 7999  sub get_dns { Line 7990  sub get_dns {
  return %iphost;   return %iphost;
     }      }
  }   }
  my %hostname = &all_hostnames();   my %name_to_host = &all_names();
  foreach my $id (keys(%hostname)) {   foreach my $name (keys(%name_to_host)) {
     my $name=&hostname($id);  
     my $ip;      my $ip;
     if (!exists($name_to_ip{$name})) {      if (!exists($name_to_ip{$name})) {
  $ip = gethostbyname($name);   $ip = gethostbyname($name);
  if (!$ip || length($ip) ne 4) {   if (!$ip || length($ip) ne 4) {
     &logthis("Skipping host $id name $name no IP found");      &logthis("Skipping name $name no IP found");
     next;      next;
  }   }
  $ip=inet_ntoa($ip);   $ip=inet_ntoa($ip);
Line 8014  sub get_dns { Line 8004  sub get_dns {
     } else {      } else {
  $ip = $name_to_ip{$name};   $ip = $name_to_ip{$name};
     }      }
     $lonid_to_ip{$id} = $ip;      foreach my $id (@{ $name_to_host{$name} }) {
     push(@{$iphost{$ip}},$id);   $lonid_to_ip{$id} = $ip;
       }
       push(@{$iphost{$ip}},@{$name_to_host{$name}});
  }   }
  &Apache::lonnet::do_cache_new('iphost','iphost',   &Apache::lonnet::do_cache_new('iphost','iphost',
       [\%iphost,\%name_to_ip,\%lonid_to_ip],        [\%iphost,\%name_to_ip,\%lonid_to_ip],

Removed from v.1.885  
changed lines
  Added in v.1.890.2.1


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