Skip to main content

Simple Python HTTP Exec Server

Project description

Pypi version Publish Package Licence PyPI Downloads Python versions

pywebexec

Simple Python HTTP(S) API/Web Server Command Launcher and Terminal sharing

Install

$ pip install pywebexec

Quick start

  • share terminal
    • start http server and spawn a new terminal shared on 0.0.0.0 port 8080 (defaults)
    • exiting terminal stops server/share
$ pywebexec shareterm
  • serve executables
    • put in a directory the scripts/commands/links to commands you want to expose
    • start http server serving current directory executables listening on 0.0.0.0 port 8080
$ pywebexec -d <dir>
  • Launch commands with params/view live output/Status using browser
  • Share your terminal output using pywebexec -d <dir> term

pywebexecnew11

all commands output / statuses are available in the executables directory in subdirectory .web_status

features

  • Serve executables in a directory
  • full API driven with dynamic swagger UI
  • Launch commands with params from web browser or API call
  • multiple share terminal output
  • Follow live output
  • Replay terminal history
  • Stop command
  • Relaunch command
  • HTTPS support
  • HTTPS self-signed certificate generator
  • Basic Auth
  • LDAP(S) password check/group member
  • Safe url token generation
  • Can be started as a daemon (POSIX)
  • Uses gunicorn to serve http/https
  • Linux/MacOS compatible
  • Markdown help for commands

Customize server

$ pywebexec --dir ~/myscripts --listen 0.0.0.0 --port 8080 --title myscripts
$ pywebexec -d ~/myscripts -l 0.0.0.0 -p 8080 -t myscripts

Sharing terminals

  • start server and share tty in one command
$ pywebexec -d ~/webshare shareterm
  • share tty with an already pywebexec server started
$ pywebexec -d ~/webshare term

if another user need to share his terminal, he need to have write permission on <dir>/.web_status directory.

Safe url token

  • generate safe url, use the url to access the server
$ pywebexec -T
$ pywebexec --tokenurl
Starting server:
http://<host>:8080?token=jSTWiNgEVkddeEJ7I97x2ekOeaiXs2mErRSKNxm3DP0
http://x.x.x.x:8080?token=jSTWiNgEVkddeEJ7I97x2ekOeaiXs2mErRSKNxm3DP0

Basic auth

  • single user/password
$ pywebexec --user myuser [--password mypass]
$ pywebexec -u myuser [-P mypass]

Generated password is given if no --pasword option

  • ldap(s) password check / group member ldap server must accept memberOf attribute for group members
$ export PYWEBEXEC_LDAP_SERVER=ldaps://ldap.mydomain.com:389
$ export PYWEBEXEC_LDAP_BIND_DN="cn=read-only-admin,dc=example,dc=com"
$ export PYWEBEXEC_LDAP_BIND_PASSWORD="password"
$ export PYWEBEXEC_LDAP_BASE_DN="dc=example,dc=com"
$ export PYWEBEXEC_LDAP_USER_ID="uid" # sAMAccountName for AD
$ export PYWEBEXEC_LDAP_GROUPS="ou=mathematicians,dc=example,dc=com ou=scientists,dc=example,dc=com"
$ pywebexec

HTTPS server

  • Generate auto-signed certificate and start https server
$ pywebexec --gencert
$ pywebexec --g
  • Start https server using existing certificate
$ pywebexec --cert /pathto/host.cert --key /pathto/host.key
$ pywebexec -c /pathto/host.cert -k /pathto/host.key

Launch server as a daemon

$ pywebexec start
$ pywebexec status
$ pywebexec stop
  • log of server are stored in directory ~/[.config/].pywebexec/pywebexec_<listen>:<port>.log

Launch command through API

$ curl http://myhost:8080/commands/myscript -H 'Content-Type: application/json' -X POST -d '{"params":["param1", ...]}'
$ curl http://myhost:8080/commands/<command_id>
$ curl http://myhost:8080/commands/<command_id>/output -H "Accept: text/plain"

Add markdown help to commands

For each exposed command, you can add a help message by creating a file named <command>.help in the same directory as the command. The help message must be written in markdown.
The help message is displayed:

  • in the web interface as tooltip when focused on param input field,
  • in the response when calling the API /executables
  • in the swagger-ui in the /commands/<command> route.

Swagger UI

A swagger UI is available at http[s]://<srv>/v0/documentation

API reference

method route params/payload returns
GET /commands/exposed commands: [
  {
    command: str,
    help: str
  },
]
GET /commands commands: [
  {
    command_id: uuid
    command: str
    start_time: isotime
    end_time: isotime
    status: str
    exit_code: int
    last_output_line: str
  },
]
GET /commands/{id} command_id: uuid
command: str
params: array[str]
start_time: isotime
end_time: isotime
status: str
exit_code: int
last_output_line: str
GET /commands/{id}/output offset: int output: str
status: str
links: { next: str }
GET /commands/{id}/output_raw offset: int output: stream raw output until end of command
curl -Ns http://srv/commands/{id}/output_raw
POST /commands command: str
params: array[str]
rows: int
cols: int
command_id: uuid
message: str
POST /commands/{cmd} params: array[str]
rows: int
cols: int
command_id: uuid
message: str
PATCH /commands/{id}/stop message: str
  • to get command output as text (without ANSI codes/Control characters) use: /commands/{id}/output with header "Accept: text/plain"

Project details


Release history Release notifications | RSS feed

This version

2.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywebexec-2.0.0.tar.gz (2.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywebexec-2.0.0-py3-none-any.whl (2.7 MB view details)

Uploaded Python 3

File details

Details for the file pywebexec-2.0.0.tar.gz.

File metadata

  • Download URL: pywebexec-2.0.0.tar.gz
  • Upload date:
  • Size: 2.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pywebexec-2.0.0.tar.gz
Algorithm Hash digest
SHA256 9e704ab64f7dc714041b6b5d0b78d382fe670154d9ddc0661d390c7adbdb5645
MD5 6aa64df49c00fb30b51bbc15da8cb3ea
BLAKE2b-256 4f4c2f9b6c3b925ac0ec56cd2332eebb6b9e56cd936aad5a4f35b62285494d30

See more details on using hashes here.

File details

Details for the file pywebexec-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: pywebexec-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for pywebexec-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91d722fff0dde55888024e09a851f44bb7596b0292f60560d77023015ca0afca
MD5 233cc49834788d002dc356c70fe8d54a
BLAKE2b-256 248cd1eaf2d2715074bc4989cfbf1c5411e4801634c62f3ce2dd571b46120b62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page