goingyt commited on
Commit
7e0dee4
Β·
verified Β·
1 Parent(s): a347a2b

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +17 -1
app/main.py CHANGED
@@ -1,10 +1,26 @@
 
 
1
  from flask import Flask, render_template
 
2
 
3
  app = Flask(__name__)
 
 
4
 
5
  @app.route('/')
6
  def index():
7
  return render_template('index.html')
8
 
 
 
 
 
 
 
 
 
 
 
 
9
  if __name__ == '__main__':
10
- app.run(host='0.0.0.0', port=7860)
 
1
+ import os
2
+ import subprocess
3
  from flask import Flask, render_template
4
+ from flask_socketio import SocketIO, emit
5
 
6
  app = Flask(__name__)
7
+ app.config['SECRET_KEY'] = 'secret!'
8
+ socketio = SocketIO(app)
9
 
10
  @app.route('/')
11
  def index():
12
  return render_template('index.html')
13
 
14
+ @socketio.on('input', namespace='/terminal')
15
+ def handle_input(data):
16
+ command = data['command']
17
+ result = execute_command(command)
18
+ emit('output', {'output': result})
19
+
20
+ def execute_command(command):
21
+ result = subprocess.run(['docker', 'exec', 'terminal-website_ubuntu_1', 'bash', '-c', command],
22
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
23
+ return result.stdout.decode('utf-8') + result.stderr.decode('utf-8')
24
+
25
  if __name__ == '__main__':
26
+ socketio.run(app, host='0.0.0.0', port=7860)