如何从我的Web应用程序向bash脚本发送参数,然后将其结果用于在浏览器中呈现它

时间:2014-08-13 17:37:43

标签: php bash shell cgi shell-exec

我正在使用shellinabox终端将其集成到我的Web应用程序中。事实上,我希望连接到我的应用程序的每个用户都能够连接到它的机器(我已经拥有了他们的IP地址)。为此,我想放一个按钮,当用户点击它时,我将IP地址作为参数($ param)发送到脚本。然后脚本将获取此参数,并尝试在CGI模式下启动shellinabox以连接到其远程主机。

这是我的脚本代码:

#!/bin/bash

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

function connect {
shellinaboxd --cgi -c /var/lib/shellinabox -s /:SSH:$parm
if [ $? -ne 0 ]; then
echo "$res" > /tmp/1.log
cannot_connect
fi
}
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 $parm</p>
   </body>
 EOF
 }

 case "${REQUEST_METHOD}" in
 GET)
 # Retrieve CGI parameter, then start shellinabox with this address
 parms=`echo $QUERY_STRING`
 if [ "$parm" != "" ]; then
    connect $parm
 else
    default
 fi
 ;;

 *)
 default
 ;;
 esac  

我的php文件的原理就是获取脚本的结果并在浏览器中呈现它:     有点像(原因不仅仅是这个!!)

  $message=shell_exec("/var/www/html/shellinabox.sh 2>&1");
  print_r($message);

但是我不知道如何将参数($ param)传递给脚本,以及在脚本返回结果后如何对php进行正确渲染。

你能帮帮我吗?

0 个答案:

没有答案