Skip to content

Instantly share code, notes, and snippets.

@abd1rahmane
Created June 17, 2019 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abd1rahmane/fcaea5c7e69a75c987f55df2e5ae87eb to your computer and use it in GitHub Desktop.
Save abd1rahmane/fcaea5c7e69a75c987f55df2e5ae87eb to your computer and use it in GitHub Desktop.
Bash as Rest service (unsecure)
# -*- coding: utf-8 -*-
from flask import Flask
from flask import jsonify, request, render_template
import subprocess
app = Flask(__name__)
@app.route('/bash/run/', methods=['GET'])
def run_script():
command = request.args.get('command', default = '', type = str)
print(command)
ok = False
try:
subprocess.Popen(command, shell=True,stdin=None, stdout=None, stderr=None, close_fds=True)
#print(p.read())
ok = True
except Exception as e:
print(e)
print(ok)
return jsonify(ok)
if __name__ == '__main__':
app.run(host='0.0.0.0',port='5050',debug=False) #
@abd1rahmane
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment