création de depo
This commit is contained in:
commit
2c9f5edea7
6 changed files with 90 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
config.ini
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "re2oapi"]
|
||||
path = re2oapi
|
||||
url = https://gitlab.adm.crans.org/nounous/re2oapi.git
|
17
README.md
Normal file
17
README.md
Normal file
|
@ -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
|
4
config.ini.example
Normal file
4
config.ini.example
Normal file
|
@ -0,0 +1,4 @@
|
|||
[Re2o]
|
||||
hostname = re2o.example.net
|
||||
username = my_api_username
|
||||
password = my_api_password
|
64
main.py
Executable file
64
main.py
Executable file
|
@ -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
|
1
re2oapi
Submodule
1
re2oapi
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit c3277c2e6eb3a85e8580c906266cad46c4043677
|
Loading…
Add table
Add a link
Reference in a new issue