-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapp.py
More file actions
68 lines (48 loc) · 1.51 KB
/
app.py
File metadata and controls
68 lines (48 loc) · 1.51 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# coding=utf-8
from public import app, socketio
from flask import render_template
from utils.command import ps_command, top_command, tail_command
@app.route('/')
def index():
return render_template('index.html')
@app.route('/tail', methods=['GET'])
def tail_html():
return render_template('tail.html')
@app.route('/top', methods=['GET'])
def top_html():
return render_template('top.html')
@app.route('/ps_aux', methods=['GET'])
def ps_aux_html():
return render_template('ps_aux.html')
@socketio.on('connect', namespace="/shell")
def connect():
print("connect..")
@socketio.on('disconnect', namespace="/shell")
def disconnect():
print("disconnect..")
@socketio.on('client', namespace="/shell")
def client_info(data):
print('client data', data)
_type = data.get('_type')
if _type == 'tail':
tail_command.background_thread()
elif _type == 'ps':
ps_command.background_thread()
elif _type == 'top':
top_command.background_thread()
else:
socketio.emit('response', {'text': '未知命令'}, namespace='/shell')
@socketio.on('leave', namespace="/shell")
def leave(data):
print('leave data', data)
_type = data.get('_type')
if _type == 'tail':
tail_command.leave()
elif _type == 'ps':
ps_command.leave()
elif _type == 'top':
top_command.leave()
else:
socketio.emit('response', {'text': '未知命令'}, namespace='/shell')
if __name__ == '__main__':
socketio.run(app, host='0.0.0.0', port=8000)