server/serverctl.py
changeset 7595 83872394b5d9
parent 7577 9892937d9041
parent 7594 d177c0755b10
child 7669 b96c41c6de4d
equal deleted inserted replaced
7591:cb6ece9cdb78 7595:83872394b5d9
   565     <instance>
   565     <instance>
   566       the identifier of the instance
   566       the identifier of the instance
   567     """
   567     """
   568     name = 'reset-admin-pwd'
   568     name = 'reset-admin-pwd'
   569     arguments = '<instance>'
   569     arguments = '<instance>'
       
   570     options = (
       
   571         ('password',
       
   572          {'short': 'p', 'type' : 'string', 'metavar' : '<new-password>',
       
   573           'default' : None,
       
   574           'help': 'Use this password instead of prompt for one.\n'
       
   575                   '/!\ THIS IS AN INSECURE PRACTICE /!\ \n'
       
   576                   'the password will appear in shell history'}
       
   577          ),
       
   578         )
   570 
   579 
   571     def run(self, args):
   580     def run(self, args):
   572         """run the command with its specific arguments"""
   581         """run the command with its specific arguments"""
   573         from cubicweb.server.utils import crypt_password, manager_userpasswd
   582         from cubicweb.server.utils import crypt_password, manager_userpasswd
   574         appid = args[0]
   583         appid = args[0]
   591             print ("-> error: admin user %r specified in sources doesn't exist "
   600             print ("-> error: admin user %r specified in sources doesn't exist "
   592                    "in the database" % adminlogin)
   601                    "in the database" % adminlogin)
   593             print "   fix your sources file before running this command"
   602             print "   fix your sources file before running this command"
   594             cnx.close()
   603             cnx.close()
   595             sys.exit(1)
   604             sys.exit(1)
   596         # ask for a new password
   605         if self.config.password is None:
   597         _, passwd = manager_userpasswd(adminlogin, confirm=True,
   606             # ask for a new password
   598                                        passwdmsg='new password for %s' % adminlogin)
   607             msg = 'new password for %s' % adminlogin
       
   608             _, pwd = manager_userpasswd(adminlogin, confirm=True, passwdmsg=msg)
       
   609         else:
       
   610             pwd = self.config.password
   599         try:
   611         try:
   600             cursor.execute("UPDATE cw_CWUser SET cw_upassword=%(p)s WHERE cw_login=%(l)s",
   612             cursor.execute("UPDATE cw_CWUser SET cw_upassword=%(p)s WHERE cw_login=%(l)s",
   601                            {'p': dbhelper.binary_value(crypt_password(passwd)), 'l': adminlogin})
   613                            {'p': dbhelper.binary_value(crypt_password(pwd)), 'l': adminlogin})
   602             sconfig = Configuration(options=USER_OPTIONS)
   614             sconfig = Configuration(options=USER_OPTIONS)
   603             sconfig['login'] = adminlogin
   615             sconfig['login'] = adminlogin
   604             sconfig['password'] = passwd
   616             sconfig['password'] = pwd
   605             sourcescfg['admin'] = sconfig
   617             sourcescfg['admin'] = sconfig
   606             config.write_sources_file(sourcescfg)
   618             config.write_sources_file(sourcescfg)
   607         except Exception, ex:
   619         except Exception, ex:
   608             cnx.rollback()
   620             cnx.rollback()
   609             import traceback
   621             import traceback