server/serverctl.py
changeset 7595 83872394b5d9
parent 7577 9892937d9041
parent 7594 d177c0755b10
child 7669 b96c41c6de4d
--- a/server/serverctl.py	Wed Jun 29 16:29:15 2011 +0200
+++ b/server/serverctl.py	Fri Jul 01 11:51:04 2011 +0200
@@ -567,6 +567,15 @@
     """
     name = 'reset-admin-pwd'
     arguments = '<instance>'
+    options = (
+        ('password',
+         {'short': 'p', 'type' : 'string', 'metavar' : '<new-password>',
+          'default' : None,
+          'help': 'Use this password instead of prompt for one.\n'
+                  '/!\ THIS IS AN INSECURE PRACTICE /!\ \n'
+                  'the password will appear in shell history'}
+         ),
+        )
 
     def run(self, args):
         """run the command with its specific arguments"""
@@ -593,15 +602,18 @@
             print "   fix your sources file before running this command"
             cnx.close()
             sys.exit(1)
-        # ask for a new password
-        _, passwd = manager_userpasswd(adminlogin, confirm=True,
-                                       passwdmsg='new password for %s' % adminlogin)
+        if self.config.password is None:
+            # ask for a new password
+            msg = 'new password for %s' % adminlogin
+            _, pwd = manager_userpasswd(adminlogin, confirm=True, passwdmsg=msg)
+        else:
+            pwd = self.config.password
         try:
             cursor.execute("UPDATE cw_CWUser SET cw_upassword=%(p)s WHERE cw_login=%(l)s",
-                           {'p': dbhelper.binary_value(crypt_password(passwd)), 'l': adminlogin})
+                           {'p': dbhelper.binary_value(crypt_password(pwd)), 'l': adminlogin})
             sconfig = Configuration(options=USER_OPTIONS)
             sconfig['login'] = adminlogin
-            sconfig['password'] = passwd
+            sconfig['password'] = pwd
             sourcescfg['admin'] = sconfig
             config.write_sources_file(sourcescfg)
         except Exception, ex: