Commit 1ce40ec8 authored by Julian Rother's avatar Julian Rother
Browse files

Removed dependencies on mysql and ldap libraries

parent 38d3345c
#!/bin/python
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__)
......@@ -43,6 +41,7 @@ def dict_factory(cursor, row):
def query(operation, *params):
if config['DB_ENGINE'] == 'mysql':
import mysql.connector
if 'db' not in g or not g.db.is_connected():
g.db = mysql.connector.connect(user=config['MYSQL_USER'], password=config['MYSQL_PASSWD'], host=config['MYSQL_HOST'], database=config['MYSQL_DB'])
cur = g.db.cursor(dictionary=True)
......@@ -78,6 +77,7 @@ def ldapauth(user, password):
notldap = {'videoag':('videoag', ['users','videoag']), 'gustav':('passwort', ['users'])}
user = LDAP_USERRE.sub(r'', user.lower())
if 'LDAP_HOST' in config:
import ldap3
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']):
......@@ -95,6 +95,7 @@ def ldapget(user):
'gustav': {'uid': 'gustav', 'givenName': 'Gustav', 'sn': 'Geier'}}
user = LDAP_USERRE.sub(r'', user.lower())
if 'LDAP_HOST' in config:
import ldap3
conn = ldap3.Connection('ldaps://rumo.fsmpi.rwth-aachen.de', auto_bind=True)
conn.search("ou=users,dc=fsmpi,dc=rwth-aachen,dc=de", "(uid=%s)"%user,
attributes=ldap3.ALL_ATTRIBUTES)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment