CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
problem with IF in Perl 32 script



Jan 31, 2000, 12:18 PM

Post #1 of 2 (4848 views)
problem with IF in Perl 32 script Can't Post

I have written a script which calls a telnet session to allow users to change their RAS passwords via a web page. It works fine as long as a user never makes a mistake (fat chance of that!!!) I put in an if statement to handle problems if the user gets an access denied. This also works fine...the first time only. Once the user gets access denied once, however, it gives the error back to user no matter if the entries are correct. I can't figure out the problem. Here is a snippet of the code that creates the problem. It works fine if the user does everything right, gives the correct error if the user does something wrong, and then gives the error every time after that until I change the "eq" to "==" or vice versa and rerun the script with the change.....doesn't make any sense to me. Any suggestions would be appreciated.

Also, another weird thing is that I have had to do a getline then lastline to get the correct string back from the telnet session (which is also doesn't return the access denied until I do a getline, lastline, then another lastline).


my($t, $hostname, $username, $tmppasswd, $newpwd, $confnewpwd, $passwd, $numchars, $logfile, $outlog, $dumplog);
use CGI;
use Net::Telnet ();
$formdata = new CGI;
$hostname = "---.---.---.---"; #IP num $passwd = "\#\#$tmppasswd";
. (this section has form validation stuff
sub telnetForm
if ($formValid=1)
$t = new Net::Telnet (Input_log => $logfile, Output_log => $outlog, Option_log => $optlog);
#The following print lines for for debug only
print $formdata->header;
print "<HTML><HEAD><TITLE>Test</TITLE><BODY>BEFORE IF:<BR>LINE1: $line1<BR>LINE2: $line2<BR>LINE3: $line3<BR></BODY></HTML>";
if ($line3 eq "Access denied")
print $formdata->header; #line100
print "<HTML><HEAD><TITLE>RAS Change Error</TITLE><BODY>".
"<CENTER><H1>You have entered a Username or Password ".
"that is not recognized by the RAS server</CENTER><BR><BR></H1>".
"<H2>The username you entered was: $username<BR><BR>".
"The password you entered was: $passwd<BR>".
" [ignore the \#\# in front of the password]".
" <BR>LINE5:$line5</H2></CENTER></BODY></HTML>";
#the following print lines is for debug only
print $formdata->header;
print "<HTML><HEAD><TITLE>Test</TITLE><BODY>If bombed $line LINE2 $line2 LINE3 $line3 </BODY></HTML>";

$t->waitfor('/Please enter.*$/');
$t->waitfor('/Please retype.*$/');
print $formdata->header;
print "<HTML><HEAD><TITLE>RAS Change Made Successfully".
"</TITLE><BODY><CENTER><H3>The change to your RAS ".
"account has been made successfully.".
} #end of if formValid
} #end of subroutine


Jan 31, 2000, 2:13 PM

Post #2 of 2 (4848 views)
Re: problem with IF in Perl 32 script [In reply to] Can't Post

I'm not sure about this, but I think that when the host responds with an access denied response, it responds with a new "username" prompt. If you're trying to "open" the hostname again, instead of resending the username and then the new password, this may be where your error is.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives