From 20b69dd91f259dde9c0bab5ad007edbe4350342b Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 19 Jun 2017 23:40:39 +0000 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9e=20une=20commande=20de=20management=20?= =?UTF-8?q?pour=20la=20synchro=20ldap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update_ldap.py | 53 -------------------------- users/management/commands/ldap_sync.py | 40 +++++++++++++++++++ 2 files changed, 40 insertions(+), 53 deletions(-) delete mode 100644 update_ldap.py create mode 100644 users/management/commands/ldap_sync.py diff --git a/update_ldap.py b/update_ldap.py deleted file mode 100644 index f606aee1..00000000 --- a/update_ldap.py +++ /dev/null @@ -1,53 +0,0 @@ -# Re2o est un logiciel d'administration développé initiallement au rezometz. Il -# se veut agnostique au réseau considéré, de manière à être installable en -# quelques clics. -# -# Copyright © 2017 Gabriel Détraz -# Copyright © 2017 Goulven Kermarec -# Copyright © 2017 Augustin Lemesle -# -# 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 should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -### Appellé par cron, mets à jour la base de donnée ldap, par défaut le dialup access -### Argument full, mets tout à jour - -import os, sys - -proj_path = "/var/www/re2o/" -# This is so Django knows where to find stuff. -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "re2o.settings") -sys.path.append(proj_path) - -# This is so my local_settings.py gets loaded. -os.chdir(proj_path) - -# This is so models get loaded. -from django.core.wsgi import get_wsgi_application -application = get_wsgi_application() - -from users.models import User - -def refresh_ldap(base=False, access_refresh=True, mac_refresh=False): - for u in User.objects.all(): - u.ldap_sync(base=base, access_refresh=access_refresh, mac_refresh=mac_refresh) - return - -if __name__ == '__main__': - if "base" in sys.argv: - refresh_ldap(base=True, access_refresh=True, mac_refresh=False) - elif "full" in sys.argv: - refresh_ldap(base=True, access_refresh=True, mac_refresh=True) - else: - refresh_ldap() diff --git a/users/management/commands/ldap_sync.py b/users/management/commands/ldap_sync.py new file mode 100644 index 00000000..7588ffc9 --- /dev/null +++ b/users/management/commands/ldap_sync.py @@ -0,0 +1,40 @@ +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# 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 should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +from django.core.management.base import BaseCommand, CommandError + +from users.models import User + +class Command(BaseCommand): + help = 'Synchronise le ldap à partir du sql. A utiliser dans un cron' + + def add_arguments(self, parser): + + # Named (optional) arguments + parser.add_argument( + '--full', + action='store_true', + dest='full', + default=False, + help='Régénération complète du ldap (y compris des machines)', + ) + + def handle(self, *args, **options): + for usr in User.objects.all(): + usr.ldap_sync(mac_refresh=options['full']) +