-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (53 loc) · 2.33 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/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
for service in api_client.list("services/regen/"):
if service['hostname'] == client_hostname and \
service['service_name'] == 'dns' and \
service['need_regen']:
reconfigure(api_client)
api_client.patch(service['api_url'], data={'need_regen': False})