From 1d88a5cf142eb88d0e795de8a2f273a37ae22941 Mon Sep 17 00:00:00 2001 From: Shubhamoy Chakrabarty Date: Thu, 1 Mar 2018 10:03:43 +0530 Subject: [PATCH 1/8] Modify user fingerprint enrollment --- zk/base.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/zk/base.py b/zk/base.py index 82432cc..c5d642a 100644 --- a/zk/base.py +++ b/zk/base.py @@ -417,17 +417,21 @@ class ZK(object): cmd_response = self.__send_command(command=command) print cmd_response - def enroll_user(self, uid): + def enroll_user(self, uid=''): ''' start enroll user ''' command = const.CMD_STARTENROLL - uid = chr(uid % 256) + chr(uid >> 8) command_string = pack('2s', uid) - cmd_response = self.__send_command(command=command, command_string=command_string) + + checksum = 0 + session_id = self.__sesion_id + reply_id = self.__reply_id + response_size = 8 + cmd_response = self.__send_command(command, command_string, checksum, session_id, reply_id, response_size) print cmd_response - + def clear_data(self): ''' clear all data (include: user, attendance report, finger database ) From 67f1b724fa5daa8739e25685d6469269c9e1cdf6 Mon Sep 17 00:00:00 2001 From: Shubhamoy Chakrabarty Date: Thu, 1 Mar 2018 10:10:29 +0530 Subject: [PATCH 2/8] Simple Implementation for Remote Fingerprint Enrollment --- test_user_enrollment.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test_user_enrollment.py diff --git a/test_user_enrollment.py b/test_user_enrollment.py new file mode 100644 index 0000000..9fa8bf9 --- /dev/null +++ b/test_user_enrollment.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +import sys + +from zk import ZK, const + +sys.path.append("zk") + +conn = None +zk = ZK('192.168.2.2', port=4370, timeout=5) + +try: + conn = zk.connect() + conn.disable_device() + zk.set_user(26, 'Shubhamoy Chakrabarty', 0, '', '1', '26') + zk.enroll_user('26') + conn.enable_device() +except Exception, e: + print "Process terminate : {}".format(e) +finally: + if conn: + conn.disconnect() \ No newline at end of file From 500c8f5e9857a7fd89f17d808a5440eacd8da94b Mon Sep 17 00:00:00 2001 From: Shubhamoy Chakrabarty Date: Thu, 1 Mar 2018 10:12:54 +0530 Subject: [PATCH 3/8] Add default ip for zk devices --- test_user_enrollment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_user_enrollment.py b/test_user_enrollment.py index 9fa8bf9..42613e4 100644 --- a/test_user_enrollment.py +++ b/test_user_enrollment.py @@ -6,7 +6,7 @@ from zk import ZK, const sys.path.append("zk") conn = None -zk = ZK('192.168.2.2', port=4370, timeout=5) +zk = ZK('192.168.1.201', port=4370, timeout=5) try: conn = zk.connect() From 66d8ef5ff036e528b7cb10d5a7d20418bc297216 Mon Sep 17 00:00:00 2001 From: Shubhamoy Chakrabarty Date: Thu, 1 Mar 2018 15:26:09 +0530 Subject: [PATCH 4/8] Update README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index a2736c5..acdf53c 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,11 @@ users = conn.get_users() conn.delete_user(uid=1) ``` +* Remote Fingerprint Enrollment +``` +zk.enroll_user('23') +``` + * Attendance Record ``` # Get attendances (will return list of Attendance object) From 160bc57e23eb240257bb0897749ba24ad4d0cb27 Mon Sep 17 00:00:00 2001 From: "Fanani M. Ihsan" Date: Wed, 7 Mar 2018 16:26:03 +0700 Subject: [PATCH 5/8] upgrade to version 6.0 --- zk/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk/__init__.py b/zk/__init__.py index 94900e7..f091567 100644 --- a/zk/__init__.py +++ b/zk/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from base import ZK -VERSION = (0, 3) +VERSION = (0, 6) __all__ = ['ZK'] From f8664246615f0e577d553f8c7d7df5a4d462aff0 Mon Sep 17 00:00:00 2001 From: "Fanani M. Ihsan" Date: Wed, 7 Mar 2018 16:32:19 +0700 Subject: [PATCH 6/8] update pypi setup file --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ae455e6..aeb4112 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name='pyzk', - version='0.5', + version='0.6', description='an unofficial library of zksoftware fingerprint device', url='https://github.com/fananimi/pyzk', author='Fanani M. Ihsan', From 7dd807502a95825429b9ec0a464f77097a8691a0 Mon Sep 17 00:00:00 2001 From: alsum Date: Tue, 17 Jul 2018 11:05:41 +0200 Subject: [PATCH 7/8] adding set-time func --- zk/base.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/zk/base.py b/zk/base.py index c5d642a..aba3645 100644 --- a/zk/base.py +++ b/zk/base.py @@ -514,3 +514,17 @@ class ZK(object): return True else: raise ZKErrorResponse("Invalid response") + + def set_time(self, time): + """Set the time on the machine""" + command = const.CMD_SET_TIME + command_string = '' + response_size = 8 + chksum = 0 + session_id = self.__sesion_id + reply_id = self.__reply_id + cmd_response = self.__send_command(command,command_string, chksum, session_id, reply_id, response_size) + if cmd_response.get('status'): + return True + else: + raise ZKErrorResponse("Invalid response") \ No newline at end of file From 0cb0d6c03566f113de52a41388cbc5d97db8d901 Mon Sep 17 00:00:00 2001 From: alsum Date: Tue, 17 Jul 2018 11:28:01 +0200 Subject: [PATCH 8/8] handling unauthorized connnections --- zk/base.py | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/zk/base.py b/zk/base.py index aba3645..28e33fe 100644 --- a/zk/base.py +++ b/zk/base.py @@ -10,17 +10,17 @@ from zk.user import User class ZK(object): - is_connect = False __data_recv = None __sesion_id = 0 __reply_id = 0 - def __init__(self, ip, port=4370, timeout=60): + def __init__(self, ip, port=4370, timeout=60,password=0): self.__address = (ip, port) self.__sock = socket(AF_INET, SOCK_DGRAM) self.__sock.settimeout(timeout) + self.__password = password def __create_header(self, command, command_string, checksum, session_id, reply_id): ''' @@ -146,6 +146,11 @@ class ZK(object): response_size = 8 cmd_response = self.__send_command(command, command_string, checksum, session_id, reply_id, response_size) + self.__sesion_id = unpack('HHHH', self.__data_recv[:8])[2] + if cmd_response.get('code') == const.CMD_ACK_UNAUTH: + command_string = make_commkey(self.__password, self.__sesion_id) + cmd_response = self.__send_command(const.CMD_AUTH, command_string, checksum, self.__sesion_id, + self.__reply_id, response_size) if cmd_response.get('status'): self.is_connect = True # set the session id @@ -527,4 +532,40 @@ class ZK(object): if cmd_response.get('status'): return True else: - raise ZKErrorResponse("Invalid response") \ No newline at end of file + raise ZKErrorResponse("Invalid response") + + +def make_commkey(key, session_id, ticks=50): + """take a password and session_id and scramble them to send to the time + clock. + copied from commpro.c - MakeKey""" + key = int(key) + session_id = int(session_id) + k = 0 + for i in range(32): + if (key & (1 << i)): + k = (k << 1 | 1) + else: + k = k << 1 + k += session_id + + k = pack(b'I', k) + k = unpack(b'BBBB', k) + k = pack( + b'BBBB', + k[0] ^ ord('Z'), + k[1] ^ ord('K'), + k[2] ^ ord('S'), + k[3] ^ ord('O')) + k = unpack(b'HH', k) + k = pack(b'HH', k[1], k[0]) + + B = 0xff & ticks + k = unpack(b'BBBB', k) + k = pack( + b'BBBB', + k[0] ^ B, + k[1] ^ B, + B, + k[3] ^ B) + return k \ No newline at end of file