Пример #1
0
    def put(self, agent_id):
        try:
            username = self.get_current_user()
            customer_name = get_user_property(username, UserKeys.CurrentCustomer)
            uri = self.request.uri
            method = self.request.method
            rebooted = self.arguments.get(AgentKey.Rebooted)
            plugins = self.arguments.get(AgentKey.Plugins)
            system_info = self.arguments.get(AgentKey.SystemInfo)
            hardware = self.arguments.get(AgentKey.Hardware)
            logger.info("data received on startup: %s" % self.request.body)
            agent_data = update_agent(agent_id, system_info, hardware, rebooted, username, customer_name, uri, method)
            uris = get_result_uris(agent_id, username, uri, method)
            uris[AgentOperationKey.Operation] = AgentOperations.REFRESH_RESPONSE_URIS
            agent_data.pop("data")
            agent_data["data"] = [uris]
            self.set_status(agent_data["http_status"])

            if agent_data["http_status"] == 200:
                if "rv" in plugins:
                    RvHandOff(username, customer_name, uri, method).startup_operation(agent_id, plugins["rv"]["data"])

                if "ra" in plugins:
                    RaHandoff.startup(agent_id, plugins["ra"])

            self.set_header("Content-Type", "application/json")
            self.write(dumps(agent_data))

        except Exception as e:
            status = GenericResults(username, uri, method).something_broke(agent_id, "startup", e)

            logger.exception(status["message"])
            self.write(dumps(status))
Пример #2
0
    def post(self):
        username = self.get_current_user()
        customer_name = self.arguments.get(AgentKey.CustomerName)
        plugins = self.arguments.get(AgentKey.Plugins)
        rebooted = self.arguments.get(AgentKey.Rebooted)
        system_info = self.arguments.get(AgentKey.SystemInfo)
        hardware = self.arguments.get(AgentKey.Hardware)
        uri = self.request.uri
        method = self.request.method
        logger.info('data received on newagent: %s' % (self.request.body))
        self.set_header('Content-Type', 'application/json')

        try:
            new_agent_results = (add_agent(system_info, hardware, username,
                                           customer_name, uri, method))
            self.set_status(new_agent_results[ApiResultKeys.HTTP_STATUS_CODE])

            if (new_agent_results[ApiResultKeys.VFENSE_STATUS_CODE] ==
                    AgentResultCodes.NewAgentSucceeded):

                agent_info = new_agent_results[ApiResultKeys.DATA][-1]
                agent_id = (
                    new_agent_results[ApiResultKeys.GENERATED_IDS].pop())
                uris = get_result_uris(agent_id, username, uri, method)
                uris[AgentOperationKey.Operation] = (
                    AgentOperations.REFRESH_RESPONSE_URIS)
                json_msg = {
                    AgentOperationKey.Operation: "new_agent_id",
                    AgentOperationKey.OperationId: "",
                    OperationPerAgentKey.AgentId: agent_id
                }
                new_agent_results[ApiResultKeys.DATA] = [json_msg, uris]
                try:
                    if 'rv' in plugins:
                        RvHandOff(username, customer_name, uri,
                                  method).new_agent_operation(
                                      agent_id, plugins['rv']['data'],
                                      agent_info)

                    if 'ra' in plugins:
                        RaHandoff.startup(agent_id, plugins['ra'])

                except Exception as e:
                    logger.exception(e)

                self.write(dumps(new_agent_results, indent=4))

            else:
                self.write(dumps(new_agent_results, indent=4))

        except Exception as e:
            status = (GenericResults(username, uri, method).something_broke(
                'agent', 'new_agent', e))
            logger.exception(e)
            self.write(dumps(status, indent=4))
Пример #3
0
    def get(self, agent_id):
        username = self.get_current_user()
        uri = self.request.uri
        method = self.request.method
        try:
            results = get_result_uris(agent_id, username, uri, method)
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))

        except Exception as e:
            status = (GenericResults(username, uri, method).something_broke(
                'uris', 'refresh_response_uris', e))
            logger.exception(e)
            self.write(json.dumps(status, indent=4))
