Exemple #1
0
    def _start_remote_desktop(self, operation):

        logger.info('Starting remote desktop.')
        operation.urn_response = RaUrn.RdResults
        operation.request_method = RequestMethod.POST

        vine_running = False

        local_port = tunnels.get_available_port()

        if local_port:

            vine_running, error = vine.start(local_port)

        else:
            # No local port available!?
            operation.success = False
            operation.error = 'No local port available. How did this happen?!'

        if vine_running:

            if operation.tunnel_needed:

                operation.success, operation.error = (
                    tunnels.create_reverse_tunnel(local_port,
                                                  operation.host_port,
                                                  settings.ServerAddress,
                                                  operation.ssh_port))

                if not operation.success:
                    vine.stop()

        operation.raw_result = formatter.rd_results(operation)
        # TODO: Fix ugly response hack. Formetter should go here...
        #operation.raw_result = json.dumps({
        #    'plugin': 'ra',
        #    'host_port': operation.host_port,
        #    'agent_id': settings.AgentId,
        #    'operation': operation.type,
        #    'operation_id': operation.id,
        #    'error': error,
        #})

        logger.info('Done.')
        return operation
Exemple #2
0
    def _start_remote_desktop(self, operation):

        logger.info("Starting remote desktop.")
        operation.urn_response = RaUrn.RdResults
        operation.request_method = RequestMethod.POST

        vine_running = False

        local_port = tunnels.get_available_port()

        if local_port:

            vine_running, error = vine.start(local_port)

        else:
            # No local port available!?
            operation.success = False
            operation.error = "No local port available. How did this happen?!"

        if vine_running:

            if operation.tunnel_needed:

                operation.success, operation.error = tunnels.create_reverse_tunnel(
                    local_port, operation.host_port, settings.ServerAddress, operation.ssh_port
                )

                if not operation.success:
                    vine.stop()

        operation.raw_result = formatter.rd_results(operation)
        # TODO: Fix ugly response hack. Formetter should go here...
        # operation.raw_result = json.dumps({
        #    'plugin': 'ra',
        #    'host_port': operation.host_port,
        #    'agent_id': settings.AgentId,
        #    'operation': operation.type,
        #    'operation_id': operation.id,
        #    'error': error,
        # })

        logger.info("Done.")
        return operation
Exemple #3
0
    def _set_rd_password(self, operation):

        logger.info('Setting remote desktop password.')
        operation.urn_response = RaUrn.RdResults
        operation.request_method = RequestMethod.POST

        error = ''

        try:

            result, error = vine.save_password(operation.password)

            if result:

                operation.success = True
                operation.error = ""

            else:

                operation.success = False
                operation.error = error

        except Exception as e:

            operation.success = False
            operation.error = "Unable to set password: %s" % str(e)
            if error:
                operation.error += error

            logger.error(operation.error)
            logger.exception(e)

        finally:

            operation.raw_result = formatter.rd_results(operation)

        logger.info('Done.')
        return operation
Exemple #4
0
    def _set_rd_password(self, operation):

        logger.info("Setting remote desktop password.")
        operation.urn_response = RaUrn.RdResults
        operation.request_method = RequestMethod.POST

        error = ""

        try:

            result, error = vine.save_password(operation.password)

            if result:

                operation.success = True
                operation.error = ""

            else:

                operation.success = False
                operation.error = error

        except Exception as e:

            operation.success = False
            operation.error = "Unable to set password: %s" % str(e)
            if error:
                operation.error += error

            logger.error(operation.error)
            logger.exception(e)

        finally:

            operation.raw_result = formatter.rd_results(operation)

        logger.info("Done.")
        return operation