558 <instance> |
558 <instance> |
559 the identifier of the instance |
559 the identifier of the instance |
560 """ |
560 """ |
561 name = 'reset-admin-pwd' |
561 name = 'reset-admin-pwd' |
562 arguments = '<instance>' |
562 arguments = '<instance>' |
|
563 options = ( |
|
564 ('password', |
|
565 {'short': 'p', 'type' : 'string', 'metavar' : '<new-password>', |
|
566 'default' : None, |
|
567 'help': 'Use this password instead of prompt for one.\n' |
|
568 '/!\ THIS IS AN INSECURE PRACTICE /!\ \n' |
|
569 'the password will appear in shell history'} |
|
570 ), |
|
571 ) |
563 |
572 |
564 def run(self, args): |
573 def run(self, args): |
565 """run the command with its specific arguments""" |
574 """run the command with its specific arguments""" |
566 from cubicweb.server.utils import crypt_password, manager_userpasswd |
575 from cubicweb.server.utils import crypt_password, manager_userpasswd |
567 appid = args[0] |
576 appid = args[0] |
584 print ("-> error: admin user %r specified in sources doesn't exist " |
593 print ("-> error: admin user %r specified in sources doesn't exist " |
585 "in the database" % adminlogin) |
594 "in the database" % adminlogin) |
586 print " fix your sources file before running this command" |
595 print " fix your sources file before running this command" |
587 cnx.close() |
596 cnx.close() |
588 sys.exit(1) |
597 sys.exit(1) |
589 # ask for a new password |
598 if self.config.password is None: |
590 _, passwd = manager_userpasswd(adminlogin, confirm=True, |
599 # ask for a new password |
591 passwdmsg='new password for %s' % adminlogin) |
600 msg = 'new password for %s' % adminlogin |
|
601 _, pwd = manager_userpasswd(adminlogin, confirm=True, passwdmsg=msg) |
|
602 else: |
|
603 pwd = self.config.password |
592 try: |
604 try: |
593 cursor.execute("UPDATE cw_CWUser SET cw_upassword=%(p)s WHERE cw_login=%(l)s", |
605 cursor.execute("UPDATE cw_CWUser SET cw_upassword=%(p)s WHERE cw_login=%(l)s", |
594 {'p': dbhelper.binary_value(crypt_password(passwd)), 'l': adminlogin}) |
606 {'p': dbhelper.binary_value(crypt_password(pwd)), 'l': adminlogin}) |
595 sconfig = Configuration(options=USER_OPTIONS) |
607 sconfig = Configuration(options=USER_OPTIONS) |
596 sconfig['login'] = adminlogin |
608 sconfig['login'] = adminlogin |
597 sconfig['password'] = passwd |
609 sconfig['password'] = pwd |
598 sourcescfg['admin'] = sconfig |
610 sourcescfg['admin'] = sconfig |
599 config.write_sources_file(sourcescfg) |
611 config.write_sources_file(sourcescfg) |
600 except Exception, ex: |
612 except Exception, ex: |
601 cnx.rollback() |
613 cnx.rollback() |
602 import traceback |
614 import traceback |