Beispiel #1
0
    def get_access(self, rfid):
        "given an integer rfid card number, return None or a tuple of (username,allowed)"

        self.reload()

        # hash the RFID key.  legacy stuff from original circa 2011 system.  becausejoe.
        m = hashlib.sha224()
        rfidStr = "%.10d" % (int(rfid))
        m.update(str(rfidStr).encode())
        rfid_hash = m.hexdigest()

        botlog.debug('rfid_hash: %s' % rfid_hash)

        if rfid_hash not in self.card_data:
            return None

        return self.card_data[rfid_hash]
Beispiel #2
0
    def get_access(self, rfid) :
        "given an integer rfid card number, return None or a tuple of (username,allowed)"

        self.reload()

        # hash the RFID key.  legacy stuff from original circa 2011 system.  becausejoe.        
        m = hashlib.sha224()
        rfidStr = "%.10d"%(int(rfid))
        m.update(str(rfidStr).encode())
        rfid_hash = m.hexdigest()
        
        botlog.debug( 'rfid_hash: %s' % rfid_hash)

        if rfid_hash not in self.card_data :
            return None

        return self.card_data[rfid_hash]
Beispiel #3
0
    def onData(self):
        rfid_str = self.reader.get_card()
        if not rfid_str:
            return
        
        botlog.debug( 'RFID string >>%s<<' % rfid_str)

        # Several things can happen:
        # 1. some error in reading.
        # 2. good card, not allowed
        # 3. good card, allowed:
        # 3a.  schedule permits access at this time, so open door
        # 3b.  schedule does not permit access at this time.
        # 4. bad card from some reason
        # 5. unknown card
        try :
            self.setStatus(Status.READING)
            rfid = int(rfid_str)
            
            access = self.authenticate.get_access(rfid)
                    
            if access:
                allowed = access['allowed']
                member = access['member']
                plan = access['plan']
                
                print(allowed)
                print(access)
                print(plan)
                
                if 'allowed' in allowed :
                    if qsetup.schedule.isAllowed(plan):
                        # 3a. open the door
                        #
                        botlog.info('%s allowed' % member)

                        self.setStatus(Status.ALLOWED)
                        self.setStatus(Status.LATCHED)
                    
                        self.hw.latch(open=True)
                        self.notifier.setEnabled(False)
                        self.latchTimer.start(4000)
                    else:
                        # 3b. denied due to local schedule
                        botlog.warning('%s DENIED due to schedule restriction' % member)

                        allowed = 'denied'

                        if member['warning'] is None or member['warning'] == '':
                            member['warning'] = qsetup.schedule.scheduleDesc()
                        else:
                            member['warning'] += '\n%s' % qsetup.schedule.scheduleDesc()
                            
                        self.setStatus(Status.DENIED)
                        self.notifier.setEnabled(False)
                        self.delayTimer.start(3000)
                else :
                    #2
                    # access failed.  blink the red
                    #
                    botlog.warning('%s DENIED' % member)
                    self.setStatus(Status.DENIED)
                    self.notifier.setEnabled(False)
                    self.delayTimer.start(3000)


            else :
                #5
                botlog.warning('Unknown card %s ' % rfid_str)
                self.setStatus(Status.UNKNOWN)
                self.signalAccess.emit('denied', {'member':'Unknown.RFID.Tag', 'plan':None, 'tagid':'', 'allowed':'denied', 'nickname':None, 'warning':'This RFID tag is not recognized.  Be sure you are using the correct tag and hold it steady over the read antenna.\n\nContact [email protected] if you continue to have problems.'})

                self.notifier.setEnabled(False)
                self.delayTimer.start(3000)

            self.signalAccess.emit(allowed, access)


        except :
            #4
            # bad input catcher, also includes bad cards
            #
            botlog.warning('bad card %s ' % rfid_str)
            # other exception?
            e = traceback.format_exc().splitlines()[-1]
            botlog.error('door loop unexpected exception: %s' % e)
            self.setStatus(Status.ERROR)
            self.notifier.setEnabled(False)
            self.delayTimer.start(3000)
Beispiel #4
0
 def setStatus(self, s):
     botlog.debug('status change from %s to %s' % (self.status, s))
     self.status = s
     self.signalStatusChange.emit(s)
     self.updateLEDs()