initial commit
This commit is contained in:
commit
97e4817a59
4 changed files with 41 additions and 0 deletions
8
auth-testing.ini
Normal file
8
auth-testing.ini
Normal 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
3
auth.cfg.dist
Normal 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
25
auth.py
Normal 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
5
templates/login.html
Normal 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>
|
Loading…
Add table
Reference in a new issue