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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



dcodding
Deleted

Jan 31, 2000, 12:18 PM

Post #1 of 2 (2018 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!!!)....so 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 strange...it doesn't return the access denied until I do a getline, lastline, then another lastline).

CODE SNIPPET:

my($t, $hostname, $username, $tmppasswd, $newpwd, $confnewpwd, $passwd, $numchars, $logfile, $outlog, $dumplog);
use CGI;
use Net::Telnet ();
$formdata = new CGI;
$username=$formdata->param("User");
$tmppasswd=$formdata->param("OldPwd");
$newpwd=$formdata->param("NewPwd");
$confnewpwd=$formdata->param("NewPwdConfirm");
$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);
$t->open("$hostname");
$t->waitfor('/Username.*$/');
$t->print("$username");
$t->waitfor('/Password.*$/');
$t->print("$passwd");
$line1=$t->getline;
$line2=$t->lastline;
$line3=$t->lastline;
#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>";
chomp($line3);
if ($line3 eq "Access denied")
{
$line5=$t->lastline;
$t->print("exit");
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>";
exit;
}
else
{
$t->print("$newpwd");
}
#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->print("$newpwd");
$t->waitfor('/Please retype.*$/');
$t->print("$newpwd");
$t->waitfor('/rafbcs1>.*$/');
$t->print("exit");
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.".
"</H3></BODY></HTML>";
$t->close;
} #end of if formValid
} #end of subroutine




ljfaraci
Deleted

Jan 31, 2000, 2:13 PM

Post #2 of 2 (2018 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