Example #1
0
    def post_hba(self, agent_address, agent_port):
        try:
            self.logger.info("Posting HBA (proxy).")
            instance = None
            role = None

            self.load_auth_cookie()
            self.start_db_session()

            role = self.current_user
            if not role:
                raise TemboardUIError(302, "Current role unknown.")

            instance = get_instance(self.db_session, agent_address, agent_port)
            if not instance:
                raise TemboardUIError(404, "Instance not found.")
            if __name__ not in [
                    plugin.plugin_name for plugin in instance.plugins
            ]:
                raise TemboardUIError(408, "Plugin not active.")
            self.db_session.expunge_all()
            self.db_session.commit()
            self.db_session.close()
            xsession = self.get_secure_cookie(
                "temboard_%s_%s" %
                (instance.agent_address, instance.agent_port))
            if not xsession:
                raise TemboardUIError(401, "Authentication cookie is missing.")

            data = temboard_post_conf_file(
                self.ssl_ca_cert_file, 'hba', instance.agent_address,
                instance.agent_port, xsession,
                tornado.escape.json_decode(self.request.body))
            # And reload postgresql configuration.
            temboard_post_administration_control(self.ssl_ca_cert_file,
                                                 instance.agent_address,
                                                 instance.agent_port, xsession,
                                                 {'action': 'reload'})
            self.logger.info("Done.")
            return JSONAsyncResult(http_code=200, data=data)
        except (TemboardUIError, TemboardError, Exception) as e:
            self.logger.exception(str(e))
            self.logger.info("Failed.")
            try:
                self.db_session.close()
            except Exception:
                pass
            if (isinstance(e, TemboardUIError)
                    or isinstance(e, TemboardError)):
                return JSONAsyncResult(http_code=e.code,
                                       data={'error': e.message})
            else:
                return JSONAsyncResult(http_code=500,
                                       data={'error': e.message})
Example #2
0
    def post_hba(self, agent_address, agent_port):
        self.logger.info("Posting HBA (proxy).")

        self.setUp(agent_address, agent_port)
        self.check_active_plugin(__name__)

        xsession = self.get_secure_cookie("temboard_%s_%s" %
                                          (agent_address, agent_port))
        if not xsession:
            raise TemboardUIError(401, "Authentication cookie is missing.")

        data = temboard_post_conf_file(
            self.ssl_ca_cert_file, 'hba', agent_address, agent_port, xsession,
            tornado.escape.json_decode(self.request.body))
        # And reload postgresql configuration.
        temboard_post_administration_control(self.ssl_ca_cert_file,
                                             agent_address, agent_port,
                                             xsession, {'action': 'reload'})
        self.logger.info("Done.")
        return JSONAsyncResult(http_code=200, data=data)
Example #3
0
    def post_configuration_file(self, agent_address, agent_port):
        error_code = None
        error_message = None
        ret_post = None

        self.logger.info("Posting configuration (file).")

        self.setUp(agent_address, agent_port)
        self.check_active_plugin(__name__)

        xsession = self.get_secure_cookie("temboard_%s_%s" %
                                          (agent_address, agent_port))
        if not xsession:
            raise TemboardUIError(401, "Authentication cookie is missing.")
        try:
            # Send file content ..
            ret_post = temboard_post_file_content(
                self.ssl_ca_cert_file, self.file_type, agent_address,
                agent_port, xsession, {
                    'content': self.request.arguments['content'][0],
                    'new_version': True
                })
            # .. and reload configuration.
            ret_post = temboard_post_administration_control(
                self.ssl_ca_cert_file, agent_address, agent_port, xsession,
                {'action': 'reload'})
        except (TemboardError, Exception) as e:
            self.logger.exception(str(e))
            if isinstance(e, TemboardError):
                error_code = e.code
                error_message = e.message
            else:
                error_code = 500
                error_message = "Internale error."
        # Load file content.
        file_content = temboard_get_file_content(self.ssl_ca_cert_file,
                                                 self.file_type, agent_address,
                                                 agent_port, xsession)
        self.logger.info("Done.")
        return HTMLAsyncResult(http_code=200,
                               template_path=self.template_path,
                               template_file='edit_file.html',
                               data={
                                   'nav': True,
                                   'role': self.current_user,
                                   'instance': self.instance,
                                   'plugin': __name__,
                                   'file_type': self.file_type,
                                   'file_content': file_content,
                                   'error_code': error_code,
                                   'error_message': error_message,
                                   'xsession': xsession,
                                   'ret_post': ret_post
                               })
