You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

  1. import ldap as l
  2. from flask import Flask
  3. from flask_sqlalchemy import SQLAlchemy
  4. from flask_login import LoginManager, login_manager
  5. from flask_bootstrap import Bootstrap
  6. from flask_cachebuster import CacheBuster
  7. import os
  8. app = Flask(__name__)
  9. Bootstrap(app)
  10. app.secret_key = 'asdf'
  11. app.debug = True
  12. app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///../users.db'
  13. app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  14. app.config['WTF_CSRF_SECRET_KEY'] = 'asdf'
  15. # Base
  16. app.config['LDAP_REALM_NAME'] = 'OpenLDAP Authentication'
  17. app.config['LDAP_HOST'] = os.environ.get('LDAP_HOST')
  18. app.config['LDAP_BASE_DN'] = os.environ.get('LDAP_BASE_DN')
  19. app.config['LDAP_USERNAME'] = os.environ.get('LDAP_USERNAME')
  20. app.config['LDAP_PASSWORD'] = os.environ.get('LDAP_PASSWORD')
  21. # OpenLDAP
  22. app.config['LDAP_OBJECTS_DN'] = 'dn'
  23. app.config['LDAP_OPENLDAP'] = True
  24. app.config['LDAP_USER_OBJECT_FILTER'] = '(&(objectclass=posixAccount)(uid=%s))'
  25. # Login cookies
  26. app.config['SESSION_COOKIE_DOMAIN'] = os.environ.get('COOKIE_DOMAIN')
  27. app.config['REMEMBER_COOKIE_DOMAIN'] = os.environ.get('COOKIE_DOMAIN')
  28. db = SQLAlchemy(app)
  29. login_manager = LoginManager(app)
  30. login_manager.init_app(app)
  31. login_manager.login_view = 'auth.login'
  32. config = {"extensions": [".js", ".css", ".csv"], "hash_size": 5}
  33. cache_buster = CacheBuster(config=config)
  34. cache_buster.init_app(app)
  35. from accounts.auth.views import auth
  36. app.register_blueprint(auth)
  37. db.create_all()