LoginSignup
20

More than 1 year has passed since last update.

shell2httpを作ってHTTP経由でお手軽にCLIツールを実行する

Last updated at Posted at 2022-08-12

shell2httpをsnapで入れると動かず、Flask-Shell2HTTPはファイルを直接弄らないといけないのでPythonで作ってみました。

PythonPyPI

インストール

pip install shell2http

使い方

http://localhost:8080/ をブラウザで開くことでコマンドが実行されます。8080は変更可能です。

shell2http [options] ["shell command" for /] /path "shell command" /path2 "shell command2" ...
options:
    -p, --port NNNN : port for http server ( default 8080 )

Windows

curl localhost:8080するとシャットダウンできます。 http://localhost:8080/ を開いてもシャットダウンできます。

shell2http 'shutdown -s -t 0'

curl localhost:8080/beepでビープ音が鳴ります。

shell2http 'shutdown -s -t 0' /beep 'echo ^G'

http://localhost:3306/beep を開くとビープ音が鳴ります。

shell2http --port 3306 /beep 'echo ^G'

Linux

curl localhost:8080すると通知が届きます。 http://localhost:8080/ を開いても通知が届きます。

shell2http 'notify-send Hello root'

curl localhost:3000/pathでサウンドが再生されます。

shell2http -p3000 'notify-send Hello root' /path 'canberra-gtk-play -i desktop-login'
shell2http -p3000 /path 'canberra-gtk-play -i desktop-login'

例えば、ポートフォワーディング(UPnP)してプロセスがやられたら、外からデスクトップに音を鳴らしたり通知できます。リクエストのパラメータを使用しないのでosコマンドインジェクションも問題ないと思います。

本家のshell2httpよりも5倍高速で100ms以内に実行できます。
image.png

謝辞

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20