initial commit

master
Tomek Dubrownik 2012-09-14 22:45:25 +02:00
commit 97e4817a59
4 changed files with 41 additions and 0 deletions

8
auth-testing.ini Normal file
View File

@ -0,0 +1,8 @@
[uwsgi]
plugins = python27
http = 0.0.0.0:8082
master = 1
threads = 10
module = auth
callable = app
debug = true

3
auth.cfg.dist Normal file
View File

@ -0,0 +1,3 @@
LDAP_URL = 'ldap://ldap.hackerspace.pl'
DN_STRING = 'uid=%s,ou=People,dc=hackerspace,dc=pl'
FAIL_DELAY = 0.5

25
auth.py Normal file
View File

@ -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)

5
templates/login.html Normal file
View File

@ -0,0 +1,5 @@
<form action="" method="POST">
<label for="login">Login<input type="text" name="login"/></label>
<label for="password">Password<input type="password" name="password"/></label>
<input type="submit" value="login" />
</form>