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
5d160889
Commit
5d160889
authored
Oct 15, 2017
by
Andreas Valder
Browse files
moved ldap stuff from db.py to ldap.py closes
#343
parent
170a7a86
Changes
3
Hide whitespace changes
Inline
Side-by-side
db.py
View file @
5d160889
from
server
import
*
import
re
if
config
[
'DB_ENGINE'
]
==
'sqlite'
:
import
sqlite3
...
...
@@ -25,7 +24,6 @@ if config['DB_ENGINE'] == 'sqlite':
cur
=
db
.
cursor
()
if
config
[
'SQLITE_INIT_SCHEMA'
]:
cur
.
executescript
(
open
(
config
[
'DB_SCHEMA'
]).
read
())
if
config
[
'SQLITE_INIT_DATA'
]
and
created
:
cur
.
executescript
(
open
(
config
[
'DB_DATA'
]).
read
())
db
.
commit
()
db
.
close
()
...
...
@@ -144,31 +142,3 @@ def searchquery(text, columns, match, tables, suffix, *suffixparams):
return
[]
expr
=
'SELECT *,SUM(_prio) AS _score FROM (%s) AS _tmp %s'
%
(
' UNION '
.
join
(
subexprs
),
suffix
)
return
query
(
expr
,
*
(
list
(
params
)
+
list
(
suffixparams
)))
LDAP_USERRE
=
re
.
compile
(
r
'[^a-z0-9]'
)
if
'LDAP_HOST'
in
config
:
import
ldap3
def
ldapauth
(
user
,
password
):
user
=
LDAP_USERRE
.
sub
(
r
''
,
user
.
lower
())
try
:
conn
=
ldap3
.
Connection
(
ldap3
.
Server
(
config
[
'LDAP_HOST'
],
port
=
config
[
'LDAP_PORT'
],
use_ssl
=
True
),
'fsmpi
\\
%s'
%
user
,
password
,
auto_bind
=
True
,
check_names
=
False
)
except
ldap3
.
core
.
exceptions
.
LDAPBindError
:
return
{},
[]
conn
.
search
(
"cn=users,dc=fsmpi,dc=rwth-aachen,dc=de"
,
"(cn=%s)"
%
user
,
attributes
=
[
'memberOf'
,
'givenName'
,
'sn'
])
info
=
{
'uid'
:
user
,
'givenName'
:
conn
.
response
[
0
][
'attributes'
][
'givenName'
][
0
],
'sn'
:
conn
.
response
[
0
][
'attributes'
][
'sn'
][
0
]}
groups
=
[
g
.
split
(
','
)[
0
].
split
(
'='
)[
-
1
]
for
g
in
conn
.
response
[
0
][
'attributes'
][
'memberOf'
]]
conn
.
unbind
()
return
info
,
groups
else
:
notldap
=
{
'videoag'
:(
'videoag'
,
[
'fachschaft'
,
'videoag'
],
{
'uid'
:
'videoag'
,
'givenName'
:
'Video'
,
'sn'
:
'Geier'
}),
'gustav'
:(
'passwort'
,
[
'fachschaft'
],
{
'uid'
:
'gustav'
,
'givenName'
:
'Gustav'
,
'sn'
:
'Geier'
})
}
def
ldapauth
(
user
,
password
):
user
=
LDAP_USERRE
.
sub
(
r
''
,
user
.
lower
())
if
config
.
get
(
'DEBUG'
)
and
user
in
notldap
and
password
==
notldap
[
user
][
0
]:
return
notldap
[
user
][
2
],
notldap
[
user
][
1
]
return
{},
[]
ldap.py
0 → 100644
View file @
5d160889
from
server
import
*
import
re
LDAP_USERRE
=
re
.
compile
(
r
'[^a-z0-9]'
)
if
'LDAP_HOST'
in
config
:
import
ldap3
def
ldapauth
(
user
,
password
):
user
=
LDAP_USERRE
.
sub
(
r
''
,
user
.
lower
())
try
:
conn
=
ldap3
.
Connection
(
ldap3
.
Server
(
config
[
'LDAP_HOST'
],
port
=
config
[
'LDAP_PORT'
],
use_ssl
=
True
),
'fsmpi
\\
%s'
%
user
,
password
,
auto_bind
=
True
,
check_names
=
False
)
except
ldap3
.
core
.
exceptions
.
LDAPBindError
:
return
{},
[]
conn
.
search
(
"cn=users,dc=fsmpi,dc=rwth-aachen,dc=de"
,
"(cn=%s)"
%
user
,
attributes
=
[
'memberOf'
,
'givenName'
,
'sn'
])
info
=
{
'uid'
:
user
,
'givenName'
:
conn
.
response
[
0
][
'attributes'
][
'givenName'
][
0
],
'sn'
:
conn
.
response
[
0
][
'attributes'
][
'sn'
][
0
]}
groups
=
[
g
.
split
(
','
)[
0
].
split
(
'='
)[
-
1
]
for
g
in
conn
.
response
[
0
][
'attributes'
][
'memberOf'
]]
conn
.
unbind
()
return
info
,
groups
else
:
notldap
=
{
'videoag'
:(
'videoag'
,
[
'fachschaft'
,
'videoag'
],
{
'uid'
:
'videoag'
,
'givenName'
:
'Video'
,
'sn'
:
'Geier'
}),
'gustav'
:(
'passwort'
,
[
'fachschaft'
],
{
'uid'
:
'gustav'
,
'givenName'
:
'Gustav'
,
'sn'
:
'Geier'
})
}
def
ldapauth
(
user
,
password
):
user
=
LDAP_USERRE
.
sub
(
r
''
,
user
.
lower
())
if
config
.
get
(
'DEBUG'
)
and
user
in
notldap
and
password
==
notldap
[
user
][
0
]:
return
notldap
[
user
][
2
],
notldap
[
user
][
1
]
return
{},
[]
server.py
View file @
5d160889
...
...
@@ -72,7 +72,8 @@ app.jinja_env.globals['gitversion'] = { 'hash': output[1], 'longhash': output[0]
if
not
config
.
get
(
'SECRET_KEY'
,
None
):
config
[
'SECRET_KEY'
]
=
os
.
urandom
(
24
)
from
db
import
query
,
modify
,
show
,
searchquery
,
ldapauth
from
db
import
query
,
modify
,
show
,
searchquery
from
ldap
import
ldapauth
mod_endpoints
=
[]
...
...
Julian Rother
@julianr
mentioned in commit
49dfffcf
·
Oct 16, 2017
mentioned in commit
49dfffcf
mentioned in commit 49dfffcfc3d7864eddfc3d07fe55124c6fe8fb09
Toggle commit list
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