-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
52 lines (39 loc) · 1.55 KB
/
server.py
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
from flask import Flask, jsonify, request, Response
from flask_httpauth import HTTPBasicAuth
import subprocess
from flask_cors import CORS
app = Flask(__name__)
auth = HTTPBasicAuth()
CORS(app)
def pass_store():
pass_store.var = 'mypass'
@auth.verify_password
def verify_password(username, password):
pass_store.var = password
if username != "":
return True
return False
@auth.get_password
def get_password(username):
return pass_store.var
pass_store()
@app.route('/grades', methods = ['GET'])
@auth.login_required
def myhome():
cmd = ['/bin/bash', '/opt/dualis-app/NOTEN.sh', '-u', auth.username(), '-p', get_password(auth.username())]
o = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
data = o.decode('utf-8')
if (data == "[\n]\n"):
return Response("{\"error\": {\"status\": 401, \"message\":\"Bad Authentication data!\"}}", status=401, mimetype='application/json')
return Response(data, mimetype='application/json')
@app.route('/modules', methods = ['GET'])
@auth.login_required
def mymodules():
cmd = ['/bin/bash', '/opt/dualis-app/MODULE.sh', '-u', auth.username(), '-p', get_password(auth.username())]
o = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
data = o.decode('utf-8')
if (data == "[\n]\n"):
return Response("{\"error\": {\"status\": 401, \"message\":\"Bad Authentication data!\"}}", status=401, mimetype='application/json')
return Response(data, mimetype='application/json')
if __name__ == '__main__':
app.run(debug = True, host='0.0.0.0', port='5001')