sanku has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have doubt in cgi perl scripting. while i am using the Net::SCP program alone in perl it's working fine. if i am getting the ip and pwd through the html input values and i am trying to pass that values to the Nect::SCP program and i am trying to run it in web browser like running other cgi script but it's not scp the file and also not at all showing error for that. Can any one clarify my doubt's. Thanks in Advance...
=code is as follows. #########code1############ #!/usr/bin/perl print "Content-type:text/html\n\n"; print "<html>"; print "<head>"; print "</head>"; print "<body>"; print "<form name=frm method=post action=sshcgi.pl>"; print "<select name=ip>"; print "<option ip=1>1.4.1.7</option>"; print "<option ip=2>1.1.5.87</option>"; print "<option ip=3>22.6.15.1</option>"; print "</select>"; print "<input type=password name=password>"; print "<input type=submit name=submit value=Submit>"; print "</form>"; print "</body>"; print "</html>"; ################################## ##############code-2############## if($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$buf,$ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buf); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1 +))/eg; $in{$name} = $value; if($value =~ /^\d{2,3}\.\d{2,3}\.\d{2,3}\.\d{2,3}$/){ +$ip=$value;} elsif($value !~ /\d{2,3}\.\d{2,3}\.\d{2,3}\.\d{2,3}/ & +& $value !~ /Submit/){$pwd=$value; } } } chomp($ip,$pwd); use Net::SCP::Expect; $scpe= Net::SCP::Expect->new; $svr = "root\@$ip"; $user='root'; $file ='app_talkdetect.so'; $scpe->login("$user","$pwd"); $scpe->scp("$svr:/home/$file", "/home/"); print "....done\n"; ######################################
hi Error code in error_log for httpd is Mon Aug 11 11:17:36 2008 error client 1.4.1.7 pty_allocate(nonfatal): getpt(): No such file or directory at /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/IO/Pty.pm line 24., referer: http://1.4.1.7/cgi-bin/ssh.pl Mon Aug 11 11:17:36 2008 error client 1.4.1.7 pty_allocate(nonfatal): openpty(): No such file or directory at /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/IO/Pty.pm line 24., referer: http://1.4.1.7/cgi-bin/ssh.pl Mon Aug 11 11:17:36 2008 error client 1.4.1.7 pty_allocate(nonfatal): open(/dev/ptmx): Permission denied at /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/IO/Pty.pm line 24., referer: http://1.4.1.7/cgi-bin/ssh.pl Mon Aug 11 11:17:36 2008 error client 1.4.1.7 Cannot open a pty at /usr/lib/perl5/site_perl/5.8.5/Net/SCP/Expect.pm line 172, referer: http://1.4.1.7/cgi-bin/ssh.pl

Replies are listed 'Best First'.
Re: Net::SCP with cgi script doubt
by davorg (Chancellor) on Aug 08, 2008 at 13:43 UTC

    You should really use CGI.pm to handle your parameter parsing. Your hand-crafted CGI parameter parser almost certainly has potential bugs in it. I'd also strongly recommend using a templating engine to produce your HTML output.

    You put your CGI parameters into the hash %in, but you ignore that and instead you also get the parameter values using regexes and some rather ropey looking boolean logic.

    In your line $scpe->login("$user","$pwd") you don't need to quote either of the variables.

    You don't check the return values from any of the methods that could potentially fail.

    Is this web server running HTTPS? Sending a password across HTTP isn't very secure.

    You don't have either use strict or use warnings in your program. Why program without a safety net?

    I don't know if any of these issues are causing the problems that you're seeing, but cleaning them up first would make it far easier to track down the real problems.

    --

    See the Copyright notice on my home node.

    "The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg

Re: Net::SCP with cgi script doubt
by jethro (Monsignor) on Aug 08, 2008 at 13:29 UTC

    Some general advice:

    Add use warnings; to every script you write

    Maybe not immediately but eventually you also should use use strict; and declare variables with my in every script you write

    I don't see any error handling code in your script. You can define an error_handler routine with Net::SCP::Expect. As it is now, your script just croaks which should probably leave an error message in some log file. Did you check the apache log files?

      ya i didn't check the apache log file so far.