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:
#!/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 console output (mostly :-)
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--
and...
Here is the browser output:
Logging In<br>
Also, in apache/errors.log I get:
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.
34 is the 'my @lines' line...
Any thoughts?