Skip to content

Simple Python HTTP(S) API/Web Terminal share / Remote executor

License

Notifications You must be signed in to change notification settings

joknarf/pywebexec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pypi version example Licence PyPI Downloads Python versions

pywebexec

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

Install

$ pip install pywebexec

Quick start

  • share terminal
$ 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
  • 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

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
$ export PYWEBEXEC_LDAP_SERVER=ldap://ldap.forumsys.com:389
$ export PYWEBEXEC_LDAP_BIND_DN="cn=read-only-admin,dc=example,dc=com"
$ export PYWEBEXEC_LDAP_BIND_PASSWORD="password"
$ export PYWEBEXEC_LDAP_GROUPS="ou=mathematicians,ou=scientists"
$ export PYWEBEXEC_LDAP_USER_ID="uid"
$ export PYWEBEXEC_LDAP_BASE_DN="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/run_command -H 'Content-Type: application/json' -X POST -d '{ "command":"myscript", "params":["param1", ...]}'
$ curl http://myhost:8080/command_status/<command_id>
$ curl http://myhost:8080/command_output/<command_id> -H "Accept: text/plain"

API reference

method route params/payload returns
POST /run_command command: str
params: array[str]
command_id: uuid
message: str
POST /stop_command/command_id message: str
GET /command_status/command_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 /command_output/command_id offset: int output: str
status: str
links: { next: str }
GET /commands array of
command_id: uuid
command: str
start_time: isotime
end_time: isotime
status: str
exit_code: int
last_output_line: str
GET /executables array of str