This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[In this commit] -New Configuration system, using an object for holding the config data. Includes new EXTRA_FIELDS, ADMIN_GROUP and SEARCH_ATTRS options. -Way less hardcoded configuration -New Background. -New Footer and copyright. [In this release] -Complete Python 3.8 compatibility. -Redesign visual style. -New Search bar in the tree view. -Lots of bug fixes!!!
- Loading branch information
Showing
12 changed files
with
174 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#!/usr/bin/python2 | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (C) 2012-2015 Stéphane Graber | ||
# Author: Stéphane Graber <[email protected]> | ||
|
||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You can find the license on Debian systems in the file | ||
# /usr/share/common-licenses/GPL-2 | ||
|
||
import argparse | ||
import os | ||
|
||
app_prefix = "/opt/samba4-manager-master/" | ||
|
||
# Check if running from bzr | ||
for path in ('libs', 'plugins', 'static', 'templates'): | ||
if not os.path.exists(path): | ||
break | ||
else: | ||
app_prefix = "." | ||
|
||
parser = argparse.ArgumentParser(description="Samba4 Gestor Web") | ||
args = parser.parse_args() | ||
|
||
if not os.path.exists(app_prefix): | ||
raise Exception("Missing app dir: %s" % app_prefix) | ||
|
||
# Import the rest of the stuff we need | ||
from flask import Flask, g | ||
import glob | ||
import importlib | ||
|
||
# Look at the right place | ||
import sys | ||
sys.path.append(app_prefix) | ||
|
||
# Import our modules | ||
from libs.common import ReverseProxied | ||
from libs.common import iri_for as url_for | ||
from settings import Settings | ||
|
||
# Prepare the web server | ||
app = Flask(__name__, | ||
static_folder="%s/static" % app_prefix, | ||
template_folder="%s/templates" % app_prefix) | ||
|
||
app.config.from_object(Settings) | ||
app.jinja_env.globals['url_for'] = url_for | ||
|
||
if 'URL_PREFIX' in app.config: | ||
app.wsgi_app = ReverseProxied(app.wsgi_app, app.config['URL_PREFIX']) | ||
|
||
# Check for mandatory configuration | ||
for key in ("LDAP_DOMAIN", "SECRET_KEY", "SEARCH_DN"): | ||
if key not in app.config: | ||
raise KeyError("Missing mandatory %s option in configuration." % key) | ||
|
||
# LDAP configuration | ||
if "LDAP_DN" not in app.config: | ||
app.config['LDAP_DN'] = "DC=%s" % ",DC=".join( | ||
app.config['LDAP_DOMAIN'].split(".")) | ||
|
||
if "LDAP_SERVER" not in app.config: | ||
import dns.resolver | ||
import dns.rdatatype | ||
import operator | ||
|
||
record = "_ldap._tcp.%s." % app.config['LDAP_DOMAIN'] | ||
answers = [] | ||
|
||
# Query the DNS | ||
try: | ||
for answer in dns.resolver.query(record, dns.rdatatype.SRV): | ||
address = (answer.target.to_text()[:-1], answer.port) | ||
answers.append((address, answer.priority, answer.weight)) | ||
except: | ||
# Ignore exceptions, an empty list will trigger an exception anyway | ||
pass | ||
|
||
# Order by priority and weight | ||
servers = [entry[0][0] for entry in sorted(answers, | ||
key=operator.itemgetter(1, 2))] | ||
if not servers: | ||
raise Exception("No LDAP server in domain '%s'." % | ||
app.config['LDAP_DOMAIN']) | ||
|
||
if len(servers) == 1: | ||
app.config['LDAP_SERVER'] = servers[0] | ||
else: | ||
app.config['LDAP_SERVER'] = servers | ||
|
||
if "SICCIP_AWARE" not in app.config: | ||
app.config['SICCIP_AWARE'] = False | ||
|
||
# Load the plugins | ||
for plugin_file in glob.glob("%s/plugins/*.py" % app_prefix): | ||
plugin_name = plugin_file.split('/')[-1].replace('.py', '') | ||
if plugin_name == "__init__": | ||
continue | ||
|
||
plugin = importlib.import_module("plugins.%s" % plugin_name) | ||
plugin.init(app) | ||
|
||
|
||
@app.before_request | ||
def pre_request(): | ||
""" | ||
Setup any of the global variables before the request is processed. | ||
""" | ||
g.menu = [] | ||
g.menu.append((url_for("core_index"), "Mi Cuenta")) | ||
g.menu.append((url_for("tree_base"), u"Directorio")) | ||
g.menu.append((url_for("core_logout"), "Log out")) | ||
|
||
# LDAP connection settings | ||
g.ldap = {'domain': app.config['LDAP_DOMAIN'], 'dn': app.config['LDAP_DN'], 'server': app.config['LDAP_SERVER'], | ||
'search_dn': app.config['SEARCH_DN']} | ||
|
||
# The various caches | ||
|
||
g.ldap_cache = {} | ||
|
||
# SICC-IP integrations | ||
g.siccip = app.config['SICCIP_AWARE'] | ||
# Extra fields form | ||
g.extra_fields = app.config['EXTRA_FIELDS'] | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(host='::', port=8080) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Settings: | ||
SECRET_KEY = "AHDGIWIWBQSBKQYUQXBXKGAsdhahdflkjfgierqhs" | ||
LDAP_DOMAIN = "cujae.edu.cu" | ||
SEARCH_DN = "dc=cujae,dc=edu,dc=cu" | ||
LDAP_SERVER = "10.8.1.63" | ||
DEBUG = True | ||
# URL_PREFIX = "/domain" | ||
SICCIP_AWARE = False | ||
EXTRA_FIELDS = True | ||
ADMIN_GROUP = "SM Admins" | ||
SEARCH_ATTRS = [('cUJAEPersonDNI', 'Carné ID'), ('sAMAccountName', 'Usuario'), ('givenName', 'Nombre')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters