[LON-CAPA-cvs] cvs: loncom /cgi ping.pl

www lon-capa-cvs@mail.lon-capa.org
Mon, 18 Feb 2002 20:59:36 -0000


www		Mon Feb 18 15:59:36 2002 EDT

  Added files:                 
    /loncom/cgi	ping.pl 
  Log:
  Ping cgi-bin script
  
  

Index: loncom/cgi/ping.pl
+++ loncom/cgi/ping.pl
#!/usr/bin/perl

# The LearningOnline Network with CAPA
# ping cgi-script


$|=1;

use IO::File;
use IO::Socket;

# -------------------------------------------------- Non-critical communication
sub reply {
    my ($cmd,$server)=@_;
    my $peerfile="$perlvar{'lonSockDir'}/$server";
    my $client=IO::Socket::UNIX->new(Peer    =>"$peerfile",
                                     Type    => SOCK_STREAM,
                                     Timeout => 10)
       or return "con_lost";
    print $client "$cmd\n";
    my $answer=<$client>;
    chomp($answer);
    if (!$answer) { $answer="con_lost"; }
    return $answer;
}


# ------------------------------------------------------------ Read access.conf
{
    my $config=IO::File->new("/etc/httpd/conf/access.conf");

    while (my $configline=<$config>) {
        if ($configline =~ /PerlSetVar/) {
	   my ($dummy,$varname,$varvalue)=split(/\s+/,$configline);
           $perlvar{$varname}=$varvalue;
        }
    }
    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";