Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from VicentGJ/v1.0
Browse files Browse the repository at this point in the history
V1.0
  • Loading branch information
VicentGJ authored Jan 11, 2021
2 parents 728d5cc + e0e0b30 commit 89d16a9
Show file tree
Hide file tree
Showing 21 changed files with 212 additions and 168 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/AD-webmanager.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions samba4-manager.py → ADwebmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@
import argparse
import os

config_file = "/opt/samba4-manager-master/manager.cfg"
app_prefix = "/opt/samba4-manager-master/"

# Check if running from bzr
for path in ('manager.cfg', 'libs', 'plugins', 'static', 'templates'):
for path in ('libs', 'plugins', 'static', 'templates'):
if not os.path.exists(path):
break
else:
config_file = "%s/manager.cfg" % os.getcwd()
app_prefix = "."

parser = argparse.ArgumentParser(description="Samba4 Gestor Web")
parser.add_argument("--config", metavar="CONFIG", default=config_file)
args = parser.parse_args()

if not os.path.exists(args.config):
raise Exception("Missing configuration file: %s" % args.config)

if not os.path.exists(app_prefix):
raise Exception("Missing app dir: %s" % app_prefix)

Expand All @@ -53,14 +47,14 @@
# 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_pyfile(args.config)

app.config.from_object(Settings)
app.jinja_env.globals['url_for'] = url_for

if 'URL_PREFIX' in app.config:
Expand Down Expand Up @@ -129,18 +123,18 @@ def pre_request():
g.menu.append((url_for("core_logout"), "Log out"))

# LDAP connection settings
g.ldap = {}
g.ldap['domain'] = app.config['LDAP_DOMAIN']
g.ldap['dn'] = app.config['LDAP_DN']
g.ldap['server'] = app.config['LDAP_SERVER']
g.ldap['search_dn'] = app.config['SEARCH_DN']
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
# 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)
18 changes: 0 additions & 18 deletions AUTHORS

This file was deleted.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The goal is to be able to do most common directory operations directly
through this web interface rather than have to rely on command tools or
Windows interfaces.

Its compatible with both Windows AD y Samba4 domain controllers.
Its compatible with both Windows Active Directory and Samba4 domain controllers.

# History
This project is a fork of samba4-manager, created by Stéphane Graber
Expand All @@ -32,13 +32,14 @@ and we will love to receive all kinds of feedback and contributions.

# Using

* Copy manager.cfg.example to manager.cfg
* Access settings.py to configure
* Put a random string in SECRET\_KEY
* Set LDAP\_DOMAIN to your Samba4 domain
* Set LDAP\_DOMAIN to your Directory domain
* Set LDAP\_SERVER to your Domain Controller IP
* Start the server with:

```
./samba4-manager
./ADwebmanager.py
```

You may then connect through: [http://localhost:8080](http://localhost:8080)
Expand Down
10 changes: 5 additions & 5 deletions libs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from flask import url_for
from werkzeug.urls import uri_to_iri
from configparser import SafeConfigParser


class ReverseProxied(object):
Expand Down Expand Up @@ -57,7 +58,7 @@ def get_parsed_pager_attribute(pager):
D its Dansguaridan
For example a user with Full Internet access, 25.50 Units of quota for Internet, with Full email access and
40 quota units for email and whos user should be filtered acording with dansguardian group 2 will have a pager
40 quota units for email and who's user should be filtered according with dansguardian group 2 will have a pager
attribute like the following
IF25.50|EF40.0|D2
Expand All @@ -77,9 +78,8 @@ def get_parsed_pager_attribute(pager):
email_type = letter_type if letter_type == 'F' or letter_type == 'R' else 'L'
email_quota = float(pager_parts[1][2:])
dansguardian_filter_number = int(pager_parts[2][1:])
return {'internet_type':internet_type, 'internet_quota':internet_quota,
'socialnetwork_quota': socialnetwork_quota, 'email_type':email_type,
'email_quota' : email_quota, 'dansguardian_filter':dansguardian_filter_number}
return {'internet_type': internet_type, 'internet_quota': internet_quota,
'socialnetwork_quota': socialnetwork_quota, 'email_type': email_type,
'email_quota': email_quota, 'dansguardian_filter': dansguardian_filter_number}
except ValueError:
return None

21 changes: 7 additions & 14 deletions libs/ldap_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ def ldap_get_entry_simple(filter_dict):
for key, value in filter_dict.items():
fields += "(%s=%s)" % (key, value)
ldap_filter = "(&%s)" % fields

return ldap_get_entry(ldap_filter)


Expand All @@ -178,22 +177,12 @@ def ldap_get_entry(ldap_filter):
Return the attributes for a single entry or None if it doesn't exist or
if the filter matches multiple entries and False on errors.
"""

entries = ldap_get_entries(ldap_filter)
# Only allow a single entry
if isinstance(entries,list) and len(entries) == 1:
return entries[0]

#raise Exception(entries)

return None
# Only allow a single entry
# try:
# if entries == False:
# return None
# except:
# if len(entries) != 1:
# return None
# return entries[0]


def ldap_get_entries(ldap_filter, base=None, scope=None, ignore_erros=False):
Expand Down Expand Up @@ -274,7 +263,6 @@ def ldap_get_membership(name=None):
"""
Return the list of all groups the entry is a memberOf.
"""

entry = ldap_get_entry_simple({'sAMAccountName': name})
if not entry:
return None
Expand All @@ -288,7 +276,6 @@ def ldap_get_membership(name=None):
# Retrieve secondary groups for user
if 'memberOf' in entry:
groups += entry['memberOf']

return groups


Expand All @@ -302,6 +289,9 @@ def ldap_in_group(groupname, username=None):

group = ldap_get_group(groupname)
groups = ldap_get_membership(username)

if group is None:
return False
# Start by looking at direct membership
if group['distinguishedName'] in groups:
return True
Expand All @@ -313,6 +303,8 @@ def ldap_in_group(groupname, username=None):
while to_check != checked:
for entry in to_check - checked:
attr = ldap_get_group(entry, "distinguishedName")
if attr is None:
return None
if 'memberOf' in attr:
if group['distinguishedName'] in attr['memberOf']:
return True
Expand All @@ -321,6 +313,7 @@ def ldap_in_group(groupname, username=None):

return group['distinguishedName'] in checked


def ldap_update_attribute(dn, attribute, value=None, objectClass=None):
"""
Set/Update a given attribute.
Expand Down
8 changes: 0 additions & 8 deletions manager.cfg

This file was deleted.

6 changes: 0 additions & 6 deletions manager.cfg.example

This file was deleted.

Loading

0 comments on commit 89d16a9

Please sign in to comment.