fwalters has asked for the wisdom of the Perl Monks concerning the following question:
I have a small 'test.cgi' file where I'm just trying to ssh to a router to get some commands (the entire project is a BGP Lookingglass but this is where the problem lies).
It runs fine from command line, as the www-data user that is executing from apache (at least based on the ENV vars), but when I run it from the browser it's just a blank page.
I checked to make sure that 755 was everywhere as appropriate, for now (at least until I figure this out) www-data is able to login and like I said runs the script fine...
I checked the socket directory to make sure it was permed right as well and did some searching before posting (don't want to be shame flamed!).
Here's the code:and... Here is the console output (mostly :-)#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use File::Temp qw/ tempdir /; # necessary minimum for CGI print "Content-type: text/plain\n\n"; # prepare temp dir my $temp = "/home/www-data"; + my $login_user= "xxxxx"; my $login_pass = "xxxxx"; # open SSH session my %opts = ( user => $login_user, password => $login_pass, ctl_dir => $temp, strict_mode => 0 ## NOT recommended - see my comments ); my $ssh = Net::OpenSSH->new("n.n.n.n", %opts); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error; # perform command and print output my @lines = $ssh->capture("sh int desc") or die "remote command failed: " . $ssh->error; print "OUTPUT<br>\n"; print @lines;
and... Here is the browser output:Content-type: text/plain This system is for authorized users only. Unauthorized access is prohi +bited. --snip-- Logging In<br> OUTPUT<br> Last switch-over Thu Dec 29 12:08:33 2016: 6 weeks, 6 days, 1 hour, 52 + minutes ago Wed Feb 15 14:00:58.710 cst Interface Status Protocol Description ---------------------------------------------------------------------- +---------- --snip--
Also, in apache/errors.log I get:Logging In<br>
34 is the 'my @lines' line... Any thoughts?This system is for authorized users only. Unauthorized access is prohi +bited. --snip-- Connection to n.n.n.n closed by remote host. remote command failed: 0 at /usr/lib/cgi-bin/test2.cgi line 34.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::OpenSSH + CGI problem
by salva (Canon) on Feb 16, 2017 at 07:47 UTC | |
by fwalters (Novice) on Feb 16, 2017 at 13:32 UTC | |
by fwalters (Novice) on Feb 16, 2017 at 14:51 UTC | |
by salva (Canon) on Feb 16, 2017 at 21:07 UTC | |
by fwalters (Novice) on Feb 17, 2017 at 13:29 UTC | |
|