def xmlrpc_add_hosts(self, request, hosts):
        try:
            x_real_ip = request.received_headers.get("X-Real-IP")
            remote_ip = x_real_ip or request.getClientIP()

            logging.info("add_hosts({}) from {}".format(hosts, remote_ip))
            for cracker_ip in hosts:
                if not self.is_valid_ip_address(cracker_ip):
                    logging.warning("Illegal host ip address {} from {}".format(cracker_ip, remote_ip))
                    raise xmlrpc.Fault(101, "Illegal IP address \"{}\".".format(cracker_ip))

                logging.debug("Adding report for {} from {}".format(cracker_ip, remote_ip))
                yield utils.wait_and_lock_host(cracker_ip)
                try:
                    cracker = yield Cracker.find(where=['ip_address=?', cracker_ip], limit=1)
                    if cracker is None:
                        now = time.time()
                        cracker = Cracker(ip_address=cracker_ip, first_time=now,
                            latest_time=now, resiliency=0, total_reports=0, current_reports=0)
                        yield cracker.save()
                    yield controllers.add_report_to_cracker(cracker, remote_ip)
                finally:
                    utils.unlock_host(cracker_ip)
                logging.debug("Done adding report for {} from {}".format(cracker_ip,remote_ip))
        except xmlrpc.Fault, e:
            raise e
Beispiel #2
0
    def xmlrpc_test_bulk_insert(self, count, same_crackers = False):
        if same_crackers and len(self._crackers) < count:
            logging.debug("Filling static crackers from {} to {}".format(len(self._crackers), count))
            for i in xrange(len(self._crackers), count):
                self._crackers.append(self.random_ip_address())

        for i in xrange(count):
            reporter = self.random_ip_address()
            if same_crackers:
                cracker_ip = self._crackers[i]
            else:
                cracker_ip = self.random_ip_address()

            logging.debug("Adding report for {} from {}".format(cracker_ip, reporter))

            yield utils.wait_and_lock_host(cracker_ip)
            
            cracker = yield Cracker.find(where=['ip_address=?', cracker_ip], limit=1)
            if cracker is None:
                now = time.time()
                cracker = Cracker(ip_address=cracker_ip, first_time=now, latest_time=now, total_reports=0, current_reports=0)
                yield cracker.save()
            yield controllers.add_report_to_cracker(cracker, reporter)
            
            utils.unlock_host(cracker_ip)
            logging.debug("Done adding report for {} from {}".format(cracker_ip,reporter))
        total = yield Cracker.count()
        total_reports = yield Report.count()
        returnValue((total,total_reports))
    def xmlrpc_test_bulk_insert(self, count, same_crackers = False, when=None):
        if same_crackers and len(self._crackers) < count:
            logging.debug("Filling static crackers from {} to {}".format(len(self._crackers), count))
            for i in xrange(len(self._crackers), count):
                self._crackers.append(self.random_ip_address())

        if when is None:
            when = time.time()

        for i in xrange(count):
            reporter = self.random_ip_address()
            if same_crackers:
                cracker_ip = self._crackers[i]
            else:
                cracker_ip = self.random_ip_address()

            logging.debug("Adding report for {} from {} at {}".format(cracker_ip, reporter, when))

            yield utils.wait_and_lock_host(cracker_ip)
            
            cracker = yield Cracker.find(where=['ip_address=?', cracker_ip], limit=1)
            if cracker is None:
                cracker = Cracker(ip_address=cracker_ip, first_time=when, latest_time=when, total_reports=0, current_reports=0)
                yield cracker.save()
            yield controllers.add_report_to_cracker(cracker, reporter, when=when)
            
            utils.unlock_host(cracker_ip)
            logging.debug("Done adding report for {} from {}".format(cracker_ip,reporter))
        total = yield Cracker.count()
        total_reports = yield Report.count()
        returnValue((total,total_reports))
    def xmlrpc_add_hosts(self, request, hosts):
        try:
            x_real_ip = request.received_headers.get("X-Real-IP")
            remote_ip = x_real_ip or request.getClientIP()

            logging.info("add_hosts({}) from {}".format(hosts, remote_ip))
            for cracker_ip in hosts:
                if not self.is_valid_ip_address(cracker_ip):
                    logging.warning(
                        "Illegal host ip address {} from {}".format(
                            cracker_ip, remote_ip))
                    raise xmlrpc.Fault(
                        101, "Illegal IP address \"{}\".".format(cracker_ip))

                logging.debug("Adding report for {} from {}".format(
                    cracker_ip, remote_ip))
                yield utils.wait_and_lock_host(cracker_ip)
                try:
                    cracker = yield Cracker.find(
                        where=['ip_address=?', cracker_ip], limit=1)
                    if cracker is None:
                        now = time.time()
                        cracker = Cracker(ip_address=cracker_ip,
                                          first_time=now,
                                          latest_time=now,
                                          resiliency=0,
                                          total_reports=0,
                                          current_reports=0)
                        yield cracker.save()
                    yield controllers.add_report_to_cracker(cracker, remote_ip)
                finally:
                    utils.unlock_host(cracker_ip)
                logging.debug("Done adding report for {} from {}".format(
                    cracker_ip, remote_ip))
        except xmlrpc.Fault, e:
            raise e