跳转到主要内容

安全地在浏览器中提供多个隔离的终端会话

项目描述

runthis-server

RunThis Server是一个通过HTTP提供唯一、交互式终端会话的工具。这使得各种命令行应用程序的交互式演示页面和文档成为可能。

安装

RunThis-server可以使用conda或pip进行安装

# use the conda-forge channel
$ conda install -c conda-forge runthis-server

# Or you can use Pip, if you must.
$ pip install runthis-server

测试用法

您可以使用runthis-server命令行工具启动服务器。

$ runthis-server --help
usage: runthis-server [-h] [--config CONFIG]

optional arguments:
  -h, --help       show this help message and exit
  --config CONFIG  Path to config file

生产用法

对于生产环境,我们推荐使用hypercorn,因为这里的服务器是一个Quart应用程序。要一起使用RunThis Server + hypercorn,请运行以下命令

$ hypercorn runthis.server.hypercorn:app

或者如果您需要使用HTTPS证书运行

$ hypercorn runthis.server.hypercorn:app \
    --certfile /pat/to/certs/fullchain.pem \
    --keyfile /path/to/certs/privkey.pem \
    --bind 0.0.0.0:80

注意:当前在hypercorn下运行时,无法将配置文件路径传递给runthis服务器。服务器将仅在当前工作目录中查找runthis-server.yml文件并使用它。如果不存在此类文件,将使用默认值!请在运行hypercorn之前将目录更改到runthis-server.yml文件的位置。

配置

默认情况下,服务器配置为通过在当前工作目录中查找runthis-server.yml文件来运行。您可以使用--config标志传入特定的配置文件。

所有配置变量都是可选的。以下列出其含义和默认值。通常,这些作为YAML文件中的顶级键出现

# The path to the public certificate file. This is currently only
# used by the hypercorn interface, and is passed directly though
# to hypercorn's configuration.
certfile: None

# The command variable is a string that lists ths command, or path
# to run whenever a new instance is requested. Nominally, this is
# a command that starts a REPL, but doesn't have to be.
command: "python3"

# The docker variable is a boolean that determines whether or not
# the command should be run in its own single-use docker container.
# Docker, of course, must be available on the host.
docker: true

# The docker_image varible specifies which docker image should be
# started up if the command is being run in a docker container.
docker_image: "ubuntu:latest"

# The host variable is the URL or IP address that the server is
# running on. By default, this is "127.0.0.1". Other valid options are
# "0.0.0.0", which will expose the server to the outside world, as well
# as any valid CNAME or IP address. RunThis Server works by taking in
# a request and then redirecting to a new port on this server. The selection
# of the host determines the redirection address. Here is the mapping:
#
#  host        -> TTY redirect_base
#  127.0.0.1   -> 0.0.0.0
#  0.0.0.0     -> IP address of server as seen by https://api.ipify.org
#  IP or CNAME -> Same IP or CNAME
host: "127.0.0.1"

# The path to the private certificate file. This is currently only
# used by the hypercorn interface, and is passed directly though
# to hypercorn's configuration.
certfile: None

# The port variable is an int that specifies the port number that the
# the RunThis Server itself operates on. The TTY redirects go to
# separate ports. Therefore you would access the RunThis Server as f"http://{host}:{port}"
port: 5000

# The tty_server variable is a string flag that represents the TTY server software that
# will be executed each time a request is made. Currently, the valid options are:
#
#  gotty: go-based TTY server https://github.com/yudai/gotty
#  ttyd: C++ TTY server https://tsl0922.github.io/ttyd/
tty_server: "gotty"

# The gotty_path is the path to the gotty executable
gotty_path: "gotty"

# The ttyd_path is the path to the ttyd executable
ttyd_path: "ttyd"

# The tty_server_port_start variable is an integer at which the TTY servers
# will start serving their terminals. Each successive request increases this
# value by one, so that each session recieves its own unique value.
tty_server_port_start: 8080

如果需要与其他文件兼容,上述值也可以嵌入到顶级runthis键中。例如,

runthis:
    host: 0.0.0.0
    port: 80

请求参数

服务器请求发送到URL "http://{host}:{port}"。然而,此URL接受GET或POST请求,并以下列参数作为选项。

预设:这是新解释器会话初始化的代码。它执行时不会通知用户。

设置:这是在执行预设代码后,解释器启动时执行的代码。此外,在执行之前,此代码以源形式打印(显示)给用户。这对于运行示例很好。

例如,以下GET请求将静默运行import sys,然后在打印"print(sys.executable)"后执行print(sys.executable)

http://127.0.0.1:5000/?presetup=import+sys&setup=print%28sys.executable%29

通常,您应该使用URL编码库为您生成这些URL。

项目详情


下载文件

下载适合您平台文件的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分发

runthis-server-0.0.4.tar.gz (6.9 kB 查看哈希值)

上传时间

由以下支持