| import os |
| import pexpect |
| from flask import Flask, render_template |
| from flask_socketio import SocketIO, emit |
|
|
| app = Flask(__name__) |
|
|
| socketio = SocketIO(app) |
|
|
| @app.route('/') |
| def index(): |
| return render_template('index.html') |
|
|
| @socketio.on('command') |
| def handle_command(command): |
| output = run_command(command) |
| emit('output', output) |
|
|
| def run_command(command): |
| child = pexpect.spawn(command) |
| child.timeout = 5 |
| try: |
| child.expect(pexpect.EOF) |
| return child.before.decode('utf-8') |
| except pexpect.exceptions.TIMEOUT: |
| return 'Command timed out.' |
|
|
|
|
| |
| |
|
|