-
Notifications
You must be signed in to change notification settings - Fork 0
/
ad_import_users.py
40 lines (31 loc) · 1.25 KB
/
ad_import_users.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
#!/usr/bin/python3
import json
import os
import sys
import time
# Get the config
config_path = input('Config file path: ')
with open(config_path, encoding='utf-8') as config_file:
config = json.load(config_file)
# Validate data
if 'teams' not in config:
sys.exit('Config must contain teams')
teams = config['teams']
for team in teams:
if 'user_name' not in team or 'password' not in team:
sys.exit('Teams must have user_name, password')
# Import teams
domain = 'OU=POLYPROG-Workstations,OU=POLYPROG,OU=SCIENC-CULT,OU=ASSOCIATIONS,OU=EHE,DC=intranet,DC=epfl,DC=ch'
uid = 500000
gid = 20192 # should probably (?) be the GID of the user configured to use adtool
#for team in teams:
# os.system('adtool usercreate ' + team['user_name'] + ' ' + domain)
# make sure changes have propagated
#time.sleep(10)
for idx, team in enumerate(teams):
# os.system('adtool setpass ' + team['user_name'] + " '" + team['password'] + "'")
os.system('adtool userunlock ' + team['user_name'])
os.system('adtool attributereplace ' + team['user_name'] + ' uid ' + team['user_name'])
os.system('adtool attributereplace ' + team['user_name'] + ' uidNumber ' + str(uid + idx))
os.system('adtool attributereplace ' + team['user_name'] + ' gidNumber ' + str(gid))
print('Done!')