From 4b5040599c69fea4120ef2371d3b1d981231d28c Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 22 Jun 2018 17:54:55 -0400 Subject: [PATCH] ucsAccounts: Add script to populate UCS domain controller from MembershipWorks --- ucsAccounts.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ucsAccounts.py diff --git a/ucsAccounts.py b/ucsAccounts.py new file mode 100644 index 0000000..f8a527b --- /dev/null +++ b/ucsAccounts.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import random +import subprocess +import string + +from common import * + +LDAP_BASE = "cn=users,dc=sawtooth,dc=claremontmakerspace,dc=org" +RAND_PW_LEN = 20 + +def main(): + members = getMembershipworksData("lvl,phn,eml,lbl,nam,end,_id") + + for member in members: + randomPass = ''.join(random.choice(string.ascii_letters + string.digits) + for x in range(0, RAND_PW_LEN)) + props = { + "title": "", # Title + "firstname": member["First Name"], + "lastname": member["Last Name"], # (c) + "username": member["Account Name"].lower().replace(" ", "."), # (cmr) + "description": "", # Description + "password": randomPass, # (c) Password + #"mailPrimaryAddress": member["Email"], # Primary e-mail address + #"displayName": "", # Display name + #"birthday": "", # Birthdate + #"jpegPhoto": "", # Picture of the user (JPEG format) + + "employeeNumber": member["Account ID"], + #"employeeType": "", # Employee type + + #"groups": "", # Groups + + "disabled": "1" if member["Account on Hold"] != "" else "0", + #"userexpiry": member["Renewal Date"], + + "pwdChangeNextLogin": "1", # User has to change password on next login + + #"sambaLogonHours": "", # Permitted times for Windows logins + + "e-mail": member["Email"], # ([]) E-mail address + "phone": member["Phone"], # Telephone number + #"PasswordRecoveryMobile": member["Phone"], # Mobile phone number + "PasswordRecoveryEmail": member["Email"] + } + + propSets = sum([["--set", key + "=" + value] + for key, value in props.items()], []) + + + cmd = ["udm", "users/user", "create", + "--position", LDAP_BASE] + propSets + + subprocess.call(cmd) + + # props = { + # 'Name': , + # 'Renewal Date': member['Renewal Date'], + # 'Account on Hold': "Yes" if member['Account on Hold'] != '' else "No" } + +if __name__ == "__main__": + main()