commit 2c9f5edea773fb51b61a2a3a5176c6159512af55 Author: root Date: Tue Aug 7 10:42:05 2018 +0200 création de depo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2fa7ce7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.ini diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a0d74b4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "re2oapi"] + path = re2oapi + url = https://gitlab.adm.crans.org/nounous/re2oapi.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..32b9d00 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +#Re2o Home + +This service uses Re2oApi to verify and create the home directory of the users following the structure: + +\home-adh + \symlink to {pseudo} + \{pseudo initial} + \{pseudo} + \Mail + \OwnCloud + + + +## Requirements + +* python3 +* requirements in https://gitlab.adm.crans.org/nounous/re2oapi.git diff --git a/config.ini.example b/config.ini.example new file mode 100644 index 0000000..60a6b33 --- /dev/null +++ b/config.ini.example @@ -0,0 +1,4 @@ +[Re2o] +hostname = re2o.example.net +username = my_api_username +password = my_api_password diff --git a/main.py b/main.py new file mode 100755 index 0000000..0c85ae4 --- /dev/null +++ b/main.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +from configparser import ConfigParser +import socket + +from re2oapi import Re2oAPIClient +from django.core.mail import send_mail +from django.template import loader, Context + +import os +import grp + +config = ConfigParser() +config.read('config.ini') + +api_hostname = config.get('Re2o', 'hostname') +api_password = config.get('Re2o', 'password') +api_username = config.get('Re2o', 'username') + +api_client = Re2oAPIClient(api_hostname,api_username,api_password) + +client_hostname = socket.gethostname().split('.',1)[0] + +def reconfigure(api_client): + + users = api_client.list("users/homecreation") + + error = False + + for user in users: + print('creation du home de {}'.format(user['pseudo'])) + home = '/home-adh/{}/{}/'.format(user['pseudo'][0].lower(),user['pseudo'].lower()) + uid = user['uid'] + gid = user['gid'] + + if not os.path.exists(home): # Home dosen't exist, create it + os.makedirs(home,0o701) + os.chown(home,int(uid),int(gid)) + + # Mail + if not os.path.exists(home + '/Mail'): + os.makedirs(home + '/Mail', 0o700) + os.chown(home + '/Mail', int(uid), int(gid)) + if not os.path.exists('/home-adh/mail/' + user['pseudo']): + os.makedirs('/home-adh/mail/' + user['pseudo'], 0o700) + os.chown('/home-adh/mail/' + user['pseudo'], int(uid), 8) + + # Owncloud dans le home + if not os.path.exists(home + '/OwnCloud'): + os.makedirs(home + '/OwnCloud') + os.chown(home + '/OwnCloud',int(uid),grp.getgrnam('www-data').gr_gid) + os.chmod(home + '/OwnCloud', 0o770) + + # Simlink + link = '/home-adh/{}'.format(user['pseudo'].lower()) + if not os.path.islink(link): + os.symlink(home, link) + + if not (os.path.exists(home+'/Mail') and os.path.exists(home+'OwnCloud') and os.path.islink(link)): + error = True + + print("error: {}".format(error)) + input("passer au suivant ?") + + api_client.patch(service['home'], data={'need_regen': error}) # regen it if there is an error diff --git a/re2oapi b/re2oapi new file mode 160000 index 0000000..c3277c2 --- /dev/null +++ b/re2oapi @@ -0,0 +1 @@ +Subproject commit c3277c2e6eb3a85e8580c906266cad46c4043677