2018-06-22 17:54:55 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import random
|
2018-08-14 14:51:48 -04:00
|
|
|
import re
|
2018-06-22 17:54:55 -04:00
|
|
|
import string
|
2019-11-22 16:39:31 -05:00
|
|
|
import subprocess
|
2018-06-22 17:54:55 -04:00
|
|
|
|
2020-02-06 17:48:09 -05:00
|
|
|
from common import membershipworks
|
2018-06-22 17:54:55 -04:00
|
|
|
|
|
|
|
LDAP_BASE = "cn=users,dc=sawtooth,dc=claremontmakerspace,dc=org"
|
2018-08-14 14:51:48 -04:00
|
|
|
GROUP_BASE = "cn=groups,dc=sawtooth,dc=claremontmakerspace,dc=org"
|
2020-03-30 14:01:39 -04:00
|
|
|
GROUPS_REGEX = "|".join(["Certified: .*", "Access .*\?", "CMS .*", "Volunteer: .*"])
|
2018-06-22 17:54:55 -04:00
|
|
|
RAND_PW_LEN = 20
|
|
|
|
|
2020-03-30 14:01:39 -04:00
|
|
|
|
2018-08-14 14:51:48 -04:00
|
|
|
def makeGroups(members):
|
2020-03-30 14:01:39 -04:00
|
|
|
groups = [
|
|
|
|
key.replace(":", ".").replace("?", "")
|
|
|
|
for key in members[0].keys()
|
|
|
|
if re.match(GROUPS_REGEX, key) is not None
|
|
|
|
]
|
2018-08-14 14:51:48 -04:00
|
|
|
for group in groups:
|
2020-03-30 14:01:39 -04:00
|
|
|
subprocess.call(
|
|
|
|
[
|
|
|
|
"udm",
|
|
|
|
"groups/group",
|
|
|
|
"create",
|
|
|
|
"--position",
|
|
|
|
GROUP_BASE,
|
|
|
|
"--set",
|
|
|
|
"name=" + group,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2018-08-14 14:51:48 -04:00
|
|
|
|
2018-07-20 11:45:45 -04:00
|
|
|
def makeSets(props):
|
2020-03-30 14:01:39 -04:00
|
|
|
return sum([["--set", key + "=" + value] for key, value in props.items()], [])
|
|
|
|
|
2018-07-20 11:45:45 -04:00
|
|
|
|
2018-08-14 14:51:48 -04:00
|
|
|
def makeAppendGroups(member):
|
2020-03-30 14:01:39 -04:00
|
|
|
groups = [
|
|
|
|
key.replace(":", ".").replace("?", "")
|
|
|
|
for key, value in member.items()
|
|
|
|
if re.match(GROUPS_REGEX, key) is not None and value != ""
|
|
|
|
]
|
|
|
|
return sum(
|
|
|
|
[["--append", "groups=cn=" + group + "," + GROUP_BASE] for group in groups], []
|
|
|
|
)
|
|
|
|
|
2018-08-14 14:51:48 -04:00
|
|
|
|
2018-06-22 17:54:55 -04:00
|
|
|
def main():
|
2020-03-30 14:01:39 -04:00
|
|
|
members = membershipworks.get_members(
|
|
|
|
["Members", "CMS Staff"], "lvl,phn,eml,lbl,nam,end,_id"
|
|
|
|
)
|
2018-08-14 14:51:48 -04:00
|
|
|
makeGroups(members)
|
2018-06-22 17:54:55 -04:00
|
|
|
|
|
|
|
for member in members:
|
2020-03-30 14:01:39 -04:00
|
|
|
randomPass = "".join(
|
|
|
|
random.choice(string.ascii_letters + string.digits)
|
|
|
|
for x in range(0, RAND_PW_LEN)
|
|
|
|
)
|
2018-07-20 11:45:45 -04:00
|
|
|
username = member["Account Name"].lower().replace(" ", ".")
|
|
|
|
|
2018-06-22 17:54:55 -04:00
|
|
|
props = {
|
2020-03-30 14:01:39 -04:00
|
|
|
"title": "", # Title
|
2018-07-20 11:45:45 -04:00
|
|
|
"firstname": member["First Name"],
|
2020-03-30 14:01:39 -04:00
|
|
|
"lastname": member["Last Name"], # (c)
|
|
|
|
"username": username, # (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)
|
2018-07-20 11:45:45 -04:00
|
|
|
"employeeNumber": member["Account ID"],
|
2020-03-30 14:01:39 -04:00
|
|
|
# "employeeType": "", # Employee type
|
|
|
|
"homedrive": "H:", # Windows home drive
|
|
|
|
"sambahome": "\\\\ucs\\" + username, # Windows home path
|
|
|
|
"profilepath": "%LOGONSERVER%\\%USERNAME%\\windows-profiles\\default", # Windows profile directory
|
2018-07-20 11:45:45 -04:00
|
|
|
"disabled": "1" if member["Account on Hold"] != "" else "0",
|
2020-03-30 14:01:39 -04:00
|
|
|
# "userexpiry": member["Renewal Date"],
|
|
|
|
"pwdChangeNextLogin": "1", # User has to change password on next login
|
|
|
|
# "sambaLogonHours": "", # Permitted times for Windows logins
|
2018-07-20 11:45:45 -04:00
|
|
|
"e-mail": member["Email"], # ([]) E-mail address
|
2020-03-30 14:01:39 -04:00
|
|
|
"phone": member["Phone"], # Telephone number
|
|
|
|
# "PasswordRecoveryMobile": member["Phone"], # Mobile phone number
|
|
|
|
"PasswordRecoveryEmail": member["Email"],
|
2018-07-20 11:45:45 -04:00
|
|
|
}
|
2018-06-22 17:54:55 -04:00
|
|
|
|
2020-03-30 14:01:39 -04:00
|
|
|
subprocess.call(
|
|
|
|
["udm", "users/user", "create", "--position", LDAP_BASE] + makeSets(props)
|
|
|
|
)
|
2018-06-22 17:54:55 -04:00
|
|
|
|
2018-07-20 11:45:45 -04:00
|
|
|
# remove props we don't want to reset
|
|
|
|
props.pop("password")
|
|
|
|
props.pop("pwdChangeNextLogin")
|
2018-06-22 17:54:55 -04:00
|
|
|
|
2020-03-30 14:01:39 -04:00
|
|
|
subprocess.call(
|
|
|
|
["udm", "users/user", "modify", "--dn", "uid=" + username + "," + LDAP_BASE]
|
|
|
|
+ makeSets(props)
|
|
|
|
+ makeAppendGroups(member)
|
|
|
|
)
|
|
|
|
|
2018-06-22 17:54:55 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|