Fix indentation, update props, allow for updating existing accounts
should have split these up, but messed up indentation, and too lazy to fix right now
This commit is contained in:
parent
4b5040599c
commit
cec414ca36
71
ucsAccounts.py
Normal file → Executable file
71
ucsAccounts.py
Normal file → Executable file
@ -8,55 +8,62 @@ from common import *
|
|||||||
LDAP_BASE = "cn=users,dc=sawtooth,dc=claremontmakerspace,dc=org"
|
LDAP_BASE = "cn=users,dc=sawtooth,dc=claremontmakerspace,dc=org"
|
||||||
RAND_PW_LEN = 20
|
RAND_PW_LEN = 20
|
||||||
|
|
||||||
|
def makeSets(props):
|
||||||
|
return sum([["--set", key + "=" + value]
|
||||||
|
for key, value in props.items()], [])
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
members = getMembershipworksData("lvl,phn,eml,lbl,nam,end,_id")
|
members = getMembershipworksData("lvl,phn,eml,lbl,nam,end,_id")
|
||||||
|
|
||||||
for member in members:
|
for member in members:
|
||||||
randomPass = ''.join(random.choice(string.ascii_letters + string.digits)
|
randomPass = ''.join(random.choice(string.ascii_letters + string.digits)
|
||||||
for x in range(0, RAND_PW_LEN))
|
for x in range(0, RAND_PW_LEN))
|
||||||
|
username = member["Account Name"].lower().replace(" ", ".")
|
||||||
|
|
||||||
props = {
|
props = {
|
||||||
"title": "", # Title
|
"title": "", # Title
|
||||||
"firstname": member["First Name"],
|
"firstname": member["First Name"],
|
||||||
"lastname": member["Last Name"], # (c)
|
"lastname": member["Last Name"], # (c)
|
||||||
"username": member["Account Name"].lower().replace(" ", "."), # (cmr)
|
"username": username, # (cmr)
|
||||||
"description": "", # Description
|
"description": "", # Description
|
||||||
"password": randomPass, # (c) Password
|
"password": randomPass, # (c) Password
|
||||||
#"mailPrimaryAddress": member["Email"], # Primary e-mail address
|
#"mailPrimaryAddress": member["Email"], # Primary e-mail address
|
||||||
#"displayName": "", # Display name
|
#"displayName": "", # Display name
|
||||||
#"birthday": "", # Birthdate
|
#"birthday": "", # Birthdate
|
||||||
#"jpegPhoto": "", # Picture of the user (JPEG format)
|
#"jpegPhoto": "", # Picture of the user (JPEG format)
|
||||||
|
|
||||||
"employeeNumber": member["Account ID"],
|
"employeeNumber": member["Account ID"],
|
||||||
#"employeeType": "", # Employee type
|
#"employeeType": "", # Employee type
|
||||||
|
|
||||||
#"groups": "", # Groups
|
#"groups": "", # Groups
|
||||||
|
|
||||||
"disabled": "1" if member["Account on Hold"] != "" else "0",
|
"homedrive": "H:", # Windows home drive
|
||||||
#"userexpiry": member["Renewal Date"],
|
"sambahome": "\\\\ucs\\" + username, # Windows home path
|
||||||
|
"profilepath": "%LOGONSERVER%\\%USERNAME%\\windows-profiles\\default", # Windows profile directory
|
||||||
|
|
||||||
"pwdChangeNextLogin": "1", # User has to change password on next login
|
"disabled": "1" if member["Account on Hold"] != "" else "0",
|
||||||
|
#"userexpiry": member["Renewal Date"],
|
||||||
|
|
||||||
#"sambaLogonHours": "", # Permitted times for Windows logins
|
"pwdChangeNextLogin": "1", # User has to change password on next login
|
||||||
|
|
||||||
"e-mail": member["Email"], # ([]) E-mail address
|
#"sambaLogonHours": "", # Permitted times for Windows logins
|
||||||
"phone": member["Phone"], # Telephone number
|
|
||||||
#"PasswordRecoveryMobile": member["Phone"], # Mobile phone number
|
"e-mail": member["Email"], # ([]) E-mail address
|
||||||
"PasswordRecoveryEmail": member["Email"]
|
"phone": member["Phone"], # Telephone number
|
||||||
|
#"PasswordRecoveryMobile": member["Phone"], # Mobile phone number
|
||||||
|
"PasswordRecoveryEmail": member["Email"]
|
||||||
}
|
}
|
||||||
|
|
||||||
propSets = sum([["--set", key + "=" + value]
|
subprocess.call(["udm", "users/user", "create",
|
||||||
for key, value in props.items()], [])
|
"--position", LDAP_BASE] + makeSets(props))
|
||||||
|
|
||||||
|
# remove props we don't want to reset
|
||||||
|
props.pop("password")
|
||||||
|
props.pop("pwdChangeNextLogin")
|
||||||
|
|
||||||
cmd = ["udm", "users/user", "create",
|
subprocess.call(["udm", "users/user", "modify",
|
||||||
"--position", LDAP_BASE] + propSets
|
"--dn", "uid=" + username + "," + LDAP_BASE]
|
||||||
|
+ makeSets(props))
|
||||||
subprocess.call(cmd)
|
|
||||||
|
|
||||||
# props = {
|
|
||||||
# 'Name': ,
|
|
||||||
# 'Renewal Date': member['Renewal Date'],
|
|
||||||
# 'Account on Hold': "Yes" if member['Account on Hold'] != '' else "No" }
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Reference in New Issue
Block a user