-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
42 lines (34 loc) · 1.2 KB
/
app.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
from flask import Flask, request, session, render_template, redirect
from dnd_ldap import lookup
import re
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def index():
qlist_txt = request.form.get('qlist_txt') or request.args.get('qlist_txt') or ''
separator = request.form.get('separator') or request.args.get('separator') or ';'
if qlist_txt:
qlist_txt = qlist_txt.strip(',;\n\r ')
qlist = re.split(',|;|\n', qlist_txt)
else:
qlist = []
conflicts = []
not_founds = []
blitzlist = []
for query in qlist:
results = lookup(query)
if results is None:
blitzlist = []
err_msg = "LDAP query failed"
elif len(results) == 1:
result = results[0]
blitzlist.append(result['Email'])
elif len(results) == 0:
not_founds.append(query)
elif len(results) > 1:
conflicts.append(query)
to_string = ("%s " % separator).join(blitzlist)
conflict_string = ", ".join(conflicts)
not_founds_string = ", ".join(not_founds)
return render_template('listr.html', **locals())
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=False)