|
from flask import Flask, render_template |
|
from flask_socketio import SocketIO, emit |
|
import subprocess |
|
|
|
app = Flask(__name__) |
|
app.config['SECRET_KEY'] = 'secret!' |
|
socketio = SocketIO(app) |
|
|
|
@app.route('/') |
|
def index(): |
|
return render_template('index.html') |
|
|
|
@socketio.on('execute_command') |
|
def handle_command(command): |
|
try: |
|
|
|
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
|
while True: |
|
output = process.stdout.readline() |
|
if output == '' and process.poll() is not None: |
|
break |
|
if output: |
|
emit('command_output', {'output': output.strip()}) |
|
|
|
|
|
error = process.stderr.read() |
|
if error: |
|
emit('command_output', {'output': error.strip()}) |
|
|
|
|
|
emit('command_output', {'output': '[Command execution finished]'}) |
|
except Exception as e: |
|
emit('command_output', {'output': str(e)}) |
|
|
|
if __name__ == '__main__': |
|
socketio.run(app, host='0.0.0.0', port=7860) |