def load(self): "return a dictionary of dictionaries with member info indexed by hashed rfid" try: f = open(self.filename) lines = f.read().splitlines() f.close() except: botlog.critical("authenticate can't read CSV %s" % self.filename) return {} cd = {} for l in lines[1:]: try: (member, value, key, allowed, tagid, lastAccessed) = [x[1] for x in self.csv_regexp.findall(l)] cd[tagid] = { 'member': member, 'allowed': allowed, 'tagid': tagid, 'warning': None, 'plan': None, 'nickname': None } except: botlog.error('authenticate CSV fail: %s %s' % (l, sys.exc_info())) botlog.info("authenticate read CSV %s %d entries" % (self.filename, len(cd))) return cd
def onConnect(self): botlog.info('New connection to SocketServer') try: self.client = self.server.nextPendingConnection() self.client.disconnected.connect(self.onDisconnect) except: botlog.error('exception creating client') self.connected = True self.sendReadStatus() self.sendCurrentSchedule()
def load(self): "return a dictionary of dictionaries with member info indexed by hashed rfid" cd = {} try: with open(self.filename) as json_file: json_data = json.load(json_file) for member in json_data: cd[member['tagid']] = member except: botlog.error('exception loading JSON ACL %s: %s' % (self.filename, sys.exc_info())) return cd
def load(self): "return a dictionary of dictionaries with member info indexed by hashed rfid" try: f = open(self.filename) lines = f.read().splitlines() f.close() except: botlog.critical( "authenticate can't read CSV %s" % self.filename) return {} cd = {} for l in lines[1:] : try : (member,value,key,allowed,tagid,lastAccessed) = [x[1] for x in self.csv_regexp.findall(l)] cd[tagid] = {'member': member, 'allowed': allowed, 'tagid':tagid, 'warning':None, 'plan':None, 'nickname':None} except: botlog.error( 'authenticate CSV fail: %s %s' % (l, sys.exc_info())) botlog.info( "authenticate read CSV %s %d entries" % (self.filename, len(cd))) return cd
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)