Beispiel #1
0
 def change_password(self, master_pwd, master_pwd_new):
     try:
         dispatch_rpc('db', 'change_admin_password',
                      [master_pwd, master_pwd_new])
         return request.redirect('/web/database/manager')
     except Exception as e:
         error = "Master password update error: %s" % (str(e) or repr(e))
         return self._render_template(error=error)
Beispiel #2
0
 def drop(self, master_pwd, name):
     insecure = odoo.tools.config.verify_admin_password('admin')
     if insecure and master_pwd:
         dispatch_rpc('db', 'change_admin_password', ["admin", master_pwd])
     try:
         dispatch_rpc('db', 'drop', [master_pwd, name])
         if request.db == name:
             request.env.cr._closed = True  # the underlying connection was closed
         if request.session.db == name:
             request.session.logout()
         return request.redirect('/web/database/manager')
     except Exception as e:
         _logger.exception("Database deletion error.")
         error = "Database deletion error: %s" % (str(e) or repr(e))
         return self._render_template(error=error)
Beispiel #3
0
 def restore(self, master_pwd, backup_file, name, copy=False):
     insecure = odoo.tools.config.verify_admin_password('admin')
     if insecure and master_pwd:
         dispatch_rpc('db', 'change_admin_password', ["admin", master_pwd])
     try:
         data_file = None
         db.check_super(master_pwd)
         with tempfile.NamedTemporaryFile(delete=False) as data_file:
             backup_file.save(data_file)
         db.restore_db(name, data_file.name, str2bool(copy))
         return request.redirect('/web/database/manager')
     except Exception as e:
         error = "Database restore error: %s" % (str(e) or repr(e))
         return self._render_template(error=error)
     finally:
         if data_file:
             os.unlink(data_file.name)
Beispiel #4
0
 def _xmlrpc(self, service):
     """Common method to handle an XML-RPC request."""
     data = request.httprequest.get_data()
     params, method = xmlrpc.client.loads(data)
     result = dispatch_rpc(service, method, params)
     return xmlrpc.client.dumps((result, ),
                                methodresponse=1,
                                allow_none=False)
Beispiel #5
0
 def duplicate(self, master_pwd, name, new_name):
     insecure = odoo.tools.config.verify_admin_password('admin')
     if insecure and master_pwd:
         dispatch_rpc('db', 'change_admin_password', ["admin", master_pwd])
     try:
         if not re.match(DBNAME_PATTERN, new_name):
             raise Exception(
                 _('Invalid database name. Only alphanumerical characters, underscore, hyphen and dot are allowed.'
                   ))
         dispatch_rpc('db', 'duplicate_database',
                      [master_pwd, name, new_name])
         if request.db == name:
             request.env.cr.close(
             )  # duplicating a database leads to an unusable cursor
         return request.redirect('/web/database/manager')
     except Exception as e:
         _logger.exception("Database duplication error.")
         error = "Database duplication error: %s" % (str(e) or repr(e))
         return self._render_template(error=error)
Beispiel #6
0
 def backup(self, master_pwd, name, backup_format='zip'):
     insecure = odoo.tools.config.verify_admin_password('admin')
     if insecure and master_pwd:
         dispatch_rpc('db', 'change_admin_password', ["admin", master_pwd])
     try:
         odoo.service.db.check_super(master_pwd)
         ts = datetime.datetime.utcnow().strftime("%Y-%m-%d_%H-%M-%S")
         filename = "%s_%s.%s" % (name, ts, backup_format)
         headers = [
             ('Content-Type', 'application/octet-stream; charset=binary'),
             ('Content-Disposition', content_disposition(filename)),
         ]
         dump_stream = odoo.service.db.dump_db(name, None, backup_format)
         response = werkzeug.wrappers.Response(dump_stream,
                                               headers=headers,
                                               direct_passthrough=True)
         return response
     except Exception as e:
         _logger.exception('Database.backup')
         error = "Database backup error: %s" % (str(e) or repr(e))
         return self._render_template(error=error)
Beispiel #7
0
 def create(self, master_pwd, name, lang, password, **post):
     insecure = odoo.tools.config.verify_admin_password('admin')
     if insecure and master_pwd:
         dispatch_rpc('db', 'change_admin_password', ["admin", master_pwd])
     try:
         if not re.match(DBNAME_PATTERN, name):
             raise Exception(
                 _('Invalid database name. Only alphanumerical characters, underscore, hyphen and dot are allowed.'
                   ))
         # country code could be = "False" which is actually True in python
         country_code = post.get('country_code') or False
         dispatch_rpc('db', 'create_database', [
             master_pwd, name,
             bool(post.get('demo')), lang, password, post['login'],
             country_code, post['phone']
         ])
         request.session.authenticate(name, post['login'], password)
         request.session.db = name
         return request.redirect('/web')
     except Exception as e:
         _logger.exception("Database creation error.")
         error = "Database creation error: %s" % (str(e) or repr(e))
     return self._render_template(error=error)
Beispiel #8
0
 def get_lang_list(self):
     try:
         return dispatch_rpc('db', 'list_lang', []) or []
     except Exception as e:
         return {"error": e, "title": _("Languages")}
Beispiel #9
0
 def jsonrpc(self, service, method, args):
     """ Method used by client APIs to contact OpenERP. """
     return dispatch_rpc(service, method, args)