diff --git a/importUsers.py b/importUsers.py index 93c2cb7..375ee16 100755 --- a/importUsers.py +++ b/importUsers.py @@ -1,6 +1,12 @@ # Simple Cloudron bulk user import script # Uses the Cloudron REST API v1 -# Rev 1.2, 03/019/21, changes: +# Rev 1.3, 10/16/22, changes: +# - added option to add passwords as part of the import +# Please note that this method obviously discloses passwords to the admin, so +# users should be encouraged to change their password on first login. +# - updated help output to include the optional mailbox and password options +# - fixed the revision date of the last commit +# Rev 1.2, 03/19/21, changes: # - removed the she-bang because it was interfering with alternate python paths. Use python importUsers.py to run # - changed the CSV file format. The person_id field is gone, user_groups is in. This change allows flexibility # on group membership (arbitrary number of groups) @@ -53,15 +59,16 @@ def main(argv): username = '' dataFilePath = './users.csv' addmailbox = False + addpassword = False try: opts, args = getopt.getopt(argv,"hf:d:u:m",["help","file=","domain=","username=","add-mailbox"]) except getopt.GetoptError: - print("importUsers.py -f -d -u ") + print("importUsers.py -f -d -u [-m] [-p]") sys.exit(2) for opt, arg in opts: if opt == '-h': - print("importUsers.py -f -d -u ") + print("importUsers.py -f -d -u [-m] [-p]") sys.exit() elif opt in ('-f', '--file'): dataFilePath = arg @@ -71,6 +78,8 @@ def main(argv): username = arg elif opt in ('-m','--add-mailbox'): addmailbox = True + elif opt in ('-p','--add-password'): + addpassword = True if( domain == '' ): print("domainname must be provided, use the -d flag") @@ -96,7 +105,10 @@ def main(argv): displayName = entry['first_name'] + ' ' + entry['last_name'] requestUrl = apiBasePath + '/users?access_token='+accessToken - payload = {"email":entry['email_address'], "username":entry['sis_username'], "displayName":displayName, "password":""} + password = "" + if( addpassword == True ) + password = entry['password'] + payload = {"email":entry['email_address'], "username":entry['sis_username'], "displayName":displayName, "password":password} r = requests.post(requestUrl, json=payload) if( r.status_code == requests.codes.created ):