Repository navigation
Expand file tree
/
Copy pathFlaskControl.py
More file actions
72 lines (56 loc) · 1.67 KB
/
Copy pathFlaskControl.py
File metadata and controls
72 lines (56 loc) · 1.67 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
69
70
71
72
from flask import Flask, render_template, redirect, url_for, request
import subprocess
app = Flask(__name__)
USERNAME = 'dan'
@app.route("/")
def index():
"""
Index view that displays the ls output of the shares dir
"""
out = subprocess.check_output('ls -l ~/shares/', shell=True)
lines = out.split("\n")
return render_template('shares.html', lines=lines, uname=USERNAME)
@app.route("/remount")
def remount():
"""
Triggers a remount of the shares
"""
out = "output:\n"
out += subprocess.check_output(['./remount.sh', USERNAME, '&'], stderr=subprocess.STDOUT)
return render_template('shares.html', output=out)
@app.route("/kill")
def kill():
"""
Kills a pid
"""
pid = request.args.get('pid')
subprocess.call(["kill", pid])
return redirect(url_for('procs',p=pid))
@app.route("/procs")
def procs():
"""
Displays the output from ps -ef
-p filters the output
"""
pname = request.args.get('p', '')
procs = []
out = subprocess.check_output(['ps -ef'], shell=True)
lines = out.split("\n")
headers = lines[0].split()
for l in lines[1:]:
if pname != '' and pname in l:
procs.append(splitproc(l,headers))
elif pname == '':
procs.append(splitproc(l,headers))
return render_template('procs.html', procs=procs, headers=headers)
def splitproc(input, headers):
"""
Takes a line of output from ps & column headers
Returns a dict using the headers as keys
"""
vals = input.split(None,len(headers)-1)
output = dict(zip(headers,vals))
return output
if __name__ == "__main__":
app.debug = True
app.run(host="0.0.0.0")