Example #1
0
def checkCards():
#	log.debug("Starting NFC read")
	nfcID = interfaceControl.nfcGetUID()
#	log.debug("Finished NFC read")
	#interfaceControl.setPowerStatus(False)

	if nfcID != None:
		log.info("Scanned card ID: %s" % nfcID)
		user = backend.getUserByKeyID(nfcID)	
		if user != None:
			if user['status'] == 'active':
				log.info("ACCEPTED card ID: %s" % nfcID)
				log.info("Access granted to '%s %s'" % (user['firstName'], user['lastName']))
				backend.log('unlock', nfcID, user['userID'])
				log.info("Door 1: UNLOCKED")
				interfaceControl.unlockDoor()
				proc = subprocess.Popen(['/home/pi/code/makeictelectronicdoor/vista/disarm.sh'], stdout=subprocess.PIPE)
				proc.communicate()
				log.info("Door 1: LOCKED")
			else:
				log.warning("DENIED card  ID: %s" % nfcID)
				log.warning("Reason: '%s %s' is not active" % (user['firstName'], user['lastName']))
				backend.log('deny', nfcID, user['userID'])
				interfaceControl.showBadCardRead()
		else:
			log.warning("DENIED card  ID: %s" % nfcID)
			log.warning("Reason: card not registered")
			backend.log('deny', nfcID)
			interfaceControl.showBadCardRead()
Example #2
0
def checkCards():
    #	log.debug("Starting NFC read")
    nfcID = interfaceControl.nfcGetUID()
    #	log.debug("Finished NFC read")
    #interfaceControl.setPowerStatus(False)

    if nfcID != None:
        log.info("Scanned card ID: %s" % nfcID)
        user = backend.getUserByKeyID(nfcID)
        if user != None:
            if user['status'] == 'active':
                log.info("ACCEPTED card ID: %s" % nfcID)
                log.info("Access granted to '%s %s'" %
                         (user['firstName'], user['lastName']))
                backend.log('unlock', nfcID, user['userID'])
                log.info("Door 1: UNLOCKED")
                interfaceControl.unlockDoor()
                proc = subprocess.Popen(
                    ['/home/pi/code/makeictelectronicdoor/vista/disarm.sh'],
                    stdout=subprocess.PIPE)
                proc.communicate()
                log.info("Door 1: LOCKED")
            else:
                log.warning("DENIED card  ID: %s" % nfcID)
                log.warning("Reason: '%s %s' is not active" %
                            (user['firstName'], user['lastName']))
                backend.log('deny', nfcID, user['userID'])
                interfaceControl.showBadCardRead()
        else:
            log.warning("DENIED card  ID: %s" % nfcID)
            log.warning("Reason: card not registered")
            backend.log('deny', nfcID)
            interfaceControl.showBadCardRead()
Example #3
0
def enroll(userID=None, nfcID=None, steal=False, quiet=False, reader=False):
	if os.geteuid() != 0:
		print "Root is required to run this script"
		return

	user = getUser(userID, confirm=(False if userID else True))
	if user == None:
		return
	userID = user['userID']
	
	if not reader:
		if not nfcID:
			putMessage(       "Enter key UID manually,")
			choice = getInput("or read key from NFC reader?", options=['m', 'r'])
			if choice == 'm':
				nfcID = getInput("Enter key UID")
	if not nfcID:
		try:
			restartDoorLock = True if killDoorLock() == 0 else False
			from rpi import interfaceControl
			while True:
				log.debug("Starting NFC read")
				if not quiet:
					putMessage("Swipe card now")
				retry = 0
				while retry < 30:
					interfaceControl.setPowerStatus(True)
					nfcID = interfaceControl.nfcGetUID()
					interfaceControl.setPowerStatus(False)
					if nfcID:
						break
					time.sleep(0.75)
					retry += 1
				log.debug("Finished NFC read")
				if not nfcID and not quiet:
					retry = getInput("Couldn't read card. Retry?", options=['y', 'n'])
					if nfcID != None or retry != 'y':
						break
				else:
					break
		
		except KeyboardInterrupt:
			log.info("Received KeyboardInterrupt")

		except:
			putMessage("Unexpected error: {:}".format(sys.exc_info()[0]),
				   level=severity.ERROR)
			log.error("Unexpected error: {:}".format(sys.exc_info()[0]))
			raise

		finally:
			interfaceControl.cleanup()
			if restartDoorLock:
				log.info("restarting door-lock.py")
				startDoorLock()
	if nfcID != None:
		# @TODO: catch duplicate key error, exit with error status
		try:
			backend.enroll(nfcID, userID, steal)
			putMessage("User [{:d}] enrolled with ID: {:s}".format(userID, nfcID),level=severity.OK)
		except IntegrityError:
			putMessage("Key is already assigned!",level=severity.WARNING)
			putMessage("User not enrolled",level=severity.ERROR)
	else:
		putMessage("Did not enroll user", level=severity.WARNING)
Example #4
0
def enroll(userID=None, nfcID=None, steal=False, quiet=False, reader=False):
    if os.geteuid() != 0:
        print "Root is required to run this script"
        return

    user = getUser(userID, confirm=(False if userID else True))
    if user == None:
        return
    userID = user['userID']

    if not reader:
        if not nfcID:
            putMessage("Enter key UID manually,")
            choice = getInput("or read key from NFC reader?",
                              options=['m', 'r'])
            if choice == 'm':
                nfcID = getInput("Enter key UID")
    if not nfcID:
        try:
            restartDoorLock = True if killDoorLock() == 0 else False
            from rpi import interfaceControl
            while True:
                log.debug("Starting NFC read")
                if not quiet:
                    putMessage("Swipe card now")
                retry = 0
                while retry < 30:
                    interfaceControl.setPowerStatus(True)
                    nfcID = interfaceControl.nfcGetUID()
                    interfaceControl.setPowerStatus(False)
                    if nfcID:
                        break
                    time.sleep(0.75)
                    retry += 1
                log.debug("Finished NFC read")
                if not nfcID and not quiet:
                    retry = getInput("Couldn't read card. Retry?",
                                     options=['y', 'n'])
                    if nfcID != None or retry != 'y':
                        break
                else:
                    break

        except KeyboardInterrupt:
            log.info("Received KeyboardInterrupt")

        except:
            putMessage("Unexpected error: {:}".format(sys.exc_info()[0]),
                       level=severity.ERROR)
            log.error("Unexpected error: {:}".format(sys.exc_info()[0]))
            raise

        finally:
            interfaceControl.cleanup()
            if restartDoorLock:
                log.info("restarting door-lock.py")
                startDoorLock()
    if nfcID != None:
        # @TODO: catch duplicate key error, exit with error status
        try:
            backend.enroll(nfcID, userID, steal)
            putMessage("User [{:d}] enrolled with ID: {:s}".format(
                userID, nfcID),
                       level=severity.OK)
        except IntegrityError:
            putMessage("Key is already assigned!", level=severity.WARNING)
            putMessage("User not enrolled", level=severity.ERROR)
    else:
        putMessage("Did not enroll user", level=severity.WARNING)