Diff for /loncom/cgi/ping.pl between versions 1.5 and 1.9

version 1.5, 2003/09/01 03:37:27 version 1.9, 2011/10/17 17:23:25
Line 25 Line 25
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
   use strict;
 $|=1;  $|=1;
   
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA::Configuration;  use Apache::lonnet;
   use LONCAPA::loncgi;
 use IO::File;  use LONCAPA::lonauthcgi;
 use IO::Socket;  
   print("Content-type: text/plain\n\n");
 my %perlvar;  
   &main();
 # -------------------------------------------------- Non-critical communication  
 sub reply {  sub main {
     my ($cmd,$server)=@_;      my $remote_ip = $ENV{'REMOTE_ADDR'};
     my $peerfile="$perlvar{'lonSockDir'}/$server";      my $allowed;
     my $client=IO::Socket::UNIX->new(Peer    =>"$peerfile",      my @hosts = &Apache::lonnet::get_hosts_from_ip($remote_ip);
                                      Type    => SOCK_STREAM,      if (@hosts > 0) {
                                      Timeout => 10)          $allowed = 1;
        or return "con_lost";      } elsif (&LONCAPA::lonauthcgi::check_ipbased_access('ping',$remote_ip)) {
     print $client "$cmd\n";          $allowed = 1;
     my $answer=<$client>;      } elsif (&LONCAPA::loncgi::check_cookie_and_load_env()) {
     chomp($answer);          if (&LONCAPA::lonauthcgi::can_view('ping')) {
     if (!$answer) { $answer="con_lost"; }              $allowed = 1;
     return $answer;          }
       }
       if ($allowed) {
           my $testhost=$ENV{'QUERY_STRING'};
           $testhost=~s/\W//g;
           if (&Apache::lonnet::hostname($testhost) ne '') {
               print &Apache::lonnet::reply('ping',$testhost)."\n";
           } else {
               print 'unknown_host';
           }
       } else {
           print 'forbidden';
       }
       return;
 }  }
   
   
 # --------------------- Read loncapa.conf (and by default loncapa_apache.conf).  
 my $perlvarref=LONCAPA::Configuration::read_conf('loncapa.conf');  
 %perlvar=%{$perlvarref};  
 undef $perlvarref; # remove since sensitive and not needed  
 delete $perlvar{'lonReceipt'}; # remove since sensitive and not needed  
 delete $perlvar{'lonSqlAccess'}; # remove since sensitive and not needed  
   
 $testhost=$ENV{'QUERY_STRING'};  
 $testhost=~s/\W//g;  
   
 print "Content-type: text/plain\n\n".  
       &reply('ping',$testhost)."\n";  

Removed from v.1.5  
changed lines
  Added in v.1.9


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