mellon85 / shellinabox

Automatically exported from code.google.com/p/shellinabox
Other
0 stars 0 forks source link

Integrate shellinabox in CGI mode into my web application #260

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

Could you please tell me how we can use a script (for using shellinabox in CGI 
mode)from a php file. In fact, I have a web application and I want every time 
to specify which host to connect to, every time a user wants to connect to his 
machine, and then return the terminal to him in another window. In brief, I 
don't know how to make the script and php to interact with each other, to make 
the app take the result rendered by the script.

Thank you in advance !!

What I tried is this 

== shellinabox.sh ==

#!/bin/bash

# ssh.sh
# This is a CGI script that uses shellinabox in CGI mode.

function connect {
    #printf 'Connection to:'
    #printf $parms
    shellinaboxd --cgi -c /var/lib/shellinabox -s /:SSH:$parms
    #printf 'Connection2'
    if [ $? -ne 0 ]; then
    echo "$res" > /tmp/1.log
    cannot_connect
    fi
}

function default {
     # First time that the CGI script was called. Show initial HTML page.
     printf 'Content-Type: text/html\r\n\r\n'
     cat <<EOF
     <html>
       <head>
         <title>SSH Shell</title>
       </head>
       <body>
         <h1>SSH Shell</h1>

         <p>Enter address to connect to:
         <form method="POST">
           <input type="text" name="cmd" style="width: 40em" value="127.0.0.1" />
            <button type="submit" value="Klick!">Submit</button>
         </form>
         </p>
       </body>
EOF
}

function cannot_connect {
     printf 'Content-Type: text/html\r\n\r\n'
     cat <<EOF
     <html>
       <head>
         <title>SSH Shell</title>
       </head>
       <body>
         <h1>SSH Shell</h1>

         <p>Unable to establish connection with $parms</p>
       </body>
EOF
}

parms="$1"
     if [ "$parms" != "" ]; then
        connect $parms
     else
        default
     fi

and my simple php file is :

== terminal.php ==

<?php
      $message=shell_exec("/var/www/html/shellinabox2.sh 10.197.160.42 2>&1");
      print_r($message);
    ?>

=========
The problem is that the app doesn't return the terminal, but the following code:

X-ShellInABox-Port: 58196 X-ShellInABox-Pid: 10535 Content-type: text/html; 
charset=utf-8 

Please any help ?

Original issue reported on code.google.com by Abderrah...@gmail.com on 14 Aug 2014 at 1:35