linux - 是否可以通过 http 创建适当的交互式 shell?

标签 linux

我想通过 http 进行 shell 访问以与我的服务器上运行的程序进行交互(而不是 SSH 和其他协议(protocol))。我做了一些研究,发现了两种主要方式,php 方式如 http://sourceforge.net/projects/phpterm/和CGI方式。尽管这些会导致通过 http 产生类似 shell 的终端,但如果不在运行时传递参数,我就无法与具有标准输入/输出的程序进行交互:./prog -options etc.. 使用基于 netcat 的标准外壳,例如 ./prog 将提供完整的交互,以便它可以提示输入等。

我运行的测试程序是:

#include<stdio.h>
#include<sys/types.h>
include<stdlib.h>
int main ()
{

    // set up keyword(passcode)
    char this[14];
    char that[128];

    // check the password and exit if it doesn't match;
    fgets(this, 14, stdin);
    if (strncmp(this, "passwd\n", 14)) {
        exit(0);
    }
    printf("shell interaction success! \n");
    fgets(that, 128, stdin);
    system(that);
    exit(0);
}  

如果从 netcat 运行,会发生这种情况:

./prog
passwd
Shell interaction success

如果通过 http 从其他 shell 解决方案运行,我会访问:

./prog
then nothing.

希望有人知道怎么做!

最佳答案

您可以这样做,但由于 HTTP 是一种无连接的请求-响应协议(protocol),它不会只使用一个 HTTP 连接。

  • 浏览器会请求在远程服务器上启动 shell
  • 将启动一个后端服务来创建所需的进程并捕获标准输入/标准输出管道
  • 浏览器上的 Javascript 会向服务器发送(可能是 POST)请求说“这个用户输入了一些字符”
  • 某种 AJAX 请求轮询循环将从后端进程获取新的输出并将其显示在浏览器上

或者,这可以使用 WebSockets 大大简化这是一种流协议(protocol)(由某些浏览器实现,但不是 HTTP)。

关于linux - 是否可以通过 http 创建适当的交互式 shell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8983882/

相关文章:

linux - Tshark 和 Web 服务器响应时间

c++ - clock_getres 和 clock_gettime

linux - Bash:如果管道 IO 空闲则关闭

linux - 尽管与存档有直接链接,但对任何 libc 符号的 undefined reference

mysql - linux下MYSQL获取数据问题

c - 逐 block 反转文件内容

php - 从 php 启动一个独立进程(通过 httpd)

linux - 在 *nix 环境中,我如何将列组合在一起?

java - "No X11 DISPLAY variable"- 这是什么意思?

linux - 在 Linux 中编写快捷的临时 GUI 应用程序的最简单方法(语言、工具等)是什么?