All of lore.kernel.org
 help / color / mirror / Atom feed
From: rmccabe@sourceware.org <rmccabe@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/luci/utils luci_admin
Date: 3 Aug 2006 15:55:55 -0000	[thread overview]
Message-ID: <20060803155555.17673.qmail@sourceware.org> (raw)

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)
 



             reply	other threads:[~2006-08-03 15:55 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-03 15:55 rmccabe [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-03-25 20:14 [Cluster-devel] conga/luci/utils luci_admin rmccabe
2007-09-19  5:17 rmccabe
2007-08-10 18:36 rmccabe
2007-08-10 18:33 rmccabe
2007-08-10 18:32 rmccabe
2007-08-07 20:22 rmccabe
2006-10-13  6:56 kupcevic
2006-08-18 18:03 rmccabe
2006-08-04 19:19 rmccabe
2006-08-04 18:37 rmccabe
2006-08-03 22:58 kupcevic
2006-08-03 21:19 rmccabe
2006-08-03 21:11 rmccabe
2006-08-03 16:32 rmccabe
2006-08-03 12:26 rmccabe
2006-08-03  3:58 rmccabe
2006-08-03  3:30 rmccabe
2006-08-02 23:29 rmccabe
2006-08-02 20:52 rmccabe
2006-08-02 20:45 rmccabe
2006-07-26  1:17 rmccabe
2006-07-25 22:36 rmccabe
2006-07-11 18:46 rmccabe
2006-07-11 14:51 rmccabe
2006-06-29 18:04 rmccabe
2006-06-29 17:51 rmccabe
2006-06-27 19:50 rmccabe
2006-06-27 19:40 rmccabe
2006-06-27 18:19 rmccabe
2006-06-26 22:30 rmccabe
2006-06-26 20:01 rmccabe
2006-06-21 23:06 rmccabe
2006-06-21 17:41 rmccabe
2006-06-21 17:06 rmccabe
2006-06-18 15:02 rmccabe
2006-06-18 12:50 rmccabe
2006-06-18  3:26 rmccabe
2006-06-16 23:19 rmccabe
2006-06-16 19:35 rmccabe
2006-06-16 18:17 rmccabe
2006-06-16 17:44 rmccabe
2006-06-16  5:35 rmccabe
2006-06-13 18:42 rmccabe
2006-06-13 17:36 rmccabe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060803155555.17673.qmail@sourceware.org \
    --to=rmccabe@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.