Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user verification mode #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions zk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,27 @@ def disconnect(self):
else:
raise ZKErrorResponse("can't disconnect")

def get_user_verif_mode(self, uid: int):
cmd_response = self.__send_command(const.CMD_VERIFY_RRQ, pack('<H', uid), 40)
if not cmd_response.get('status'):
raise ZKErrorResponse("can't get verif mode")
mode = self.__data[2]
if not mode & 128:
return None # means Group
return const.VERIF_MODES[mode & 127]

def set_user_verif_mode(self, uid: int, mode: str):
if not mode:
code = 0
elif not mode in const.VERIF_MODES:
raise ZKErrorResponse("unknown mode")
else:
code = const.VERIF_MODES.index(mode) | 128
cmd_response = self.__send_command(const.CMD_VERIFY_WRQ, pack('<HB21s', uid, code, b'\x00' * 21))
if not cmd_response.get('status'):
raise ZKErrorResponse("can't set verif mode")


def enable_device(self):
"""
re-enable the connected device and allow user activity in device again
Expand Down Expand Up @@ -900,9 +921,10 @@ def set_user(self, uid=None, name='', privilege=0, password='', group_id='', use
if not user_id:
user_id = str(uid) #ZK6 needs uid2 == uid
#TODO: check what happens if name is missing...
if privilege not in [const.USER_DEFAULT, const.USER_ADMIN]:
privilege = const.USER_DEFAULT
privilege = int(privilege)
privilege = privilege & 15
privilege |= privilege >> 1 & -2
privilege |= privilege >> 1 & -2
if self.user_packet_size == 28: #self.firmware == 6:
if not group_id:
group_id = 0
Expand Down
7 changes: 6 additions & 1 deletion zk/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
CMD_DOORSTATE_RRQ = 75 # Obtain the door condition
CMD_WRITE_MIFARE = 76 # Write the Mifare card
CMD_EMPTY_MIFARE = 78 # Clear the Mifare card
CMD_VERIFY_WRQ = 79 # Change verification style of a given user
CMD_VERIFY_RRQ = 80 # Read verification style of a given user
_CMD_GET_USERTEMP = 88 # (UNDOCUMENTED!) get an specific user template (uid, fid)
_CMD_SAVE_USERTEMPS = 110 # (UNDOCUMENTED!) save user and multiple templates!
_CMD_DEL_USER_TEMP = 134 # (UNDOCUMENTED!) delete an specific user template (uid, fid)
Expand Down Expand Up @@ -112,4 +114,7 @@
FCT_UDATA = 7

MACHINE_PREPARE_DATA_1 = 20560 # 0x5050
MACHINE_PREPARE_DATA_2 = 32130 # 0x7282
MACHINE_PREPARE_DATA_2 = 32130 # 0x7282


VERIF_MODES = ['FP+PW+RF', 'FP', 'PIN', 'PW', 'RF', 'FP+PW', 'FP+RF', 'PW+RF', 'PIN&FP', 'FP&PW', 'FP&RF', 'PW&RF', 'FP&PW&RF', 'PIN&FP&PW', 'FP&RF+PIN']