From 97e4817a59db7e044c5d7337e5b284f8b34d0873 Mon Sep 17 00:00:00 2001 From: Tomek Dubrownik Date: Fri, 14 Sep 2012 22:45:25 +0200 Subject: [PATCH] initial commit --- auth-testing.ini | 8 ++++++++ auth.cfg.dist | 3 +++ auth.py | 25 +++++++++++++++++++++++++ templates/login.html | 5 +++++ 4 files changed, 41 insertions(+) create mode 100644 auth-testing.ini create mode 100644 auth.cfg.dist create mode 100644 auth.py create mode 100644 templates/login.html diff --git a/auth-testing.ini b/auth-testing.ini new file mode 100644 index 0000000..0252046 --- /dev/null +++ b/auth-testing.ini @@ -0,0 +1,8 @@ +[uwsgi] +plugins = python27 +http = 0.0.0.0:8082 +master = 1 +threads = 10 +module = auth +callable = app +debug = true diff --git a/auth.cfg.dist b/auth.cfg.dist new file mode 100644 index 0000000..20566bd --- /dev/null +++ b/auth.cfg.dist @@ -0,0 +1,3 @@ +LDAP_URL = 'ldap://ldap.hackerspace.pl' +DN_STRING = 'uid=%s,ou=People,dc=hackerspace,dc=pl' +FAIL_DELAY = 0.5 diff --git a/auth.py b/auth.py new file mode 100644 index 0000000..e9b301a --- /dev/null +++ b/auth.py @@ -0,0 +1,25 @@ +import ldap +from flask import Flask, render_template, request +from time import sleep +app = Flask('auth') +app.config.from_object(__name__) +app.config.from_pyfile('auth.cfg') + +@app.route('/', methods=['GET']) +def form(): + return render_template('login.html') + +@app.route('/', methods=['POST']) +def login(): + conn = ldap.initialize(app.config['LDAP_URL']) + conn.start_tls_s() + try: + conn.simple_bind_s(app.config['DN_STRING'] % request.form['login'], + request.form.get('password', '')) + except ldap.LDAPError: + sleep(app.config['FAIL_DELAY']) + return "ERROR" + return "OK" + +if __name__ == '__main__': + app.run('0.0.0.0', 8082, debug=True) diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..5e8b562 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,5 @@ +
+ + + +