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?

In reply to Net::OpenSSH + CGI problem by fwalters

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.