Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Video AG Infrastruktur
website
Commits
0701bac8
Commit
0701bac8
authored
8 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Added ldap wrapper
parent
22c06b14
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server.py
+20
-1
20 additions, 1 deletion
server.py
with
20 additions
and
1 deletion
server.py
+
20
−
1
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
(
'''
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment