def test_data_record(parse_options): assert parse_options, "Invalid run settings" opts = parse_options ip_address = opts['ip-address'] # set the ip address of the device to test machine_port = 4370 z = pyzatt.ZKSS() misc.print_header("TEST OF DATA-RECORD FUNCTIONS") misc.print_header("1.Read attendance log test") misc.print_info("First, connect to the device and then disable the device") z.connect_net(ip_address, machine_port) z.disable_device() z.read_att_log() z.print_attlog() # print_info("Clear attendance log") # z.clear_att_log() # z.read_att_log() # z.print_attlog() misc.print_header("2.Read operation log test") z.read_op_log() z.print_oplog() # print_info("Clear operation log") # z.clear_log() # z.read_op_log() # z.print_oplog() # finally enable the device and terminate the connection z.enable_device() z.disconnect()
def test_enroll(parse_options): assert parse_options, "Invalid run settings" opts = parse_options ip_address = opts['ip-address'] # set the ip address of the device to test machine_port = 4370 z = pyzatt.ZKSS() z.connect_net(ip_address, machine_port) misc.print_header("1. Enrolling a users fingerprints") misc.print_info("Before enrolling users") z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() misc.print_info("Enrolling User 1") user1_id = "8888" user1_fp_idx = 4 enroll(z_inst=z, id=user1_id, fp_idx=user1_fp_idx, fp_flag=1) z.disable_device() with open('fp1.bin', 'wb') as outfile: outfile.write(z.download_fp(user1_id, user1_fp_idx)) z.enable_device() misc.print_info("Enrolling User 2") user2_id = "9999" user2_fp_idx = 3 enroll(id=user2_id, fp_idx=user2_fp_idx, fp_flag=1) z.disable_device() with open('fp2.bin', 'wb') as outfile: outfile.write(z.download_fp(user2_id, user2_fp_idx)) misc.print_info("After enrolling users") z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() z.enable_device() z.disconnect()
def enroll(z_inst, id, fp_idx, fp_flag): misc.print_info("Enrolling user:"******"User ID = ", id) print("Finger index = ", fp_idx) print("Fingerprint type = ", fp_flag) misc.print_info("Delete previous fingerprint") z_inst.delete_fp(id, fp_idx) misc.print_info("Ready to enroll!") if z_inst.enroll_user(id, fp_idx, fp_flag): print("Enrolling was successful") z_inst.read_all_user_id() z_inst.refresh_data() else: print("Something went wrong")
def test_data_user(parse_options): assert parse_options, "Invalid run settings" opts = parse_options ip_address = opts['ip-address'] # set the ip address of the device to test machine_port = 4370 misc.print_header("TEST OF DATA-USER FUNCTIONS") z = pyzatt.ZKSS() z.connect_net(ip_address, machine_port) z.disable_device() misc.print_header("1.Read all user info") # delete user if it exists user1_id = "5555" if z.id_exists(user1_id): z.delete_user(user1_id) z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() misc.print_header("2.Changing verification mode") # set user params z.set_user_info(user_id=user1_id, name="Dummy 1", password="******", card_no=333, admin_lv=0, neg_enabled=0, user_group=1, user_tzs=[1, 0, 0]) z.read_all_user_id() z.set_verify_style(user1_id, DEFS.GROUP_VERIFY) print("User: %s" % user1_id) print("Verify style: %i" % z.get_verify_style(user1_id)) z.set_verify_style(user1_id, DEFS.FPorRF) print("New verify style: %i" % z.get_verify_style(user1_id)) misc.print_header("3. Clear and set password") print("Users password: %s" % z.get_password(user1_id)) z.clear_password(user1_id) z.set_password(user1_id, "99") print("New password is: %s" % z.get_password(user1_id)) misc.print_header("4. Uploading/deleteting templates") fp1_tmp = bytearray() fp1_fn = 'fp1.bin' # filename template 1 fp1_idx = 8 # finger index template 1 fp1_flg = 1 # finger flag template 1 fp2_tmp = bytearray() fp2_fn = 'fp2.bin' # filename template 2 fp2_idx = 7 # finger index template 2 fp2_flg = 3 # finger flag template 2, duress # delete the templates if they already exists z.delete_fp(user1_id, fp1_idx) z.delete_fp(user1_id, fp2_idx) # read previously generated templates if os.path.isfile(fp1_fn) and os.path.isfile(fp2_fn): with open(fp1_fn, 'rb') as infile: fp1_tmp = infile.read() with open(fp2_fn, 'rb') as infile: fp2_tmp = infile.read() misc.print_info("Uploading templates") print("Upload template 1, user= %s, finger=%i, flag=%i" % (user1_id, fp1_idx, fp1_flg)) z.upload_fp(user1_id, fp1_tmp, fp1_idx, fp1_flg) print("Upload template 2, user= %s, finger=%i, flag=%i" % (user1_id, fp2_idx, fp2_flg)) z.upload_fp(user1_id, fp2_tmp, fp2_idx, fp2_flg) misc.print_info("Now the templates should be available") z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() else: print("Run the script test_data_other.py before this script!") z.enable_device() z.disconnect() return ans = input("Delete user %s, y/n: " % user1_id) if ans == 'y': z.delete_user(user1_id) else: misc.print_info("Now you may go and test both finger templates") misc.print_header("") z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() z.enable_device() z.disconnect()
def test_multiple_realtime(): # constant machine port machine_port = 4370 # define a list of ip addresses instead ip_addresses = ['192.168.19.152', '192.168.19.153', '192.168.19.154'] # a list of ZKSS objects is needed to keep each # connection alive and separate zkss = [pyzatt.ZKSS() for x in range(len(ip_addresses))] # a dict is created zk_dev = zip(ip_addresses, zkss) misc.print_header("TEST OF REALTIME FUNCTIONS FROM MULTIPLE DEVICES") print(zkss) # connect and enable realtime for each device for [ip_addr, z] in zk_dev: print(ip_addr, z) continue # connection z.connect_net(ip_addr, machine_port) # read user ids z.disable_device() z.read_all_user_id() z.enable_device() # enable the report of rt packets z.enable_realtime() misc.print_info("Ready to receive events from the machines") try: while True: for [ip_addr, z] in zk_dev: # wait for event z.recv_event() ev = z.get_last_event() # process the event print("\n" + "#" * 50) print("Received event from:", ip_addr) if ev == DEFS.EF_ALARM: print("EF_ALARM:") alarm_code = z.parse_alarm_type() # check alarm source if alarm_code == 0x3A: # misoperation print("Misoperation alarm!") elif alarm_code == 0x37: # tamper print("Tampering alarm!") elif alarm_code == 0x35: # exit button print("Exit button pressed!") elif alarm_code == 0x54: # door is closing print("Door is closing") elif alarm_code == 0xffffffff: # duress alarm durr_type = z.parse_duress_alarm()[0] if durr_type == 0x20: print("Duress alarm!") print("User index: %s, matching type: %i" % tuple(z.parse_duress_alarm()[1:])) elif durr_type == 0x22: print("Passback alarm!") else: print("Unknown duress alarm") else: print("Unknown alarm") elif ev == DEFS.EF_ATTLOG: print("EF_ATTLOG: New attendance entry") print("User id: %s, verify type %i, date: %s" % tuple(z.parse_event_attlog())) elif ev == DEFS.EF_FINGER: print("EF_FINGER: Finger placed on reader") elif ev == DEFS.EF_ENROLLUSER: print("EF_ENROLLUSER: Enrolled user") elif ev == DEFS.EF_ENROLLFINGER: print("EF_ENROLLFINGER: Enroll finger finished") print("Successful: %s, user ID: %s, finger index: %s, " "size fp template: %i" % tuple(z.parse_event_enroll_fp())) elif ev == DEFS.EF_BUTTON: print("EF_BUTTON: Pressed button") elif ev == DEFS.EF_UNLOCK: print("EF_UNLOCK: Unlock event") elif ev == DEFS.EF_VERIFY: print("EF_VERIFY: Verified user") user_sn = z.parse_verify_event() if user_sn == 0xffffffff: user_id = '-1' else: user_id = z.users[user_sn].user_id print("User id: %s" % user_id) elif ev == DEFS.EF_FPFTR: print("EF_FPFTR: ") print("Score: %i" % z.parse_score_fp_event()) else: print("Unknown event:") misc.print_hex(z.get_last_packet()) except KeyboardInterrupt: misc.print_info("\nExiting...") for [ip_addr, z] in zk_dev: z.disconnect()
def test_realtime(parse_options): assert parse_options, "Invalid run settings" opts = parse_options ip_address = opts['ip-address'] # set the ip address of the device to test machine_port = 4370 z = pyzatt.ZKSS() misc.print_header("TEST OF REALTIME FUNCTIONS") # connection misc.print_header("1.Realtime Test") z.connect_net(ip_address, machine_port) # read user ids z.disable_device() z.read_all_user_id() z.enable_device() # enable the report of rt packets z.enable_realtime() misc.print_info("Ready to receive events from the machine") try: while True: # wait for event z.recv_event() ev = z.get_last_event() # process the event print("\n" + "#" * 50) print("Received event") if ev == DEFS.EF_ALARM: print("EF_ALARM:") alarm_code = z.parse_alarm_type() # check alarm source if alarm_code == 0x3A: # misoperation print("Misoperation alarm!") elif alarm_code == 0x37: # tamper print("Tampering alarm!") elif alarm_code == 0x35: # exit button print("Exit button pressed!") elif alarm_code == 0x54: # door is closing print("Door is closing") elif alarm_code == 0xffffffff: # duress alarm durr_type = z.parse_duress_alarm()[0] if durr_type == 0x20: print("Duress alarm!") print("User index: %s, matching type: %i" % tuple(z.parse_duress_alarm()[1:])) elif durr_type == 0x22: print("Passback alarm!") else: print("Unknown duress alarm") else: print("Unknown alarm") elif ev == DEFS.EF_ATTLOG: print("EF_ATTLOG: New attendance entry") print("User id: %s, verify type %i, date: %s" % tuple(z.parse_event_attlog())) elif ev == DEFS.EF_FINGER: print("EF_FINGER: Finger placed on reader") elif ev == DEFS.EF_ENROLLUSER: print("EF_ENROLLUSER: Enrolled user") elif ev == DEFS.EF_ENROLLFINGER: print("EF_ENROLLFINGER: Enroll finger finished") print("Successful: %s, user ID: %s, finger index: %s, " "size fp template: %i" % tuple(z.parse_event_enroll_fp())) elif ev == DEFS.EF_BUTTON: print("EF_BUTTON: Pressed button") elif ev == DEFS.EF_UNLOCK: print("EF_UNLOCK: Unlock event") elif ev == DEFS.EF_VERIFY: print("EF_VERIFY: Verified user") user_sn = z.parse_verify_event() if user_sn == 0xffffffff: user_id = '-1' else: user_id = z.users[user_sn].user_id print("User id: %s" % user_id) elif ev == DEFS.EF_FPFTR: print("EF_FPFTR: ") print("Score: %i" % z.parse_score_fp_event()) else: print("Unknown event:") misc.print_hex(z.get_last_packet()) except KeyboardInterrupt: misc.print_info("\nExiting...") z.disconnect()
def test_access(parse_options): assert parse_options, "Invalid run settings" opts = parse_options ip_address = opts['ip-address'] # set the ip address of the device to test machine_port = 4370 misc.print_header("TEST OF ACCESS FUNCTIONS") z = pyzatt.ZKSS() z.connect_net(ip_address, machine_port) z.disable_device() misc.print_header("1.Read all user info") # delete test uses if they exists user1_id = "5555" user2_id = "6666" if z.id_exists(user1_id): z.delete_user(user1_id) z.delete_user(user2_id) z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() misc.print_header("2.Create users and upload fingerprints") z.set_user_info(user_id=user1_id, name="Dummy 1", password="******", card_no=333, admin_lv=0, neg_enabled=0, user_group=1, user_tzs=[1, 0, 0]) z.set_user_info(user_id=user2_id, name="Dummy 2", password="******", card_no=777, admin_lv=0, neg_enabled=0, user_group=1, user_tzs=[1, 0, 0]) z.read_all_user_id() z.set_verify_style(user1_id, DEFS.GROUP_VERIFY) z.set_verify_style(user2_id, DEFS.GROUP_VERIFY) fp1_tmp = bytearray() fp1_fn = 'fp1.bin' # filename template 1 fp1_idx = 8 # finger index template 1 fp1_flg = 1 # finger flag template 1 fp2_tmp = bytearray() fp2_fn = 'fp2.bin' # filename template 2 fp2_idx = 7 # finger index template 2 fp2_flg = 1 # finger flag template 2, duress # read previously generated templates if os.path.isfile(fp1_fn) and os.path.isfile(fp2_fn): with open(fp1_fn, 'rb') as infile: fp1_tmp = infile.read() with open(fp2_fn, 'rb') as infile: fp2_tmp = infile.read() misc.print_info("Uploading templates") print("Upload template 1, user= %s, finger=%i, flag=%i" % (user1_id, fp1_idx, fp1_flg)) z.upload_fp(user1_id, fp1_tmp, fp1_idx, fp1_flg) print("Upload template 2, user= %s, finger=%i, flag=%i" % (user1_id, fp2_idx, fp2_flg)) z.upload_fp(user2_id, fp2_tmp, fp2_idx, fp2_flg) misc.print_info("Now the templates should be available") z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() else: print("Run the script test_data_other.py before this script!") z.enable_device() z.disconnect() misc.print_header("3. Set/get timezones") print("Timezone 1:", z.get_tz_info(1)) z.set_tz_info(49, z.get_tz_info(1)) tz49 = z.get_tz_info(49) print("Timezone 49:", tz49) sat_tz = [5, 33, 23, 20] print("Changing Sat tz:", sat_tz) tz49[6] = sat_tz z.set_tz_info(49, tz49) # uploading update timezone print("New timezone 49:", z.get_tz_info(49)) misc.print_header("4. Creating groups") z.set_group_info([35, [1, 49], 0, 1]) z.set_group_info([36, [1, 49], 0, 1]) print("Group 35: %s" % z.get_group_info(35)) print("Group 36: %s" % z.get_group_info(36)) print("Adding user %s to group 35" % user1_id) print("Adding user %s to group 36" % user2_id) z.set_user_group(user1_id, 35) z.set_user_group(user2_id, 36) print("New group of user %s: %i" % (user1_id, z.get_user_group(user1_id))) print("New group of user %s: %i" % (user2_id, z.get_user_group(user2_id))) z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() misc.print_header("5. Users timezones") for n in range(3): tz_no = 40 + n print("Creating timezone: ", tz_no) z.set_tz_info(tz_no, z.get_tz_info(1)) print("Setting user %s timezones" % user1_id) user1_tzs = [40, 41, 42] z.set_user_tzs(user1_id, user1_tzs) print("User %s should be using timezones: %s" % (user1_id, user1_tzs)) print("Making user %s, use group's timezones" % user2_id) z.disable_user_tzs(user2_id) z.read_all_user_id() z.print_users_summary() misc.print_header("6. Unlock combinations") misc.print_info("Creating unlock combination") z.set_unlock_comb(9, [35, 36]) print("Created unlock combination %i, with groups: %s" % (9, z.get_unlock_comb(9))) misc.print_header("7. Unlock door") print("Door unlock: 20 seconds") time.sleep(10) z.door_unlock(20) misc.print_header("") misc.print_info("Now to test this configuration, press [n], go to the" "device and you should need both fingers (corresponding " "to the templates) to get access, because both belong to " "different users and from different groups, and they are " "in an unlock combination.") ans = input("Delete users %s, y/n: " % user1_id) if ans == 'y': z.delete_user(user1_id) z.delete_user(user2_id) else: misc.print_info("Now you may go and test access with " "both finger templates") misc.print_header("") z.read_all_user_id() z.read_all_fptmp() z.print_users_summary() z.enable_device() z.disconnect()
def test_terminal(parse_options): assert parse_options, "Invalid run settings" opts = parse_options ip_address = opts['ip-address'] # set the ip address of the device to test machine_port = 4370 z = pyzatt.ZKSS() misc.print_header("TEST OF TERMINAL FUNCTIONS") # connection misc.print_header("1.Connection Test") misc.print_info("First, connect to the device and then disable the device") z.connect_net(ip_address, machine_port) z.disable_device() # get/set time misc.print_header("2.Set/Get time test") misc.print_info("The time is ") misc.print_info("Get current time") print(z.get_device_time()) misc.print_info("Set a new time") z.set_device_time(datetime.datetime(2018, 1, 1, 18, 17, 16)) print(z.get_device_time()) misc.print_info("Set the time to now") z.set_device_time(datetime.datetime.now()) print(z.get_device_time()) # get status misc.print_header("3.Get status test") misc.print_info("You may request all the values") stat_keys = defs.get_status_keys() res = z.get_device_status(dict(zip(stat_keys, [-1]*len(stat_keys)))) for k in res: print("{0} = {1}".format(k, res[k])) misc.print_info("Or maybe just request a couple," " but in both cases the machine" " reply has all the fields") res = z.get_device_status({'attlog_count': -1, 'user_count': -1, 'admin_count': -1}) for k in res: print("{0} = {1}".format(k, res[k])) misc.print_info("So you may read the fields of a" " previously requested status," " using the read_status function") res = z.read_status(defs.STATUS['pwd_count']) print("{0} = {1}".format('pwd_count', res)) # get more params misc.print_header("4.Device info test") misc.print_info("Some parameter requests:") print('Vendor = ' + z.get_vendor()) print('Product code = |{0}|'.format(z.get_product_code())) print('Product time = |{0}|'.format(z.get_product_time())) print('card function = |{0}|'.format(z.get_cardfun())) print('User max id width = |{0}|'.format(z.get_device_info('~PIN2Width'))) print('Firmware version = |{0}|'.format(z.get_firmware_version())) misc.print_info("Some write operations:") misc.print_info("Changing lock timer:") print('Original value = |{0}|'.format(z.get_device_info('LockOn'))) z.set_device_info('LockOn', '8') print('New value = |{0}|'.format(z.get_device_info('LockOn'))) z.set_device_info('LockOn', '5') print('Back to default value = |{0}|'.format(z.get_device_info('LockOn'))) # get state misc.print_header("5.Get device state") print('Device state = |{0}|'.format(z.get_device_state())) # finally enable the device and terminate the connection z.enable_device() z.disconnect()