Example #4
0
    def post_configuration_file(self, agent_address, agent_port):
        error_code = None
        error_message = None
        ret_post = None
        try:
            self.logger.info("Posting configuration (file).")
            instance = None
            role = None

            self.load_auth_cookie()
            self.start_db_session()

            role = self.current_user
            if not role:
                raise TemboardUIError(302, "Current role unknown.")

            instance = get_instance(self.db_session, agent_address, agent_port)
            if not instance:
                raise TemboardUIError(404, "Instance not found.")
            if __name__ not in [
                    plugin.plugin_name for plugin in instance.plugins
            ]:
                raise TemboardUIError(408, "Plugin not active.")
            self.db_session.expunge_all()
            self.db_session.commit()
            self.db_session.close()
            xsession = self.get_secure_cookie(
                "temboard_%s_%s" %
                (instance.agent_address, instance.agent_port))
            if not xsession:
                raise TemboardUIError(401, "Authentication cookie is missing.")
            try:
                # Send file content ..
                ret_post = temboard_post_file_content(
                    self.ssl_ca_cert_file, self.file_type,
                    instance.agent_address, instance.agent_port, xsession, {
                        'content': self.request.arguments['content'][0],
                        'new_version': True
                    })
                # .. and reload configuration.
                ret_post = temboard_post_administration_control(
                    self.ssl_ca_cert_file, instance.agent_address,
                    instance.agent_port, xsession, {'action': 'reload'})
            except (TemboardError, Exception) as e:
                self.logger.exception(str(e))
                if isinstance(TemboardError, e):
                    error_code = e.code
                    error_message = e.message
                else:
                    error_code = 500
                    error_message = "Internale error."
            # Load file content.
            file_content = temboard_get_file_content(self.ssl_ca_cert_file,
                                                     self.file_type,
                                                     instance.agent_address,
                                                     instance.agent_port,
                                                     xsession)
            self.logger.info("Done.")
            return HTMLAsyncResult(http_code=200,
                                   template_path=self.template_path,
                                   template_file='edit_file.html',
                                   data={
                                       'nav': True,
                                       'role': role,
                                       'instance': instance,
                                       'plugin': 'pgconf',
                                       'file_type': self.file_type,
                                       'file_content': file_content,
                                       'error_code': error_code,
                                       'error_message': error_message,
                                       'xsession': xsession,
                                       'ret_post': ret_post
                                   })
        except (TemboardUIError, TemboardError, Exception) as e:
            self.logger.exception(str(e))
            self.logger.info("Failed.")
            try:
                self.db_session.expunge_all()
                self.db_session.rollback()
                self.db_session.close()
            except Exception:
                pass
            if (isinstance(e, TemboardUIError)
                    or isinstance(e, TemboardError)):
                if e.code == 401:
                    return HTMLAsyncResult(http_code=401,
                                           redirection="/server/%s/%s/login" %
                                           (agent_address, agent_port))
                elif e.code == 302:
                    return HTMLAsyncResult(http_code=401, redirection="/login")
                code = e.code
            else:
                code = 500
            return HTMLAsyncResult(http_code=code,
                                   template_file='error.html',
                                   data={
                                       'nav': True,
                                       'role': role,
                                       'instance': instance,
                                       'code': e.code,
                                       'error': e.message
                                   })