--- loncom/cgi/ping.pl 2008/12/25 01:56:03 1.8 +++ loncom/cgi/ping.pl 2011/10/17 17:23:25 1.9 @@ -1,6 +1,6 @@ #!/usr/bin/perl # ping cgi-script -# $Id: ping.pl,v 1.8 2008/12/25 01:56:03 raeburn Exp $ +# $Id: ping.pl,v 1.9 2011/10/17 17:23:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,19 +38,28 @@ print("Content-type: text/plain\n\n"); &main(); sub main { - if (!&LONCAPA::lonauthcgi::check_ipbased_access('ping')) { - if (!&LONCAPA::loncgi::check_cookie_and_load_env()) { - return; + my $remote_ip = $ENV{'REMOTE_ADDR'}; + my $allowed; + my @hosts = &Apache::lonnet::get_hosts_from_ip($remote_ip); + if (@hosts > 0) { + $allowed = 1; + } elsif (&LONCAPA::lonauthcgi::check_ipbased_access('ping',$remote_ip)) { + $allowed = 1; + } elsif (&LONCAPA::loncgi::check_cookie_and_load_env()) { + if (&LONCAPA::lonauthcgi::can_view('ping')) { + $allowed = 1; } - - if (!&LONCAPA::lonauthcgi::can_view('ping')) { - return; + } + 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'; } - - my $testhost=$ENV{'QUERY_STRING'}; - $testhost=~s/\W//g; - - print &Apache::lonnet::reply('ping',$testhost)."\n"; return; }