-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent
More file actions
31 lines (25 loc) · 1.06 KB
/
Copy pathagent
File metadata and controls
31 lines (25 loc) · 1.06 KB
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
import subprocess
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/execute', methods=['POST'])
def execute_command():
data = request.get_json()
commands = data.get('commands')
if not commands:
return jsonify({"error": "No commands provided"}), 400
# Execute the commands locally on the server where this agent is running
command_output = {}
for command in commands:
try:
result = subprocess.run(command, shell=True, capture_output=True, text=True)
command_output[command] = {
"success": result.returncode == 0,
"output": result.stdout.strip() if result.returncode == 0 else None,
"error": result.stderr.strip() if result.returncode != 0 else None
}
except Exception as e:
command_output[command] = {"success": False, "error": str(e)}
return jsonify({"commands_executed": command_output})
if __name__ == '__main__':
# Start Flask app, listening on port 5001
app.run(host='0.0.0.0', port=5001)