C
Carl Lafferty
I have posted before and received a LOT of help on a project for my
public library. Right now I am having an issue using that information.
I was able to get my net::telnet application to work. it returns the
information that I want and I am in the process of converting it to a
usable script but I have run into a problem.
When the code executes I have the CGI display a form asking for a title
to search for and give them a submit button. say you enter "Tom Swift".
my script is then called again with that parameter, spends a few seconds
talking to the telnet server I have to talk to and then returns my data.
This works PERFECTLY (well some warnings but I will work those out
later) from the commandline. (I simulate the 'get something from the
script' code to run from cmd line) When I run it from the browser, it
simply gives me "internal server error" and my
/var/log/apache2/error.log says Premature end of script headers.
The code generated from the command line looks like this:
_________________
Content-type: text/html
<html><body bgcolor=blue text=white>Results:<br> <br>
Tom Swift and his aquatom Appleton, Victor J APPLETON
|ocm03632157|1 <br>
Tom Swift and his atomic Appleton, Victor J APPLETON
|ocm02915922|1 <br>
Tom Swift and his deep-se Appleton, Victor J APPLETON |
58014649|1 <br>
Tom Swift and his electro Appleton, Victor J APPLETON
|ocm01088658|1 <br>
Tom Swift and his flying Appleton, Victor J APPLETON |
54000408|1 <br>
Tom Swift and his repelat Appleton, Victor J APPLETON
|CNV02382170|1 <br>
Tom Swift and his space s Appleton, Victor J APPLETON
|ocm01088653|1 <br>
Tom Swift and his ultraso Appleton, Victor J APPLETON |
57004843|1 <br>
Tom Swift in the caves of Appleton, Victor J APPLETON
|ocm02635857|1 <br>
Tom Swift on the phantom Appleton, Victor J APPLETON
|ocm04678341|1 <br>
</body></html>
_____________________________
My question is that since it takes a 2-4 seconds to retrieve the data
(there is a delay as the telnet server accpets the login that is beyond
my control at all), could this be causing the browser to timeout????
Below is my code for my first real try into this as a cgi script.
Any help is appreciated. (
______________________________
#!/usr/bin/perl
use Net::Telnet;
#use warnings;
use CGI;
sub connect
{
#
# setup the connection to the server.
#
$galaxy = new Net::Telnet (Host => "10.10.20.220",
Port => 2001,
Timeout => 10,
Dump_Log => 'dump.log',
output_record_separator => "\x0d",
Input_log => 'input.log',
Option_log => 'option.log',
Output_log => 'output.log',
Prompt => '//',
Telnetmode => '0');
eval {
$ok = $galaxy->waitfor('/option:/');
$ok = $galaxy->print(">>>G");
$ok = $galaxy->waitfor('/option:/');
$ok = $galaxy->print("\x1c\xc0\xc1\xc0\xa7\xa8");
$ok = $galaxy->waitfor('/\x1e\x59/');
$ok = $galaxy->print("0001 AUTO||O|1.11 (800)");
$ok = $galaxy->waitfor('/YN|3/');
$ok = $galaxy->print("5000 5166 30");
$ok = $galaxy->waitfor('/0001 00000 /');
$ok = $galaxy->print("0020 ");
$ok = $galaxy->waitfor('/ile/');
$ok = $galaxy->print("0021 ");
$ok = $galaxy->waitfor('/NNNNNNNNNNN/');
$ok = $galaxy->print("0022 ");
$ok = $galaxy->waitfor('/NNNNNNNNNN/');
$ok = $galaxy->print("5000 5170 00 00 L ");
$ok = $galaxy->waitfor('/0004 000\x8f/');
$ok = $galaxy->print("5000 5163 00 00 01 ");
$ok = $galaxy->waitfor('/0001 00000/');
};
if ( $@ ) {print qq! <h1 align=center>Temporary Error</h1> <h3
align=center>A timeout with the server has occured, this page will be
refreshed in a few seconds</h3> !;}
}
sub logout
{
$galaxy->print("999");
$galaxy->print("0005 GALAXY||20");
$galaxy->print("0010");
$galaxy->close;
# print "</html>";
} #logout
sub displaymenu
{
print qq!
<form action="http://splinter.fclib.org/cgi-bin/newbooks.cgi" method="GET">
Enter title you wish to search for <input type="text" name="lookfor"
width="30"><br>
<input type="submit" value="Click to search">
</form>
!
}
sub displayheader
{
print qq!
Content-type: text/html
<html>
<head><title>Booklookup First Trial</title></head>
<body bgcolor="blue" text="white">
<h1 align="center">Book lookup trial</h1>
!
}
sub getsearchresults
{
&connect();
#put checks here to take into account different search types later.
$galaxy->print("5000 5002 30 0 $lookfor");
#get the first thing sent back which will look like " xxx xxxx xxx"
hence the
#funny looking split below to take care of the leading space.. all I am
#interested in is the $howmany variable
($temp) = $galaxy->waitfor("/\x8f/");
($junk, $howmany, $junk, $junk) = split (/ /,$temp);
#Initailly I am only going to worry about the first 10 hits since
#most of the hits you look for will be in the fist 10 but I am going to
include the
#loop that I need to do more than that incase I get ... loopy.
#gonna use parallel arrays initally here.. may use hashes later on
#
$main = 1;
@titles = ();
@cards = ();
@available = ();
while ($main < 2) {
$count = 1;
while ($count <= $howmany-1) {
($info) = $galaxy->waitfor("/\x8f/");
($controlnum) = $galaxy->waitfor("/\x8f/");
($hilite) = $galaxy->waitfor("/\x8f/");
$titles[$count] = $info . "|" . $controlnum . "|" . $hilite;
$count = $count + 1;
} #while $count
#clear out buffer
$galaxy->waitfor("/\x8f/");
$galaxy->waitfor("/\x8f/");
$main = $main + 1;
}
} #getsearchresults
sub displaysearchresults
{
print "Content-type: text/html\n\n";
print qq!<html><body bgcolor=blue text=white>!;
print qq!Results:<br>!;
$line = "";
foreach $line (@titles) { print "$line <br>\n"; }
} #displaysearchresults
##################main
$formdata = new CGI();
#print "Content-type: text/html\n\n";
#since I am only doing TITLE right now I am not going to
#worry about the search type for NOW
#
$lookfor = $formdata->param("lookfor");
$lookfor = "Tom Swift";
#$lookfor = <STDIN>;
if ($lookfor eq "") {
print "Content-type: text/html\n\n";
&displaymenu();
} else {
&getsearchresults();
&displaysearchresults();
print qq!</body></html>!;
&logout;
};
public library. Right now I am having an issue using that information.
I was able to get my net::telnet application to work. it returns the
information that I want and I am in the process of converting it to a
usable script but I have run into a problem.
When the code executes I have the CGI display a form asking for a title
to search for and give them a submit button. say you enter "Tom Swift".
my script is then called again with that parameter, spends a few seconds
talking to the telnet server I have to talk to and then returns my data.
This works PERFECTLY (well some warnings but I will work those out
later) from the commandline. (I simulate the 'get something from the
script' code to run from cmd line) When I run it from the browser, it
simply gives me "internal server error" and my
/var/log/apache2/error.log says Premature end of script headers.
The code generated from the command line looks like this:
_________________
Content-type: text/html
<html><body bgcolor=blue text=white>Results:<br> <br>
Tom Swift and his aquatom Appleton, Victor J APPLETON
|ocm03632157|1 <br>
Tom Swift and his atomic Appleton, Victor J APPLETON
|ocm02915922|1 <br>
Tom Swift and his deep-se Appleton, Victor J APPLETON |
58014649|1 <br>
Tom Swift and his electro Appleton, Victor J APPLETON
|ocm01088658|1 <br>
Tom Swift and his flying Appleton, Victor J APPLETON |
54000408|1 <br>
Tom Swift and his repelat Appleton, Victor J APPLETON
|CNV02382170|1 <br>
Tom Swift and his space s Appleton, Victor J APPLETON
|ocm01088653|1 <br>
Tom Swift and his ultraso Appleton, Victor J APPLETON |
57004843|1 <br>
Tom Swift in the caves of Appleton, Victor J APPLETON
|ocm02635857|1 <br>
Tom Swift on the phantom Appleton, Victor J APPLETON
|ocm04678341|1 <br>
</body></html>
_____________________________
My question is that since it takes a 2-4 seconds to retrieve the data
(there is a delay as the telnet server accpets the login that is beyond
my control at all), could this be causing the browser to timeout????
Below is my code for my first real try into this as a cgi script.
Any help is appreciated. (
______________________________
#!/usr/bin/perl
use Net::Telnet;
#use warnings;
use CGI;
sub connect
{
#
# setup the connection to the server.
#
$galaxy = new Net::Telnet (Host => "10.10.20.220",
Port => 2001,
Timeout => 10,
Dump_Log => 'dump.log',
output_record_separator => "\x0d",
Input_log => 'input.log',
Option_log => 'option.log',
Output_log => 'output.log',
Prompt => '//',
Telnetmode => '0');
eval {
$ok = $galaxy->waitfor('/option:/');
$ok = $galaxy->print(">>>G");
$ok = $galaxy->waitfor('/option:/');
$ok = $galaxy->print("\x1c\xc0\xc1\xc0\xa7\xa8");
$ok = $galaxy->waitfor('/\x1e\x59/');
$ok = $galaxy->print("0001 AUTO||O|1.11 (800)");
$ok = $galaxy->waitfor('/YN|3/');
$ok = $galaxy->print("5000 5166 30");
$ok = $galaxy->waitfor('/0001 00000 /');
$ok = $galaxy->print("0020 ");
$ok = $galaxy->waitfor('/ile/');
$ok = $galaxy->print("0021 ");
$ok = $galaxy->waitfor('/NNNNNNNNNNN/');
$ok = $galaxy->print("0022 ");
$ok = $galaxy->waitfor('/NNNNNNNNNN/');
$ok = $galaxy->print("5000 5170 00 00 L ");
$ok = $galaxy->waitfor('/0004 000\x8f/');
$ok = $galaxy->print("5000 5163 00 00 01 ");
$ok = $galaxy->waitfor('/0001 00000/');
};
if ( $@ ) {print qq! <h1 align=center>Temporary Error</h1> <h3
align=center>A timeout with the server has occured, this page will be
refreshed in a few seconds</h3> !;}
}
sub logout
{
$galaxy->print("999");
$galaxy->print("0005 GALAXY||20");
$galaxy->print("0010");
$galaxy->close;
# print "</html>";
} #logout
sub displaymenu
{
print qq!
<form action="http://splinter.fclib.org/cgi-bin/newbooks.cgi" method="GET">
Enter title you wish to search for <input type="text" name="lookfor"
width="30"><br>
<input type="submit" value="Click to search">
</form>
!
}
sub displayheader
{
print qq!
Content-type: text/html
<html>
<head><title>Booklookup First Trial</title></head>
<body bgcolor="blue" text="white">
<h1 align="center">Book lookup trial</h1>
!
}
sub getsearchresults
{
&connect();
#put checks here to take into account different search types later.
$galaxy->print("5000 5002 30 0 $lookfor");
#get the first thing sent back which will look like " xxx xxxx xxx"
hence the
#funny looking split below to take care of the leading space.. all I am
#interested in is the $howmany variable
($temp) = $galaxy->waitfor("/\x8f/");
($junk, $howmany, $junk, $junk) = split (/ /,$temp);
#Initailly I am only going to worry about the first 10 hits since
#most of the hits you look for will be in the fist 10 but I am going to
include the
#loop that I need to do more than that incase I get ... loopy.
#gonna use parallel arrays initally here.. may use hashes later on
#
$main = 1;
@titles = ();
@cards = ();
@available = ();
while ($main < 2) {
$count = 1;
while ($count <= $howmany-1) {
($info) = $galaxy->waitfor("/\x8f/");
($controlnum) = $galaxy->waitfor("/\x8f/");
($hilite) = $galaxy->waitfor("/\x8f/");
$titles[$count] = $info . "|" . $controlnum . "|" . $hilite;
$count = $count + 1;
} #while $count
#clear out buffer
$galaxy->waitfor("/\x8f/");
$galaxy->waitfor("/\x8f/");
$main = $main + 1;
}
} #getsearchresults
sub displaysearchresults
{
print "Content-type: text/html\n\n";
print qq!<html><body bgcolor=blue text=white>!;
print qq!Results:<br>!;
$line = "";
foreach $line (@titles) { print "$line <br>\n"; }
} #displaysearchresults
##################main
$formdata = new CGI();
#print "Content-type: text/html\n\n";
#since I am only doing TITLE right now I am not going to
#worry about the search type for NOW
#
$lookfor = $formdata->param("lookfor");
$lookfor = "Tom Swift";
#$lookfor = <STDIN>;
if ($lookfor eq "") {
print "Content-type: text/html\n\n";
&displaymenu();
} else {
&getsearchresults();
&displaysearchresults();
print qq!</body></html>!;
&logout;
};