30 lines
854 B
Python
30 lines
854 B
Python
from flask import Flask, request, jsonify
|
|
import subprocess
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route('/execute', methods=['POST'])
|
|
def execute_command():
|
|
data = request.json
|
|
# The 'command' key in the JSON request should contain the command to be executed.
|
|
command = data.get('command', '')
|
|
|
|
# Execute the command without any safety checks.
|
|
try:
|
|
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
stdout, stderr = process.communicate()
|
|
|
|
return jsonify({
|
|
'status': 'success',
|
|
'output': stdout.decode(),
|
|
'error': stderr.decode()
|
|
})
|
|
except Exception as e:
|
|
return jsonify({
|
|
'status': 'error',
|
|
'message': str(e)
|
|
}), 500
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True, host="0.0.0.0")
|