Diff for /loncom/lonnet/perl/londns.pm between versions 1.3 and 1.7

version 1.3, 2013/09/02 14:40:18 version 1.7, 2021/06/06 23:14:18
Line 31  package Apache::londns; Line 31  package Apache::londns;
   
 use strict;  use strict;
 use LONCAPA;  use LONCAPA;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http :remotehost);
 use Apache::lonnet;  use Apache::lonnet;
   
 sub serve_file {  sub serve_file {
     my ($r,$file,$type)=@_;      my ($r,$dir,$file,$type)=@_;
     open(my $config,"<$Apache::lonnet::perlvar{'lonTabDir'}/$file");      if (($dir eq '') || ($file eq '')) {
     my $file = join('',<$config>);          return FORBIDDEN;
     $r->content_type($type);      }
     $r->send_http_header;      if (open(my $config,"<","$dir/$file")) {
     return OK if $r->header_only;          my $contents = join('',<$config>);
     $r->print($file);          close($config);
     return OK;          $r->content_type($type);
           $r->send_http_header;
           return OK if $r->header_only;
           $r->print($contents);
           return OK;
       } else {
           return FORBIDDEN;
       }
 }  }
   
 sub handler {  sub handler {
     my ($r) = @_;      my ($r) = @_;
   
       my $reqhost = $r->get_remote_host(REMOTE_NOLOOKUP);
       my @hostids= &Apache::lonnet::get_hosts_from_ip($reqhost);
       if (!@hostids && $reqhost ne '127.0.0.1' ) {
           $r->log_reason("Unable to find a host for ".
                          $r->get_remote_host(REMOTE_NOLOOKUP));
           return FORBIDDEN;
       }
   
     my $command = (split('/',$r->uri))[3];      my $command = (split('/',$r->uri))[3];
     if ($command eq 'hosts') {      my ($dir,$file) = &Apache::lonnet::parse_getdns_url($command,$r->uri);
  return &serve_file($r,'dns_hosts.tab','loncapa/hosts');      my %types = (
     } elsif ($command eq 'domain') {                      hosts      => 'loncapa/hosts',
  return &serve_file($r,'dns_domain.tab','loncapa/domain');                      domain     => 'loncapa/domain',
     } elsif ($command eq 'checksums') {                      checksums  => 'loncapa/versions',
         my $version = (split('/',$r->uri))[4];                      loncapaCRL => 'application/x-pem-file',
         return &serve_file($r,"dns_checksums/$version.tab",'loncapa/versions');                  );
       if (exists($types{$command})) {
           return &serve_file($r,$dir,$file,$types{$command});
     }      }
     return FORBIDDEN;      return FORBIDDEN;
 }  }

Removed from v.1.3  
changed lines
  Added in v.1.7


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