Пример #4
0
    def put(self, agent_id):
        try:
            username = self.get_current_user()
            customer_name = (get_user_property(username,
                                               UserKeys.CurrentCustomer))
            uri = self.request.uri
            method = self.request.method
            rebooted = self.arguments.get(AgentKey.Rebooted)
            plugins = self.arguments.get(AgentKey.Plugins)
            system_info = self.arguments.get(AgentKey.SystemInfo)
            hardware = self.arguments.get(AgentKey.Hardware)
            logger.info('data received on startup: %s' % self.request.body)
            agent_data = (update_agent(
                agent_id,
                system_info,
                hardware,
                rebooted,
                username,
                customer_name,
                uri,
                method,
            ))
            uris = get_result_uris(agent_id, username, uri, method)
            uris[AgentOperationKey.Operation] = (
                AgentOperations.REFRESH_RESPONSE_URIS)
            agent_data.pop('data')
            agent_data['data'] = [uris]
            self.set_status(agent_data['http_status'])

            if agent_data['http_status'] == 200:
                if 'rv' in plugins:
                    RvHandOff(username, customer_name, uri,
                              method).startup_operation(
                                  agent_id, plugins['rv']['data'])

                if 'ra' in plugins:
                    RaHandoff.startup(agent_id, plugins['ra'])

            self.set_header('Content-Type', 'application/json')
            self.write(dumps(agent_data))

        except Exception as e:
            status = (GenericResults(username, uri, method).something_broke(
                agent_id, 'startup', e))

            logger.exception(status['message'])
            self.write(dumps(status))
Пример #5
0
    def get(self, agent_id):
        username = self.get_current_user()
        uri = self.request.uri
        method = self.request.method
        try:
            results = get_result_uris(agent_id, username, uri, method)
            self.set_header('Content-Type', 'application/json')
            self.write(dumps(results, indent=4))

        except Exception as e:
            status = (
                GenericResults(
                    username, uri, method
                ).something_broke('uris', 'refresh_response_uris', e)
            )
            logger.exception(e)
            self.write(dumps(status, indent=4))
Пример #6
0
    def post(self):
        username = self.get_current_user()
        customer_name = self.arguments.get(AgentKey.CustomerName)
        plugins = self.arguments.get(AgentKey.Plugins)
        rebooted = self.arguments.get(AgentKey.Rebooted)
        system_info = self.arguments.get(AgentKey.SystemInfo)
        hardware = self.arguments.get(AgentKey.Hardware)
        uri = self.request.uri
        method = self.request.method
        logger.info('data received on newagent: %s' % (self.request.body))
        self.set_header('Content-Type', 'application/json')

        try:
            new_agent_results = (
                add_agent(
                    system_info, hardware, username, customer_name, uri, method
                )
            )
            self.set_status(
                new_agent_results[ApiResultKeys.HTTP_STATUS_CODE]
            )

            if (
                    new_agent_results[ApiResultKeys.VFENSE_STATUS_CODE] ==
                    AgentResultCodes.NewAgentSucceeded
                ):

                agent_info = new_agent_results[ApiResultKeys.DATA][-1]
                agent_id = (
                    new_agent_results[ApiResultKeys.GENERATED_IDS].pop()
                )
                uris = get_result_uris(agent_id, username, uri, method)
                uris[AgentOperationKey.Operation] = (
                    AgentOperations.REFRESH_RESPONSE_URIS
                )
                json_msg = {
                    AgentOperationKey.Operation: "new_agent_id",
                    AgentOperationKey.OperationId: "",
                    OperationPerAgentKey.AgentId: agent_id
                }
                new_agent_results[ApiResultKeys.DATA] = [json_msg, uris]
                try:
                    if 'rv' in plugins:
                        RvHandOff(
                            username, customer_name, uri, method
                        ).new_agent_operation(
                            agent_id,
                            plugins['rv']['data'],
                            agent_info
                        )

                    if 'ra' in plugins:
                        RaHandoff.startup(agent_id, plugins['ra'])

                except Exception as e:
                    logger.exception(e)

                self.write(dumps(new_agent_results, indent=4))

            else:
                self.write(dumps(new_agent_results, indent=4))

        except Exception as e:
            status = (
                GenericResults(
                    username, uri, method
                ).something_broke('agent', 'new_agent', e)
            )
            logger.exception(e)
            self.write(dumps(status, indent=4))