All Projects → eshaan7 → Flask-Shell2HTTP

eshaan7 / Flask-Shell2HTTP

Licence: BSD-3-Clause license
Execute shell commands via HTTP server (via flask's endpoints).

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Flask-Shell2HTTP

executor
A powerful "short-cutter" to your console to you and your team!
Stars: ✭ 21 (-77.42%)
Mutual labels:  executor
orbiter
Orbiter is a tool for collecting and redistributing webhooks over the network.
Stars: ✭ 20 (-78.49%)
Mutual labels:  webhook
movie-trailer
🎥 Fetch movie trailers: "Crash" ➔ http://path/to/trailer
Stars: ✭ 19 (-79.57%)
Mutual labels:  callback
create-shopify-app
Create Shopify App With JWT Authentication using NodeJs, React, Shopify Polaris and MongoDb
Stars: ✭ 58 (-37.63%)
Mutual labels:  webhook
imageswap-webhook
Image Swap Mutating Admission Webhook for Kubernetes
Stars: ✭ 72 (-22.58%)
Mutual labels:  webhook
pm2-githook
receive webhook from github/gitlab and ask pm2 to reload the application for you
Stars: ✭ 39 (-58.06%)
Mutual labels:  webhook
notify
推送通知 sdk(Bark、Chanify、钉钉群机器人、Discord、邮件、飞书群机器人、Gitter、Google Chat、iGot、Logger、Mattermost、Now Push、PushBack、Push、PushDeer、PushPlus、QQ 频道机器人、Rocket Chat、Server 酱、Showdoc Push、Slack、Telegram、Webhook、企业微信群机器人、息知、Zulip)。
Stars: ✭ 335 (+260.22%)
Mutual labels:  webhook
goodfirstissue
openfaas function to handle webhooks for goodfirstissue github app
Stars: ✭ 20 (-78.49%)
Mutual labels:  webhook
DiscordWebhook
Discord webhook library in C#
Stars: ✭ 22 (-76.34%)
Mutual labels:  webhook
tilt-pitch
Simple replacement for the Tilt Hydrometer mobile apps and TiltPi with lots of features
Stars: ✭ 32 (-65.59%)
Mutual labels:  webhook
zoom-slack-status-updater
Update your Slack status automatically when you join a Zoom meeting.
Stars: ✭ 23 (-75.27%)
Mutual labels:  webhook
GitHub-Webhook-Bot
It is a Simple Telegram Bot, which will listen to GitHub Webhook and inform via Telegram
Stars: ✭ 33 (-64.52%)
Mutual labels:  webhook
laravel-dingtalk
✨基于laravel5.5开发的钉钉机器人、支持多个钉钉群
Stars: ✭ 18 (-80.65%)
Mutual labels:  webhook
pr-reviews-reminder-action
A GitHub Action to send Slack/Teams notification for Pull Request that are waiting for reviewers.
Stars: ✭ 18 (-80.65%)
Mutual labels:  webhook
teamcity-commit-hooks
Plugin for TeamCity simplifying installation of webhooks for repositories in GitHub and GitHub Enterprise.
Stars: ✭ 24 (-74.19%)
Mutual labels:  webhook
drf-stripe-subscription
An out-of-box Django REST framework solution for payment and subscription management using Stripe.
Stars: ✭ 42 (-54.84%)
Mutual labels:  webhook
datamosh
✨💾 Edit images via buffers. 💯✨
Stars: ✭ 23 (-75.27%)
Mutual labels:  callback
tesoro
Kapitan Admission Controller Webhook
Stars: ✭ 32 (-65.59%)
Mutual labels:  webhook
epump
ePump是一个基于I/O事件通知、非阻塞通信、多路复用、多线程等机制开发的事件驱动模型的 C 语言应用开发框架,利用该框架可以很容易地开发出高性能、大并发连接的服务器程序。
Stars: ✭ 26 (-72.04%)
Mutual labels:  callback
python-executor
Programmer friendly subprocess wrapper
Stars: ✭ 88 (-5.38%)
Mutual labels:  subprocess

Get Support

For urgent issues and priority support, visit https://xscode.com/eshaan7/flask-shell2http.

Flask-Shell2HTTP

flask-shell2http on pypi Build Status codecov CodeFactor Language grade: Python

A minimalist Flask extension that serves as a RESTful/HTTP wrapper for python's subprocess API.

  • Convert any command-line tool into a REST API service.
  • Execute pre-defined shell commands asynchronously and securely via flask's endpoints with dynamic arguments, file upload, callback function capabilities.
  • Designed for binary to binary/HTTP communication, development, prototyping, remote control and more.

Use Cases

  • Set a script that runs on a succesful POST request to an endpoint of your choice. See Example code.
  • Map a base command to an endpoint and pass dynamic arguments to it. See Example code.
  • Can also process multiple uploaded files in one command. See Example code.
  • This is useful for internal docker-to-docker communications if you have different binaries distributed in micro-containers. See real-life example.
  • You can define a callback function/ use signals to listen for process completion. See Example code.
    • Maybe want to pass some additional context to the callback function ?
    • Maybe intercept on completion and update the result ? See Example code
  • You can also apply View Decorators to the exposed endpoint. See Example code.

Note: This extension is primarily meant for executing long-running shell commands/scripts (like nmap, code-analysis' tools) in background from an HTTP request and getting the result at a later time.

Documentation

Documentation Status

Quick Start

Dependencies
Installation
$ pip install flask flask_shell2http
Example Program

Create a file called app.py.

from flask import Flask
from flask_executor import Executor
from flask_shell2http import Shell2HTTP

# Flask application instance
app = Flask(__name__)

executor = Executor(app)
shell2http = Shell2HTTP(app=app, executor=executor, base_url_prefix="/commands/")

def my_callback_fn(context, future):
  # optional user-defined callback function
  print(context, future.result())

shell2http.register_command(endpoint="saythis", command_name="echo", callback_fn=my_callback_fn, decorators=[])

Run the application server with, $ flask run -p 4000.

With <10 lines of code, we succesfully mapped the shell command echo to the endpoint /commands/saythis.

Making HTTP calls

This section demonstrates how we can now call/ execute commands over HTTP that we just mapped in the example above.

$ curl -X POST -H 'Content-Type: application/json' -d '{"args": ["Hello", "World!"]}' http://localhost:4000/commands/saythis
or using python's requests module,
# You can also add a timeout if you want, default value is 3600 seconds
data = {"args": ["Hello", "World!"], "timeout": 60}
resp = requests.post("http://localhost:4000/commands/saythis", json=data)
print("Result:", resp.json())

Note: You can see the JSON schema for the POST request here.

returns JSON,

{
  "key": "ddbe0a94",
  "result_url": "http://localhost:4000/commands/saythis?key=ddbe0a94&wait=false",
  "status": "running"
}

Then using this key you can query for the result or just by going to the result_url,

$ curl http://localhost:4000/commands/saythis?key=ddbe0a94&wait=true # wait=true so we do not have to poll

Returns result in JSON,

{
  "report": "Hello World!\n",
  "key": "ddbe0a94",
  "start_time": 1593019807.7754705,
  "end_time": 1593019807.782958,
  "process_time": 0.00748753547668457,
  "returncode": 0,
  "error": null
}

Inspiration

This was initially made to integrate various command-line tools easily with Intel Owl, which I am working on as part of Google Summer of Code.

The name was inspired by the awesome folks over at msoap/shell2http.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].