Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate shellinabox in CGI mode into my web application #260

Open
GoogleCodeExporter opened this issue Mar 16, 2015 · 0 comments
Open

Comments

@GoogleCodeExporter
Copy link


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 [email protected] on 14 Aug 2014 at 1:35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant