Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Video AG Infrastruktur
website
Commits
0701bac8
Commit
0701bac8
authored
Aug 24, 2016
by
Julian Rother
Browse files
Added ldap wrapper
parent
22c06b14
Changes
1
Hide whitespace changes
Inline
Side-by-side
server.py
View file @
0701bac8
#!/bin/python
from
flask
import
Flask
,
render_template
,
g
,
request
,
url_for
,
redirect
from
flask
import
Flask
,
render_template
,
g
,
request
,
url_for
,
redirect
,
session
import
mysql.connector
import
sqlite3
import
os
import
ldap3
import
re
app
=
Flask
(
__name__
)
config
=
app
.
config
...
...
@@ -71,6 +73,23 @@ def searchquery(text, columns, match, tables, suffix, *suffixparams):
expr
=
'SELECT *,SUM(_prio) AS _score FROM (%s) AS _tmp %s'
%
(
' UNION '
.
join
(
subexprs
),
suffix
)
return
query
(
expr
,
*
params
,
*
suffixparams
)
LDAP_USERRE
=
re
.
compile
(
r
'[^a-z0-9]'
)
def
ldapauth
(
user
,
password
):
notldap
=
{
'videoag'
:(
'videoag'
,
[
'users'
,
'videoag'
]),
'gustav'
:(
'passwort'
,
[
'users'
])}
user
=
LDAP_USERRE
.
sub
(
r
''
,
user
.
lower
())
if
'LDAP_HOST'
in
config
:
try
:
conn
=
ldap3
.
Connection
(
config
[
'LDAP_HOST'
],
'uid=%s,ou=users,dc=fsmpi,dc=rwth-aachen,dc=de'
%
user
,
password
,
auto_bind
=
True
)
if
conn
.
search
(
"ou=groups,dc=fsmpi,dc=rwth-aachen,dc=de"
,
"(&(cn=*)(memberUid=%s))"
%
user
,
attributes
=
[
'cn'
]):
groups
=
[
e
.
cn
.
value
for
e
in
conn
.
entries
]
conn
.
unbind
()
return
user
,
groups
except
ldap3
.
core
.
exceptions
.
LDAPBindError
:
pass
elif
config
.
get
(
'DEBUG'
)
and
user
in
notldap
and
password
==
notldap
[
user
][
0
]:
return
user
,
notldap
[
user
][
1
]
return
None
,
[]
@
app
.
route
(
'/'
)
def
index
():
return
render_template
(
'index.html'
,
latestvideos
=
query
(
'''
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment