Doubt in executeing Net::SCP via apache browser.

Discussion in 'Programming' started by sivasankari, Aug 13, 2008.

  1. #1
    Hi,
    I have doubt in cgi perl scripting.i am using the Net::SCP module in this program and i tried it to run only in perl programming it's working fine. if i am trying it same to execute in apache web browser it doesn't show any error in web page but showing error in httpd error log file. Can any one clarify my doubt's why it so like this.

    Thanks in Advance...
    
    #########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";
    ######################################
    
    Code (markup):

    I am getting the following errors in httpd errorlog file
    
    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
    
    Code (markup):
     
    sivasankari, Aug 13, 2008 IP
  2. perlbone

    perlbone Peon

    Messages:
    128
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    #########code1############
    #!/usr/bin/perl
    use strict;
    use CGI::Carp qw/fatalsToBrowser/;
    print <<SOMETHING;
    Content-type:text/html\n\n
    <html
    head
    </head>
    <body>
    <form name=frm method=post action=sshcgi.pl>
    <select name=ip>
    <option ip=1>1.4.1.7</option>
    <option ip=2>1.1.5.87</option>
    <option ip=3>22.6.15.1</option>
    </select>
    <input type=password name=password>
    <input type=submit name=submit value=Submit>
    </form>
    <center>Loading...</center><br />
    SOMETHING
    ##################################
    ##############code-2############## 
    my (%in,$ip,$pwd);
    if($ENV{'REQUEST_METHOD'} eq 'POST')
    {
            read(STDIN,my $buf,$ENV{'CONTENT_LENGTH'});
            foreach my $pair (split(/&/, $buf))
            {
                    my ($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;
    my $scpe= Net::SCP::Expect->new  || die "Module is ruined? $@";
    my $svr = "root\@$ip";
    my $user='root';
    my $file ='app_talkdetect.so'; if (!-f) {die "$file isn't found!"}
    $scpe->login("$user","$pwd") || die "Login failed";
    $scpe->scp("$svr:/home/$file", "/home/")  || die "Transfer.. f(a)iled?";
    print "....done\n</body></html>";
    ######################################
    
    Code (markup):
    Try this..
     
    perlbone, Aug 13, 2008 IP
  3. sivasankari

    sivasankari Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your reply
    Hi i tried the above code it's shows the following error
    software error:
    Cannot open a pty at /usr/lib/perl5/site_perl/5.8.5/Net/SCP/Expect.pm line 172.
     
    sivasankari, Aug 13, 2008 IP
  4. perlbone

    perlbone Peon

    Messages:
    128
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hmm.. so it died in module itself.
    Well, then it's a problem with permissions -- scripts started from httpd should not access terminals this way.. check if user that runs the apache can also access /dev/pty* for writing.
     
    perlbone, Aug 14, 2008 IP
  5. sivasankari

    sivasankari Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Can any one guide me how to create suexec user in apache.
     
    sivasankari, Aug 22, 2008 IP