main.py
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 33 34 35 36 37 38 |
from flask import Flask, request, jsonify import subprocess app = Flask(__name__) @app.route('/') def index(): return "Servidor Flask en funcionamiento." @app.route('/sistema-de-archivos', methods=['GET']) def sistema_de_archivos(): action = request.args.get('action') if action == 'listar': result = subprocess.run(['ls'], capture_output=True, text=True) elif action == 'crear': tipo = request.args.get('tipo') nombre = request.args.get('nombre') if tipo == 'file': result = subprocess.run(['touch', nombre], capture_output=True, text=True) elif tipo == 'directory': result = subprocess.run(['mkdir', nombre], capture_output=True, text=True) elif action == 'abrir': nombre = request.args.get('nombre') result = subprocess.run(['xdg-open', nombre], capture_output=True, text=True) elif action == 'eliminar': nombre = request.args.get('nombre') result = subprocess.run(['rm', '-r', nombre], capture_output=True, text=True) else: return jsonify({"error": "Acción no válida"}), 400 if result.returncode == 0: return jsonify({"output": result.stdout}) else: return jsonify({"error": result.stderr}), 500 if __name__ == '__main__': app.run(host='0.0.0.0', port=5000) |