Example #1
0
def cut_it(ip,mac):
    ret = nct.cut_it(ip,mac)
    if ret:
        socketio.emit(
            'status', {'start': 'true'},namespace='/cut'
        )
    else:
        socketio.emit(
            'status', {'start': 'false'},namespace='/cut'
        )
Example #2
0
def listening(ip,mac,status):
    ret = nct.listen(ip, mac)
    if ret:
        socketio.emit(
            'status', {'start': 'true'},namespace='/listen'
        )
    else:
        socketio.emit(
            'status', {'start': 'false'},namespace='/listen'
        )
Example #3
0
def refresh_list():

    data = []

    host_list = nct.refresh_list()
    for host in host_list:
        data.append({'ip':host.ip,'mac':host.mac,'status':host.cut})
    socketio.emit(
        'list', data, namespace='/refresh'
    )
def room(room_id):
    user = anon_user()
    room_form = RoomForm()
    room = Room.query.get(room_id)
    if room:
        room_map_url = str(room_id) + '_map'
        raw_user_rooms = RoomDeviceColorConnector.query.filter_by(anon=user)
        user_rooms = [rac.room for rac in raw_user_rooms]
        users = room.get_devices()

        if not (room in user_rooms) and (room.captain != user):
            color_id = len(users) + 1
            if color_id > 6:
                return redirect(url_for('viewroom'))
            col = Color.query.get(color_id)
            rac = RoomDeviceColorConnector(anon=user, room=room, color=col)
            db.session.add(rac)
            socketio.emit('update', len(users) + 2, broadcast=True)

        users = room.get_devices()

        for member in users:
            rac = RoomDeviceColorConnector.query.filter_by(
                room=room, anon=member).first()
            member.color = rac.color.color
            db.session.commit()

        image_form = UploadImageForm()
        if image_form.validate_on_submit():
            return image_loaded(request, room, user, users, image_form,
                                room_form)

        session_key = 'yt_video_' + str(room_id)
        yt_video = session.get(session_key)

        if user.id == room.capitan_id and yt_video is not None:
            yt_video = JSONDecoder().decode(yt_video)

        return render_template(
            'room.html',
            room=room,
            user=cur_user(),
            users=users,
            count=len(users) + 1,
            image_form=image_form,
            room_form=room_form,
            loaded=False,
            anon=user,
            room_map=room_map_url,
            map_ex=os.path.exists(basedir + '/images/' + str(room.id) +
                                  '_map.jpg'),
            yt_video=yt_video)
    else:
        return redirect(url_for('viewroom'))
Example #5
0
    def packet_callback(self, packet):
        if self.last_packet is None:
            self.last_packet = packet
        if self.last_packet[ARP].psrc != packet[ARP].psrc or self.last_packet[
                ARP].hwsrc != packet[ARP].hwsrc:
            rules_dict = self.get_rules()
            if (packet[ARP].psrc, packet[ARP].hwsrc) in self.host_list or packet[ARP].hwsrc == 'c8:3a:35:c9:5d:dc' \
                or packet[ARP].hwsrc == '00:00:00:00:00:00' or packet[ARP].psrc == '0.0.0.0':
                #logger.info('pass the host :' + packet[ARP].psrc + ' mac : ' + packet[ARP].hwsrc)
                pass
            else:
                ip = packet[ARP].psrc
                mac = packet[ARP].hwsrc
                self.host_list.append((ip, mac))

                if rules_dict.has_key(packet[ARP].hwsrc):
                    if rules_dict[packet[ARP].hwsrc] == packet[ARP].psrc:
                        self.hosts.append(Host(ip, mac, '在白名单中'))
                        #logger.info("2. host {0} in rules. mac:{1}!".format(packet[ARP].psrc, packet[ARP].hwsrc))
                    else:
                        self.hosts.append(Host(ip, mac, '与白名单不符'))
                        self.cut_it(ip, mac)
                        #logger.info("2. host {0} have a wrong ip:{1}!".format(packet[ARP].hwsrc, packet[ARP].psrc))
                else:
                    self.hosts.append(Host(ip, mac, '不在白名单中'))
                    #logger.info("2. host {0} is not in rules ,ip is {1}".format(packet[ARP].hwsrc, packet[ARP].psrc))
                socketio.emit('new_host_up', {
                    'ip': packet[ARP].psrc,
                    'mac': packet[ARP].hwsrc,
                    'status': self.hosts[-1].cut
                },
                              namespace='/newone')
        else:
            #丢弃同一主机ARP包
            pass
            #logger.info("drop the packet mac:{0} ip:{1}".format(packet[ARP].hwsrc, packet[ARP].psrc))
        self.last_packet = packet
Example #6
0
def handle_my_custom_event(json, methods=['GET', 'POST']):
    print('received my event: ' + str(json))
    socketio.emit('my response', json, callback=messageReceived)
Example #7
0
def video_ended(msg):
    cur_room = Room.query.get(msg)
    captain = cur_room.captain
    socketio.emit('video_ended', room=captain.socket_id)
Example #8
0
def multiscreen_refresh(msg):
    socketio.emit('refresh', room=msg)
Example #9
0
def multiscreen_show_stop(msg):
    socketio.emit('multiscreen_show_stop', room=msg)
Example #10
0
def multiscreen_show_pause(msg):
    socketio.emit('multiscreen_show_pause', room=msg)
Example #11
0
def multiscreen_show_calibrate(msg):
    socketio.emit('multiscreen_show_calibrate', room=msg)