From mboxrd@z Thu Jan 1 00:00:00 1970 From: rmccabe@sourceware.org Date: 3 Aug 2006 15:55:55 -0000 Subject: [Cluster-devel] conga/luci/utils luci_admin Message-ID: <20060803155555.17673.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Changes by: rmccabe at sourceware.org 2006-08-03 15:55:55 Modified files: luci/utils : luci_admin Log message: restore additional user info, nitpicking Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.36&r2=1.37 --- conga/luci/utils/luci_admin 2006/08/03 12:26:38 1.36 +++ conga/luci/utils/luci_admin 2006/08/03 15:55:54 1.37 @@ -73,8 +73,9 @@ inituser = file(INITUSER_FILE_PATH, 'w') try: os.chmod(INITUSER_FILE_PATH, 0600) except OSError, e: - print 'An error occurred while saving',user,'password:',e - try: os.unlink(INITUSER_FILE_PATH) + sys.stderr.write('An error occurred while saving user' + user + '\'s password: ' + e + '\n') + try: + os.unlink(INITUSER_FILE_PATH) except: pass inituser.close() return -1 @@ -260,6 +261,7 @@ import ImageFile import Products.PluggableAuthService.plugins.ZODBUserManager import BTrees.OOBTree + from DateTime import DateTime ImageFile.ImageFile.__init__ = lambda x,y,z:None sys.stderr = orig_stderr @@ -344,23 +346,25 @@ for u in userList: id = u.getAttribute('id') if not id: + transaction.abort() sys.stderr.write('Missing ID for user\n') - continue + return -1 id = str(id) passwd = u.getAttribute('passwd') if not passwd: + transaction.abort() sys.stderr.write('Missing password for user \"' + id + '\"\n') - continue + return -1 passwd = str(passwd) if id == 'admin': try: acl_users._user_passwords['admin'] = passwd - transaction.commit() except: + transaction.abort() sys.stderr.write('Unable to restore admin password.') - continue + return -1 else: email = u.getAttribute('email') if not email: @@ -372,9 +376,24 @@ 'username': id, 'roles': [ 'Member' ], 'domains': [], - 'email': email + 'email': email, + 'must_change_password': False } + login_time = u.getAttribute('login_time') + if login_time: + props['login_time'] = DateTime(str(login_time)) + + last_login_time = u.getAttribute('last_login_time') + if last_login_time: + props['last_login_time'] = DateTime(str(last_login_time)) + + must_change_passwd = u.getAttribute('must_change_password') + if must_change_passwd: + must_change_passwd = str(must_change_passwd) + if must_change_passwd == 'True' or '1': + props['must_change_password'] = True + portal_reg.addMember(id, passwd, props) member = portal_mem.getMemberById(id) @@ -392,16 +411,17 @@ except: transaction.abort() sys.stderr.write('An error occurred while restoring the password for user \"' + id + '\"\n') + return -1 verbose.write('Added user \"' + id + '\"\n') - transaction.commit() + transaction.commit() try: x = app.luci.systems.storage if not x: raise except: - sys.stderr.write('Cannot find the Luci storage systems directory. Your Luci installation may be corrupt.\n') transaction.abort() + sys.stderr.write('Cannot find the Luci storage systems directory. Your Luci installation may be corrupt.\n') return -1 systemList = node.getElementsByTagName('systemList') @@ -415,8 +435,8 @@ for s in systemList: id = s.getAttribute('id') if not id: - sys.stderr.write('Missing ID for storage system. Your backup may be corrupt.\n') transaction.abort() + sys.stderr.write('Missing ID for storage system. Your backup may be corrupt.\n') return -1 id = str(id) try: @@ -432,8 +452,8 @@ new_system.manage_acquiredPermissions([]) new_system.manage_role('View', ['Access contents information','View']) except: - sys.stderr.write('An error occurred while restoring storage system \"' + id + '\"\n') transaction.abort() + sys.stderr.write('An error occurred while restoring storage system \"' + id + '\"\n') return -1 userPerms = s.getElementsByTagName('permList') @@ -459,8 +479,8 @@ if not x: raise except: - sys.stderr.write('Cannot find the Luci cluster directory. Your Luci installation may be corrupt.\n') transaction.abort() + sys.stderr.write('Cannot find the Luci cluster directory. Your Luci installation may be corrupt.\n') return -1 clusterList = node.getElementsByTagName('clusterList') @@ -474,8 +494,8 @@ for c in clusterList: id = c.getAttribute('id') if not id: - sys.stderr.write('Cluster element is missing id\n') transaction.abort() + sys.stderr.write('Cluster element is missing id\n') return -1 id = str(id) @@ -494,8 +514,8 @@ new_cluster.manage_acquiredPermissions([]) new_cluster.manage_role('View', ['Access contents information','View']) except: - sys.stderr.write('An error occurred while restoring the cluster \"' + id + '\"\n') transaction.abort() + sys.stderr.write('An error occurred while restoring the cluster \"' + id + '\"\n') return -1 viewperm = list() @@ -524,8 +544,10 @@ for i in clusterSystems: newsys = i.getAttribute('id') if not newsys: + transaction.abort() sys.stderr.write('Storage system missing name for cluster \"' + id + '\"\n') - continue + return -1 + newsys = str(newsys) stitle = i.getAttribute('title') if not stitle: @@ -541,8 +563,8 @@ newcs.manage_acquiredPermissions([]) newcs.manage_role('View', ['Access contents information','View']) except: - sys.stderr.write('An error occurred while restoring the storage system \"' + newsys + '\" for cluster \"' + id + '\"\n') transaction.abort() + sys.stderr.write('An error occurred while restoring the storage system \"' + newsys + '\" for cluster \"' + id + '\"\n') return -1 transaction.commit() @@ -551,10 +573,12 @@ newcs.manage_setLocalRoles(i, ['View']) verbose.write('Added view permission to cluster system \"' + newsys + '\" for \"' + i + '\"\n') except: - sys.stderr.write('An error occurred while restoring permissions for cluster system \"' + newsys + '\" in cluster \"' + id + '\" for user \"' + i + '\"\n') transaction.abort() + sys.stderr.write('An error occurred while restoring permissions for cluster system \"' + newsys + '\" in cluster \"' + id + '\" for user \"' + i + '\"\n') return -1 + verbose.write('Added storage system \"' + newsys + '\" for cluster \"' + id + '\"\n') + verbose.write('Added cluster \"' + id + '\"\n') transaction.commit() @@ -707,14 +731,13 @@ sys.stderr.write('An error occurred while saving user information.') return -1 - save_member_properties = [ 'login_time', 'last_login_time', 'must_change_password', 'email' ] try: membertool = getToolByName(app.luci, 'portal_membership') if not membertool: raise for mem in membertool.listMembers(): try: - for i in save_member_properties: + for i in [ 'login_time', 'last_login_time', 'must_change_password', 'email' ]: prop = mem.getProperty(i) if prop != '': users[mem.id][i] = str(prop) @@ -770,6 +793,7 @@ csystem_hash['title'] = '__luci__:csystem:' + cluster_name clusters[cluster_name]['csystemList'][csystem[0]] = csystem_hash + transaction.commit() conn.close() db.pack() db.close() @@ -884,7 +908,7 @@ try: (pid, status) = os.waitpid(childpid, 0) except OSError, (errno, msg): - print __name__, "waitpid:", msg + sys.stderr.write(__name__ + 'waitpid: ' + msg + '\n') if os.WIFEXITED(status): status = os.WEXITSTATUS(status) @@ -939,9 +963,7 @@ - -def generate_password(): - password = raw_input('Enter password: ') +def generate_password_hash(password): salt_choices = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789./") @@ -964,22 +986,22 @@ def init(argv): if luci_initialized(): - print 'Luci site has been already initialized' - print 'If you want to reset admin password, execute' - print argv[0] + ' password' + sys.stderr.write('Luci site has been already initialized.\n') + sys.stderr.write('If you want to reset admin password, execute\n') + sys.stderr.write('\t' + argv[0] + ' password\n') sys.exit(1) - pass - print 'Initializing Luci site' + print 'Initializing the Luci server' print print 'Generating SSL certificates...' if generate_ssl_certs() == False: - print 'failed. exiting ...' + sys.stderr.write('failed. exiting ...\n') sys.exit(1) print - print 'Creating \'admin\' user' - save_password('admin', generate_password()) - print 'Luci server has been successfully initialized' + print 'Creating the \'admin\' user' + password = raw_input('Enter password: ') + save_password('admin', generate_password_hash(password)) + print 'The Luci server has been successfully initialized' restart_message() @@ -988,17 +1010,16 @@ def password(argv): if not luci_initialized(): - print 'Luci site has not yet been initialized' - print 'To initialize it, execute' - print argv[0] + ' init' + sys.stderr.write('The Luci site has not been initialized.\n') + sys.stderr.write('To initialize it, execute\n') + sys.stderr.write('\t' + argv[0] + ' init\n') sys.exit(1) - pass - print 'Reseting admin password' + print 'Resetting the admin user\'s password' print password = raw_input('Enter password: ') if not set_zope_passwd('admin', password): - print 'admin password has been successfully reset' + print 'The admin password has been successfully reset.' restart_message() @@ -1007,20 +1028,21 @@ def backup(argv): if not luci_initialized(): - print 'Luci site has not yet been initialized' - print 'To initialize it, execute' - print argv[0] + ' init' + sys.stderr.write('The Luci server has not yet been initialized\n') + sys.stderr.write('To initialize it, execute\n') + sys.stderr.write('\t' + argv[0] + ' init\n') sys.exit(1) print 'Backing up the Luci server...' - try: os.umask(077) + try: + os.umask(077) except: pass doc = luci_backup(argv[2:]) restore_luci_fsattr() if not doc: - sys.stderr.write('The Luci backup failed.\n') + sys.stderr.write('The Luci backup failed. Exiting.\n') sys.exit(1) try: @@ -1075,7 +1097,7 @@ if luci_restore(argv[2:]): ret = False - print 'The Luci restore failed. Try reinstalling Luci, then restoring again.' + sys.stderr.write('The Luci restore failed. Try reinstalling Luci, then restoring again.\n') else: ret = True print 'Restore was successful.' @@ -1103,15 +1125,13 @@ if len(argv) != 2: luci_help(argv) sys.exit(1) - pass # only root can modify Luci server if os.getuid() != 0: - print 'Only root can modify Luci server.' - print 'Try again with root privileges.' + sys.stderr.write('Only root can modify Luci server.\n') + sys.stderr.write('Try again with root privileges.\n') sys.exit(2) - pass if 'init' in argv: @@ -1125,8 +1145,7 @@ elif 'help' in argv: luci_help(argv) else: - print 'Unknown command' - print + sys.stderr.write('Unknown command\n\n') luci_help(argv) sys.exit(1)